#include <bits/stdc++.h>   using namespace std;   vector<int> adj[1100];   int need[1100];   bool visit[1100];   vector<pair<int, int> > vec;   int exist[1100];   void bfs(int st) {     queue<pair<int, int> > q;     memset(visit, 0, sizeof visit);     q.push({st, 0});     while (!q.empty()) {       int u = q.front().first;       int c = q.front().second;       q.pop();       if (visit[u]) continue;       visit[u] = 1;       if (need[u]) vec.push_back({c, u});       for (auto v : adj[u])         if (!visit[v]) q.push({v, c + 1});     }     sort(vec.begin(), vec.end());   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 1; i <= n; ++i) adj[i].clear();       for (int i = 0; i < n - 1; ++i) {         int a, b;         scanf( %d%d , &a, &b);         adj[a].push_back(b);         adj[b].push_back(a);       }       int k;       scanf( %d , &k);       memset(need, 0, sizeof need);       for (int i = 0; i < k; ++i) {         int x;         scanf( %d , &x);         need[x] = 1;       }       scanf( %d , &k);       memset(exist, 0, sizeof exist);       int y;       for (int i = 0; i < k; ++i) {         scanf( %d , &y);         exist[y] = 1;       }       vec.clear();       cout <<  B   << y << endl;       int st;       cin >> st;       bfs(st);       cout <<  A   << vec[0].second << endl;       cin >> y;       if (exist[y])         cout <<  C   << vec[0].second << endl;       else         cout <<  C -1  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   pair<int, int> P[105];   int main() {     cin >> N;     for (int i = 1; i <= N; i++) cin >> P[i].first >> P[i].second;     int K;     cin >> K;     for (int i = 1; i <= N; i++)       if (K >= P[i].first && K <= P[i].second) {         cout << N - i + 1 <<   n ;         return 0;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   const long long int inf = 1e18;   long long int a[N];   long long int b[N];   long long int dp[N][3];   int main() {     int t;     cin >> t;     while (t--) {       int n;       scanf( %d , &n);       for (int i = 1; i <= n; i++) scanf( %lld %lld , &a[i], &b[i]);       dp[1][0] = 0;       dp[1][1] = b[1];       dp[1][2] = 2 * b[1];       for (int i = 2; i <= n; i++) {         dp[i][0] = dp[i][1] = dp[i][2] = inf;         for (int j = 0; j <= 2; j++) {           for (int k = 0; k <= 2; k++) {             if (a[i - 1] + j == a[i] + k) continue;             dp[i][k] = min(dp[i][k], dp[i - 1][j] + k * b[i]);           }         }       }       printf( %lld n , min(dp[n][0], min(dp[n][1], dp[n][2])));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e7 + 2;   const int M = (int)5e5 + 2;   const int mod = (int)1e9 + 7;   int mu[N], cnt[N];   int n, mx, x, p[M];   long long res;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (fopen( test                 .inp ,                r )) {       freopen(            test             .inp ,            r , stdin);       freopen(            test             .out ,            w , stdout);     }     cin >> n;     p[0] = 1;     for (int i = 1; i <= n; ++i) {       cin >> x;       mx = max(mx, x);       ++cnt[x];       p[i] = 2ll * p[i - 1] % mod;     }     mu[1] = 1;     fill(mu + 2, mu + mx + 1, -1);     int s;     for (int i = 2; i <= mx; ++i) {       s = cnt[i];       for (int j = 2 * i; j <= mx; j += i) mu[j] -= mu[i], s += cnt[j];       if (mu[i] != 0)         res = (res + 1ll * (p[s] - 1) * (-mu[i]) * (n - s) % mod) % mod;     }     res += mod;     cout << res % mod;   }


#include <bits/stdc++.h>   using namespace std;   unordered_map<string, int> M;   vector<string> WHAT;   vector<int> LEFT, RIGHT;   int check(int v, int place) {     vector<int> V = {v};     for (int i = 0; i < (int)WHAT.size(); i++) {       if (WHAT[i][0] ==  0  or WHAT[i][0] ==  1 )         V.push_back(WHAT[i][place] -  0 );       else {         int left = V[LEFT[i]], right = V[RIGHT[i]];         if (WHAT[i] ==  AND ) V.push_back(left & right);         if (WHAT[i] ==  OR ) V.push_back(left | right);         if (WHAT[i] ==  XOR ) V.push_back(left ^ right);       }     }     int sum = 0;     for (int i = 1; i < (int)V.size(); i++) sum += V[i];     return sum;   }   int main() {     ios_base::sync_with_stdio(0);     int n, m;     cin >> n >> m;     LEFT.resize(n);     RIGHT.resize(n);     for (int i = 0; i < n; i++) {       string var, bs, left, op, right;       cin >> var >> bs >> left;       M[var] = i + 1;       if (not(left[0] ==  0  or left[0] ==  1 )) {         cin >> op >> right;         int noleft = (left ==  ? ) ? 0 : M[left];         int noright = (right ==  ? ) ? 0 : M[right];         WHAT.push_back(op);         LEFT[i] = noleft;         RIGHT[i] = noright;       } else {         WHAT.push_back(left);       }     }     string resmin =   ;     string resmax =   ;     for (int i = 0; i < m; i++) {       int w0 = check(0, i);       int w1 = check(1, i);       if (w1 > w0)         resmax +=  1 ;       else         resmax +=  0 ;       if (w1 < w0)         resmin +=  1 ;       else         resmin +=  0 ;     }     cout << resmin <<   n  << resmax <<   n ;     return 0;   }


#include <bits/stdc++.h>   int main() {     const int N = 8;     std::string pokemons[] = { vaporeon ,  jolteon ,  flareon ,  espeon ,                                umbreon ,   leafeon ,  glaceon ,  sylveon };     int n;     scanf( %d n , &n);     std::string hidden;     std::cin >> hidden;     std::string output =   ;     for (int p = 0; p < N; p++) {       std::string current = pokemons[p];       if (current.size() != n) {         continue;       }       bool possible = 1;       for (int q = 0; q < n; q++) {         if (hidden[q] !=  .  && hidden[q] != current[q]) {           possible = 0;           break;         }       }       if (possible) {         output = current;         break;       }     }     std::cout << output << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n, m;     while (cin >> n >> m) {       long long a[100100], b[101000], p, x, i, j, mm, l, r, cc = 0, pp, y, m1,                                                             qq = 0;       l = 1;       r = n + 1;       while (l <= r) {         x = (l + r) / 2;         mm = 1;         pp = 0;         while (1) {           if (x / mm == 0) {             break;           }           pp += x / mm;           mm *= m;         }         if (n > pp)           l = x + 1;         else           r = x - 1;       }       cout << l <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, i, n = 0, j = 0;     cin >> a >> b;     int k = sqrt(a);     if (a == b) {       cout <<  infinity  << endl;     } else       ;     if (a != b) {       for (i = 1; i * i <= a; i++) {         if ((a - b) % i == 0 && i > b) n++;         if ((a - b) % i == 0 && (a - b) / i > b && i != (a - b) / i) n++;       }       cout << n << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 6e5 + 10;   int n, k, l[maxn][2];   int fa[maxn], sz[maxn];   string s;   int get_fa(int x) {     if (x == fa[x]) return x;     return fa[x] = get_fa(fa[x]);   }   int calc(int x) {     int y;     if (x <= k)       y = x + k;     else       y = x - k;     x = get_fa(x), y = get_fa(y);     if (x == 0 || y == 0) return sz[x + y];     return min(sz[x], sz[y]);   }   void merge_dis(int x, int y) {     x = get_fa(x);     y = get_fa(y);     if (y == 0) {       swap(x, y);     }     fa[y] = x;     if (x != 0) sz[x] += sz[y];   }   int main() {     scanf( %d%d , &n, &k);     cin >> s;     for (int i = 1; i <= (int)3e5; i++)       fa[i] = i, fa[i + k] = i + k, sz[i + k] = 1;     for (int i = 1, c; i <= k; i++) {       scanf( %d , &c);       for (int j = 0, x; j < c; j++) {         scanf( %d , &x);         if (l[x][0] == 0)           l[x][0] = i;         else           l[x][1] = i;       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       if (l[i][1] == 0) {         int x = l[i][0];         if (x) {           ans -= calc(x);           if (s[i - 1] ==  1 )             fa[get_fa(x + k)] = 0;           else             fa[get_fa(x)] = 0;           ans += calc(x);         }       } else {         int x = l[i][0], y = l[i][1];         if (s[i - 1] ==  1 ) {           if (get_fa(x) != get_fa(y)) {             ans -= calc(x);             ans -= calc(y);             merge_dis(x, y);             merge_dis(x + k, y + k);             ans += calc(x);           }         } else {           if (get_fa(x + k) != get_fa(y)) {             ans -= calc(x);             ans -= calc(y);             merge_dis(x + k, y);             merge_dis(x, y + k);             ans += calc(x);           }         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename t>   t in(t q) {     cin >> q;     return q;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  [ ;     for (int i = 0; i < ((int)(v).size()); ++i) {       os << v[i];       if (i != ((int)(v).size()) - 1) os <<  , ;     }     os <<  ] ;     return os;   }   template <typename T, typename S>   ostream &operator<<(ostream &os, const map<T, S> &v) {     for (auto it : v) os <<  (  << it.first <<  :  << it.second <<  ) ;     return os;   }   template <typename T, typename S>   ostream &operator<<(ostream &os, const pair<T, S> &v) {     os <<  (  << v.first <<  ,  << v.second <<  ) ;     return os;   }   const long double PI = acosl(-1);   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());   inline int rand(int l, int r) {     return uniform_int_distribution<int>(l, r)(rng);   }   inline long long rand(long long l, long long r) {     return uniform_int_distribution<long long>(l, r)(rng64);   }   using namespace std;   const int N = 200005, M = 1005;   const long long MOD = 1e9 + 7;   const int OO = 1e9;   int a[11][11];   void solve() {     int n;     cin >> n;     for (int i = 0; i <= n; i++) {       a[i][1] = 1;       a[1][i] = 1;     }     for (int i = 2; i <= n; i++) {       for (int j = 2; j <= n; j++) {         a[i][j] = a[i - 1][j];         a[i][j] += a[i][j - 1];       }     }     cout << a[n][n] <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (1LL << 21) + 10;   int N, T, len, Imakf, bits[MAXN];   long long a[MAXN], b[MAXN];   char tem[MAXN];   void fi(const char* tem) {     if (!strlen(tem)) return;     char A[50];     const char B[4] = { . ,  i ,  n , 0}, C[5] = { . ,  o ,  u ,  t , 0};     sprintf(A,  %s%s , tem, B);     freopen(A,  r , stdin);     sprintf(A,  %s%s , tem, C);     freopen(A,  w , stdout);   }   void fwt(long long* A, int type) {     for (int mid = 1; mid < len; mid <<= 1) {       for (int j = 0; j < len; j += (mid << 1)) {         for (int k = 0; k < mid; k++) {           A[j + k + mid] += type * A[j + k];         }       }     }   }   int main() {     fi(  );     scanf( %d , &N);     len = 1LL << N, Imakf = len - 1;     for (int i = 0; i < len; i++) bits[i] = bits[i >> 1] + (i & 1);     scanf( %s , tem);     for (int i = 0; i < len; i++)       a[i] = (long long)(tem[i] -  0 ) << ((long long)bits[i] << 1);     fwt(a, 1);     scanf( %s , tem);     for (int i = 0; i < len; i++)       b[i] = (long long)(tem[i] -  0 ) << ((long long)bits[i] << 1);     fwt(b, 1);     for (int i = 0; i < len; i++) b[i] = (b[i] * a[i]);     fwt(b, -1);     for (int i = 0; i < len; i++)       printf( %lld , ((long long)b[i] >> ((long long)bits[i] << 1)) & 3);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long r, m, n, x, y, a[5000005], b[5000005];   long long fb(long long i, long long j, long long p) {     if (p < b[i]) return i - 1;     if (p >= b[j]) return j;     long long mid = (i + j) / 2;     if (b[mid] >= p && b[mid + 1] < p) return mid;     if (b[mid] > p)       return fb(i, mid, p);     else       return fb(mid + 1, j, p);   }   long long fb2(long long i, long long j, long long p) {     if (p < a[i]) return i - 1;     if (p >= a[j]) return j;     long long mid = (i + j) / 2;     if (a[mid] >= p && a[mid + 1] < p) return mid;     if (a[mid] > p)       return fb2(i, mid, p);     else       return fb2(mid + 1, j, p);   }   int main() {     ios_base::sync_with_stdio(0);     long long k = 0, t = 0, z = 1e7, l = 0, i, j;     cin >> n >> x >> y >> t;     string s;     cin >> s;     z = 0;     for (i = n - 1; i >= 0; i--) {       l = l + x;       if (s[i] ==  w ) l = l + y;       l++;       b[z++] = l;       if (l > t) break;     }     l = 0;     for (i = 0; i < n; i++) {       if (s[i] ==  w ) l = l + y;       l++;       a[i] = l;       if (l > t) break;       l = l + x;     }     sort(a, a + i);     sort(b, b + z);     long long sa = i;     l = 0;     r = 0;     i = 0;     for (i = 0; i < sa; i++) {       l = a[i];       if (l > t) break;       m = t - l - i * x;       if (m > 0) {         j = fb(0, z - 1, m) + 1;         r = max(r, i + j + 1);       } else         r = max(r, i + 1);     }     for (i = 0; i < z; i++) b[i] += a[0];     for (i = 1; i < sa; i++) a[i] = a[i] - a[0] - x;     for (i = 0; i < z; i++) {       l = b[i];       if (l > t) break;       m = t - l - (i + 2) * x;       if (m > 0) {         j = fb2(1, sa - 1, m);         r = max(r, i + j + 2);       } else         r = max(r, i + 2);     }     r = min(r, n);     cout << r;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> graph[300005];   long long col[300005];   long long ans, r, b;   pair<long long, long long> dfs(long long x, long long p = -1) {     long long a1, b1;     a1 = 0;     b1 = 0;     if (col[x] == 1) a1++;     if (col[x] == 2) b1++;     for (long long i = 0; i < graph[x].size(); i++) {       if (graph[x][i] == p) continue;       auto temp = dfs(graph[x][i], x);       if (temp.first == r && temp.second == 0) ans++;       if (temp.first == 0 && temp.second == b) ans++;       a1 += temp.first;       b1 += temp.second;     }     return {a1, b1};   }   signed main() {     long long t, i, j, a, n, a1, a2, b1, b2;     cin >> n;     b = 0;     r = 0;     ans = 0;     for (i = 1; i <= n; i++) {       cin >> j;       col[i] = j;       if (j == 1) r++;       if (j == 2) b++;     }     for (i = 0; i < n - 1; i++) {       cin >> a1 >> b1;       graph[a1].push_back(b1);       graph[b1].push_back(a1);     }     dfs(1);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int t;   string s;   int main() {     cin >> t;     while (t--) {       cin >> s;       int n = s.size();       int ans = n + 1, l = 0, c[4] = {0};       for (int i = 0; i < n; i++) {         c[s[i] -  0 ]++;         while (c[1] > 0 && c[2] > 0 && c[3] > 0) {           ans = min(i - l + 1, ans);           c[s[l++] -  0 ]--;         }       }       if (ans == n + 1)         cout << 0 << endl;       else         cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       int n, Q;       cin >> n >> Q;       string s;       cin >> s;       vector<int> pre(n, 0);       pre[0] = s[0] ==  +  ? 1 : -1;       for (int i = 1; i < n; ++i) {         pre[i] = pre[i - 1] + (s[i] ==  +  ? 1 : -1) * ((i % 2) ? -1 : 1);       }       while (Q--) {         int l, r;         cin >> l >> r;         --l, --r;         int sum = pre[r] - (l ? pre[l - 1] : 0);         if (sum == 0) {           cout << 0;         } else if ((r - l + 1) % 2 == 1) {           cout << 1;         } else {           cout << 2;         }         cout <<   n ;       }     }   }


