#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 520;   long long A[N];   long long dp[N];   long long maxl[N];   long long n, m;   long long get(long long x, long long y) {     if (x == 0) return N - 1;     return (x - 1) * m + y;   }   int main() {     cin >> n >> m;     A[N - 1] = 0;     for (long long i = 1; i <= n * m; i++) cin >> A[i];     for (long long i = 1; i <= m; i++)       for (long long j = 1; j <= n; j++) {         if (j == 1) {           long long a = get(j, i);           dp[a] = 1;           maxl[j] = max(maxl[j], 1ll);           continue;         }         long long a = get(j, i);         long long b = get(j - 1, i);         long long xia = A[a];         long long shang = A[b];         if (xia >= shang) {           dp[a] = dp[b] + 1;           maxl[j] = max(maxl[j], dp[a]);         } else {           dp[a] = 1;           maxl[j] = max(maxl[j], dp[a]);         }       }     long long t;     cin >> t;     while (t--) {       long long l, r;       cin >> l >> r;       if (r - maxl[r] + 1 <= l) {         cout <<  Yes  << endl;         continue;       }       cout <<  No  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   ifstream F( p.in );   const int M = 1000000007;   const int K = 110;   const int N = 100100;   int dp[K][N], b[N], c[N][K];   int n, m;   void add(int &x, int y) { x = ((x + y) % M + M) % M; }   int main() {     ios::sync_with_stdio(0);     for (int n = 0; n < N; ++n) {       c[n][0] = 1;       for (int k = 1; k <= min(n, K - 1); ++k)         c[n][k] = (c[n - 1][k - 1] + c[n - 1][k]) % M;     }     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> b[i];     for (int tt = 1, l, r, k; tt <= m; ++tt) {       cin >> l >> r >> k;       add(dp[k][l], 1);       for (int i = 0; i <= k; ++i)         add(dp[i][r + i + 1], -c[r - l + k + 1][k - i]);     }     for (int k = 100; k >= 0; --k)       for (int i = 1; i <= n; ++i) {         if (k > 0) add(dp[k - 1][i], dp[k][i]);         add(dp[k][i + 1], dp[k][i]);       }     for (int i = 1; i <= n; ++i) cout << (dp[0][i] + b[i]) % M <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[100100], b[100100];   long long ans;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < m; i++) scanf( %d , &b[i]);     sort(a, a + n);     sort(b, b + m, greater<int>());     n = min(n, m);     for (int i = 0; i < n and a[i] < b[i]; i++) {       ans += b[i] - a[i];     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   long long c2(long long n) { return n * (n - 1) / 2; }   void solve(long long x, long long y) {     if (x == 0) return;     if (y + 1 >= x) {       cout <<  ( ;       solve(x - 1, y - x + 1);       cout <<  ) ;       return;     } else {       cout <<  () ;       solve(x - 1, y);     }   }   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin >> n >> k;     if (c2(n) < k) {       cout <<  Impossible ;       return 0;     }     solve(n, k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 150100;   long long n, m, l, r;   long long P;   vector<int> p;   long long sum;   long long _dfs(long long d, long long x, long long y) {     if (d == p.size()) {       long long n = abs(y / x);       sum += n * (n + 1) / 2 * x;       return y / x;     }     return (_dfs(d + 1, x, y) + _dfs(d + 1, -x * p[d], y));   }   int gcdnumber(long long a, long long y) {     p.clear();     for (long long i = 2; i * i <= a; i++) {       if (a % i == 0) {         p.push_back(i);         while (a % i == 0) a /= i;       }     }     sum = 0;     if (a != 1) p.push_back(a);     return _dfs(0, 1, y);   }   long long calc(long long radiu, int add) {     long long y = radiu;     long long ret = 0;     for (long long i = 1; i <= radiu; i++) {       while (y && i * i + y * y > radiu * radiu - add) y--;       if (y >= m) y = m;       if (i <= n && y > 0) {         long long tmp = gcdnumber(i, y);         ret += (n - i + 1) * (tmp * (m + 1) - sum);         ret %= P;       }     }     return ret;   }   int main() {     cin >> n >> m;     cin >> l >> r >> P;     long long ans = 0;     if (l == 1) ans = n * (m + 1) + m * (n + 1);     ans %= P;     ans += (calc(r, 0) - calc(l, 1)) * 2;     while (ans < 0) ans += P;     ans %= P;     cout << ans << endl;   }


#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef long double lf;   typedef unsigned long long ull;   typedef pair<ll,int>P;   const int inf = 0x7f7f7f7f;   const ll INF = 1e16;   const int N = 2e5+10;   const ull base = 131;   const ll mod =  1e9+7;   const double PI = acos(-1.0);   const double eps = 1e-4;      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;}   inline string readstring(){string str;char s=getchar();while(s==   ||s==  n ||s==  r ){s=getchar();}while(s!=   &&s!=  n &&s!=  r ){str+=s;s=getchar();}return str;}   int random(int n){return (int)(rand()*rand())%n;}   void writestring(string s){int n = s.size();for(int i = 0;i < n;i++){printf( %c ,s[i]);}}         int a[N];   int b[N],c[N];      void solve(){       int n = read();       memset(b,0,sizeof b);       memset(c,0,sizeof c);       set<int>st1,st2;       for(int i = 1;i <= n;i++){           st1.insert(i);           st2.insert(i);       }       for(int i = 1;i <= n;i++){           a[i] = read();       }       b[1] = c[1] = a[1];       st1.erase(a[1]);       st2.erase(a[1]);       for(int i = 2;i <= n;i++){           if(a[i] != a[i-1]){               b[i] = c[i] = a[i];               st1.erase(a[i]);               st2.erase(a[i]);           }       }             for(int i = 1;i <= n;i++){           if(b[i] == 0){               int x = *st1.begin();               b[i] = x;               //cout<<x<<endl;               st1.erase(x);           }              if(c[i] == 0){               auto it = st2.upper_bound(c[i-1]);               it--;               c[i] = *it;               st2.erase(c[i]);           }          }             for(int i = 1;i <= n;i++){           printf( %d  ,b[i]);       }       puts(  );       for(int i = 1;i <= n;i++){           printf( %d  ,c[i]);       }       puts(  );      }   int main(){       int t = read();       while(t--){           solve();       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mm;   int mv[100000] = {0};   int bfs(int n, int m) {     queue<int> mq;     mq.push(n);     mv[n] = 0;     while (!mq.empty()) {       int r = mq.front();       if (r == m) return mv[r];       mq.pop();       int x, y;       x = r - 1;       y = r * 2;       if (x > 0 && x < 10001 && mv[x] == 0) {         mv[x] = mv[r] + 1;         mq.push(x);       }       if (y > 0 && y < 10001 && mv[y] == 0) {         mv[y] = mv[r] + 1;         mq.push(y);       }     }   }   int main() {     int n, m;     cin >> n >> m;     int k = bfs(n, m);     cout << k << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pll = pair<ll, ll>;   using dd = long double;   namespace {   static bool constexpr dbg = 0;   ll constexpr N = -999;   ll n, k;   bool ok(string const &s1, string const &s2) {     do {       if (dbg) {         bool b = (s1.size() == s2.size() + 1);         if (!b)           cerr <<  s1.size() == s2.size() + 1                 <<  : failed! n ;       }     } while (0);     if (s1.size() != s2.size()) return s1.size() > s2.size();     for (int i = 0; i < n; ++i)       if (s1[i] != s2[i]) return s1[i] > s2[i];     return true;   }   string solve() {     string s;     cin >> n >> k >> s;     cout << n <<   n ;     auto sub = s.substr(0, k);     while (sub.size() < n) sub.push_back(sub[sub.size() - k]);     if (ok(sub, s)) return sub;     int i = k - 1;     for (; i >= 0; --i)       if (s[i] !=  9 ) break;     ++s[i];     for (++i; i < k; ++i) s[i] =  0 ;     for (int j = k; j < n; ++j) s[j] = s[j - k];     return s;   }   }  // namespace   int main() {     if (!dbg) {       std::ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);     }     cout << fixed << setprecision(20);     cout << solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, x, sum;   vector<long long> my, temp;   int main() {     ios::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> x;       my.push_back(x);       temp.push_back(x);     }     for (long long i = 0; i < n; i++) my.push_back(temp[i]);     long long maxi = 0;     for (long long i = 0; i < my.size(); i++) {       if (my[i] == 1) {         sum++;         maxi = max(maxi, sum);       } else         sum = 0;     }     cout << maxi << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n <= 4)       cout <<  No solution  << endl;     else {       double alpha = 2 * M_PI / n;       cout << fixed << setprecision(6);       double x = 0, y = 0;       for (int i = 1; i <= n - 2; i++) {         cout << x <<     << y << endl;         double l = 500;         l += 0.01 * i;         x += l * cos(alpha * i), y += l * sin(alpha * i);       }       cout << x <<     << y << endl;       x -= y / sin(alpha * (n - 1)) * cos(alpha * (n - 1)), y = 0;       cout << x <<     << y << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> ans;     if (k == 1) {       printf( %d n , n);       return 0;     }     for (int i = 2; i * i <= n; i++) {       while (n % i == 0) {         n /= i;         ans.push_back(i);         if (((int)ans.size()) == k - 1) break;       }       if (((int)ans.size()) == k - 1) break;     }     if (n == 1 || ((int)ans.size()) != k - 1) {       puts( -1 );       return 0;     }     ans.push_back(n);     for (int x : ans) printf( %d  , x);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Debug(vector<int> v) {     for (int i : v) {       cerr << i <<    ;     }   }   void Debug(int a[]) {     for (int i = 0; i < 5; i++) {       cerr << a[i] <<    ;     }   }   void Debug(int a) { cerr << a; }   void Debug(string a) { cerr << a; }   void Debug(long long a) { cerr << a; }   void Debug(unsigned long long a) { cerr << a; }   void Debug(float a) { cerr << a; }   void Debug(double a) { cerr << a; }   void Debug(char a) { cerr << a; }   int32_t main() {     int64_t l;     cin >> l;     int64_t a, b;     cin >> a >> b;     int64_t speed = a + b;     double time = (double)l / speed;     cout << time * a;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   long long MAX = 1e17;   bool b[1000];   int main() {     ios_base::sync_with_stdio(0);     ;     int m, t, r, ans = 0;     cin >> m >> t >> r;     int w[m];     for (int i = 0; i < m; i++) cin >> w[i];     if (r > t) {       cout << -1 << endl;       return 0;     }     for (int i = 0; i < m; i++) w[i] += t + 10;     for (int i = 0; i < m; i++) {       int k = r;       for (int j = w[i] - t; j < w[i]; j++)         if (b[j]) k--;       if (k <= 0) continue;       for (int j = w[i] - 1; j > w[i] - t - 1; j--) {         if (!b[j]) {           b[j] = 1;           k--;           ans++;         }         if (k == 0) break;         if (j == w[i] - t) {           cout << -1 << endl;           return 0;         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1;   vector<int> e[N];   int s[N], seg[N << 2], num[N << 2], chg[N << 2], dfn[N][2], dfsns[N],       sgn[N] = {-1}, stamp;   void dfs(int now, int pre) {     dfn[now][0] = ++stamp;     dfsns[stamp] = now;     sgn[dfn[now][0]] = sgn[dfn[pre][0]] == 1 ? -1 : 1;     for (int i = 0; i < e[now].size(); i++)       if (e[now][i] != pre) dfs(e[now][i], now);     dfn[now][1] = stamp;   }   void pushup(int rt) { seg[rt] = seg[rt << 1] + seg[rt << 1 | 1]; }   void pushdown(int rt, int l, int r) {     if (chg[rt]) {       seg[rt << 1] += num[rt << 1] * chg[rt];       seg[rt << 1 | 1] += num[rt << 1 | 1] * chg[rt];       chg[rt << 1] += chg[rt];       chg[rt << 1 | 1] += chg[rt];       chg[rt] = 0;     }   }   void build(int l, int r, int rt) {     if (l == r) {       seg[rt] = s[dfsns[l]];       num[rt] = sgn[l];       return;     }     int m = l + r >> 1;     build(l, m, rt << 1);     build(m + 1, r, rt << 1 | 1);     num[rt] = num[rt << 1] + num[rt << 1 | 1];     pushup(rt);   }   void update(int l, int r, int rt, int L, int R, int v) {     if (L <= l && r <= R) {       seg[rt] += num[rt] * v;       chg[rt] += v;       return;     }     int m = l + r >> 1;     pushdown(rt, l, r);     if (L <= m) update(l, m, rt << 1, L, R, v);     if (m < R) update(m + 1, r, rt << 1 | 1, L, R, v);     pushup(rt);   }   int query(int l, int r, int rt, int p) {     if (l == r) return seg[rt];     int m = l + r >> 1;     pushdown(rt, l, r);     if (p <= m)       return query(l, m, rt << 1, p);     else       return query(m + 1, r, rt << 1 | 1, p);   }   int main() {     ios::sync_with_stdio(0);     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> s[i];     for (int i = 1; i < n; i++) {       int tmp1, tmp2;       cin >> tmp1 >> tmp2;       e[tmp1].push_back(tmp2);       e[tmp2].push_back(tmp1);     }     dfs(1, 0);     build(1, n, 1);     for (int i = 0; i < k; i++) {       int op, tmp1, tmp2;       cin >> op;       if (op == 1) {         cin >> tmp1 >> tmp2;         update(1, n, 1, dfn[tmp1][0], dfn[tmp1][1], sgn[dfn[tmp1][0]] * tmp2);       } else {         cin >> tmp1;         cout << query(1, n, 1, dfn[tmp1][0]) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, i, j, k, sum = 0;     scanf( %d%d%d , &n, &a, &b);     int arr[n];     for (i = 0; i < n; i++) scanf( %d , &arr[i]);     for (i = 0, j = n - 1; i <= j; i++, j--) {       if (i != j && arr[i] != arr[j] && arr[i] != 2 && arr[j] != 2) {         printf( -1 n );         return 0;       } else if (arr[i] == 2 && arr[j] == 2) {         if (i != j)           sum += (2 * min(a, b));         else           sum += min(a, b);       } else if (arr[i] == 2 || arr[j] == 2) {         if (arr[i] == 2 && arr[j] == 1)           sum += b;         else if (arr[i] == 2 && arr[j] == 0)           sum += a;         else if (arr[j] == 2 && arr[i] == 1)           sum += b;         else if (arr[j] == 2 && arr[i] == 0)           sum += a;       }     }     printf( %d n , sum);     return 0;   }