/** Micro Mezz Macro Flation -- Overheated Economy ., Last Update: Mar. 3th 2013 **/ //{      /** Header .. **/ //{   #define LOCAL      #include <functional>   #include <algorithm>   #include <iostream>   #include <fstream>   #include <sstream>   #include <iomanip>   #include <numeric>   #include <cstring>   #include <climits>   #include <cassert>   #include <cstdio>   #include <string>   #include <vector>   #include <bitset>   #include <queue>   #include <stack>   #include <cmath>   #include <ctime>   #include <list>   #include <set>   #include <map>      //#include <tr1/unordered_set>   //#include <tr1/unordered_map>   //#include <array>      using namespace std;      #define REP(i, n) for (int i=0;i<int(n);++i)   #define FOR(i, a, b) for (int i=int(a);i<int(b);++i)   #define DWN(i, b, a) for (int i=int(b-1);i>=int(a);--i)   #define REP_1(i, n) for (int i=1;i<=int(n);++i)   #define FOR_1(i, a, b) for (int i=int(a);i<=int(b);++i)   #define DWN_1(i, b, a) for (int i=int(b);i>=int(a);--i)   #define REP_C(i, n) for (int n____=int(n),i=0;i<n____;++i)   #define FOR_C(i, a, b) for (int b____=int(b),i=a;i<b____;++i)   #define DWN_C(i, b, a) for (int a____=int(a),i=b-1;i>=a____;--i)   #define REP_N(i, n) for (i=0;i<int(n);++i)   #define FOR_N(i, a, b) for (i=int(a);i<int(b);++i)   #define DWN_N(i, b, a) for (i=int(b-1);i>=int(a);--i)   #define REP_1_C(i, n) for (int n____=int(n),i=1;i<=n____;++i)   #define FOR_1_C(i, a, b) for (int b____=int(b),i=a;i<=b____;++i)   #define DWN_1_C(i, b, a) for (int a____=int(a),i=b;i>=a____;--i)   #define REP_1_N(i, n) for (i=1;i<=int(n);++i)   #define FOR_1_N(i, a, b) for (i=int(a);i<=int(b);++i)   #define DWN_1_N(i, b, a) for (i=int(b);i>=int(a);--i)   #define REP_C_N(i, n) for (int n____=(i=0,int(n));i<n____;++i)   #define FOR_C_N(i, a, b) for (int b____=(i=0,int(b);i<b____;++i)   #define DWN_C_N(i, b, a) for (int a____=(i=b-1,int(a));i>=a____;--i)   #define REP_1_C_N(i, n) for (int n____=(i=1,int(n));i<=n____;++i)   #define FOR_1_C_N(i, a, b) for (int b____=(i=1,int(b);i<=b____;++i)   #define DWN_1_C_N(i, b, a) for (int a____=(i=b,int(a));i>=a____;--i)      #define ECH(it, A) for (__typeof(A.begin()) it=A.begin(); it != A.end(); ++it)   #define REP_S(i, str) for (char*i=str;*i;++i)   #define REP_L(i, hd, nxt) for (int i=hd;i;i=nxt[i])   #define REP_G(i, u) REP_L(i,hd[u],suc)   #define DO(n) for ( int ____n ## __line__ = n; ____n ## __line__ -- ; )   #define REP_2(i, j, n, m) REP(i, n) REP(j, m)   #define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)   #define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l)   #define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l)   #define REP_4(i, j, k, ii, n, m, l, nn) REP(i, n) REP(j, m) REP(k, l) REP(ii, nn)   #define REP_4_1(i, j, k, ii, n, m, l, nn) REP_1(i, n) REP_1(j, m) REP_1(k, l) REP_1(ii, nn)      #define ALL(A) A.begin(), A.end()   #define LLA(A) A.rbegin(), A.rend()   #define CPY(A, B) memcpy(A, B, sizeof(A))   #define INS(A, P, B) A.insert(A.begin() + P, B)   #define ERS(A, P) A.erase(A.begin() + P)   #define BSC(A, x) (lower_bound(ALL(A), x) - A.begin())   #define CTN(T, x) (T.find(x) != T.end())   #define SZ(A) int((A).size())   #define PB push_back   #define MP(A, B) make_pair(A, B)   #define PTT pair<T, T>   #define fi first   #define se second      #define Rush for(int ____T=RD(); ____T--;)      #define Display(A, n, m) {                          REP(i, n){                                         REP(j, m) cout << A[i][j] <<    ;                  cout << endl;                    }                             }      #define Display_1(A, n, m) {            REP_1(i, n){                                     REP_1(j, m) cout << A[i][j] <<    ;          cout << endl;                    }                             }      #pragma comment(linker,  /STACK:36777216 )   //#pragma GCC optimize ( O2 )      string __file__(){       string res = __FILE__;       int r = SZ(res) - 1; while (res[r] !=   . ) --r;       int l = r - 1; while (res[l] !=     ) --l; ++l;       return res.substr(l, r-l);   }      void Exec(string a, string b, string c){       if (b.empty()) b = __file__();       string cmd = a +     + b +  .  + c;       system(cmd.c_str());   }      void Ruby(string file =   ){Exec( ruby , file,  rb );}   void Python(string file =   ){Exec( python , file,  py );}   void Haskell(string file =   ){Exec( runghc , file,  hs );}   void Pascal(string file =   ){Exec( pascal , file,  pas );}   void Ocaml(string file =   ){Exec( ocaml , file,  ml );}      typedef long long LL;   //typedef long double DB;   typedef double DB;   typedef unsigned UINT;   typedef unsigned long long ULL;      typedef vector<int> VI;   typedef vector<char> VC;   typedef vector<string> VS;   typedef vector<LL> VL;   typedef vector<DB> VF;   typedef set<int> SI;   typedef set<string> SS;   typedef map<int, int> MII;   typedef map<string, int> MSI;   typedef pair<int, int> PII;   typedef pair<LL, LL> PLL;   typedef vector<PII> VII;   typedef vector<VI> VVI;   typedef vector<VII> VVII;      template<class T> inline T& RD(T &);   template<class T> inline void OT(const T &);   //inline int RD(){int x; return RD(x);}   inline LL RD(){LL x; return RD(x);}   inline DB& RF(DB &);   inline DB RF(){DB x; return RF(x);}   inline char* RS(char *s);   inline char& RC(char &c);   inline char RC();   inline char& RC(char &c){scanf(  %c , &c); return c;}   inline char RC(){char c; return RC(c);}   //inline char& RC(char &c){c = getchar(); return c;}   //inline char RC(){return getchar();}      template<class T> inline T& RDD(T &x){       char c; for (c = getchar(); c <  - ; c = getchar());       if (c ==  - ){x =  0  - getchar(); for (c = getchar();  0  <= c && c <=  9 ; c = getchar()) x = x * 10 +  0  - c;}       else {x = c -  0 ; for (c = getchar();  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ;}       return x;   }      inline LL RDD(){LL x; return RDD(x);}      template<class T0, class T1> inline T0& RD(T0 &x0, T1 &x1){RD(x0), RD(x1); return x0;}   template<class T0, class T1, class T2> inline T0& RD(T0 &x0, T1 &x1, T2 &x2){RD(x0), RD(x1), RD(x2); return x0;}   template<class T0, class T1, class T2, class T3> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3){RD(x0), RD(x1), RD(x2), RD(x3); return x0;}   template<class T0, class T1, class T2, class T3, class T4> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0;}   template<class T0, class T1, class T2, class T3, class T4, class T5> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0;}   template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0;}   template<class T0, class T1> inline void OT(const T0 &x0, const T1 &x1){OT(x0), OT(x1);}   template<class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2){OT(x0), OT(x1), OT(x2);}   template<class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3){OT(x0), OT(x1), OT(x2), OT(x3);}   template<class T0, class T1, class T2, class T3, class T4> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}   template<class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}   template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}   inline char& RC(char &a, char &b){RC(a), RC(b); return a;}   inline char& RC(char &a, char &b, char &c){RC(a), RC(b), RC(c); return a;}   inline char& RC(char &a, char &b, char &c, char &d){RC(a), RC(b), RC(c), RC(d); return a;}   inline char& RC(char &a, char &b, char &c, char &d, char &e){RC(a), RC(b), RC(c), RC(d), RC(e); return a;}   inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f); return a;}   inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g); return a;}   inline DB& RF(DB &a, DB &b){RF(a), RF(b); return a;}   inline DB& RF(DB &a, DB &b, DB &c){RF(a), RF(b), RF(c); return a;}   inline DB& RF(DB &a, DB &b, DB &c, DB &d){RF(a), RF(b), RF(c), RF(d); return a;}   inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e){RF(a), RF(b), RF(c), RF(d), RF(e); return a;}   inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a;}   inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a;}   inline void RS(char *s1, char *s2){RS(s1), RS(s2);}   inline void RS(char *s1, char *s2, char *s3){RS(s1), RS(s2), RS(s3);}   template<class T0,class T1>inline void RDD(T0&a, T1&b){RDD(a),RDD(b);}   template<class T0,class T1,class T2>inline void RDD(T0&a, T1&b, T2&c){RDD(a),RDD(b),RDD(c);}      template<class T> inline void RST(T &A){memset(A, 0, sizeof(A));}   template<class T> inline void FLC(T &A, int x){memset(A, x, sizeof(A));}   template<class T> inline void CLR(T &A){A.clear();}      template<class T0, class T1> inline void RST(T0 &A0, T1 &A1){RST(A0), RST(A1);}   template<class T0, class T1, class T2> inline void RST(T0 &A0, T1 &A1, T2 &A2){RST(A0), RST(A1), RST(A2);}   template<class T0, class T1, class T2, class T3> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3){RST(A0), RST(A1), RST(A2), RST(A3);}   template<class T0, class T1, class T2, class T3, class T4> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);}   template<class T0, class T1, class T2, class T3, class T4, class T5> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);}   template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);}   template<class T0, class T1> inline void FLC(T0 &A0, T1 &A1, int x){FLC(A0, x), FLC(A1, x);}   template<class T0, class T1, class T2> inline void FLC(T0 &A0, T1 &A1, T2 &A2, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x);}   template<class T0, class T1, class T2, class T3> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x);}   template<class T0, class T1, class T2, class T3, class T4> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x);}   template<class T0, class T1, class T2, class T3, class T4, class T5> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x);}   template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x), FLC(A6, x);}   template<class T> inline void CLR(priority_queue<T, vector<T>, less<T> > &Q){while (!Q.empty()) Q.pop();}   template<class T> inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q){while (!Q.empty()) Q.pop();}   template<class T> inline void CLR(stack<T> &S){while (!S.empty()) S.pop();}         template<class T0, class T1> inline void CLR(T0 &A0, T1 &A1){CLR(A0), CLR(A1);}   template<class T0, class T1, class T2> inline void CLR(T0 &A0, T1 &A1, T2 &A2){CLR(A0), CLR(A1), CLR(A2);}   template<class T0, class T1, class T2, class T3> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3){CLR(A0), CLR(A1), CLR(A2), CLR(A3);}   template<class T0, class T1, class T2, class T3, class T4> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);}   template<class T0, class T1, class T2, class T3, class T4, class T5> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);}   template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);}   template<class T> inline void CLR(T &A, int n){REP(i, n) CLR(A[i]);}      template<class T> inline bool EPT(T &a){return a.empty();}   template<class T> inline T& SRT(T &A){sort(ALL(A)); return A;}   template<class T> inline T& RVS(T &A){reverse(ALL(A)); return A;}   template<class T> inline T& UNQ(T &A){A.resize(unique(ALL(SRT(A)))-A.begin());return A;}      template<class T, class C> inline T& SRT(T &A, C B){sort(ALL(A), B); return A;}      //}      /** Constant List .. **/ //{      const int MOD = int(1e9) + 7;   //int MOD = 99990001;   const int INF = 0x3f3f3f3f;   const LL INFF = 0x3f3f3f3f3f3f3f3fLL;   const DB EPS = 1e-9;   const DB OO = 1e20;   const DB PI = acos(-1.0); //M_PI;      const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, 1, 0, -1};      const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};   const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};      //}      /** Add On .. **/ //{   // <<=  0. Nichi Joo ., //{   template<class T> inline void checkMin(T &a,const T b){if (b<a) a=b;}   template<class T> inline void checkMax(T &a,const T b){if (a<b) a=b;}   template<class T> inline void checkMin(T &a, T &b, const T x){checkMin(a, x), checkMin(b, x);}   template<class T> inline void checkMax(T &a, T &b, const T x){checkMax(a, x), checkMax(b, x);}   template <class T, class C> inline void checkMin(T& a, const T b, C c){if (c(b,a)) a = b;}   template <class T, class C> inline void checkMax(T& a, const T b, C c){if (c(a,b)) a = b;}   template<class T> inline T min(T a, T b, T c){return min(min(a, b), c);}   template<class T> inline T max(T a, T b, T c){return max(max(a, b), c);}   template<class T> inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));}   template<class T> inline T max(T a, T b, T c, T d){return max(max(a, b), max(c, d));}   template<class T> inline T sqr(T a){return a*a;}   template<class T> inline T cub(T a){return a*a*a;}   inline int ceil(int x, int y){return (x - 1) / y + 1;}   inline int sgn(DB x){return x < -EPS ? -1 : x > EPS;}   inline int sgn(DB x, DB y){return sgn(x - y);}      inline DB cot(DB x){return (DB)1/tan(x);};   inline DB sec(DB x){return (DB)1/cos(x);};   inline DB csc(DB x){return (DB)1/sin(x);};      //}   // <<=  1. Bitwise Operation ., //{   namespace BO{      inline bool _1(int x, int i){return bool(x&1<<i);}   inline bool _1(LL x, int i){return bool(x&1LL<<i);}   inline LL _1(int i){return 1LL<<i;}   inline LL _U(int i){return _1(i) - 1;};      inline int reverse_bits(int x){       x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa);       x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc);       x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0);       x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00);       x = ((x >>16) & 0x0000ffff) | ((x <<16) & 0xffff0000);       return x;   }      inline LL reverse_bits(LL x){       x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL);       x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL);       x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL);       x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL);       x = ((x >>16) & 0x0000ffff0000ffffLL) | ((x <<16) & 0xffff0000ffff0000LL);       x = ((x >>32) & 0x00000000ffffffffLL) | ((x <<32) & 0xffffffff00000000LL);       return x;   }      template<class T> inline bool odd(T x){return x&1;}   template<class T> inline bool even(T x){return !odd(x);}   template<class T> inline T low_bit(T x) {return x & -x;}   template<class T> inline T high_bit(T x) {T p = low_bit(x);while (p != x) x -= p, p = low_bit(x);return p;}   template<class T> inline T cover_bit(T x){T p = 1; while (p < x) p <<= 1;return p;}   template<class T> inline int cover_idx(T x){int p = 0; while (_1(p) < x ) ++p; return p;}      inline int clz(int x){return __builtin_clz(x);}   inline int clz(LL x){return __builtin_clzll(x);}   inline int ctz(int x){return __builtin_ctz(x);}   inline int ctz(LL x){return __builtin_ctzll(x);}   inline int lg2(int x){return !x ? -1 : 31 - clz(x);}   inline int lg2(LL x){return !x ? -1 : 63 - clz(x);}   inline int low_idx(int x){return !x ? -1 : ctz(x);}   inline int low_idx(LL x){return !x ? -1 : ctz(x);}   inline int high_idx(int x){return lg2(x);}   inline int high_idx(LL x){return lg2(x);}   inline int parity(int x){return __builtin_parity(x);}   inline int parity(LL x){return __builtin_parityll(x);}   inline int count_bits(int x){return __builtin_popcount(x);}   inline int count_bits(LL x){return __builtin_popcountll(x);}      } using namespace BO;//}   // <<=  2. Number Theory .,//{   namespace NT{   inline LL __lcm(LL a, LL b){return a*b/__gcd(a,b);}   inline void INC(int &a, int b){a += b; if (a >= MOD) a -= MOD;}   inline int sum(int a, int b){a += b; if (a >= MOD) a -= MOD; return a;}   inline void DEC(int &a, int b){a -= b; if (a < 0) a += MOD;}   inline int dff(int a, int b){a -= b; if (a < 0) a  += MOD; return a;}   inline void MUL(int &a, int b){a = (LL)a * b % MOD;}   inline int pdt(int a, int b){return (LL)a * b % MOD;}      inline int sum(int a, int b, int c){return sum(sum(a, b), c);}   inline int sum(int a, int b, int c, int d){return sum(sum(a, b), sum(c, d));}   inline int pdt(int a, int b, int c){return pdt(pdt(a, b), c);}   inline int pdt(int a, int b, int c, int d){return pdt(pdt(pdt(a, b), c), d);}      inline int pow(int a, LL b){       int c(1); while (b){           if (b&1) MUL(c, a);           MUL(a, a), b >>= 1;       }       return c;   }      template<class T> inline T pow(T a, LL b){       T c(1); while (b){           if (b&1) c *= a;           a *= a, b >>= 1;       }       return c;   }      template<class T> inline T pow(T a, int b){       return pow(a, (LL)b);   }      inline int _I(int b){       int a = MOD, x1 = 0, x2 = 1, q;       while (true){           q = a / b, a %= b;           if (!a) return (x2 + MOD) % MOD;           DEC(x1, pdt(q, x2));              q = b / a, b %= a;           if (!b) return (x1 + MOD) % MOD;           DEC(x2, pdt(q, x1));       }   }      inline void DIV(int &a, int b){MUL(a, _I(b));}   inline int qtt(int a, int b){return pdt(a, _I(b));}      struct Int{       int val;          operator int() const{return val;}          Int(int val = 0):val(val){           //val %= MOD; if (val < 0) val += MOD;       }       inline Int& operator +=(const int& rhs){           INC(val, rhs);           return *this;       }       inline Int operator +(const int& rhs) const{           return sum(val, rhs);       }       inline Int& operator -=(const int& rhs){           DEC(val, rhs);           return *this;       }       inline Int operator -(const int& rhs) const{           return dff(val, rhs);       }       inline Int& operator *=(const int& rhs){           MUL(val, rhs);           return *this;       }       inline Int operator *(const int& rhs) const{           return pdt(val, rhs);       }       inline Int& operator /=(const int& rhs){           DIV(val, rhs);           return *this;       }       inline Int operator /(const int& rhs) const{           return qtt(val, rhs);       }   };      const int PMAX = 1;   VI P; bitset<PMAX> isP;   void sieve(){       FOR(i, 2, PMAX){           if (!isP[i]) P.PB(i);           for (int j=0;j<SZ(P)&&i*P[j]<PMAX;++j){               isP[i*P[j]]=1; if (!(i%P[j])) break;           }       }   }      inline int phi(int n){       int res = n; for (int i=2;sqr(i)<=n;++i) if (!(n%i)){           DEC(res, qtt(res, i));           do{n /= i;} while(!(n%i));       }       if (n != 1)           DEC(res, qtt(res, n));       return res;   }      } using namespace NT;//}   // <<=  7. Matrix Theory .,//{   namespace MT{          const int N = 100;       int n = 0;          typedef int rec;          struct matrix{           rec d[N][N];              void init(rec e = 0){RST(d); if(e) REP(i, n) d[i][i] = e;}           matrix(rec e = 0){init(e);}              matrix operator *(const matrix &rhs) const{               matrix res; //REP_3(i, j, k, n, n, n) res.d[i][j] += d[i][k] * rhs.d[k][j];               REP_2(i, j, n, n){                   LL tmp = 0; REP(k, n) tmp += (LL) d[i][k] * rhs.d[k][j];                   res.d[i][j] = tmp % MOD;               }               return res;           }              matrix& operator *=(const matrix& rhs){(*this) = (*this) * rhs;}              inline int res(){               int res = 0;               REP(i, n) INC(res, d[0][i]);               //REP_2(i, j, n, n) INC(res, d[i][j]);               return res;           }       };          /*inline matrix pow_sum(const matrix& a, LL nn){           if (nn == 1) return matrix(1);           matrix t; REP_2(i, j, n, n) t.d[i][j] = t.d[i][j+n] = a.d[i][j];           FOR_C(i, n, n*2) t.d[i][i] = 1; n <<= 1; t = pow(t, nn), n >>= 1;           REP_2(i, j, n, n) t.d[i][j] = t.d[i][j+n];           return t;       }*/          inline matrix pow_sum(const matrix& a, LL nn){           if (nn == 1) return matrix(1);           matrix t; REP_2(i, j, n, n) t.d[i][j] = a.d[i][j];           REP(i, n) t.d[i][i+n] = t.d[i+n][i+n] = 1; n <<= 1; t = pow(t, nn), n >>= 1;           REP_2(i, j, n, n) t.d[i][j] = t.d[i][j+n];           return t;       }          template<class T> T pow_sum(T a, LL nn){           int _n = n; n = 1; matrix t; t.d[0][0] = a;           t = pow_sum(t, nn), n = _n;           return t.d[0][0];       }      } //using namespace MT;//}   // <<=  8. Stringology .,//{   namespace SL{       namespace KMP{              void calc_pi(const char *P, int n, int *pi){               for (int i = 1, j = pi[0] = -1; i < n; ++i){                   while (j >= 0 && P[i] != P[j+1]) j = pi[j];                   if (P[i] == P[j+1]) ++j;                   pi[i] = j;               }               //REP(i, n) cout << pi[i] <<    ; cout << endl;           }              bool run(const char *T, int n, const char *P, int m, const int *pi){               for (int i = 0, j = -1; i < n; ++i){                   while (j >= 0 && T[i] != P[j+1]) j = pi[j];                   if (T[i] == P[j+1]) ++j;                   if (j == m - 1) return true;               }               return false;           }          } //using namespace KMP;          namespace Z{           void calc_z(const char *P, int n, int *z){                  z[0] = n;                  for (int i = 1, l = 0, r = 0; i < n; ++i){                   if (i > r){                       for(l = r = i; r < n && P[r] == P[r - l];) ++r;                       z[i] = r - l, --r;                   }                   else {                       if (z[i - l] < r - i + 1) z[i] = z[i - l];                       else {                           for (l = i;r < n && P[r] == P[r - l];) ++r;                           z[i] = r - l, --r;                       }                   }               }                  //REP(i, n) cout << z[i] <<    ; cout << endl;           }              int run(const char *T, int n, const char *P, int m, const int *z){                  int ex; REP_C_N(ex, min(n, m)) if (T[ex] != P[ex]) break;                  int res = ex == m;                  for (int i = 1, l = 0, r = 0; i < n; ++i){                   if (i > r){                       for (l = r = i; r < n && T[r] == P[r - l];) ++r;                       ex = r - l, --r;                   }                   else {                       if (z[i - l] < r - i + 1) ex = z[i - l];                       else {                           for (l = i; r < n && T[r] == P[r - l];) ++r;                           ex = r - l, --r;                       }                   }                   if (ex == m) ++res;               }                  return res;           }       } //using namespace Z;          void Manacher(char s[], int n, int p[]){           const int NN = 0;           static char ss[NN*2+2]; int nn = 2*n+2;           ss[0] =  $ , ss[nn-1] =  # , ss[nn] = 0;           REP(i, n) ss[i*2+1] = # , ss[i*2+2] = s[i];           int mx = 0, id = 0; FOR(i, 1, nn){               p[i] = mx > i ? min(p[2*id-i], mx - i) : 1;               while (ss[i+p[i]] == ss[i-p[i]]) ++p[i];               if (i + p[i] > mx) mx = i + p[i], id = i;           }       }      } //using namespace SL;//}   // <<=  9. Comutational Geometry .,//{   namespace CG{      struct Po; struct Line; struct Seg;      struct Po{       DB x, y; Po(DB _x=0, DB _y=0):x(_x), y(_y){}       friend istream& operator >>(istream& in, Po &p){return in >> p.x >> p.y;}       friend ostream& operator <<(ostream& out, Po p){return out <<  (  << p.x <<  ,   << p.y <<  ) ;}       bool operator ==(const Po& r)const{return !sgn(x-r.x) && !sgn(y-r.y);};       bool operator !=(const Po& r)const{return sgn(x-r.x) || sgn(y-r.y);}       Po operator +(const Po& r)const{return Po(x+r.x, y+r.y);}       Po operator -(const Po& r)const{return Po(x-r.x, y-r.y);}       Po operator *(DB k)const{return Po(x*k,y*k);}       Po operator /(DB k)const{return Po(x/k,y/k);}       DB operator *(const Po&) const;       DB operator ^(const Po&) const;          bool operator <(const Po &r) const{return sgn(x,r.x)<0||!sgn(x,r.x)&&sgn(y,r.y)<0;}       Po operator -()const{return Po(-x,-y);}       Po& operator +=(const Po &r){x+=r.x,y+=r.y;return *this;}       Po& operator -=(const Po &r){x-=r.x,y-=r.y;return *this;}       Po& operator *=(DB k){x*=k,y*=k;return*this;}       Po& operator /=(DB k){x/=k,y/=k;return*this;}          DB length_sqr()const{return sqr(x)+sqr(y);}       DB length()const{return sqrt(length_sqr());}       Po unit()const{return *this/length();}       bool dgt()const{return !sgn(x)&&!sgn(y);}       DB atan()const{return atan2(y,x);}       void rotate(DB alpha, const Po& o = Po()){           x -= o.x, y -= o.y;           (*this) = Po(x * cos(alpha) - y * sin(alpha), y * cos(alpha) + x * sin(alpha)) + o;       }          void input(){RF(x,y);}   };      Po operator *(DB k, Po a){return a * k;}      #define innerProduct dot   #define scalarProduct dot   #define outerProduct det   #define crossProduct det      inline DB dot(const DB &x1, const DB &y1, const DB &x2, const DB &y2){return x1 * x2 + y1 * y2;}   inline DB dot(const Po &a, const Po &b){return dot(a.x, a.y, b.x, b.y);}   inline DB dot(const Po &p0, const Po &p1, const Po &p2){return dot(p1 - p0, p2 - p0);}      inline DB det(const DB &x1, const DB &y1, const DB &x2, const DB &y2){return x1 * y2 - x2 * y1;}   inline DB det(const Po &a, const Po &b){return det(a.x, a.y, b.x, b.y);}   inline DB det(const Po &p0, const Po &p1, const Po &p2){return det(p1 - p0, p2 - p0);}      template<class T1, class T2> inline int dett(const T1 &x, const T2 &y){return sgn(det(x, y));}   template<class T1, class T2> inline int dott(const T1 &x, const T2 &y){return sgn(dot(x, y));}   template<class T1, class T2, class T3> inline int dett(const T1 &x, const T2 &y, const T3 &z){return sgn(det(x, y, z));}   template<class T1, class T2, class T3> inline int dott(const T1 &x, const T2 &y, const T3 &z){return sgn(dot(x, y, z));}   template<class T1, class T2, class T3, class T4> inline int dett(const T1 &x, const T2 &y, const T3 &z, const T4 &w){return sgn(det(x, y, z, w));}   template<class T1, class T2, class T3, class T4> inline int dott(const T1 &x, const T2 &y, const T3 &z, const T4 &w){return sgn(dot(x, y, z, w));}            inline int dist_sqr(const int &x1, const int &y1, const int &x2, const int &y2){       return sqr(x2-x1) + sqr(y2-y1);   }      inline DB dist_sqr(const DB &x, const DB &y){return sqr(x) + sqr(y);}   inline DB dist_sqr(const DB &x, const DB &y, const DB &z){return sqr(x) + sqr(y) + sqr(z);}   inline DB dist_sqr(const Po &a, const Po &b){return sqr(a.x - b.x) + sqr(a.y - b.y);}      template<class T1, class T2> inline DB dist(const T1 &x, const T2 &y){return sqrt(dist_sqr(x, y));}   template<class T1, class T2, class T3> inline DB dist(const T1 &x, const T2 &y, const T3 &z){return sqrt(dist_sqr(x, y, z));}      DB Po::operator *(const Po &r)const{return dot(*this, r);}   DB Po::operator ^(const Po &r)const{return det(*this, r);}      struct Line{       Po a, b;          Line(DB x0=0, DB y0=0, DB x1=0, DB y1=0):a(Po(x0, y0)), b(Po(x1, y1)){}       Line(const Po &a, const Po &b):a(a), b(b){}       Line(const Line &l):a(l.a), b(l.b){}          friend ostream& operator <<(ostream& out, Line p){return out << p.a <<  -  << p.b;}       Line operator +(Po x)const{return Line(a + x, b + x);}       DB length()const{return (b-a).length();}       bool dgt()const{return (b-a).dgt();}       void input(){a.input(), b.input();}          int side(const Po& p){return dett(a, b, p);}       bool same_side(const Po& p1, const Po& p2){return side(p1) == side(p2);}       void getequation(DB& A, DB& B, DB& C) const{A = a.y - b.y, B = b.x - a.x, C = det(a, b);}   };      struct Seg: Line{   };      inline DB dot(const Line &l1, const Line &l2){return dot(l1.b - l1.a, l2.b - l2.a);}   inline DB det(const Line &l1, const Line &l2){return det(l1.b - l1.a, l2.b - l2.a);}      inline DB dist_sqr(const Po &p, const Line &l){Po v0 = l.b - l.a, v1 = p - l.a; return sqr(fabs(det(v0, v1))) / v0.length_sqr();}   inline DB dist_sqr(const Po &p, const Seg &l){       Po v0 = l.b - l.a, v1 = p - l.a, v2 = p - l.b;       if (sgn(dot(v0, v1)) * sgn(dot(v0, v2)) <= 0) return dist_sqr(p, Line(l));       else return min(v1.length_sqr(), v2.length_sqr());   }   inline DB dist_sqr(Line l, Po p){return dist_sqr(p, l);}   inline DB dist_sqr(Seg l, Po p){return dist_sqr(p, l);}   inline DB dist_sqr(Line l1, Line l2){       if (sgn(det(l1, l2)) != 0) return 0;       return dist_sqr(l1.a, l2);   }   inline DB dist_sqr(Line l1, Seg l2){       Po v0 = l1.b - l1.a, v1 = l2.a - l1.a, v2 = l2.b - l1.a; DB c1 = det(v0, v1), c2 = det(v0, v2);       return sgn(c1) != sgn(c2) ? 0 : sqr(min(fabs(c1), fabs(c2))) / v0.length_sqr();   }      bool isIntersect(Seg l1, Seg l2){          if (l1.a == l2.a || l1.a == l2.b || l1.b == l2.a || l1.b == l2.b) return true;          return           min(l1.a.x, l1.b.x) <= max(l2.a.x, l2.b.x) &&           min(l2.a.x, l2.b.x) <= max(l1.a.x, l1.b.x) &&           min(l1.a.y, l1.b.y) <= max(l2.a.y, l2.b.y) &&           min(l2.a.y, l2.b.y) <= max(l1.a.y, l1.b.y) &&       sgn( det(l1.a, l2.a, l2.b) ) * sgn( det(l1.b, l2.a, l2.b) ) <= 0 &&       sgn( det(l2.a, l1.a, l1.b) ) * sgn( det(l2.b, l1.a, l1.b) ) <= 0;      }      inline DB dist_sqr(Seg l1, Seg l2){       if (isIntersect(l1, l2)) return 0;       else return min(dist_sqr(l1.a, l2), dist_sqr(l1.b, l2), dist_sqr(l2.a, l1), dist_sqr(l2.b, l1));   }      inline bool isOnSide(const Po &p, const Seg &l){       return p == l.a || p == l.b;   }      inline bool isOnSeg(const Po &p, const Seg &l){       return sgn(det(p, l.a, l.b)) == 0 &&           sgn(l.a.x, p.x) * sgn(l.b.x, p.x) <= 0 && sgn(l.a.y, p.y) * sgn(l.b.y, p.y) <= 0;   }      inline bool isOnSegg(const Po &p, const Seg &l){       return sgn(det(p, l.a, l.b)) == 0 &&           sgn(l.a.x, p.x) * sgn(l.b.x, p.x) < 0 && sgn(l.a.y, p.y) * sgn(l.b.y, p.y) < 0;   }      inline Po intersect(const Line &l1, const Line &l2){       return l1.a + (l1.b - l1.a) * (det(l2.a, l1.a, l2.b) / det(l2, l1));   }      // perpendicular foot   inline Po intersect(const Po & p, const Line &l){       return intersect(Line(p, p + Po(l.a.y - l.b.y, l.b.x - l.a.x)), l);   }      inline Po rotate(Po p, DB alpha, const Po &o = Po()){       p.rotate(alpha, o);       return p;   }      } using namespace CG;//}   //}      template<class T> int LIS(int n, T* a){       VI b; b.PB(a[0]); FOR(i, 1, n){           if (b.back() < a[i]) b.PB(a[i]);           else {               b[lower_bound(ALL(b), a[i]) - b.begin()] = a[i];           }       }       return SZ(b);   }      template<class T, class C> int LIS(int n, T* a, C cmp){       vector<T> b; b.PB(a[0]); FOR(i, 1, n){           if (cmp(b.back(), a[i])) b.PB(a[i]);           else {               b[lower_bound(ALL(b), a[i], cmp) - b.begin()] = a[i];           }       }       return SZ(b);   }         template<class T> int LISS(int n, T* a, int* pre, int& lst){       VI b; b.PB(0); pre[0] = -1; FOR(i, 1, n){           if (a[b.back()] < a[i]) pre[i] = b.back(), b.PB(i);           else {               int l = 0, r = SZ(b); while (l < r){                   int m = l + r >> 1;                   if (a[b[m]] < a[i]) l = m + 1;                   else r = m;               }               pre[i] = !r ? -1 : b[r-1];               b[r] = i;           }       }       lst = b.back();       return SZ(b);   }      template<class T, class C> int LISS(int n, T* a, int* pre, int& lst, C cmp){       VI b; b.PB(0); pre[0] = -1; FOR(i, 1, n){           if (cmp(a[b.back()], a[i])) pre[i] = b.back(), b.PB(i);           else {               int l = 0, r = SZ(b); while (l < r){                   int m = l + r >> 1;                   if (cmp(a[b[m]], a[i])) l = m + 1;                   else r = m;               }               pre[i] = !r ? -1 : b[r-1];               b[r] = i;           }       }          lst = b.back();       return SZ(b);   }      /** Miscellaneous .. **/ //{   // <<=  Random Event .. . //{   namespace RNG{   //srand((unsigned)time(NULL));   inline unsigned int rand16(){return ((rand()) << 15) ^ rand();}   inline unsigned int rand32(){return (rand16() << 16) | rand16();}   inline ULL rand64(){return ((LL)rand32() << 32) | rand32();}   inline ULL random(LL l, LL r){return l == r ? l : rand64() % (r - l) + l;}   int dice(){return rand() % 6;}   bool coin(){return bool(rand() % 2);}   } using namespace RNG;   //}   // <<=  Clock .. . //{   namespace CLOCK{   DB s0, s1, rd, k, T;   inline DB getTime(){   #ifdef LOCAL       return 1.0 * clock() / CLOCKS_PER_SEC;   #else       timeval tv;       gettimeofday(&tv, 0);       return tv.tv_sec + tv.tv_usec * 1e-6;   #endif   }      inline void st0(DB _T = 0.98){T = _T, s0 = getTime();}   inline void st1(DB _k = 1.618){k = _k, s1 = getTime();}   inline void ed1(){rd = getTime() - s1;}   inline DB elapsed(){return getTime() - s0;}   inline bool TLE(){return elapsed() + rd * k < T;}   } //using namespace CLOCK;   //}   // <<=  Temp .. . //{   namespace TMP{   template<class T> PTT operator+(const PTT &p1, const PTT &p2) {    return PTT(p1.fi + p2.fi, p1.se + p2.se);   }      template<class T> PTT operator-(const PTT &p1, const PTT &p2) {    return PTT(p1.fi - p2.fi, p1.se - p2.se);   }      template<class T> PTT operator*(const PTT &lhs, T k){       return PTT(lhs.fi * k, lhs.se * k);   }   } using namespace TMP;   //}   // <<=  Bignum ., //{   namespace BIGNUM{      const int __base = 1e8;   const int P10[] = {1, 10, int(1e2), int(1e3), int(1e4), int(1e5), int(1e6), int(1e7), int(1e8), int(1e9)};   const int MAX_BUF_SIZE = 109;   char __buf[MAX_BUF_SIZE];      class bignum{             friend istream& operator>>(istream&, bignum&);             friend ostream& operator<<(ostream&, const bignum&);             friend bignum operator +(const bignum&, const bignum&);             friend bignum operator -(const bignum&, const bignum&);             friend bignum operator *(const bignum&, const bignum&);             friend bignum operator /(const bignum&, const bignum&);             friend bignum operator %(const bignum&, const bignum&);             friend bignum operator +(const bignum&, const int&);             friend bignum operator -(const bignum&, const int&);             friend bignum operator *(const bignum&, const int&);             friend bignum operator /(const bignum&, const int&);             friend bignum operator %(const bignum&, const int&);             friend bool operator ==(const bignum&, const bignum&);             friend bool operator !=(const bignum&, const bignum&);             friend bool operator <(const bignum&, const bignum&);             friend bool operator >(const bignum&, const bignum&);             friend bool operator <=(const bignum&, const bignum&);             friend bool operator >=(const bignum&, const bignum&);             friend bool operator ==(const bignum&, const int&);             friend bool operator !=(const bignum&, const int&);             friend bool operator <(const bignum&, const int&);             friend bool operator >(const bignum&, const int&);             friend bool operator <=(const bignum&, const int&);             friend bool operator >=(const bignum&, const int&);             friend int do_comp(const bignum&, const int&);             friend int do_comp(const bignum&, const bignum&);             friend void divide(const bignum&, const bignum&, bignum&, bignum&);             friend bignum pow(bignum, int);             friend bignum pow(int, int);       public:           inline bignum(){};           inline bignum(int s){               while (s) data.PB(s%__base), s/=__base;               if (data.empty()) data.PB(0);           }              inline bignum(long long s){               while (s) data.PB(int(s%__base)), s/=__base;               if (data.empty()) data.PB(0);           }              inline bignum(string s){               int t, i; CLR(data);               for (i=int(s.size())-8;i>0;i-=8){                   istringstream(s.substr(i, 8)) >> t;                   data.PB(t);               }               istringstream(s.substr(0, i+8)) >> t;               data.PB(t);           }              void input(){               CLR(data); RS(__buf); int t = 0, c = 0;               DWN(i, strlen(__buf), 0){                   t += P10[c] * (int(__buf[i]) -  0 ), ++c;                   if (c == 8) data.PB(t), c = t = 0;               }               if (c) data.PB(t);           }              void operator =(const int);           void operator =(const string);           void operator =(const bignum);           bignum& operator +=(const bignum&);           bignum& operator -=(const bignum&);           bignum& operator *=(const bignum&);           bignum& operator /=(const bignum&);           bignum& operator %=(const bignum&);           bignum& operator +=(const int&);           bignum& operator -=(const int&);           bignum& operator *=(const int&);           bignum& operator /=(const int&);           bignum& operator %=(const int&);           bool undefined();           int do_try(const int&);           int do_try(const bignum&);           void do_trim();           list<int> data;          int size(){           list<int>::iterator it; int res = 0;           for (it=data.begin(); it!=data.end();it++)               res += 8;           it--;           if (*it >= 10000) {               if ( (*it) >= 1000000) {if (*it >=10000000) ; else res--;}               else {if ((*it) >= 100000) res-=2; else res-=3;}           }           else               if ( (*it) >= 100) {if (*it >=1000) res-=4; else res-=5;}               else {if ((*it) >= 10) res-=6; else res-=7;}              return res;       }          void do_reserve(int a){           if (a <= 0) return;           list<int>::iterator it;           for (it=data.begin(); it!=data.end() && a>0; it++) a-=8;           if (it == data.end() && a>=0) return;           a+=8, it--; int f = 1;           for (int i=0;i<a;i++) f *= 10; (*it) %= f;           data.erase(++it, data.end());           do_trim();       }   };      inline void bignum::operator =(const bignum a){       data.clear();       for (list<int>::const_iterator i=a.data.begin();i!=a.data.end();i++){           data.PB(*i);       }   }   inline void bignum::operator =(const string a){       (*this) = bignum(a);   }   inline void bignum::operator =(const int a){       (*this) = bignum(a);   }      inline istream& operator>>(istream& input, bignum& a){       string s; int t, i; input >> s; a.data.clear();       for (i=int(s.size())-8;i>0;i-=8){           istringstream(s.substr(i, 8)) >> t;           a.data.PB(t);       }       istringstream(s.substr(0, i+8)) >> t;       a.data.PB(t);       return input;   }      inline ostream& operator<<(ostream& output, const bignum& a){       list<int>::const_reverse_iterator i=a.data.rbegin();       output << *i;       for (i++;i!=a.data.rend();i++){           if (*i >= 10000) {               if (*i >= 1000000) {if (*i>=10000000) cout << *i; else cout << 0 << *i;}               else {if (*i>=100000) cout <<  00  << *i; else cout <<  000  << *i;}           }           else {               if (*i >= 100) {if (*i>=1000)  cout <<  0000  << *i; else cout <<  00000  << *i;}               else { if (*i>=10) cout <<  000000  << *i; else cout <<  0000000  << *i;}           }       }       return output;   }      inline bool bignum::undefined(){       return data.empty();   }      inline int do_comp(const bignum& a, const bignum& b){       if (a.data.size()<b.data.size()) return -1; if (a.data.size()>b.data.size()) return 1;       list<int>::const_reverse_iterator i; list<int>::const_reverse_iterator j;       for (i=a.data.rbegin(),j=b.data.rbegin(); j!=b.data.rend(); i++,j++){           if (*i<*j) return -1;              //!!!!           if (*i>*j) return 1;       }       return 0;   }   inline int do_comp(const bignum& a, const int& b){       return do_comp(a, bignum(b));   }      inline bool operator ==(const bignum& a, const bignum& b){       return do_comp(a, b) == 0;   }   inline bool operator !=(const bignum& a, const bignum& b){       return do_comp(a, b) != 0;   }   inline bool operator <(const bignum& a, const bignum& b){       return do_comp(a, b) == -1;   }   inline bool operator >(const bignum& a, const bignum& b){       return do_comp(a, b) == 1;   }   inline bool operator <=(const bignum& a, const bignum& b){       return do_comp(a, b) != 1;   }   inline bool operator >=(const bignum& a, const bignum& b){       return do_comp(a, b) != -1;   }      inline bool operator ==(const bignum& a, const int& b){       return do_comp(a, b) == 0;   }   inline bool operator !=(const bignum& a, const int& b){       return do_comp(a, b) != 0;   }   inline bool operator <(const bignum& a, const int& b){       return do_comp(a, b) == -1;   }   inline bool operator >(const bignum& a, const int& b){       return do_comp(a, b) == 1;   }   inline bool operator <=(const bignum& a, const int& b){       return do_comp(a, b) != 1;   }   inline bool operator >=(const bignum& a, const int& b){       return do_comp(a, b) != -1;   }      inline void bignum::do_trim(){       while (data.size()>1&&data.back()==0) data.pop_back();   }      inline bignum& bignum::operator +=(const bignum& a){       list<int>::iterator i; list<int>::const_iterator j; int t = 0;       for (i=data.begin(),j=a.data.begin(); i!=data.end()&&j!=a.data.end(); i++,j++){           *i+=*j+t; t=*i/__base; *i%=__base;       }       while (i!=data.end()) {*i+=t; t=*i/__base; *i%=__base; i++;}       while (j!=a.data.end()) {data.PB(t+*j); t=data.back()/__base; data.back()%=__base; j++;}       if (t!=0) data.PB(t);       return *this;   }      inline bignum& bignum::operator -=(const bignum& a){       list<int>::iterator i; list<int>::const_iterator j; int t = 0;       for (i=data.begin(),j=a.data.begin(); j!=a.data.end(); i++,j++){           *i -= t+*j; if (*i>=0) t=0; else *i+=__base, t=1;       }       while (i!=data.end()) {*i-=t; if (*i>=0) t=0;else *i+=__base, t=1; i++;}       (*this).do_trim();       return *this;   }      inline bignum& bignum::operator +=(const int& a){       return (*this)+=bignum(a);   }      inline bignum& bignum::operator -=(const int& a){       return (*this)-=bignum(a);   }      inline bignum operator +(const bignum& a, const bignum& b){       list<int>::const_iterator i, j; bignum c; int t = 0;       for (i=a.data.begin(),j=b.data.begin(); i!=a.data.end()&&j!=b.data.end(); i++,j++){           c.data.PB(t+*i+*j);           t=c.data.back()/__base; c.data.back()%=__base;       }       while (i!=a.data.end()) {c.data.PB(t+*i); t=c.data.back()/__base; c.data.back()%=__base; i++;}       while (j!=b.data.end()) {c.data.PB(t+*j); t=c.data.back()/__base; c.data.back()%=__base; j++;}       if (t!=0) c.data.PB(t);       return c;   }      inline bignum operator -(const bignum& a, const bignum& b){       list<int>::const_iterator i, j; bignum c; int t = 0;       for (i=a.data.begin(),j=b.data.begin(); j!=b.data.end(); i++,j++){           t = *i - t;           if (t>=*j) c.data.PB(t-*j), t=0;           else c.data.PB(t+__base-*j), t=1;       }       while (i!=a.data.end()) {t=*i-t; if (t>=0) c.data.PB(t), t=0;else c.data.PB(t+__base), t=1; i++;}       c.do_trim();       return c;   }      inline bignum operator *(const bignum& a, const bignum& b){       list<int>::const_iterator i, j; list<int>::iterator k, kk; bignum c; long long t = 0;          for (int i=0;i<a.data.size()+b.data.size();i++) c.data.PB(0);       for (i=a.data.begin(),k=c.data.begin(); i!=a.data.end(); i++,k++){           for (j=b.data.begin(),kk=k; j!=b.data.end(); j++,kk++){               t+=(long long)(*i)*(*j)+(*kk);               *kk=int(t%__base); t/=__base;           }           *kk+=t; t=0;       }       c.do_trim();       return c;   }      inline int bignum::do_try(const bignum& a){       int l = 1, r = 99999999, m, t;       while (l+2<r){           m = (l + r) / 2;           t = do_comp(*this, a*bignum(m));           if (t==0) return m;           if (t<0) r = m - 1;           else l = m;       }       while (do_comp(*this, a*bignum(r))<0) r--;       return r;   }      inline void divide(const bignum& a, const bignum& b, bignum& d, bignum& r){       list<int>::const_reverse_iterator i = a.data.rbegin(); int t;       d = bignum(0); r = bignum(0);       do {           while (r<b&&i!=a.data.rend()){d.data.push_front(0);r.data.push_front(*i);r.do_trim();i++;}           if (r>=b){               t = r.do_try(b); d.data.front() = t;               r-=(b*bignum(t));           }       } while (i!=a.data.rend());       d.do_trim();   }      inline bignum operator /(const bignum& a, const bignum& b){       bignum d, r;       divide(a, b, d, r);       return d;   }      inline bignum operator %(const bignum& a, const bignum& b){       bignum d, r;       divide(a, b, d, r);       return r;   }      inline bignum operator +(const bignum& a, const int& b){       return a+bignum(b);   }      inline bignum operator -(const bignum& a, const int& b){       return a-bignum(b);   }      inline bignum operator *(const bignum& a, const int& b){       return a*bignum(b);   }      inline bignum operator /(const bignum& a, const int& b){       return a/bignum(b);   }      inline bignum operator %(const bignum& a, const int& b){       return a%bignum(b);   }      inline bignum& bignum::operator *=(const bignum& a){       (*this) = (*this) * a;       return *this;   }      inline bignum& bignum::operator /=(const bignum& a){       (*this) = (*this) / a;       return *this;   }      inline bignum& bignum::operator %=(const bignum& a){       (*this) = (*this) % a;       return *this;   }      inline bignum& bignum::operator *=(const int& a){       return (*this)*=bignum(a);   }      inline bignum& bignum::operator /=(const int& a){       return (*this)/=bignum(a);   }      inline bignum& bignum::operator %=(const int& a){       return (*this)%=bignum(a);   }      inline bignum pow(bignum a,int b){       bignum c(1);       while (b!=0) {           if (b&1) c *= a;           a = a * a; b >>= 1;       }       return c;   }   inline bignum pow(int a, int b){       return pow(bignum(a), b);   }      } //using namespace BIGNUM;   //}   //}      /** I/O Accelerator Interface .. **/ //{   template<class T> inline T& RD(T &x){       //cin >> x;       //scanf( %d , &x);       char c; for (c = getchar(); c <  0 ; c = getchar()); x = c -  0 ; for (c = getchar();  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ;       //char c; c = getchar(); x = c -  0 ; for (c = getchar(); c >=  0 ; c = getchar()) x = x * 10 + c -  0 ;       return x;   }      inline DB& RF(DB &x){       //cin >> x;       scanf( %lf , &x);       /*char t; while ((t=getchar())==   ||t==  n ); x = t -  0 ;       while ((t=getchar())!=   &&t!=  n &&t!= . )x*=10,x+=t- 0 ;       if (t== . ){DB l=1; while ((t=getchar())!=   &&t!=  n )l*=0.1,x += (t- 0 )*l;}*/       return x;   }      inline char* RS(char *s){       //gets(s);       scanf( %s , s);       return s;   }      LL last_ans; int Case; template<class T> inline void OT(const T &x){       //printf( Case %d: %d n , ++Case, x);       printf( %lld  , x);       //printf( %d n , x);       //cout << x << endl;       //last_ans = x;   }   //}      //}/* .................................................................................................................................. */      const int N = int(2e3) + 9;      int Sun[N][N], Ray[N][N];   int n, m; VI R;      bool inGrid(int x, int y){       return x >= 0 && y >= 0 && x < n && y < m;   }      const int _D = 4, _C = 10;      int dfss(int x, int y){       if (!Ray[x][y]) return 0;       Ray[x][y] = 0; int res = 1; REP(i, 4){           int xx = x + dx[i], yy = y + dy[i];           if (inGrid(xx, yy) && Ray[xx][yy]) res += dfss(xx, yy);       }       return res;   }      int dfs(int x, int y){       Sun[x][y] = 0; int res = dfss(x, y) >= 10; REP(i, 4){           int xx = x + dx[i], yy = y + dy[i];           if (inGrid(xx, yy) && Sun[xx][yy]) res += dfs(xx, yy);       }       return res;   }      int main(){      #ifndef ONLINE_JUDGE       freopen( 01.in.txt ,  r , stdin);       //freopen( out.txt ,  w , stdout);   #endif          RD(n, m); REP_2(i, j, n, m) RD(Sun[i][j]);             REP_2(i, j, n, m) if (Sun[i][j]){           int x, y, bj1, bj2;              bj1 = bj2 = 0; REP_1(d, _D){               x = i + d, y = j; if (inGrid(x, y) && !Sun[x][y]) bj1 = 1;               x = i - d, y = j; if (inGrid(x, y) && !Sun[x][y]) bj2 = 1;           }           if (bj1 && bj2){Ray[i][j] = 1; continue;}              bj1 = bj2 = 0; REP_1(d, _D){               x = i, y = j + d; if (inGrid(x, y) && !Sun[x][y]) bj1 = 1;               x = i, y = j - d; if (inGrid(x, y) && !Sun[x][y]) bj2 = 1;           }           if (bj1 && bj2){Ray[i][j] = 1; continue;}       }          REP_2(i, j, n, m) if (Sun[i][j]){           R.PB(dfs(i, j));       }          /*REP_2(i, j, n, m){           cout << Ray[i][j];           if (j == m - 1) cout << endl;       }*/          SRT(R); cout << SZ(R) <<endl;       ECH(it, R) cout << (*it) <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int h;   long long n, des;   long long GetRes(long long l) {     if (l == 1) return 0;     if ((l + l / 2) % 2) {       return 1 + GetRes(l / 2);     } else {       return pow(2, h - (int)(log2(l)) + 1) + GetRes(l / 2);     }   }   int main() {     while (cin >> h >> n) {       des = pow(2, h) - 1 + n;       cout << GetRes(des) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[1000];     int b[1000];     for (int i = 0; i < 1000; i++) a[i] = 1;     int n, k, r = 1, fl;     cin >> n >> k;     for (int i = 0; i < k; i++) {       cin >> b[i];       a[b[i]] = 0;     }     for (int i = 0; i < k; i++) {       fl = 1;       cout << b[i] <<    ;       while (fl < n) {         if (a[r] != 0) {           cout << r <<    ;           fl++;           a[r] = 0;         }         r++;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int maxn = 2e5 + 10;   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   using namespace std;   int q, op, pos, r, x, len, l;   char ch[10], str[maxn];   int tr[26][maxn];   int lowbit(int x) { return x & (-x); }   void update(int x, int y, int n, int p) {     for (int i = x; i <= n; i += lowbit(i)) tr[p][i] += y;   }   int getsum(int x, int p) {     int ans = 0;     for (int i = x; i; i -= lowbit(i)) ans += tr[p][i];     return ans;   }   int main() {     str[0] =  a ;     scanf( %s n%d , str + 1, &q);     len = strlen(str);     for (int i = 1; i < len; ++i) {       update(i, 1, len, str[i] -  a );     }     while (q--) {       scanf( %d , &op);       if (op == 1) {         scanf( %d %s , &pos, ch);         update(pos, -1, len, str[pos] -  a );         str[pos] = ch[0];         update(pos, 1, len, str[pos] -  a );       } else {         scanf( %d %d , &l, &r);         int ans = 0;         for (int i = 0; i < 26; ++i) {           if (getsum(r, i) - getsum(l - 1, i)) ++ans;         }         printf( %d n , ans);       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct Data {     int sgn;     long long delta;     set<pair<long long, long long>> ranges;     void flip(int a) { sgn = -sgn, delta = a - delta; }     void trim(int l, int r) {       if (l > r) return;       long long xl = sgn * (l - delta), xr = sgn * (r - delta);       if (sgn < 1) swap(xl, xr);       while (!ranges.empty()) {         pair<long long, long long> cur = *ranges.begin();         if (cur.first >= xl) break;         ranges.erase(ranges.begin());         if (cur.second < xl) continue;         ranges.insert(make_pair(xl, cur.second));       }       while (!ranges.empty()) {         pair<long long, long long> cur = *ranges.rbegin();         if (cur.second <= xr) break;         ranges.erase(prev(ranges.end()));         if (cur.first > xr) continue;         ranges.insert(make_pair(cur.first, xr));       }     }     bool empty() { return ranges.empty(); }     void add(int l, int r) {       long long xl = sgn * (l - delta), xr = sgn * (r - delta);       if (sgn == -1) swap(xl, xr);       ranges.insert(make_pair(xl, xr));     }     void add(int y) {       long long x = sgn * (y - delta);       ranges.insert({x, x});     }     void clear() {       ranges.clear();       sgn = 1;       delta = 0;     }     bool contain(int y) {       long long x = sgn * (y - delta);       auto it = ranges.upper_bound({x, LLONG_MAX});       if (it == ranges.begin()) return 0;       return (prev(it)->second) >= x && (prev(it)->first) <= x;     }   };   int n, a[500005];   int solve() {     int cnt = 0;     Data Seg;     Seg.clear();     for (int i = 0; i < n; i++) {       Seg.trim(1, a[i] - 1);       if (Seg.empty())         Seg.add(1, a[i] - 1);       else         cnt++;       Seg.flip(a[i]);       if (a[i] % 2 == 0) {         int b = a[i] / 2;         if (Seg.contain(b)) {           cnt++;           Seg.clear();         }         Seg.add(b);       }     }     return 2 * n - cnt;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int T;     for (cin >> T; T--;) {       cin >> n;       for (int i = 0; i < n; i++) cin >> a[i];       cout << solve() << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   int n, k, m;   int a[1000000];   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> k;     int d = 0;     if (n % 2 == 1) {       d = (n / 2 + 1) * (n / 2 + 1);       d += (n / 2) * (n / 2);     } else {       d = (n / 2) * (n / 2);       d *= 2;     }     if (d < k)       cout <<  NO ;     else {       cout <<  YES  << endl;       int cnt = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           if (cnt < k) {             if (i % 2 == 1) {               if (j % 2 == 1)                 cout <<  L , cnt++;               else                 cout <<  S ;             } else {               if (j % 2 == 0)                 cout <<  L , cnt++;               else                 cout <<  S ;             }           } else             cout <<  S ;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e4 + 100;   const int maxq = 2e4 + 100;   const int maxd = 15;   const int ha1 = 317, ha2 = 443, mod = 364417;   struct Que_Typ {     int y, id;     Que_Typ(int a = 0, int b = 0) { y = a, id = b; }   };   int N, Que;   vector<Que_Typ> ope[maxn];   long long Ans[maxq];   struct Hash {     int x, y;     Hash(int a = 0, int b = 0) { x = a, y = b; }     friend Hash operator+(const Hash &a, const Hash &b) {       return Hash((a.x + b.x) % mod, (a.y + b.y) % mod);     }     friend Hash operator*(const Hash &a, const Hash &b) {       return Hash((long long)a.x * b.x % mod, (long long)a.y * b.y % mod);     }     friend bool operator==(const Hash &a, const Hash &b) {       return (a.x == b.x && a.y == b.y);     }     friend bool operator<(const Hash &a, const Hash &b) {       if (a.x != b.x) return a.x < b.x;       return a.y < b.y;     }     void printt() { printf( Hash %d %d n , x, y); }   };   Hash po[(1 << maxd) + 10];   struct Edge {     int node, next, cha;     Edge(int a = 0, int b = 0, int c = 0) { node = a, next = b, cha = c; }   } E[maxn * 2];   int e_cnt, head[maxn];   int bary[maxn];   int siz[maxn], wei, minf;   struct Trie {     int root, cnt, go[maxn][26], val[maxn];     long long sum[maxn], sum2[maxn];     map<Hash, int> Map;     int create() {       ++cnt;       memset(go[cnt], 0, sizeof(go[cnt]));       sum[cnt] = 0;       sum2[cnt] = 0;       val[cnt] = 0;       return cnt;     }     void dfs(int last, int x, int p, Hash v, int d) {       Map[v] = p;       ++val[p];       for (int i = head[x]; i != -1; i = E[i].next) {         int y = E[i].node, c = E[i].cha;         if (bary[y] || y == last) continue;         if (!go[p][c - 1]) go[p][c - 1] = create();         dfs(x, y, go[p][c - 1], v + Hash(c, c) * po[d], d + 1);       }     }     void Pre_sum(int p, long long &ret) {       sum[p] = ret;       ret += val[p];       for (int i = (0), _i = (25); i <= _i; ++i)         if (go[p][i]) Pre_sum(go[p][i], ret);       sum2[p] = ret;     }     void build(int last, int x, int c = 0) {       cnt = 0;       root = create();       Map.clear();       if (c) {         int p = root, d = 1;         Hash v = Hash(0, 0);         Map[v] = p;         go[p][c - 1] = create();         dfs(last, x, go[p][c - 1], v + Hash(c, c) * po[d], d + 1);       } else         dfs(last, x, root, Hash(0, 0), 1);       val[root] = 0;       long long tt = 0;       Pre_sum(root, tt);     }   } Trie1, Trie2;   struct Tree {     int wei, tim, id[maxn], fa[maxd][maxn];     Hash dtu[maxd][maxn], utd[maxd][maxn];     int siz[maxn], path[maxn], dep[maxn];     void get_skip_table(int x) {       for (int j = (1), _j = (maxd - 1); j <= _j; ++j) {         int y = fa[j - 1][x];         int z = fa[j - 1][y];         fa[j][x] = z;         dtu[j][x] = dtu[j - 1][x] + dtu[j - 1][y] * po[1 << (j - 1)];         utd[j][x] = utd[j - 1][y] + utd[j - 1][x] * po[1 << (j - 1)];       }     }     int get_lca(int x, int y) {       if (x == y) return x;       if (id[x] > id[y]) swap(x, y);       for (int j = (maxd - 1), _j = (0); j >= _j; --j)         if (id[x] < id[fa[j][y]]) y = fa[j][y];       return fa[0][y];     }     int skip(int x, int k) {       for (; k; k -= (k & (-k))) {         x = fa[__builtin_ctz(k)][x];       }       return x;     }     int move(int x, int y, int k) {       int lca = get_lca(x, y);       int lenx = dep[x] - dep[lca];       int len = lenx + dep[y] - dep[lca];       return (k <= lenx ? skip(x, k) : skip(y, len - k));     }     Hash get_dtu(int x, int k) {       Hash ret = Hash(0, 0), s = Hash(1, 1);       for (; k; k -= (k & (-k))) {         int j = __builtin_ctz(k);         ret = ret + dtu[j][x] * s;         s = s * po[1 << j];         x = fa[j][x];       }       return ret;     }     Hash get_utd(int x, int k) {       Hash ret = Hash(0, 0);       for (; k; k -= (k & (-k))) {         int j = __builtin_ctz(k);         ret = ret * po[1 << j] + utd[j][x];         x = fa[j][x];       }       return ret;     }     void dfs(int last, int x) {       siz[x] = 1;       id[x] = ++tim;       get_skip_table(x);       for (int i = head[x]; i != -1; i = E[i].next) {         int y = E[i].node, c = E[i].cha;         if (y == last || bary[y]) continue;         fa[0][y] = x;         utd[0][y] = dtu[0][y] = Hash(c, c) * po[1];         dep[y] = dep[x] + 1;         path[y] = c;         dfs(x, y);         siz[x] += siz[y];       }     }     void build(int x) {       tim = 0;       wei = x;       fa[0][wei] = wei;       utd[0][wei] = dtu[0][wei] = Hash(0, 0);       dep[wei] = 0;       path[wei] = 0;       dfs(0, wei);     }   } T0, T1;   void add_Edge(int x, int y, int c) {     E[e_cnt] = Edge(y, head[x], c);     head[x] = e_cnt++;   }   int compare(int x, int y, int wei) {     int lca = T0.get_lca(x, y);     int lenx = T0.dep[x] - T0.dep[lca];     int len = lenx + T0.dep[y] - T0.dep[lca];     int towei = T1.dep[x] - T1.dep[wei];     int le = 0, ri = min(towei, len) + 1;     while (le + 1 < ri) {       int mid = (le + ri) >> 1;       Hash s1 = T1.get_dtu(x, mid);       Hash s0 = (mid <= lenx ? T0.get_dtu(x, mid)                              : T0.get_dtu(x, lenx) +                                    T0.get_utd(T0.skip(y, len - mid), mid - lenx) *                                        po[lenx]);       (s1 == s0 ? le = mid : ri = mid);     }     if (le == towei) return 0;     int c1 = T1.path[T1.skip(x, le)];     int c0 =         (le < len              ? T0.path[(le < lenx ? T0.skip(x, le) : T0.skip(y, len - le - 1))]              : 0);     return c1 - c0;   }   long long calc_cmp0(int x, int y, Trie &Tr, int &flag) {     x = T0.move(x, y, T1.dep[x] - T1.dep[wei]);     int lca = T0.get_lca(x, y);     int lenx = T0.dep[x] - T0.dep[lca];     int len = lenx + T0.dep[y] - T0.dep[lca];     flag = (len > 0);     int le = 0, ri = len + 1;     while (le + 1 < ri) {       int mid = (le + ri) >> 1;       Hash s0 = (mid <= lenx ? T0.get_dtu(x, mid)                              : T0.get_dtu(x, lenx) +                                    T0.get_utd(T0.skip(y, len - mid), mid - lenx) *                                        po[lenx]);       (Tr.Map.find(s0) != Tr.Map.end() ? le = mid : ri = mid);     }     Hash s0 =         (le <= lenx ? T0.get_dtu(x, le)                     : T0.get_dtu(x, lenx) +                           T0.get_utd(T0.skip(y, len - le), le - lenx) * po[lenx]);     int c0 =         (le < len              ? T0.path[(le < lenx ? T0.skip(x, le) : T0.skip(y, len - le - 1))]              : 0);     int num = (le == 0 ? Tr.root : Tr.Map[s0]);     long long ret = Tr.sum[num];     if (c0 == 0) return Tr.sum[num];     for (int i = (c0 - 1), _i = (25); i <= _i; ++i)       if (Tr.go[num][i]) return Tr.sum[Tr.go[num][i]];     return Tr.sum2[num];   }   void work(int last, int x, int &gg) {     for (int i = (0), _i = (ope[x].size() - 1); i <= _i; ++i) {       int y = ope[x][i].y, id = ope[x][i].id;       int cmp = compare(x, y, wei);       if (cmp < 0) {         Ans[id] += gg;       } else if (cmp == 0) {         int flag;         Ans[id] += calc_cmp0(x, y, Trie1, flag) - calc_cmp0(x, y, Trie2, flag);         Ans[id] += flag;       }     }     for (int i = head[x]; i != -1; i = E[i].next) {       int y = E[i].node;       if (bary[y] || y == last) continue;       work(x, y, gg);     }   }   void solve() {     Trie1.build(0, wei);     for (int i = (0), _i = (ope[wei].size() - 1); i <= _i; ++i) {       int y = ope[wei][i].y, id = ope[wei][i].id;       int flag;       Ans[id] += calc_cmp0(wei, y, Trie1, flag);     }     for (int i = head[wei]; i != -1; i = E[i].next) {       int y = E[i].node, c = E[i].cha;       if (bary[y]) continue;       Trie2.build(wei, y, c);       int gg = T1.siz[wei] - T1.siz[y];       work(wei, y, gg);     }   }   void find_bary(int last, int x, int &n) {     siz[x] = 1;     int maxf = 0;     for (int i = head[x]; i != -1; i = E[i].next) {       int y = E[i].node;       if (y == last || bary[y]) continue;       find_bary(x, y, n);       siz[x] += siz[y];       maxf = max(maxf, siz[y]);     }     maxf = max(maxf, n - siz[x]);     if (maxf < minf) minf = maxf, wei = x;   }   void vdc(int x, int n) {     minf = N + 2, wei = x;     find_bary(0, x, n);     T1.build(wei);     solve();     bary[wei] = 1;     for (int i = head[wei]; i != -1; i = E[i].next) {       int y = E[i].node;       if (bary[y]) continue;       vdc(y, siz[y]);     }   }   int main() {     po[0] = Hash(1, 1);     po[1] = Hash(ha1, ha2);     for (int i = (2), _i = ((1 << maxd)); i <= _i; ++i) po[i] = po[i - 1] * po[1];     for (; scanf( %d%d , &N, &Que) != EOF;) {       e_cnt = 0;       memset(head, 255, sizeof(head[0]) * (N + 2));       for (int i = (1), _i = (N - 1); i <= _i; ++i) {         int x, y;         char c[5];         scanf( %d%d%s , &x, &y, c);         add_Edge(x, y, c[0] -  a  + 1);         add_Edge(y, x, c[0] -  a  + 1);       }       for (int i = (1), _i = (N); i <= _i; ++i) ope[i].clear();       for (int i = (1), _i = (Que); i <= _i; ++i) {         int x, y;         scanf( %d%d , &x, &y);         ope[x].push_back(Que_Typ(y, i));       }       memset(bary, 0, sizeof(bary[0]) * (N + 2));       memset(Ans, 0, sizeof(Ans[0]) * (N + 2));       T0.build(1);       vdc(1, N);       for (int i = (1), _i = (Que); i <= _i; ++i) printf( %I64d n , Ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using std::cin;   using std::cout;   long long MOD = 998244353;   int main() {     long long n, q;     cin >> n >> q;     for (int i = 0; i < q; i++) {       long long curr;       cin >> curr;       string s;       cin >> s;       for (int c = 0; c < s.size(); c++) {         long long bit = curr & -curr;         if (s[c] ==  U ) {           if (curr != (n + 1) / 2) {             if (((curr - bit) & -(curr - bit)) != bit * 2)               curr += bit;             else               curr -= bit;           }         } else if (s[c] ==  R ) {           if (bit == 1)             curr += 0;           else             curr += bit / 2;         } else if (s[c] ==  L ) {           if (bit == 1)             curr += 0;           else             curr -= bit / 2;         }       }       cout << curr <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NN = 100 * 1000 + 5;   map<pair<pair<int, long long>, int>, long long> dp;   vector<int> adj[NN];   vector<long long> x;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int mod = (int)1e9 + 7;   int rec(int node, int parent, long long g, int state) {     pair<pair<int, long long>, int> p = make_pair(make_pair(node, g), state);     if (dp.find(p) != dp.end()) return dp[p];     long long& res = dp[p];     res = gcd(g, x[node]);     res %= mod;     long long new_g = gcd(g, x[node]);     for (int child : adj[node]) {       if (child == parent) continue;       if (state == 0) {         res += rec(child, node, g, 0);         res %= mod;       }       res += rec(child, node, new_g, 1);       res %= mod;     }     return res;   }   int main() {     int n;     scanf( %d , &n);     x.resize(n);     for (int i = 0; i < n; i++) {       scanf( %lld , &x[i]);     }     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       a--;       b--;       adj[a].push_back(b);       adj[b].push_back(a);     }     long long ans = rec(0, -1, 0, 0);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> graph[100001];   bool vis[100001];   vector<long long int> ans;   void dfs(long long int root) {     vis[root] = true;     ans.push_back(root);     sort(graph[root].begin(), graph[root].end());     for (int i = 0; i < graph[root].size(); i++) {       if (!vis[graph[root][i]]) dfs(graph[root][i]);     }   }   void solve() {     long long int a, b, c, d, i, j, k, l;     cin >> a >> b;     for (i = 0; i < b; i++) {       cin >> c >> d;       graph[c].push_back(d);       graph[d].push_back(c);     }     memset(vis, false, sizeof(vis));     map<int, int> m;     m[1] = 0;     while (m.size()) {       k = m.begin()->first;       m.erase(k);       ans.push_back(k);       vis[k] = true;       for (i = 0; i < graph[k].size(); i++) {         if (!vis[graph[k][i]]) {           m[graph[k][i]] = 0;         }       }     }     for (i = 0; i < ans.size(); i++) cout << ans[i] <<    ;   }   int main() {     int t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int cost;     double amount;     cin >> cost;     string s[n];     for (int i = 0; i < n; i++) {       cin >> s[i];     }     int counter = 0;     double sum = 0.0;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  halfplus ) {         counter++;         sum = (sum + 0.5) * 2;       } else if (s[i] ==  half ) {         sum = sum * 2;       }     }     double num;     num = sum - (0.5 * counter);     amount = cost * num;     cout << (long long int)amount << endl;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, y = 1;     char ch =    ;     for (; (ch !=  -  && (ch >  9  || ch <  0 )); ch = getchar())       ;     if (ch ==  - ) y = -1, ch = getchar();     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch - 48;     return x * y;   }   const int N = 1e6 + 10;   struct node {     int to, nex;   } e[N << 1];   int bgn[N], d[N], mx[N], son[N], ans[N], dfn[N], id[N], c[N];   int n, cnt, tot;   void add(int x, int y) {     e[++cnt] = (node){y, bgn[x]};     bgn[x] = cnt;   }   void dfs(int x, int fa) {     mx[x] = d[x] = d[fa] + 1;     for (register int i = bgn[x]; i; i = e[i].nex) {       int y = e[i].to;       if (y == fa) continue;       dfs(y, x);       if (mx[y] > mx[son[x]]) {         son[x] = y;         mx[x] = mx[y];       }     }   }   void ins(int &p, int x, int k) {     c[x] += k;     if (c[x] > c[p] || c[x] == c[p] && p > x) p = x;   }   void solve(int x, int fa) {     dfn[++tot] = x;     id[x] = tot;     if (son[x]) solve(son[x], x);     int p = ans[son[x]];     for (register int i = bgn[x]; i; i = e[i].nex) {       int y = e[i].to;       if (y == fa || y == son[x]) continue;       solve(y, x);       for (register int j = 0; j <= mx[y] - d[y]; ++j)         ins(p, id[x] + j + 1, c[id[y] + j]);     }     ins(p, id[x], 1);     ans[x] = p;   }   int main() {     int x, y, z, k;     n = read();     for (register int i = 1; i < n; ++i) {       x = read();       y = read();       add(x, y);       add(y, x);     }     dfs(1, 0);     solve(1, 0);     for (register int i = 1; i <= n; ++i) printf( %d n , ans[i] - id[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool tep(pair<string, int> a, pair<string, int> b) {     return a.second > b.second;   }   bool f(string s) {     for (int i = 0; i < 10; i++) {       if ((i == 2 || i == 5) && s[i] !=  - ) return 0;       if ((i != 2 && i != 5) && s[i] ==  - ) return 0;     }     if (s.substr(6) !=  2013  && s.substr(6) !=  2014  && s.substr(6) !=  2015 )       return 0;     if ((s[3] !=  0  && s[4] !=  0  && s[4] !=  1  && s[4] !=  2 ) ||         s[3] >  1  || (s[3] ==  0  && s[4] ==  0 ))       return 0;     if (s.substr(0, 2) ==  00 ) return 0;     if (s.substr(3, 2) ==  02  && (s[0] >=  3  || (s[0] ==  2  && s[1] >  8 )))       return 0;     if ((s.substr(3, 2) ==  04  || s.substr(3, 2) ==  06  ||          s.substr(3, 2) ==  09  || s.substr(3, 2) ==  11 ) &&         (s[0] >  3  || (s[0] ==  3  && s[1] >  0 )))       return 0;     else if (s.substr(3, 2) !=  02  &&              (s[0] >  3  || (s[0] ==  3  && s[1] >  1 )))       return 0;     return 1;   }   int main() {     string str;     vector<pair<string, int> > x;     int xn = 0;     cin >> str;     for (int i = 0; i < str.length() - 9; i++) {       string ss = str.substr(i, 10);       if (f(ss)) {         int j;         for (j = 0; j < xn; j++)           if (ss == x[j].first) {             x[j].second++;             break;           }         if (j == xn) {           xn++;           x.push_back(make_pair(ss, 1));         }       }     }     pair<string, int> xx[xn];     for (int i = 0; i < xn; i++) {       xx[i].first = x[i].first;       xx[i].second = x[i].second;     }     sort(xx, xx + xn, tep);     cout << xx[0].first << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double pie = 3.14159265358979323846;   bool isPowerOfTwo(long long int n) {     if (n == 0) return false;     return (ceill(log2l(n)) == floorl(log2l(n)));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int T, i, j, j1, k = 0, n, m, co = 0, check, mi, l, sum;     long long int ans = 0;     cin >> T;     for (i = 0; i < T; i++) {       string s, s1 =  twone , s2 =  two ;       cin >> s;       n = s.length();       set<long long int> second;       for (j = 0; j < n - 4; j++) {         co = 0;         for (k = 0; k < 5; k++) {           if (s[j + k] != s1[k]) {             co = 1;             break;           }         }         if (co == 0) second.insert(j + 2);       }       for (j = 0; j < n - 2; j++) {         co = 0;         for (k = 0; k < 3; k++) {           if (s[j + k] != s2[k]) {             co = 1;             break;           }         }         if (co == 0 && second.find(j + 2) == second.end()) second.insert(j + 1);       }       s2 =  one ;       for (j = 0; j < n - 2; j++) {         co = 0;         for (k = 0; k < 3; k++) {           if (s[j + k] != s2[k]) {             co = 1;             break;           }         }         if (co == 0 && second.find(j) == second.end()) second.insert(j + 1);       }       cout << second.size() << endl;       for (auto w : second) {         cout << w + 1 <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     string s;     cin >> s;     int ans = n;     for (int i = 0; i < n / 2; i++) {       string temp1 = s.substr(0, i + 1);       string temp2 = s.substr(i + 1, i + 1);       if (temp1 == temp2) ans = min(ans, n - i);     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int M = 2e3 + 50;   const int INF = 0x7fffffff;   const int mod = 1e9 + 7;   const int sz = 18;   const double eps = 1e-10;   const double pi = acos(-1);   long long n, m;   char str[N];   int f[N];   template <class T>   inline void read(T &x) {     char c;     x = 1;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) x = -1;     T res = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) res = res * 10 + c -  0 ;     x *= res;   }   int main() {     int t;     read(t);     while (t--) {       read(n);       read(m);       long long l, r;       for (int i = 1; i <= n; i++) {         long long tmp = 1ll * i * (i - 1) / 2;         if (tmp >= m) {           l = i;           break;         }       }       r = (l - 1) - ((l - 1) * l / 2 - m);       l = n - l + 1;       r = n - r + 1;       for (int i = 1; i <= n; i++) {         if (i == l || i == r)           cout <<  b ;         else           cout <<  a ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   int main(void) {     int n, m;     scanf( %d%d , &n, &m);     char c;     scanf( %c , &c);     int i, j;     char word[n + 2][m + 2];     for (i = 0; i < n + 2; i++)       for (j = 0; j < m + 2; j++) word[i][j] =  W ;     int v[n + 1], h[m + 1];     for (i = 0; i <= n; i++) v[i] = 0;     for (j = 0; j <= m; j++) h[j] = 0;     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         scanf( %c , &word[i][j]);         if (word[i][j] ==  B ) {           v[i] += 1;           h[j] += 1;         }       }       scanf( %c , &c);     }     int left = m + 1, right = 0;     for (j = 1; j <= m; j++) {       if ((h[j] > 0) && (j < left)) left = j;       if ((h[j] > 0) && (j > right)) right = j;     }     int up = 0, down = n + 1;     for (i = 1; i <= n; i++) {       if ((v[i] > 0) && (i > up)) up = i;       if ((v[i] > 0) && (i < down)) down = i;     }     int notTrue = 0;     for (i = down; i <= up; i++) {       if (v[i] == 0)         notTrue = 1;       else {         int black = 0;         for (j = left; j <= right; j++) {           if ((word[i][j] ==  B ) && (black == 0)) black = 1;           if ((word[i][j] ==  W ) && (black == 1)) black = 2;           if ((word[i][j] ==  B ) && (black == 2)) notTrue = 1;         }       }     }     for (j = left; j <= right; j++) {       if (h[j] == 0)         notTrue = 1;       else {         int black = 0;         for (i = down; i <= up; i++) {           if ((word[i][j] ==  B ) && (black == 0)) black = 1;           if ((word[i][j] ==  W ) && (black == 1)) black = 2;           if ((word[i][j] ==  B ) && (black == 2)) notTrue = 1;         }       }     }     while (up > down) {       int lv = right, pv = left, ln = right, pn = left;       for (j = left; j <= right; j++) {         if ((word[up][j] ==  B ) && (lv > j)) lv = j;         if ((word[up][j] ==  B ) && (pv < j)) pv = j;         if ((word[down][j] ==  B ) && (ln > j)) ln = j;         if ((word[down][j] ==  B ) && (pn < j)) pn = j;       }       if (lv > ln) lv = ln;       if (ln > lv) ln = lv;       if (pn < pv) pn = pv;       if (pv < pn) pv = pn;       if (((word[up][ln] ==  W ) && (word[up][pn] ==  B ) &&            (word[down][lv] ==  B ) && (word[down][pv] ==  W )) ||           ((word[down][lv] ==  W ) && (word[down][pv] ==  B ) &&            (word[up][ln] ==  B ) && (word[up][pn] ==  W )))         notTrue = 1;       --up;       ++down;     }     if (notTrue == 0) {       printf( YES );     } else {       printf( NO );     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(4)   using namespace std;   char _buf[100000], *_p1 = _buf, *_p2 = _buf;   inline int gi() {     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 << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return (f == 1) ? x : -x;   }   inline int max(int a, int b) { return a > b ? a : b; }   inline int min(int a, int b) { return a < b ? a : b; }   int T, n, m;   struct node {     int x[3], y[3];     node(int a1, int b1, int a2, int b2, int a3, int b3) {       x[0] = a1, x[1] = a2, x[2] = a3;       y[0] = b1, y[1] = b2, y[2] = b3;     }     inline void output() {       for (int i = 0; i <= 2; ++i) printf( %d %d  , x[i], y[i]);     }   };   const int maxn = 105;   vector<node> vec;   int a[maxn][maxn];   char s[maxn];   inline void init() {     memset(a, 0, sizeof(a));     vec.clear();   }   inline void input() {     n = gi(), m = gi();     for (int i = 1; i <= n; ++i) {       scanf( %s , s + 1);       for (int j = 1; j <= m; ++j) a[i][j] = s[j] -  0 ;     }   }   inline void change(int a1, int b1, int a2, int b2, int a3, int b3) {     vec.push_back(node(a1, b1, a2, b2, a3, b3));     a[a1][b1] ^= 1, a[a2][b2] ^= 1, a[a3][b3] ^= 1;   }   inline void solve() {     for (int i = 1; i <= n - 2; ++i) {       for (int j = 1; j <= m - 1; ++j) {         if (a[i][j] == 0 && a[i][j + 1] == 0)           continue;         else {           if (a[i][j] == 0) {             change(i, j + 1, i + 1, j, i + 1, j + 1);           } else if (a[i][j + 1] == 1) {             change(i, j, i, j + 1, i + 1, j);           } else {             change(i, j, i + 1, j, i + 1, j + 1);           }         }       }     }     for (int i = 1; i <= m - 1; ++i) {       if (a[n - 1][i] == 1 && a[n][i] == 1) {         change(n - 1, i, n, i, n - 1, i + 1);       } else if (a[n - 1][i] == 1) {         change(n - 1, i, n, i + 1, n - 1, i + 1);       } else if (a[n][i] == 1) {         change(n, i, n - 1, i + 1, n, i + 1);       }     }     if (a[n][m] == 1 && a[n - 1][m] == 1) {       change(n - 1, m - 1, n - 1, m, n, m - 1);       change(n - 1, m - 1, n, m - 1, n, m);     } else if (a[n - 1][m] == 1) {       change(n - 1, m, n - 1, m - 1, n, m - 1);       change(n - 1, m - 1, n, m, n - 1, m);       change(n, m - 1, n, m, n - 1, m);     } else if (a[n][m] == 1) {       change(n, m, n - 1, m - 1, n, m - 1);       change(n - 1, m - 1, n, m, n - 1, m);       change(n, m - 1, n, m, n - 1, m);     }     printf( %d n , (int)(vec.size()));     for (auto x : vec) {       x.output();       printf(  n );     }   }   int main() {     T = gi();     while (T--) {       init();       input();       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long l, r, k, p, num;     cin >> l >> r >> k;     num = 1;     int ans = 0;     while (num <= r) {       if (num >= l && num <= r) {         cout << num;         ans++;       }       num *= k;       if (ans != 0) cout << endl;       if (num % k != 0) break;     }     if (ans == 0) printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, p;   int cnt[26], cnt1[26], ans;   bool check() {     for (int i = 0; i < 26; i++)       if (cnt[i] > cnt1[i]) return false;     return true;   }   int main() {     cin >> s >> p;     if (p.size() > s.size()) {       cout << 0;       return 0;     }     for (int i = 0; i < p.size(); i++) cnt1[p[i] -  a ]++;     for (int i = 0; i < p.size(); i++) {       if (s[i] !=  ? ) cnt[s[i] -  a ]++;     }     if (check() == true) ans++;     for (int i = 1; i < s.size() - p.size() + 1; i++) {       if (s[i - 1] !=  ? ) cnt[s[i - 1] -  a ]--;       if (s[i + p.size() - 1] !=  ? ) cnt[s[i + p.size() - 1] -  a ]++;       if (check()) ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string name[1001];   int fen[1001];   vector<pair<string, int> > old;   vector<pair<int, string> > xin;   vector<int> ff;   int main(int argc, char *argv[]) {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> name[i] >> fen[i];       old.push_back(make_pair(name[i], fen[i]));     }     sort(old.begin(), old.end());     for (int i = 0; i < (int)old.size(); i++) {       if (i == (int)old.size() - 1 || old[i].first != old[i + 1].first) {         xin.push_back(make_pair(old[i].second, old[i].first));       }     }     sort(xin.begin(), xin.end());     for (int i = 0; i < (int)xin.size(); i++) {       ff.push_back(xin[i].first);     }     int sz = ff.size(), wz;     cout << sz << endl;     for (int i = 0; i < (int)xin.size(); i++) {       wz = sz - (upper_bound(ff.begin(), ff.end(), ff[i]) - ff.begin());       if (wz * 2 > sz) {         cout << xin[i].second <<   noob n ;       } else if (wz * 5 > sz) {         cout << xin[i].second <<   random n ;       } else if (wz * 10 > sz) {         cout << xin[i].second <<   average n ;       } else if (wz * 100 > sz) {         cout << xin[i].second <<   hardcore n ;       } else {         cout << xin[i].second <<   pro n ;       }     }     return EXIT_SUCCESS;   }