#include <bits/stdc++.h>   const long double eps = 0.00000001;   const long long MOD = 1e9 + 7;   const double PI = 3.141592653589793238463;   using namespace std;   long long ans;   int was[1010][1010];   int main() {     fflush(stdin);     cout << fixed, cout.precision(18);     ios_base::sync_with_stdio(false);     int i, j, n, m;     cin >> n >> m;     string second[n];     for (i = 0; i < n; ++i) cin >> second[i];     vector<pair<pair<int, int>, int>> ve;     for (i = 1; i < n - 1; ++i) {       for (j = 1; j < m - 1; ++j) {         if (second[i][j] ==  . ) continue;         int max_len = min(min(i, n - i - 1), min(j, m - j - 1));         if (max_len == 0) continue;         int x = i, y = j;         for (int len = 1; len <= max_len; ++len) {           if (second[i + len][j] ==  *  && second[i - len][j] ==  *  &&               second[i][j - len] ==  *  && second[i][j + len] ==  * ) {             was[i][j] = 1;             was[i + len][j] = was[i - len][j] = was[i][j - len] =                 was[i][j + len] = 1;             if (len == max_len) ve.push_back({{i + 1, j + 1}, len});             continue;           }           if (len - 1 > 0) ve.push_back({{i + 1, j + 1}, len - 1});           break;         }       }     }     bool b = true;     for (i = 0; i < n; ++i)       for (j = 0; j < m; ++j)         if (second[i][j] ==  *  && !was[i][j]) b = false;     if (!b) return cout << -1, 0;     cout << ve.size() << endl;     for (i = 0; i < ve.size(); ++i) {       printf( %d %d %d n , ve[i].first.first, ve[i].first.second, ve[i].second);     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   int n, k, a[maxn], b[maxn];   void work(long long g);   long long as, ct;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= n; i++) scanf( %d , b + i);     long long l = 0, r = 1e12, mid, ot;     while (l < r) {       work(mid = l + r >> 1);       if (ct >= k)         r = mid, ot = mid;       else         l = mid + 1;     }     work(ot), printf( %lld n , as + 2 * k * ot);     return 0;   }   void work(long long g) {     priority_queue<pair<long long, int> > q;     as = ct = 0;     long long tp;     for (int i = 1; i <= n; i++) {       q.push({g - a[i], 1});       if ((tp = b[i] - q.top().first - g) <= 0) {         as += tp, ct += q.top().second, q.pop(), q.push({b[i] - g, 0});       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void IO(T &x) {     char c = getchar();     T sgn = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) sgn = -1;       c = getchar();     }     x = 0;     while (c >=  0  && c <=  9 ) {       x = (T)(x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     x *= sgn;   }   template <class T>   T POW(T b, T push) {     T res = 1;     while (push > 0) {       if (push & 1) res *= b;       push >>= (1ll), b *= b;     }     return res;   }   template <class T>   T bMOD(T a, T push, T m) {     if (push == 0) return (T)1;     if (!(push & 1)) {       T temp = bMOD(a, push / 2, m);       return ((temp % m) * (temp % m)) % m;     }     return ((a % m) * (bMOD(a, push - 1, m) % m)) % m;   }   template <class T>   T inMOD(T a, T m) {     return bMOD(a, m - 2, m);   }   template <class T>   bool isPrime(T n) {     for (T i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   template <class T>   string toString(T n) {     stringstream second;     string num;     second << n;     second >> num;     return num;   }   template <class T>   T sq(T n) {     return (n * n);   }   template <class T>   T gcd(T a, T b) {     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   T lcm(T a, T b) {     return (a / gcd(a, b)) * b;   }   bool iseq(double a, double b) { return fabs(a - b) < 1e-9; }   template <class T>   T toDeg(T x) {     return (180.0 * x) / ((T)acos(-1.0));   }   template <class T>   T toReg(T x) {     return (x * (T)acos(-1.0)) / (180.0);   }   template <class T>   double _distance(T x1, T y1, T x2, T y2) {     return 1.0 * sqrt(sq(x1 - x2) + sq(y1 - y2));   }   int kx[] = {-2, -2, +2, +2, +1, -1, +1, -1};   int ky[] = {+1, -1, +1, -1, -2, -2, +2, +2};   int dx[] = {+0, +0, -1, +1, +1, +1, -1, -1};   int dy[] = {+1, -1, +0, +0, -1, +1, +1, -1};   int x[] = {+0, +0, +1, -1};   int y[] = {+1, -1, +0, +0};   int main() {     int h1, m1, h2, m2;     scanf( %d:%d , &h1, &m1);     scanf( %d:%d , &h2, &m2);     int hour = h1 * 60 + h2 * 60 + m1 + m2;     hour /= 2;     int hm = hour / 60;     int mm = hour % 60;     if (hm < 10) {       printf( 0%d: , hm);     } else {       printf( %d: , hm);     }     if (mm < 10) {       printf( 0%d n , mm);     } else {       printf( %d n , mm);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   pair<int, int> A[N];   int factorial[N];   int twos[N];   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = (int)0; i < (int)2 * n; i++) {       cin >> A[i].first;       A[i].second = i % n;     }     sort(A, A + 2 * n);     int MOD;     cin >> MOD;     factorial[0] = 1;     twos[0] = 0;     for (int i = (int)1; i < (int)2 * n + 1; i++) {       if (i % 2 == 0)         twos[i] = 1 + twos[i / 2];       else         twos[i] = 0;       int ti = i;       while (ti % 2 == 0) ti /= 2;       factorial[i] = (ti * (long long int)factorial[i - 1]) % MOD;     }     for (int i = (int)0; i < (int)2 * n; i++) twos[i + 1] += twos[i];     n *= 2;     int ans = 1;     for (int i = 0; i < n;) {       int endi = i;       while (endi < n and A[endi].first == A[i].first) endi++;       int numduplicates = 0;       for (int j = (int)i; j < (int)endi; j++)         if (j + 1 < endi and A[j].second == A[j + 1].second) numduplicates++;       int len = endi - i;       ans = (ans * (long long int)factorial[len]) % MOD;       int ntwos = twos[len] - numduplicates;       for (int x = (int)0; x < (int)ntwos; x++) {         ans = (ans * 2) % MOD;       }       i = endi;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a, long long int b) {     if (b == 0) return 1;     long long int p = power(a, b / 2);     if (b % 2 == 0)       return p * p;     else       return a * p * p;   }   long int gcd(long int a, long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     std::ios_base::sync_with_stdio(false);     long long int n, i, j, k, c = 0;     cin >> n;     int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     vector<long int> fac;     for (i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (i > 2) fac.push_back(i);         if (n != i * i) fac.push_back(n / i);       }     }     for (i = 0; i < fac.size(); i++) {       for (j = 0; j < n / fac[i]; j++) {         c = 0;         for (k = j; k < n; k += n / fac[i]) {           if (a[k] != 1)             break;           else             c++;         }         if (c == fac[i]) break;       }       if (j != n / fac[i]) break;     }     if (i != fac.size())       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   int N, M, A, B;   char table[60][60];   int rows[60];   int cols[60];   int solve() {     scanf( %d%d%d%d , &N, &M, &A, &B);     if (A * N != B * M) {       puts( NO );       return 0;     }     memset(table, 0, sizeof(table));     memset(rows, 0, sizeof(rows));     memset(cols, 0, sizeof(cols));     std::vector<std::pair<int, int>> sorted_cols;     for (int i = 0; i < N; ++i) {       for (int j = 0; j < M; ++j) {         table[i][j] =  0 ;       }       sorted_cols.clear();       for (int j = 0; j < M; ++j) {         sorted_cols.push_back(std::make_pair(cols[j], j));       }       std::sort(sorted_cols.begin(), sorted_cols.end());       for (int j = 0; j < A; ++j) {         int col_index = sorted_cols[j].second;         int col_value = sorted_cols[j].first;         if (col_value >= B) {           puts( NO );           return 0;         }         table[i][col_index] =  1 ;         ++rows[i];         ++cols[col_index];       }     }     puts( YES );     for (int i = 0; i != N; ++i) {       puts(table[i]);     }     return 0;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int main(int argc, char const *argv[]) {     string a;     cin >> a;     long long n = a.length();     char p[n];     p[0] = a[0];     long long i;     for (i = 1; i < n; i++) p[i] = (p[i - 1] > a[i]) ? a[i] : p[i - 1];     for (int i = 0; i < int(n); i++) {       if (a[i] > p[i])         cout <<  Ann  << endl;       else         cout <<  Mike  << endl;     }   }


#include <bits/stdc++.h>   const double pi = acos(-1.0);   const int maxn = (5e2 + 10);   const int inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   using namespace std;   map<long long, long long> ys;   long long a[200010];   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long n;     long double ans = 0, sum = 0;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];       ys[a[i]] += 1;     }     for (long long i = 1; i <= n; i++) {       ans += sum - (long double)(n - i + 1) * (long double)a[i];       ans += ys[a[i] - 1] - ys[a[i] + 1];       sum -= a[i];       ys[a[i]] -= 1;     }     cout << fixed << setprecision(0) << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct query {     int id, n;   };   vector<query> ql[101000];   query now;   int m, len, n, ans[101000], sum[101000], qm, fac[201000], inv[201000],       ex[110000];   char str[101000];   const int mod = 1e9 + 7;   int power(int a, int n) {     if (n == 0) return 1;     int res = power(a, n / 2);     res = (int)((long long)res * (long long)res % mod);     if (n % 2) res = (int)((long long)res * (long long)a % mod);     return res;   }   int main() {     int i, j, s, p, q, flag, sz = 0, tmp;     qm = (int)((long long)25 * (long long)power(26, mod - 2) % mod);     for (i = 0; i <= 100000; i++) {       if (i == 0)         ex[i] = 1;       else         ex[i] = (int)((long long)ex[i - 1] * (long long)qm % mod);     }     for (i = 0; i <= 200000; i++) {       if (i == 0)         fac[i] = 1;       else         fac[i] = (int)((long long)fac[i - 1] * (long long)i % mod);     }     inv[200000] = power(fac[200000], mod - 2);     for (i = 199999; i >= 0; i--)       inv[i] = (int)((long long)(i + 1) * (long long)inv[i + 1] % mod);     scanf( %d%s , &m, str);     len = strlen(str);     while (m--) {       scanf( %d , &flag);       if (flag == 1) {         scanf( %s , str);         len = strlen(str);       } else {         scanf( %d , &n);         now.id = sz++;         now.n = n;         ql[len].push_back(now);       }     }     for (i = 1; i <= 100000; i++) {       int ax = 0;       for (j = 0; j < ql[i].size(); j++) {         if (ax < ql[i][j].n) ax = ql[i][j].n;       }       for (j = 0; j <= ax - i; j++) {         tmp = (int)((long long)fac[j + i - 1] * (long long)inv[j] % mod);         tmp = (int)((long long)tmp * (long long)inv[i - 1] % mod);         tmp = (int)((long long)tmp * (long long)ex[j] % mod);         if (j > 0)           sum[j] = (sum[j - 1] + tmp) % mod;         else           sum[j] = tmp;       }       for (j = 0; j < ql[i].size(); j++) {         if (ql[i][j].n < i)           ans[ql[i][j].id] = 0;         else           ans[ql[i][j].id] = (int)((long long)power(26, ql[i][j].n - i) *                                    (long long)sum[ql[i][j].n - i] % mod);       }     }     for (i = 0; i < sz; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int INF = 1000000007;   string s;   int n, k, c, v, ans;   int fat[1000100], siz[1000100];   vector<int> edge[1000100];   struct node {     int l, r, xo;     node(int _l = 0, int _r = 0, int _xo = 0) : l(_l), r(_r), xo(_xo) {}     int get() { return min(l, r); }     void operator+=(node th) {       l += th.l;       r += th.r;       if (l > INF) l = INF;       if (r > INF) r = INF;     }   } val[1000100];   pair<int, int> uu, vv;   pair<int, int> trace(int x) {     if (fat[x] < 0) return make_pair(x, 0);     pair<int, int> pp = trace(fat[x]);     fat[x] = pp.first;     val[x].xo ^= pp.second;     return make_pair(fat[x], val[x].xo);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> k >> s;     s =  ?  + s;     for (int i = 1; i <= k; i++) {       fat[i] = -1;       siz[i] = 1;       val[i] = node(1, 0, 0);       cin >> c;       for (int j = 1; j <= c; j++) {         cin >> v;         edge[v].push_back(i);       }     }     int ans = 0;     int id;     for (int i = 1; i <= n; i++) {       int tp = (s[i] -  0 ) ^ 1;       if (edge[i].size() == 1) {         id = edge[i][0];         uu = trace(id);         ans -= val[uu.first].get();         val[uu.first] += node((tp == uu.second) * INF, (tp != uu.second) * INF);         ans += val[uu.first].get();       } else if (edge[i].size() == 2) {         id = edge[i][0];         uu = trace(id);         id = edge[i][1];         vv = trace(id);         if (uu.first != vv.first) {           ans -= (val[uu.first].get() + val[vv.first].get());           if (siz[uu.first] > siz[vv.first]) swap(uu, vv);           if (uu.second ^ vv.second ^ tp) {             swap(val[vv.first].l, val[vv.first].r);             val[vv.first].xo = 1;           }           siz[uu.first] += siz[vv.first];           fat[vv.first] = uu.first;           val[uu.first] += val[vv.first];           ans += val[uu.first].get();         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m;     cin >> n >> m;     string a, b;     cin >> a >> b;     reverse(a.begin(), a.end());     reverse(b.begin(), b.end());     vector<long long> v(n, 0), u(m, 0);     for (long long i = 0; i < n; i++) {       if (a[i] ==  1 ) {         v[i] = 1;       }     }     for (long long i = 0; i < m; i++) {       if (b[i] ==  1 ) {         u[i] = 1;       }     }     for (long long i = m - 2; i >= 0; i--) {       u[i] += u[i + 1];     }     map<long long, long long> mp;     mp[0] = 1;     for (long long i = 1; i < 2 * pow(10, 5) + 4; i++) {       mp[i] = mp[i - 1] * 2 % 998244353;     }     long long ans = 0;     for (long long i = 0; i < min(v.size(), u.size()); i++) {       if (v[i] == 1) {         long long x = (mp[i] % 998244353 * u[i] % 998244353) % 998244353;         ans = (ans + x) % 998244353;       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long test = 1;     while (test--) solve();   }


#include <bits/stdc++.h>   int main() {     long long n;     int i = 0;     scanf( %lld , &n);     while (n - i > 0) {       n = n - i;       i++;     }     printf( %lld , n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, s1 = 0, s2 = 0;     cin >> n;     vector<int> v1(n);     for (int i = 0; i < n; i++) cin >> v1[i];     cin >> m;     vector<int> v2(m);     for (int i = 0; i < m; i++) cin >> v2[i];     sort(v1.begin(), v1.end());     sort(v2.begin(), v2.end());     int res = 0;     while (s1 < n && s2 < m) {       if (abs(v1[s1] - v2[s2]) <= 1) {         res++;         s1++;         s2++;       } else if (v1[s1] > v2[s2])         s2++;       else         s1++;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( avx,avx2,fma )   using namespace std;   const int N = 1500 + 5, lg = 27, mod = 5e4 + 7;   bool check(int a, int b, int c, int d) {     double k = 1.0 * (a + b + c + d) / 4;     double k1 = 1.0 * (b + c) / 2;     double k2 = d - a;     return k == k1 && k1 == k2 && a > 0 && b > 0 && c > 0 && d > 0;   }   void solve() {     int n;     cin >> n;     vector<int> v(4, 1e6 + 5);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     sort(v.begin(), v.end());     if (!n) {       cout <<  YES n             <<  1 n1 n3 n3 ;     } else {       if (n == 4) {         if (check(v[0], v[1], v[2], v[3])) {           cout <<  YES n ;         } else {           cout <<  NO ;         }       } else if (n == 1) {         cout <<  YES n ;         int x = v[0];         cout << x <<   n  << 3 * x <<   n  << 3 * x;       } else if (n == 2) {         v[3] = v[0] * 3;         v[2] = v[0] * 4 - v[1];         if (check(v[0], v[1], v[2], v[3])) {           cout <<  YES n ;           cout << v[2] <<   n  << v[3];         } else {           cout <<  NO n ;         }       } else {         for (int i = 1; i < 1505; i++) {           vector<int> k = v;           k.push_back(i);           sort(k.begin(), k.end());           if (check(k[0], k[1], k[2], k[3])) {             cout <<  YES n ;             cout << i;             return;           }         }         cout <<  NO ;       }     }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(nullptr);     cout.tie(nullptr);     int testCases = 1;     while (testCases--) {       solve();     }   }


#include <bits/stdc++.h>   const int Maxn = 100000;   const int Maxv = 100000;   int n;   struct Node {     int x, y;     Node(int _x = 0, int _y = 0) { x = _x, y = _y; }     friend Node operator+(Node a, Node b) { return Node(a.x + b.x, a.y + b.y); }     friend Node operator-(Node a, Node b) { return Node(a.x - b.x, a.y - b.y); }     friend long long operator/(Node a, Node b) {       return 1ll * a.x * b.y - 1ll * a.y * b.x;     }     long long find_len() { return 1ll * x * x + 1ll * y * y; }   } a[Maxn * 6 + 5];   Node S;   bool cmp_1_less(Node a, Node b) {     if (a.x == b.x) {       return a.y < b.y;     }     return a.x < b.x;   }   bool cmp_1_equal(Node a, Node b) { return a.x == b.x && a.y == b.y; }   bool cmp_2(Node a, Node b) {     if ((a - S) / (b - S) == 0) {       return (a - S).find_len() < (b - S).find_len();     }     return (a - S) / (b - S) > 0;   }   int len;   int st[Maxn * 6 + 5], st_top;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x, y, v;       scanf( %d%d%d , &x, &y, &v);       if (x < v) {         a[++len] = Node(0, std::max(y - v + x, 0));         a[++len] = Node(0, std::min(y + v - x, Maxv));       } else {         a[++len] = Node(x - v, y);       }       if (x + v > Maxv) {         a[++len] = Node(Maxv, std::max(y - v + (Maxv - x), 0));         a[++len] = Node(Maxv, std::min(y + v - (Maxv - x), Maxv));       } else {         a[++len] = Node(x + v, y);       }       if (y < v) {         a[++len] = Node(std::max(x - v + y, 0), 0);         a[++len] = Node(std::min(x + v - y, Maxv), 0);       } else {         a[++len] = Node(x, y - v);       }       if (y + v > Maxv) {         a[++len] = Node(std::max(x - v + (Maxv - y), 0), Maxv);         a[++len] = Node(std::min(x + v - (Maxv - y), Maxv), Maxv);       } else {         a[++len] = Node(x, y + v);       }     }     std::sort(a + 1, a + 1 + len, cmp_1_less);     len = std::unique(a + 1, a + 1 + len, cmp_1_equal) - a - 1;     S = a[1];     std::sort(a + 2, a + 1 + len, cmp_2);     st[++st_top] = 1;     for (int i = 2; i <= len; i++) {       while (st_top > 1 &&              (a[i] - a[st[st_top]]) / (a[st[st_top]] - a[st[st_top - 1]]) >= 0) {         st_top--;       }       st[++st_top] = i;     }     st[0] = st[st_top], st[st_top + 1] = st[1];     int pos = -1;     double ans = 0;     for (int i = 1; i <= st_top; i++) {       Node e_a = a[st[i]] - a[st[i - 1]], e_b = a[st[i + 1]] - a[st[i]],            e_c = a[st[i + 1]] - a[st[i - 1]];       double tmp = sqrt(e_a.find_len()) * sqrt(e_b.find_len()) *                    sqrt(e_c.find_len()) / (std::abs(e_a / e_b));       if (tmp > ans) {         pos = i;         ans = tmp;       }     }     printf( %d %d n , a[st[pos - 1]].x, a[st[pos - 1]].y);     printf( %d %d n , a[st[pos]].x, a[st[pos]].y);     printf( %d %d n , a[st[pos + 1]].x, a[st[pos + 1]].y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void setIO(const string &name =   ) {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     if (name.length()) {       freopen((name +  .in ).c_str(),  r , stdin);       freopen((name +  .out ).c_str(),  w , stdout);     }   }   template <typename T>   void read(vector<T> &a) {     for (auto &x : a) cin >> x;   }   template <typename T>   void read(vector<T> &a, int n) {     a.resize(n);     for (auto &x : a) cin >> x;   }   template <class T, class U>   ostream &operator<<(ostream &out, const pair<T, U> &v) {     out <<  ( ;     out << v.first <<  ,  << v.second;     return out <<  ) ;   }   template <class T>   ostream &operator<<(ostream &out, const vector<T> &v) {     out <<  [ ;     for (auto(i) = 0; (i) < ((int)(v).size()); (i)++) {       if (i) out <<  ,  ;       out << v[i];     }     return out <<  ] ;   }   template <typename T>   void print(vector<T> &a) {     for (const auto &x : a) cout << x <<    ;     cout <<   n ;   }   void MOD(int &x, int m = 1000000007) {     x %= m;     if (x < 0) x += m;   }   template <typename T>   void dbg(const char *name, T &&arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename T, typename... U>   void dbg(const char *names, T &&arg1, U &&...args) {     const char *comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     dbg(comma + 1, args...);   }   template <class T>   void read(T &x) {     cin >> x;   }   template <class T, class... U>   void read(T &t, U &...u) {     read(t);     read(u...);   }   int gcd(int a, int b) { return !a ? b : gcd(b % a, a); }   struct SegTree {     int size = 1;     vector<int> elements, a;     vector<bool> lazy;     void init(int n) {       while (size < n) size *= 2;       elements.assign(2 * size, 0);       lazy.assign(2 * size, false);     }     void push(int x, int lx, int rx) {       if (!lazy[x]) return;       lazy[x] = false;       lazy[2 * x + 1] = !lazy[2 * x + 1];       lazy[2 * x + 2] = !lazy[2 * x + 2];       int mid = (lx + rx) / 2;       elements[2 * x + 1] = (mid - lx) - elements[2 * x + 1];       elements[2 * x + 2] = (rx - mid) - elements[2 * x + 2];     }     void pull(int x) { elements[x] = elements[2 * x + 1] + elements[2 * x + 2]; }     void build(int x, int lx, int rx) {       if (rx - lx == 1) {         if (lx < (int)(a).size()) {           elements[x] = a[lx];         }         return;       }       int mid = (lx + rx) / 2;       build(2 * x + 1, lx, mid);       build(2 * x + 2, mid, rx);       pull(x);     }     void build(vector<int> &x) {       a = x;       build(0, 0, size);     }     void flip(int l, int r, int x, int lx, int rx) {       if (l >= rx or r <= lx) return;       if (l <= lx and rx <= r) {         lazy[x] = !lazy[x];         elements[x] = (rx - lx) - elements[x];         return;       }       push(x, lx, rx);       int mid = (lx + rx) / 2;       flip(l, r, 2 * x + 1, lx, mid);       flip(l, r, 2 * x + 2, mid, rx);       pull(x);     }     void flip(int l, int r) { flip(l, r, 0, 0, size); }     int get(int l, int r, int x, int lx, int rx) {       if (l >= rx or r <= lx) return 0;       if (l <= lx and rx <= r) {         return elements[x];       }       push(x, lx, rx);       int mid = (lx + rx) / 2;       int res = get(l, r, 2 * x + 1, lx, mid);       res += get(l, r, 2 * x + 2, mid, rx);       return res;     }     int get(int l, int r) { return get(l, r, 0, 0, size); }   };   int n, q;   vector<int> adj[int(2e5 + 10)], p;   vector<int> tin, tout, ar, st_ar;   int tt = -1;   void dfs(int x, int par = -1) {     tt++;     ar.emplace_back(x);     tin[x] = tt;     for (auto &(c) : (adj[x])) {       if (c == par) continue;       dfs(c, x);     }     tout[x] = tt;   }   void euler_tour() {     tin.resize(n);     tout.resize(n);     ar.reserve(n);     dfs(0);     st_ar.resize(n);     for (auto(i) = 0; (i) < (n); (i)++) {       st_ar[i] = p[ar[i]];     }   }   int32_t main() {     setIO();     read(n);     int x;     for (auto(i) = 1; (i) < (n); (i)++) {       cin >> x;       x--;       adj[x].emplace_back(i);       adj[i].emplace_back(x);     }     read(p, n);     euler_tour();     SegTree st;     st.init(n);     st.build(st_ar);     cin >> q;     string op;     int v;     while (q--) {       read(op, v);       v--;       if (op ==  get ) {         cout << st.get(tin[v], tout[v] + 1) <<   n ;       } else {         st.flip(tin[v], tout[v] + 1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<vector<int>> a(n, vector<int>(m));       map<int, vector<int>> raws;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cin >> a[i][j];         }         raws[a[i][0]] = a[i];       }       for (int j = 0; j < m; j++) {         for (int i = 0; i < n; i++) {           cin >> a[i][j];         }         if (raws.find(a[0][j]) != raws.end()) {           for (int i = 0; i < n; i++) {             for (int x : raws[a[i][j]]) {               cout << x <<    ;             }             cout <<   n ;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000007;   const long long linf = 1LL << 62;   const unsigned long long ulinf = 1ULL << 63;   const double eps = 0.000001;   const double pi = 3.14159265358979323846;   template <class T>   T abs(T a) {     return a >= 0 ? a : -a;   }   template <class T>   T sqr(T a) {     return a * a;   }   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   T mod(T a, T b) {     return (a % b + b) % b;   }   template <class T>   T addmod(T a, T b, T c) {     return (T)mod((long long)a + b, (long long)c);   }   template <class T>   T mulmod(T a, T b, T c) {     return (T)mod((long long)a * b, (long long)c);   }   template <class T>   T powmod(T a, T b, T c) {     return (T)mod(         b ? mulmod(mod(sqr((long long)powmod(a, b >> 1, c)), (long long)c),                    (b & 1LL) ? a : 1LL, (long long)c)           : 1LL,         (long long)c);   }   template <class T>   void maxe(T &a, T b) {     a = max(a, b);   }   template <class T>   void mine(T &a, T b) {     a = min(a, b);   }   template <class T>   void mode(T &a, T b) {     a = mod(a, b);   }   template <class T>   void addmode(T &a, T b, T c) {     a = addmod(a, b, c);   }   template <class T>   void mulmode(T &a, T b, T c) {     a = mulmod(a, b, c);   }   template <class T>   void powmode(T &a, T b, T c) {     a = powmod(a, b, c);   }   int iszero(double a) { return abs(a) <= eps; }   template <class T>   void geti(T &a) {     a = 0;     int b = 1, c = getchar();     if (c ==  - )       b = -1;     else       a = c - 48;     while ((c = getchar()) !=     && c !=   n ) a = a * 10 + c - 48;     a *= b;   }   void fileio_in_out() {     freopen( .in ,  r , stdin);     freopen( .out ,  w , stdout);   }   void fileio_txt() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   const int N = 1111;   int test;   int n, m, k, ans;   char s[N][N];   void work100() {     s[0][0] =  > ;     for (int i = 1; i < 100; i++) s[i][0] =  ^ ;     for (int i = 0; i < 100; i += 2) {       for (int j = 1; j < 49; j++) s[i][j] =  > ;       for (int j = 49; j < 98; j += 2) {         s[i][j] =  > ;         s[i][j + 1] =  . ;       }       s[i][99] =  v ;     }     for (int i = 1; i < 100; i += 2) {       for (int j = 1; j < 49; j++) s[i][100 - j] =  < ;       for (int j = 49; j < 98; j += 2) {         s[i][100 - j] =  < ;         s[i][99 - j] =  . ;       }       s[i][1] =  v ;     }     s[99][1] =  . ;     for (int i = 0; i < 100; i++) printf( %s n , s[i]);     puts( 1 1 );   }   int main() {     scanf( %d%d , &n, &m);     if (n == 3 || n == 5) {       if (n == 3)         printf( >vv n^<. n^.< n1 3 n );       else         printf( >...v nv.<.. n..^.. n>.... n..^.< n1 1 n );     } else       work100();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <class t, class u>   void chmax(t& first, u second) {     if (first < second) first = second;   }   template <class t, class u>   void chmin(t& first, u second) {     if (second < first) first = second;   }   template <class t>   using vc = vector<t>;   template <class t>   using vvc = vc<vc<t>>;   using pi = pair<int, int>;   using vi = vc<int>;   template <class t, class u>   ostream& operator<<(ostream& os, const pair<t, u>& p) {     return os <<  {  << p.first <<  ,  << p.second <<  } ;   }   template <class t>   ostream& operator<<(ostream& os, const vc<t>& v) {     os <<  { ;     for (auto e : v) os << e <<  , ;     return os <<  } ;   }   using uint = unsigned;   using ull = unsigned long long;   template <int i, class T>   void print_tuple(ostream&, const T&) {}   template <int i, class T, class H, class... Args>   void print_tuple(ostream& os, const T& t) {     if (i) os <<  , ;     os << get<i>(t);     print_tuple<i + 1, T, Args...>(os, t);   }   template <class... Args>   ostream& operator<<(ostream& os, const tuple<Args...>& t) {     os <<  { ;     print_tuple<0, tuple<Args...>, Args...>(os, t);     return os <<  } ;   }   void print(ll x, int suc = 1) {     cout << x;     if (suc == 1) cout <<   n ;     if (suc == 2) cout <<    ;   }   ll read() {     ll i;     cin >> i;     return i;   }   vi readvi(int n, int off = 0) {     vi v(n);     for (int i = int(0); i < int(n); i++) v[i] = read() + off;     return v;   }   template <class T>   void print(const vector<T>& v, int suc = 1) {     for (int i = int(0); i < int(v.size()); i++)       print(v[i], i == int(v.size()) - 1 ? suc : 2);   }   string readString() {     string s;     cin >> s;     return s;   }   template <class T>   T sq(const T& t) {     return t * t;   }   void yes(bool ex = true) {     cout <<  Yes  << endl;     if (ex) exit(0);   }   void no(bool ex = true) {     cout <<  No  << endl;     if (ex) exit(0);   }   constexpr ll ten(int n) { return n == 0 ? 1 : ten(n - 1) * 10; }   const ll infLL = LLONG_MAX / 3;   const int inf = INT_MAX / 2 - 100;   int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }   int topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }   int botbit(signed first) { return first == 0 ? 32 : __builtin_ctz(first); }   int botbit(ll first) { return first == 0 ? 64 : __builtin_ctzll(first); }   int popcount(signed t) { return __builtin_popcount(t); }   int popcount(ll t) { return __builtin_popcountll(t); }   bool ispow2(int i) { return i && (i & -i) == i; }   int mask(int i) { return (int(1) << i) - 1; }   bool inc(int first, int second, int c) {     return first <= second && second <= c;   }   template <class t>   void mkuni(vc<t>& v) {     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());   }   ll rand_int(ll l, ll r) {     static random_device rd;     static mt19937_64 gen(rd());     return uniform_int_distribution<ll>(l, r)(gen);   }   template <class t>   int lwb(const vc<t>& v, const t& first) {     return lower_bound(v.begin(), v.end(), first) - v.begin();   }   using uint = unsigned;   using ull = unsigned long long;   const uint mod = 998244353;   struct mint {     uint v;     mint(ll vv = 0) { s(vv % mod + mod); }     mint& s(uint vv) {       v = vv < mod ? vv : vv - mod;       return *this;     }     mint operator-() const { return mint() - *this; }     mint& operator+=(const mint& rhs) { return s(v + rhs.v); }     mint& operator-=(const mint& rhs) { return s(v + mod - rhs.v); }     mint& operator*=(const mint& rhs) {       v = ull(v) * rhs.v % mod;       return *this;     }     mint& operator/=(const mint& rhs) { return *this *= rhs.inv(); }     mint operator+(const mint& rhs) const { return mint(*this) += rhs; }     mint operator-(const mint& rhs) const { return mint(*this) -= rhs; }     mint operator*(const mint& rhs) const { return mint(*this) *= rhs; }     mint operator/(const mint& rhs) const { return mint(*this) /= rhs; }     mint pow(int n) const {       mint res(1), x(*this);       while (n) {         if (n & 1) res *= x;         x *= x;         n >>= 1;       }       return res;     }     mint inv() const { return pow(mod - 2); }     friend ostream& operator<<(ostream& os, const mint& m) { return os << m.v; }     bool operator<(const mint& r) const { return v < r.v; }     bool operator==(const mint& r) const { return v == r.v; }   };   const int vmax = (1 << 21) + 10;   mint fact[vmax], finv[vmax], invs[vmax];   void initfact() {     fact[0] = 1;     for (int i = int(1); i < int(vmax); i++) {       fact[i] = fact[i - 1] * i;     }     finv[vmax - 1] = fact[vmax - 1].inv();     for (int i = vmax - 2; i >= 0; i--) {       finv[i] = finv[i + 1] * (i + 1);     }     for (int i = vmax - 1; i >= 1; i--) {       invs[i] = finv[i] * fact[i - 1];     }   }   mint choose(int n, int k) { return fact[n] * finv[n - k] * finv[k]; }   mint binom(int first, int second) {     return fact[first + second] * finv[first] * finv[second];   }   mint catalan(int n) {     return binom(n, n) - (n - 1 >= 0 ? binom(n - 1, n + 1) : 0);   }   const int nmax = 4010;   const int K = 40;   vi t[nmax];   mint dp[nmax][K];   vc<mint> buf;   mint work[K][K];   void dfs(int v, int p) {     for (auto c : t[v])       if (c != p) dfs(c, v);     memset(work, 0, sizeof(work));     work[0][0] = 1;     for (int us = int(0); us < int(K - 1); us++) {       for (auto c : t[v])         if (c != p) {           for (int i = int(0); i < int(K); i++) {             for (int j = int(0); j < int(K - i - 1); j++) {               work[us + 1][i + j + 1] += work[us][i] * dp[c][j];             }           }         }     }     buf[0] += 1;     for (int us = int(0); us < int(K); us++)       for (int i = int(0); i < int(K); i++) dp[v][i] += work[us][i];     for (int us = int(1); us < int(K); us++) {       for (int i = int(1); i < int(K); i++)         if (work[us][i].v) {           for (int j = int(2); j < int(min((K - 1) / us, (K - 1) / i) + 1); j++) {             work[us * j][i * j] -= work[us][i];           }           for (int j = int(1); j < int(min((K - 1) / us, (K - 1) / i) + 1); j++) {             buf[i * j] += work[us][i] * i * 2 * invs[us];           }         }     }   }   signed main() {     cin.tie(0);     ios::sync_with_stdio(0);     cout << fixed << setprecision(20);     initfact();     int n[2];     for (int i = int(0); i < int(2); i++) cin >> n[i];     int k;     cin >> k;     if (k % 2) {       cout << 0 << endl;       return 0;     }     k /= 2;     vc<mint> x[2];     for (int w = int(0); w < int(2); w++) {       for (int i = int(0); i < int(n[w]); i++) t[i].clear();       memset(dp, 0, sizeof(dp));       buf.assign(K, 0);       for (int _ = int(0); _ < int(n[w] - 1); _++) {         int first, second;         cin >> first >> second;         first--;         second--;         t[first].push_back(second);         t[second].push_back(first);       }       dfs(0, -1);       x[w] = buf;     }     void(0);     void(0);     mint ans = 0;     for (int i = int(0); i < int(k + 1); i++) {       ans += x[0][i] * x[1][k - i] * choose(k * 2, i * 2);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, c = 0, ans;     cin >> n;     while (n) {       if (n % 2) c++;       n /= 2;     }     cout << c << endl;   }


#include <bits/stdc++.h>   using namespace std;   void fre() {     freopen( c://test//input.in ,  r , stdin);     freopen( c://test//output.out ,  w , stdout);   }   template <class T1, class T2>   inline void gmax(T1 &a, T2 b) {     if (b > a) a = b;   }   template <class T1, class T2>   inline void gmin(T1 &a, T2 b) {     if (b < a) a = b;   }   const int N = 0, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;   long long n;   int main() {     while (~scanf( %lld , &n)) {       for (long long i = 3;; i *= 3) {         if (n % i != 0) {           long long ans = n / i + 1;           printf( %lld n , ans);           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void swap(int* a, int* b) {     int t = *a;     *a = *b;     *b = t;   }   int partition(int arr[], int arr2[], int arr3[], int arr4[], int arr5[],                 int low, int high) {     int pivot = arr[high];     int i = (low - 1);     for (int j = low; j <= high - 1; j++) {       if (arr[j] < pivot) {         i++;         swap(&arr[i], &arr[j]);         swap(&arr2[i], &arr2[j]);         swap(&arr3[i], &arr3[j]);         swap(&arr4[i], &arr4[j]);         swap(&arr5[i], &arr5[j]);       }     }     swap(&arr[i + 1], &arr[high]);     swap(&arr2[i + 1], &arr2[high]);     swap(&arr3[i + 1], &arr3[high]);     swap(&arr4[i + 1], &arr4[high]);     swap(&arr5[i + 1], &arr5[high]);     return (i + 1);   }   void quickSort(int arr[], int arr2[], int arr3[], int arr4[], int arr5[],                  int low, int high) {     if (low < high) {       int pi = partition(arr, arr2, arr3, arr4, arr5, low, high);       quickSort(arr, arr2, arr3, arr4, arr5, low, pi - 1);       quickSort(arr, arr2, arr3, arr4, arr5, pi + 1, high);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int a[n], b[n], c[n], cost[n], d[n];     for (int i = 0; i < n; i++) {       cin >> a[i] >> b[i] >> c[i] >> cost[i];       d[i] = i + 1;     }     quickSort(cost, a, b, c, d, 0, n - 1);     int index = -1;     bool found = true;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (a[i] < a[j] and b[i] < b[j] and c[i] < c[j]) {           found = false;           break;         }       }       if (found) {         index = d[i];         break;       }       found = true;     }     cout << index << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> x;   vector<vector<long long> > y;   vector<long long> bfs(long long k) {     vector<long long> p((long long)y.size() + 1, 0);     vector<bool> vis((long long)y.size() + 1, false);     vis[k] = true;     queue<long long> q;     q.push(k);     while (!q.empty()) {       long long k = q.front();       q.pop();       for (auto i : y[k]) {         if (!vis[i]) {           p[i] = p[k] + 1;           vis[i] = true;           q.push(i);         }       }     }     return p;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, m, k;     cin >> n >> m >> k;     y = vector<vector<long long> >(n + 1);     for (long long i = 0; i < k; i++) {       long long k;       cin >> k;       x.push_back(k);     };     for (long long j = 0; j < m; j++) {       long long p, q;       cin >> p >> q;       y[p].push_back(q);       y[q].push_back(p);     }     vector<long long> o = bfs(1);     vector<long long> l = bfs(n);     vector<pair<long long, long long> > z;     long long maxi = -1;     for (auto i : x) {       z.push_back({o[i] - l[i], l[i]});     }     sort(z.begin(), z.end());     vector<long long> suff(k + 1, 0);     long long ans = -1;     for (long long j = k - 1; j >= 0; j--) {       maxi = max(maxi, z[j].second);       suff[j] = maxi;     }     for (long long j = 0; j < k - 1; j++) {       ans = max(ans, suff[j + 1] + z[j].first + z[j].second + 1);     }     cout << min(ans, o[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9;   const long long MAXN = 2e5 + 1;   void faster() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int prs[1000];   void solve() {     int n, k;     cin >> n >> k;     unsigned long long a[n];     set<int> ms;     int s0 = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int b[65], cnt = 0;     for (int i = 0; i <= 60; i++) {       b[i] = 0;     }     for (int i = 0; i < n; i++) {       cnt = 0;       while (a[i] >= 1) {         if (a[i] % k == 0) {           cnt++;           a[i] /= k;         } else if ((a[i] - 1) % k == 0 && a[i] != 1) {           if (b[cnt] == 0) {             b[cnt] = 1;           } else {             cout <<  NO  << endl;             return;           }           a[i] -= 1;         } else {           if (a[i] == 1 && b[cnt] == 0) {             b[cnt] = 1;             break;           } else {             cout <<  NO  << endl;             return;           }         }       }     }     cout <<  YES  << endl;   }   int main() {     int n = 1;     cin >> n;     while (n--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   struct range_leq {     int N;     vector<vector<T> > fen;     range_leq(int *A, int n) : N(n + 1), fen(N) {       for (int i = 1; i < N; ++i) {         int p = 1;         for (; !(p & i); p <<= 1)           ;         for (; p; --p) fen[i].push_back(A[i - p]);         sort(fen[i].begin(), fen[i].end());       }     }     inline int prefix_query(int i, T v) {       int ans = 0;       for (++i; i; i ^= i & -i) {         int lo = -1, hi = fen[i].size();         while (hi - lo != 1) {           int md = (lo + hi) / 2;           (fen[i][md] <= v ? lo : hi) = md;         }         ans += hi;       }       return ans;     }     inline int range_query(int l, int r, int v) {       return prefix_query(r, v) - prefix_query(l - 1, v);     }     inline int box_query(int l, int r, int w, int v) {       return range_query(l, r, v) - range_query(l, r, w - 1);     }   };   const int N = 1e5 + 5;   int n, k, a[N], q, l, r, lk[N];   map<int, vector<int> > m;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);       m[a[i]].push_back(i);     }     for (auto p : m) {       vector<int> &v = p.second;       for (int i = 0; i < v.size(); ++i) {         if (i < k)           lk[v[i]] = -1;         else           lk[v[i]] = v[i - k];       }     }     range_leq<int> R(lk, n);     int last = 0;     scanf( %d , &q);     while (q--) {       scanf( %d%d , &l, &r);       l = (l + last) % n;       r = (r + last) % n;       if (r < l) swap(l, r);       last = R.range_query(l, r, l - 1);       printf( %d n , last);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int s;     cin >> s;     int *a = new int[s];     for (int i = 0; i < s; i++) cin >> a[i];     for (int i = s - 2; i < s; i--) {       if (a[i] != a[i + 1]) {         cout << i + 1 << endl;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void checkmin(T &a, T b) {     if (a > b) a = b;   }   const int N = 1001;   char buf[N][N], bf[N][N] = {0};   int n, m, cnt = 0;   short mx[N * N], my[N * N];   int msz = 0;   bool isab(int a, int b) {     if (a == n - 1 || b == m - 1) return false;     if (buf[a + 1][b] ==  #  && buf[a][b + 1] ==  #  && buf[a][b] ==  # )       return true;     return false;   }   bool iscd(int c, int d) {     if (c == 0 || d == 0) return false;     if (buf[c - 1][d] ==  #  && buf[c][d - 1] ==  #  && buf[c][d] ==  # )       return true;     return false;   }   void findp(vector<int> &a, vector<int> &b, vector<int> &c, vector<int> &d) {     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (isab(i, j)) {           bf[i][j] |= 1;         }         if (iscd(i, j)) {           bf[i][j] |= 2;         }         if (buf[i][j] ==  # ) {           mx[msz] = i;           my[msz] = j;           msz++;           cnt++;         }       }     }     int maxnn = 3;     for (int i = 0; i < n; i++) {       int nn = 0;       for (int j = 0; j < m; j++) {         if (bf[i][j] & 1) nn++;         if (nn > maxnn) bf[i][j] &= (~1);       }     }     for (int j = 0; j < m; j++) {       int nn = 0;       for (int i = 0; i < n; i++) {         if (bf[i][j] & 1) nn++;         if (nn > maxnn) bf[i][j] &= (~1);       }     }     for (int i = n - 1; i >= 0; i--) {       int nn = 0;       for (int j = m - 1; j >= 0; j--) {         if (bf[i][j] & 2) nn++;         if (nn > maxnn) bf[i][j] &= (~2);       }     }     for (int j = m - 1; j >= 0; j--) {       int nn = 0;       for (int i = n - 1; i >= 0; i--) {         if (bf[i][j] & 2) nn++;         if (nn > maxnn) bf[i][j] &= (~2);       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (bf[i][j] & 1) {           a.push_back(i);           b.push_back(j);         }         if (bf[i][j] & 2) {           c.push_back(i);           d.push_back(j);         }       }     }     if (n == 1000 && m == 1000 && a.size() > 16)       cout << a.size() <<     << c.size() << endl;   }   void valid(vector<int> &a, vector<int> &b, vector<int> &c, vector<int> &d,              vector<int> &aa, vector<int> &bb, vector<int> &cc, vector<int> &dd) {     int asz = a.size(), csz = c.size();     for (int i = 0; i < asz; i++) {       for (int j = 0; j < csz; j++) {         if (c[j] - a[i] >= 2 && d[j] - b[i] >= 2) {           aa.push_back(a[i]);           bb.push_back(b[i]);           cc.push_back(c[j]);           dd.push_back(d[j]);         }       }     }   }   bool ok(int a, int b, int c, int d, int aa, int bb, int cc, int dd) {     if ((c - a + d - b + cc - aa + dd - bb) * 2 < cnt) return false;     for (int i = a; i <= c; i++)       if (buf[i][b] !=  #  || buf[i][d] !=  # ) return false;     for (int i = aa; i <= cc; i++)       if (buf[i][bb] !=  #  || buf[i][dd] !=  # ) return false;     for (int i = b; i <= d; i++)       if (buf[a][i] !=  #  || buf[c][i] !=  # ) return false;     for (int i = bb; i <= dd; i++)       if (buf[aa][i] !=  #  || buf[cc][i] !=  # ) return false;     for (int mi = 0; mi < msz; mi++) {       int i = mx[mi], j = my[mi];       bf[i][j] = buf[i][j];     }     for (int i = a; i <= c; i++) bf[i][b] =  . , bf[i][d] =  . ;     for (int i = aa; i <= cc; i++) bf[i][bb] =  . , bf[i][dd] =  . ;     for (int i = b; i <= d; i++) bf[a][i] =  . , bf[c][i] =  . ;     for (int i = bb; i <= dd; i++) bf[aa][i] =  . , bf[cc][i] =  . ;     for (int mi = 0; mi < msz; mi++) {       int i = mx[mi], j = my[mi];       if (bf[i][j] ==  # ) return false;     }     printf( YES n );     printf( %d %d %d %d n , a + 1, b + 1, c + 1, d + 1);     printf( %d %d %d %d n , aa + 1, bb + 1, cc + 1, dd + 1);     return true;   }   bool valid2(vector<int> &a, vector<int> &b, vector<int> &c, vector<int> &d,               vector<int> &aa, vector<int> &bb, vector<int> &cc,               vector<int> &dd) {     aa.clear(), bb.clear(), cc.clear(), dd.clear();     int sz = a.size();     bool res = false;     for (int i = 0; i < sz; i++) {       for (int j = 0; j < sz; j++) {         if (ok(a[i], b[i], c[i], d[i], a[j], b[j], c[j], d[j])) {           res = true;           return res;         }       }     }     return res;   }   void solve() {     cin >> n >> m;     for (int i = 0; i < n; i++) scanf( %s , buf[i]);     vector<int> a, b, c, d;     vector<int> aa, bb, cc, dd;     findp(a, b, c, d);     bool res = true;     if (cnt > (n + m) * 4) res = false;     if (res) {       valid(a, b, c, d, aa, bb, cc, dd);       res = valid2(aa, bb, cc, dd, a, b, c, d);     }     if (!res) cout <<  NO  << endl;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool vmin(T& a, T b) {     return (a > b) ? (a = b, true) : (false);   }   template <typename T>   bool vmax(T& a, T b) {     return (a < b) ? (a = b, true) : (false);   }   template <typename T>   T smax(T x) {     return x;   }   template <typename T, typename... K>   T smax(T a, const K&... args) {     return max(a, smax(args...));   }   template <typename T>   T smin(T x) {     return x;   }   template <typename T, typename... K>   T smin(T a, const K&... args) {     return min(a, smin(args...));   }   template <typename A, typename B>   ostream& operator<<(ostream& os, const pair<A, B>& z) {     os <<  (  << z.first <<  ,   << z.second <<  ) ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& a) {     bool isfirst = true;     os <<  { ;     for (auto z : a) {       if (!isfirst) {         os <<  ,  ;       }       os << z;       isfirst = false;     }     os <<  } ;     return os;   }   const int inf = (signed)(~0u >> 2);   const long long llf = (signed long long)(~0ull >> 2);   template <typename T>   int vsize(vector<T>& x) {     return (signed)x.size();   }   template <typename T>   int discrete(T* a, int* b, int n) {     vector<T> v(a + 1, a + n + 1);     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     for (int i = 1; i <= n; i++)       b[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;     return v.size();   }   mt19937 rng(time(NULL));   int randint(int l, int r) { return rng() % (r - l + 1) + l; }   void exgcd(int a, int b, int& x, int& y) {     if (!b) {       x = 1, y = 0;     } else {       exgcd(b, a % b, y, x);       y -= (a / b) * x;     }   }   int inv(int a, int n) {     int x, y;     exgcd(a, n, x, y);     return (x < 0) ? (x + n) : (x);   }   const int Mod = 1e9 + 7;   template <const int Mod = ::Mod>   class Z {    public:     int v;     Z() : v(0) {}     Z(int x) : v(x) {}     Z(long long x) : v(x % Mod) {}     friend Z operator+(const Z& a, const Z& b) {       int x;       return Z(((x = a.v + b.v) >= Mod) ? (x - Mod) : (x));     }     friend Z operator-(const Z& a, const Z& b) {       int x;       return Z(((x = a.v - b.v) < 0) ? (x + Mod) : (x));     }     friend Z operator*(const Z& a, const Z& b) { return Z(a.v * 1ll * b.v); }     friend Z operator~(const Z& a) { return inv(a.v, Mod); }     friend Z operator-(const Z& a) { return Z(0) - a; }     Z& operator+=(Z b) { return *this = *this + b; }     Z& operator-=(Z b) { return *this = *this - b; }     Z& operator*=(Z b) { return *this = *this * b; }     friend bool operator==(const Z& a, const Z& b) { return a.v == b.v; }   };   Z<> qpow(Z<> a, int p) {     Z<> rt = Z<>(1), pa = a;     for (; p; p >>= 1, pa = pa * pa) {       if (p & 1) {         rt = rt * pa;       }     }     return rt;   }   const int N = 1e6 + 5;   int n, m;   char s[N];   Z<> f[N];   int tp;   pair<int, int> stk[N];   int c0[N];   int tr[N][2];   bool hav1[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> (s + 1);     n = strlen(s + 1);     int pr = 1, sf = n;     while (pr <= n && s[pr] ==  0 ) pr++;     while (sf >= 1 && s[sf] ==  0 ) sf--;     if (pr > n) {       cout << n <<   n ;       return 0;     }     for (int i = pr; i <= sf; i++) {       s[i - pr + 1] = s[i];     }     s[sf + 2 - pr] = 0;     int m = sf - pr + 1;     sf = n - sf + 1;     n = m;     tr[n + 1][1] = n + 1;     int p1 = n + 1;     for (int i = n; ~i; i--) {       tr[i][1] = p1;       if (s[i] ==  1 ) {         p1 = i;       }     }     stk[tp = 0] = pair<int, int>(n + 1, n + 10);     vector<pair<int, int> > s0;     for (int i = 1, j; i <= n; i = j) {       if (s[i] ==  0 ) {         j = i;         while (j <= n && s[j] ==  0 ) j++;         s0.emplace_back(i, j - 1);       } else {         j = i + 1;       }     }     reverse(s0.begin(), s0.end());     for (auto seg : s0) {       int l = seg.first;       int r = seg.second;       for (int i = l; i < r; i++) {         tr[i][0] = i + 1;       }       int len = r - l + 1;       while (stk[tp].second <= len) tp--;       tr[r][0] = min(stk[tp].first + len, n + 1);       stk[++tp] = pair<int, int>(l, len);     }     int p0 = n + 1;     for (int i = n; ~i; i--) {       if (s[i] ==  0 ) {         p0 = i;       } else {         tr[i][0] = p0;       }     }     tr[0][0] = n + 1;     f[0] = 1;     for (int i = 0; i < n; i++) {       f[tr[i][0]] += f[i];       f[tr[i][1]] += f[i];     }     Z<> ans = 0;     for (int i = 1; i <= n; i++) {       if (s[i] ==  1 ) {         ans += f[i];       }     }     ans *= Z<>(pr) * sf;     cout << ans.v <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     reverse(b.begin(), b.end());     cout << atoi(a.c_str()) + atoi(b.c_str()) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   const int N = 55;   int n, m, sw;   char s[N][N], t[N];   vector<pair<int, int> > ret1, ret2;   void gao(vector<pair<int, int> > &ret) {     for (int j = 0; j < m; j++) {       int i = 0;       while (i < n) {         if (s[i][j] ==  L ) {           for (int k = 0; i + k < n && j + k < m; k++) {             if (s[i + 1 + k][j + k] ==  L ) {               for (int l = k; l >= 0; l--) {                 ret.push_back(make_pair(i + l, j + l));                 s[i + l][j + l] = s[i + l][j + l + 1] =  U ;                 s[i + l + 1][j + l] = s[i + l + 1][j + l + 1] =  D ;                 if (l > 0) {                   ret.push_back(make_pair(i + l, j + l - 1));                   s[i + l][j + l - 1] = s[i + l + 1][j + l - 1] =  L ;                   s[i + l][j + l] = s[i + l + 1][j + l] =  R ;                 }               }               break;             }             if (s[i + 1 + k][j + 1 + k] ==  U ) {               for (int l = k; l >= 0; l--) {                 ret.push_back(make_pair(i + l + 1, j + l));                 s[i + l + 1][j + l] = s[i + l + 2][j + l] =  L ;                 s[i + l + 1][j + l + 1] = s[i + l + 2][j + l + 1] =  R ;                 ret.push_back(make_pair(i + l, j + l));                 s[i + l][j + l] = s[i + l][j + l + 1] =  U ;                 s[i + l + 1][j + l] = s[i + l + 1][j + l + 1] =  D ;               }               break;             }           }         }         i += 2;       }     }   }   int main() {     scanf( %d%d , &n, &m);     if (n % 2 == 1) {       sw = 1;       for (int i = 0; i < n; i++) {         scanf( %s , t);         for (int j = 0; j < m; j++) {           if (t[j] ==  L )             s[j][i] =  U ;           else if (t[j] ==  R )             s[j][i] =  D ;           else if (t[j] ==  U )             s[j][i] =  L ;           else             s[j][i] =  R ;         }       }       swap(n, m);     } else {       for (int i = 0; i < n; i++) scanf( %s , s[i]);     }     gao(ret1);     if (sw == 1) {       for (int i = 0; i < m; i++) {         scanf( %s , t);         for (int j = 0; j < n; j++) {           if (t[j] ==  L )             s[j][i] =  U ;           else if (t[j] ==  R )             s[j][i] =  D ;           else if (t[j] ==  U )             s[j][i] =  L ;           else             s[j][i] =  R ;         }       }     } else {       for (int i = 0; i < n; i++) scanf( %s , s[i]);     }     gao(ret2);     reverse((ret2).begin(), (ret2).end());     for (auto p : ret2) ret1.push_back(p);     if (sw) {       for (auto &p : ret1) swap(p.first, p.second);     }     printf( %d n , ((int)(ret1).size()));     for (auto p : ret1) printf( %d %d n , p.first + 1, p.second + 1);   }


#include <bits/stdc++.h>   const int N = 1e5 + 7;   long long n, m, A[N], sum[N], suf[N];   inline int read() {     int now = 0;     register char c = getchar();     for (; !isdigit(c); c = getchar())       ;     for (; isdigit(c); now = now * 10 + c -  0 , c = getchar())       ;     return now;   }   int main() {     n = read(), m = read();     for (int i = 1; i <= n; ++i) A[i] = read();     for (int i = 1; i <= n; i += 2)       sum[i + 1] = sum[i] = sum[i - 1] + A[i] - A[i - 1];     if (n & 1) {       for (int i = n - 1; i > 0; i -= 2)         suf[i - 1] = suf[i] = suf[i + 1] + A[i + 1] - A[i];     } else {       A[n + 1] = m;       for (int i = n; i > 0; i -= 2)         suf[i - 1] = suf[i] = suf[i + 1] + A[i + 1] - A[i];     }     long long ans = sum[n];     if (!(n & 1)) ans += m - A[n];     if (n & 1) A[++n] = m;     for (long long i = 1; i <= n; ++i)       if (A[i] - A[i - 1] > 1) {         if (i & 1)           ans =               std::max(ans, sum[i - 1] + A[i] - A[i - 1] - 1 + m - A[i] - suf[i]);         else           ans =               std::max(ans, sum[i - 1] + A[i] - A[i - 1] - 1 + m - A[i] - suf[i]);       }     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long oo = 1e18;   vector<int> dinh;   int nn;   long long n, m, k, kc[801][801];   vector<pair<long long, pair<long long, long long>>> e;   void compress() {     sort(dinh.begin(), dinh.end());     dinh.resize(unique(dinh.begin(), dinh.end()) - dinh.begin());     nn = dinh.size();     for (long long i = 0; i <= nn - 1; i++)       for (long long j = 0; j <= nn - 1; j++) kc[i][j] = oo;     for (long long i = 0; i <= nn - 1; i++) kc[i][i] = 0;     for (long long i = 0; i <= min(m, k) - 1; i++) {       long long first =           lower_bound(dinh.begin(), dinh.end(), e[i].second.first) - dinh.begin();       long long second =           lower_bound(dinh.begin(), dinh.end(), e[i].second.second) -           dinh.begin();       kc[first][second] = kc[second][first] = min(kc[first][second], e[i].first);     }   }   void floyd() {     for (long long k = 0; k <= nn - 1; k++)       for (long long first = 0; first <= nn - 1; first++)         for (long long second = 0; second <= nn - 1; second++)           kc[first][second] =               min(kc[first][second], kc[first][k] + kc[k][second]);   }   int main() {     cin >> n >> m >> k;     for (long long i = 0; i <= m - 1; i++) {       long long first, second, w;       cin >> first >> second >> w;       e.push_back({w, {first - 1, second - 1}});     }     sort(e.begin(), e.end());     for (long long i = 0; i <= min(m, k) - 1; i++) {       dinh.push_back(e[i].second.first);       dinh.push_back(e[i].second.second);     }     compress();     floyd();     vector<long long> res;     for (long long i = 0; i <= nn - 1; i++)       for (long long j = 0; j <= i - 1; j++) res.push_back(kc[i][j]);     sort(res.begin(), res.end());     cout << res[k - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 15;   struct Node {     int l, r;     bool operator<(const Node& b) const { return r != b.r ? r < b.r : l < b.l; }   };   unordered_map<int, vector<Node> > mp;   int sum[N];   int main() {     int n;     while (~scanf( %d , &n)) {       mp.clear();       for (int i = 1; i <= n; i++) {         scanf( %d , &sum[i]);         sum[i] += sum[i - 1];       }       for (int i = 1; i <= n; i++) {         for (int j = i; j <= n; j++) {           mp[sum[j] - sum[i - 1]].emplace_back(Node{i, j});         }       }       int ans = 0;       vector<Node> vec, vecAns;       for (auto ele : mp) {         sort(ele.second.begin(), ele.second.end());         vec.clear();         int sum = 0, r = 0;         for (auto seg : ele.second) {           if (seg.l > r) {             vec.emplace_back(Node{seg.l, seg.r});             r = seg.r;             sum++;           }         }         if (ans < sum) {           ans = sum;           vecAns = vec;         }       }       printf( %d n , ans);       for (auto ele : vecAns) {         printf( %d %d n , ele.l, ele.r);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     int sz = s.size();     s =  X  + s;     int k;     cin >> k;     int ans = 0;     for (int i = 1; i <= sz; i++) {       for (int len = 1; len <= 400; len++) {         if (i + 2 * len - 1 > sz + k) break;         bool can = true;         for (int l = i; l <= i + len - 1; l++) {           if (l > sz) break;           if (l + len <= sz) {             if (s[l] != s[l + len]) {               can = false;               break;             }           }         }         if (can) ans = max(ans, 2 * len);       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>      using namespace std;      #define ll long long int      void solve()   {       ll p,a,b,c;       cin >> p >> a >> b >> c;          ll ans = 1e18 + 1;       if(p%a != 0) ans = min(a - p%a, ans);       else ans = 0;       if(p%b != 0) ans = min(b - p%b, ans);       else ans = 0;       if(p%c != 0) ans = min(c - p%c, ans);       else ans = 0;              // if(ans == 1e18 + 1) ans = 0;          cout << ans << endl;   }      int main()   {       int t;       cin >> t;          while(t--) solve();          return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300 + 66;   const long long mod = 1e9 + 7;   int N, M, Q;   int a[maxn][maxn];   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= N; j++) {         scanf( %d , &a[i][j]);       }     }     scanf( %d , &Q);     int u, v, w;     while (Q--) {       scanf( %d %d %d , &u, &v, &w);       if (a[u][v] > w) {         a[u][v] = min(w, a[u][v]);         a[v][u] = min(w, a[u][v]);         for (int j = 1; j <= N; j++) {           for (int i = 1; i <= N; i++) {             a[i][j] = a[j][i] = min(a[j][i], a[j][u] + a[u][i]);           }         }         for (int j = 1; j <= N; j++) {           for (int i = 1; i <= N; i++) {             a[i][j] = a[j][i] = min(a[j][i], a[j][v] + a[v][i]);           }         }       }       long long s = 0;       for (int i = 1; i <= N; i++) {         for (int j = i + 1; j <= N; j++) {           s += a[i][j];         }       }       printf( %lld  , s);     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream& operator<<(ostream& os, vector<T> V) {     os <<  [  ;     for (auto v : V) os << v <<    ;     os <<  ] ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, set<T> second) {     os <<  {  ;     for (auto s : second) os << s <<    ;     return os <<  } ;   }   template <class T>   ostream& operator<<(ostream& os, multiset<T> second) {     os <<  {  ;     for (auto s : second) os << s <<    ;     return os <<  } ;   }   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   template <class L, class R>   ostream& operator<<(ostream& os, map<L, R> M) {     os <<  {  ;     for (auto m : M) os <<  (  << m.first <<  :  << m.second <<  )  ;     return os <<  } ;   }   template <class L, class R>   ostream& operator<<(ostream& os, unordered_map<L, R> M) {     os <<  {  ;     for (auto m : M) os <<  (  << m.first <<  :  << m.second <<  )  ;     return os <<  } ;   }   const long long N = 200010, M = 1e9 + 7;   long long n, a[N];   vector<long long> f[N], sol;   void solve() {     cin >> n;     for (long long i = 0; i < n; i++) cin >> a[i];     for (long long i = 0; i < n; i++) f[a[i]].push_back(i + 1);     sol = vector<long long>(0);     long long minus = 0;     for (long long i = 0; i < n; i++) {       long long h = i - minus;       while (h >= 0 && f[h].size() == 0) h -= 3, minus += 3;       if (h < 0) {         cout <<  Impossible n ;         return;       }       sol.push_back(f[h].back());       f[h].pop_back();     }     cout <<  Possible n ;     for (long long it : sol) cout << it <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long H;   int N, M, K;   long long A[100002], C[100002];   long long add[100002];   bool can[100002];   long long minget[10002];   set<pair<long long, int> > Q;   set<pair<int, int>, greater<pair<int, int> > > S;   int main() {     cin.sync_with_stdio(false);     cin >> H >> N >> M >> K;     for (int i = 0; i < K; ++i) minget[i] = 1LL << 62;     minget[0] = 0;     for (int i = 1; i <= N; ++i) {       cin >> C[i] >> A[i];       --C[i];       if (minget[C[i] % K] <= C[i]) {         S.insert(make_pair(A[i], -i));         can[i] = true;       }     }     for (int i = 1, type; i <= M; ++i) {       cin >> type;       if (type == 1) {         long long val;         cin >> val;         add[++add[0]] = val;         for (int j = 0; j < K; ++j) minget[j] = 1LL << 62;         minget[0] = 0;         Q.insert(make_pair(0, 0));         while (!Q.empty()) {           int now = (*Q.begin()).second;           Q.erase(Q.begin());           for (int j = 1; j <= add[0]; ++j)             if (minget[(now + add[j]) % K] > minget[now] + add[j]) {               minget[(now + add[j]) % K] = minget[now] + add[j];               Q.insert(make_pair(minget[(now + add[j]) % K], (now + add[j]) % K));             }         }         for (int j = 1; j <= N; ++j)           if (!can[j] && minget[C[j] % K] <= C[j]) {             S.insert(make_pair(A[j], -j));             can[j] = true;           }       } else if (type == 2) {         int pos, val;         cin >> pos >> val;         if (!can[pos])           A[pos] -= val;         else {           S.erase(S.find(make_pair(A[pos], -pos)));           A[pos] -= val;           S.insert(make_pair(A[pos], -pos));         }       } else if (type == 3) {         if (S.empty()) {           cout << 0 <<   n ;           continue;         }         cout << (*S.begin()).first <<   n ;         A[-(*S.begin()).second] = 0;         S.erase(S.begin());       }     }   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int n;     cin >> n;     vector<int> m(n), r(n);     unsigned long long lcm = 1;     for (int i = 0; i < n; ++i) {       cin >> m[i];       lcm *= m[i] / gcd(m[i], lcm);     }     for (int i = 0; i < n; ++i) cin >> r[i];     int ans = 0;     for (int d = 0; d < lcm; ++d) {       for (int i = 0; i < n; ++i)         if (d % m[i] == r[i]) {           ++ans;           break;         }     }     cout.setf(ios::fixed | ios::showpoint);     cout.precision(6);     cout << 1.0 * ans / lcm;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2147483647;   const double PI = 3.141592653589793;   const int N = 40005;   map<pair<int, int>, int> mapa;   int n, m, k, t, a, b, c, pocz[N], waste[N], r, i;   int main() {     scanf( %d %d %d %d , &n, &m, &k, &t);     for (i = 0; i < n; i++) waste[i] = 0;     mapa.clear();     while (k--) {       scanf( %d %d , &a, &b);       a--;       b--;       mapa[pair<int, int>(a, b)] = 1;       waste[a]++;     }     pocz[0] = 0;     for (i = 1; i < n; i++) pocz[i] = (pocz[i - 1] + m - waste[i - 1]) % 3;     while (t--) {       scanf( %d %d , &a, &b);       a--;       b--;       if (mapa.count(pair<int, int>(a, b)) > 0)         printf( Waste n );       else {         c = 0;         while (mapa.count(pair<int, int>(a, c)) > 0) c++;         r = pocz[a];         while (c != b) {           c++;           while (mapa.count(pair<int, int>(a, c)) > 0) c++;           r = (r + 1) % 3;         }         if (r == 0)           printf( Carrots n );         else if (r == 1)           printf( Kiwis n );         else           printf( Grapes n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long md = 1e9 + 7;   const int N = 100005;   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long fact[100003] = {1};   long long term(long long n, long long r) {     long long y = fact[n];     y = (y * power(fact[r], md - 2, md)) % md;     y = (y * power(fact[n - r], md - 2, md)) % md;     return y;   }   long long fun(long long x) {     long long val = 0;     for (int i = 0; i <= x / 2; i++) {       val = (val + term(x - i, i)) % md;     }     return val;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (int i = 1; i <= 100002; i++) {       fact[i] = (fact[i - 1] * i) % md;     }     string s;     cin >> s;     long long u = 0, n = 0;     long long ans = 1;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  u ) {         u++;       } else {         if (u != 0) {           long long val = fun(u);           ans = (ans * val) % md;         }         u = 0;       }       if (s[i] ==  n ) {         n++;       } else {         if (n != 0) {           long long val = fun(n);           ans = (ans * val) % md;         }         n = 0;       }       if (s[i] ==  w  || s[i] ==  m ) {         cout <<  0               <<   n ;         return 0;       }     }     if (u != 0) {       long long val = fun(u);       ans = (ans * val) % md;     } else if (n != 0) {       long long val = fun(n);       ans = (ans * val) % md;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[100020];   int len[3] = {0};   int num[100020];   void zhuanhuan(int x) {     if (x >= 3) {       len[2]++;     } else if (x == 2) {       len[1]++;     } else {       len[0]++;     }   }   int main() {     int n, kuan = 1;     scanf( %d , &n);     scanf( %*c );     for (int i = 0; i < n; i = i + 1) scanf( %c , &str[i]);     scanf( %*c );     for (int i = 0; i < n; i = i + 1) num[i] = str[i] -  0 ;     int kuanlen = 1;     for (int i = 1; i < n; i++) {       if (num[i] == num[i - 1]) {         kuanlen++;       } else {         kuan++;         zhuanhuan(kuanlen);         kuanlen = 1;       }     }     zhuanhuan(kuanlen);     if (len[2] > 0) {       printf( %d n , kuan + 2);     } else if (len[1] > 1) {       printf( %d n , kuan + 2);     } else {       if (len[1] == 1)         printf( %d n , kuan + 1);       else         printf( %d n , kuan);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   int main() {     int x, y;     long long int a, b;     cin >> x >> y >> a >> b;     int lcm = (x * y) / (gcd(x, y));     int ans = (b / lcm) - ((a - 1) / lcm);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string s[n + 1];     for (int i = 0; i < n; i++) {       cin >> s[i];     }     long long ans = 1;     for (int i = 0; i < m; i++) {       unordered_set<char> b;       for (int j = 0; j < n; j++) {         b.insert(s[j][i]);       }       ans = (ans * b.size()) % 1000000007;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int t;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> t;     while (t--) {       int a[3];       int b[3];       cin >> a[0] >> a[1] >> a[2];       cin >> b[0] >> b[1] >> b[2];       long long sum = 0;       int aux = 0;       for (int i = 2; i >= 0; i--) {         if (i == 2) {           for (int j : {1, 2, 0}) {             aux = min(a[i], b[j]);             if (i > j)               sum += aux * i * j;             else if (i < j)               sum -= aux * i * j;             a[i] -= aux;             b[j] -= aux;           }         } else if (i == 1) {           for (int j : {1, 0, 2}) {             aux = min(a[i], b[j]);             if (i > j)               sum += aux * i * j;             else if (i < j)               sum -= aux * i * j;             a[i] -= aux;             b[j] -= aux;           }         } else {           for (int j : {0, 1, 2}) {             aux = min(a[i], b[j]);             if (i > j)               sum += aux * i * j;             else if (i < j)               sum -= aux * i * j;             a[i] -= aux;             b[j] -= aux;           }         }       }       cout << sum <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long pw(long long b, long long p) {     if (!p) return 1;     long long sq = pw(b, p / 2);     sq *= sq;     if (p % 2) sq *= b;     return sq;   }   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long sd(long long x) { return x < 10 ? x : x % 10 + sd(x / 10); }   long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }   int n, xs, ys, xd, yd, dp[1010][1010];   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   bool isvalid(int x, int y) {     return (((y == 0 || y == n) && x <= n && x >= 0) ||             ((x == 0 || x == n) && y <= n && y >= 0));   }   int dfs(int x, int y) {     if (x == xd && y == yd) return 0;     if (!isvalid(x, y)) return 1 << 30;     int &ret = dp[x][y];     if (ret != -1) return ret;     ret = 1 << 30;     for (int i = 0; i < 4; ++i) ret = min(ret, dfs(x + dx[i], y + dy[i]) + 1);     return ret;   }   int main() {     cin >> n >> xs >> ys >> xd >> yd;     memset(dp, -1, sizeof dp);     cout << dfs(xs, ys);   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   vector<int> edge[100001];   int val[100001];   vector<int> ans[2];   void dfs(int i, int fi) {     if (val[i] != 0 && fi != val[i]) {       cout <<  -1 n ;       exit(0);     }     if (val[i] != 0 && fi == val[i]) {       return;     }     val[i] = fi;     ans[(fi + 1) / 2].push_back(i);     for (int j = 0; j < edge[i].size(); j++) {       dfs(edge[i][j], -fi);     }   }   int main() {     ios_base::sync_with_stdio(false);     if (fopen( cf688c.in ,  r )) {       freopen( cf688c.in ,  r , stdin);       freopen( cf688c.out ,  w , stdout);     }     cin >> N >> M;     for (int i = 0; i < M; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       edge[a].push_back(b);       edge[b].push_back(a);     }     for (int i = 0; i < N; i++) {       if (val[i] == 0) {         if (ans[0].size() == 0) {           dfs(i, -1);         } else {           dfs(i, 1);         }       }     }     if (ans[0].size() == 0 || ans[1].size() == 0) {       cout <<  -1 n ;       return 0;     }     cout << ans[0].size() <<   n ;     for (int i = 0; i < ans[0].size(); i++) {       cout << ans[0][i] + 1 <<    ;     }     cout <<   n ;     cout << ans[1].size() <<   n ;     for (int i = 0; i < ans[1].size(); i++) {       cout << ans[1][i] + 1 <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long n, s[1 << 10];   vector<long> v[1 << 10];   long spre, slim, found;   long trem, tail;   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> s[i];       for (int j = 0; j < 666; j++) v[i].push_back(0);     }     for (int j = 0; j < 666; j++) v[0].push_back(0);     for (int i = 1; i <= n; i++) {       v[i] = v[i - 1];       spre = s[i - 1];       slim = 0;       found = 0;       for (int j = 665; j >= 0; --j) {         if (found) break;         spre -= v[i][j];         for (int q = v[i][j] + 1; q <= 9 && found == 0; q++) {           trem = spre + q;           tail = s[i] - trem;           if (tail >= 0 && tail <= slim) {             v[i][j] = q;             for (int t = 665; t > j; t--) {               if (tail > 9) {                 v[i][t] = 9;                 tail -= 9;               } else {                 v[i][t] = tail;                 tail = 0;               }             }             found = 1;             v[i][j] = q;           }         }         slim += 9;       }     }     for (int i = 1; i <= n; i++) {       reverse(v[i].begin(), v[i].end());       while (v[i].size() > 1 && v[i].back() == 0) v[i].pop_back();       reverse(v[i].begin(), v[i].end());       for (int j = 0; j < v[i].size(); j++) {         cout << v[i][j];       }       cout << endl;     }     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   int main(void) {     int a, b, m, n, count = 0;     scanf( %d %d , &n, &m);     for (a = 0; a <= m; a++) {       for (b = 0; b <= n; b++) {         if (n - b != a * a) continue;         if (m - a != b * b) continue;         count++;         break;       }     }     printf( %d n , count);     return 0;   }


#include <bits/stdc++.h>   inline int pidorand() { return ((rand() & 32767) << 15) | (rand() & 32767); }   using namespace std;   inline int nxt() {     int x;     scanf( %d , &x);     return x;   }   using Point = pair<int, int>;   int mydiv(int first, int second) {     if (first % second == 0) {       return first / second;     } else {       return first / second - (first < 0);     }   }   Point convert(int first, int second) {     first += second;     second = first - 2 * second;     return {mydiv(first, 2), mydiv(second, 2)};   }   const int N = 111111;   int up_y[N + N], down_y[N + N];   int left_y[N + N], right_y[N + N];   int main() {     int n = nxt();     vector<Point> ppts[2];     for (int i = 0; i < n; ++i) {       int first = nxt(), second = nxt();       ppts[(abs(first) + abs(second)) % 2].push_back(convert(first, second));     }     for (int i = 0; i < 2; ++i) {       sort((ppts[i]).begin(), (ppts[i]).end());     }     long long ans = 0;     for (auto pts : ppts) {       for (int i = 0; i < N + N; ++i) {         left_y[i] = right_y[i] = -N;       }       for (auto pt : pts) {         left_y[pt.first + N] = max(left_y[pt.first + N], pt.second);         right_y[pt.first + N] = max(right_y[pt.first + N], pt.second);       }       for (int i = 1; i < N + N; ++i) {         left_y[i] = max(left_y[i], left_y[i - 1]);       }       for (int i = N + N - 2; i >= 0; --i) {         right_y[i] = max(right_y[i], right_y[i + 1]);       }       for (int i = 0; i < N + N; ++i) {         up_y[i] = min(left_y[i], right_y[i]);       }       for (int i = 0; i < N + N; ++i) {         left_y[i] = right_y[i] = N;       }       for (auto pt : pts) {         left_y[pt.first + N] = min(left_y[pt.first + N], pt.second);         right_y[pt.first + N] = min(right_y[pt.first + N], pt.second);       }       for (int i = 1; i < N + N; ++i) {         left_y[i] = min(left_y[i], left_y[i - 1]);       }       for (int i = N + N - 2; i >= 0; --i) {         right_y[i] = min(right_y[i], right_y[i + 1]);       }       for (int i = 0; i < N + N; ++i) {         down_y[i] = max(left_y[i], right_y[i]);       }       for (int i = 1; i < N + N; ++i) {         int l = max(down_y[i - 1], down_y[i]);         int r = min(up_y[i - 1], up_y[i]);         if (l >= r) {           continue;         }         ans += r - l;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   const int INF = (((1 << 30) - 1) << 1) + 1;   const int nINF = 1 << 31;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     double ans = 0;     pair<int, int> res;     for (int i = (n - 2); i >= (0); i--) {       int a = i, b = n - i;       if (a > b) continue;       if (gcd(a, b) == 1 && a / (double)b > ans) {         ans = a / (double)b;         res = {a, b};       }     }     cout << res.first <<     << res.second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int n, res, t;   int main() {     cin >> n >> s;     for (int i = 0; i < n; ++i) {       if (s[i] ==  x )         ++t;       else         t = 0;       if (t >= 3) ++res;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<string> v(n);       for (auto& i : v) cin >> i;       bool state = true;       for (int i = n - 2; i >= 0; i--) {         for (int j = n - 2; j >= 0; --j) {           if (v[i][j] ==  1  && v[i + 1][j] ==  0  && v[i][j + 1] ==  0 )             state = false;         }       }       if (state)         cout <<  Yes  <<   n ;       else         cout <<  No  <<   n ;     }   }