#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(0), cin.tie(0);
   int n, m;
   cin >> n >> m;
   vector<vector<int>> adj(n);
   for (int i = 0, u, v; i < m; ++i) {
     cin >> u >> v;
     --u, --v;
     adj[u].push_back(v);
     adj[v].push_back(u);
   }
   set<int> go;
   queue<int> q;
   for (int i = 0; i < n; ++i) go.insert(i);
   int ans = 0;
   for (int x = 0; x < n; ++x)
     if (go.find(x) != go.end()) {
       ++ans;
       go.erase(x);
       q.push(x);
       while (!q.empty()) {
         int u = q.front();
         q.pop();
         vector<int> add;
         for (auto v : adj[u])
           if (go.find(v) != go.end()) {
             go.erase(v);
             add.push_back(v);
           }
         for (auto v : go) q.push(v);
         go.clear();
         for (auto v : add) go.insert(v);
       }
     }
   cout << ans - 1 <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct edge {
   int v, w;
   edge* next;
 };
 const int N = 100010;
 int n, p, ordcnt;
 bool vis[N], cut[N];
 int ord[N], sum[N], mex[N], q[N], dep[N], digit[N], rdigit[N], rprod[N],
     prod[N];
 edge* g[N];
 void add_edge(int u, int v, int w);
 void calc_order(int u);
 void calc_sum(int u);
 void dfs(int u);
 long long calc(int u);
 int rev(int a);
 void ex_gcd(int a, int b, int& x, int& y);
 int main() {
   long long ans = 0;
   scanf( dd , &n, &p);
   for (int rep = 1; rep < n; ++rep) {
     int u, v, w;
     scanf( ddd , &u, &v, &w);
     add_edge(u, v, w);
     add_edge(v, u, w);
   }
   prod[0] = 1;
   rprod[0] = 1;
   rprod[1] = rev(10);
   for (int i = 1; i <= n; ++i) prod[i] = 10LL * prod[i - 1]  p;
   for (int i = 2; i <= n; ++i)
     rprod[i] = (long long)rprod[1] * rprod[i - 1]  p;
   calc_order(0);
   memset(cut, 0, sizeof(cut));
   for (int i = 0; i < n; ++i) {
     int u = ord[i];
     dep[u] = 0;
     digit[u] = 0;
     rdigit[u] = 0;
     dfs(u);
     ans += calc(u);
     cut[u] = true;
     for (edge* p = g[u]; p; p = p->next)
       if (!cut[p->v]) ans -= calc(p->v);
     ans -= 1;
     ;
   }
   printf( lld
 , ans);
   return 0;
 }
 int rev(int a) {
   int x, y;
   ex_gcd(a, p, x, y);
   if (x < 0) x += p;
   return x;
 }
 void ex_gcd(int a, int b, int& x, int& y) {
   if (b == 0) {
     x = 1;
     y = 0;
     return;
   }
   ex_gcd(b, a  b, y, x);
   y -= a / b * x;
 }
 long long calc(int u) {
   int ql = 0, qr = 1;
   long long ret = 0;
   map<int, int> mp;
   q[0] = u;
   while (ql < qr) {
     int v = q[ql++];
     vis[v] = true;
     map<int, int>::iterator it = mp.find(rdigit[v]);
     if (it != mp.end())
       ++it->second;
     else
       mp.insert(make_pair(rdigit[v], 1));
     for (edge* p = g[v]; p; p = p->next)
       if (!vis[p->v] && !cut[p->v]) q[qr++] = p->v;
   }
   for (int i = 0; i < qr; ++i) vis[q[i]] = false;
   for (int i = 0; i < qr; ++i) {
     int key = (long long)-digit[q[i]] * rprod[dep[q[i]]]  p;
     if (key < 0) key += p;
     map<int, int>::iterator it = mp.find(key);
     if (it != mp.end()) {
       ;
       ret += it->second;
     }
   }
   return ret;
 }
 void dfs(int u) {
   vis[u] = true;
   for (edge* p = g[u]; p; p = p->next)
     if (!vis[p->v] && !cut[p->v]) {
       dep[p->v] = dep[u] + 1;
       rdigit[p->v] = ((long long)prod[dep[u]] * p->w + rdigit[u])  ::p;
       digit[p->v] = (digit[u] * 10LL + p->w)  ::p;
       dfs(p->v);
     }
   vis[u] = false;
 }
 void calc_order(int u) {
   calc_sum(u);
   int s = sum[u], ql = 0, qr = 1;
   q[0] = u;
   while (ql < qr) {
     int v = q[ql++];
     vis[v] = true;
     mex[v] = max(mex[v], s - sum[v]);
     if (mex[v] < mex[u]) u = v;
     for (edge* p = g[v]; p; p = p->next)
       if (!vis[p->v] && !cut[p->v]) q[qr++] = p->v;
   }
   for (int i = 0; i < qr; ++i) vis[q[i]] = false;
   ord[ordcnt++] = u;
   cut[u] = true;
   for (edge* p = g[u]; p; p = p->next)
     if (!cut[p->v]) calc_order(p->v);
 }
 void calc_sum(int u) {
   vis[u] = true;
   mex[u] = 0;
   sum[u] = 1;
   for (edge* p = g[u]; p; p = p->next)
     if (!vis[p->v] && !cut[p->v]) {
       calc_sum(p->v);
       sum[u] += sum[p->v];
       mex[u] = max(mex[u], sum[p->v]);
     }
   vis[u] = false;
 }
 void add_edge(int u, int v, int w) {
   static edge pool[N * 2];
   static edge* p = pool;
   ++p;
   p->v = v;
   p->w = w;
   p->next = g[u];
   g[u] = p;
 }


#include <bits/stdc++.h>
 using namespace std;

 #define fastIO ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
 #define endl '
'
 #define lli long long int
 #define ld long double
 #define p_b push_back
 #define m_p make_pair
 #define fs first
 #define sc second
 #define sz(x) ((lli)x.size())
 #define all(x) x.begin(),x.end()
 const lli mod = 1e9 + 7;
 const lli N = 1e6 + 5;
 /*****************************************************/
 lli t,n,m,a[N]={0},target;
 bool dp[105][200005],vis[105][200005];
 lli F(lli idx,lli ss)
 {
     if(vis[idx][ss])
         return dp[idx][ss];
     vis[idx][ss]=true;
     if(idx>n)
     {
         if(ss==target)
             return dp[idx][ss]=true;
         return dp[idx][ss]=false;
     }
     bool ret=F(idx+1,ss),ret1=F(idx+1,ss+a[idx]);
     if(ret || ret1)
         return dp[idx][ss]=true;
     return dp[idx][ss]=false;
 }
 int main()
 {
     fastIO
     lli i,j,k,x,y;
     lli ss=0;
     cin>>n;
     for(i=1;i<=n;i++)
     {
         cin>>a[i];
         ss+=a[i];
     }
     if(ss2!=0)
     {
         cout<< 0 ;
         return 0;
     }
     target=ss/2;
     memset(vis,false,sizeof vis);
     memset(dp,false,sizeof dp);
     if(F(1,0)==false)
     {
         cout<< 0 ;
         return 0;
     }
     while(1)
     {
         for(i=1;i<=n;i++)
         {
             if(a[i]2!=0)
             {
                 cout<< 1
 <<i;
                 return 0;
             }
             a[i]/=2;
         }
     }

     // cerr<< '
' <<  Time elapsed :  << clock() * 1000.0 / CLOCKS_PER_SEC <<   ms
  ;
     return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int time_to_minute(int h, int m) { return h * 60 + m; }
 void minute_to_time(int t, int& h, int& m) {
   h = t / 60;
   m = t  60;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   int h, m, a;
   cin >> h;
   cin.ignore(1);
   cin >> m >> a;
   minute_to_time((time_to_minute(h, m) + a)  (24 * 60), h, m);
   cout << (h < 10 ?  0  :   ) << h <<  :  << (m < 10 ?  0  :   ) << m;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 100010;
 int n, BIT[N];
 void update(int idx, int val) {
   while (idx <= n) {
     BIT[idx] = max(val, BIT[idx]);
     idx += idx & -idx;
   }
 }
 int get(int idx) {
   int ret = 0;
   while (idx > 0) {
     ret = max(BIT[idx], ret);
     idx -= idx & -idx;
   }
   return ret;
 }
 int main() {
   scanf( d , &n);
   int ans = 0;
   for (int i = 0, x; i < n; ++i) {
     scanf( d , &x);
     update(x, get(x) + 1);
   }
   printf( d
 , get(n));
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int iinf = 1e9 + 7;
 const long long linf = 1ll << 60;
 const double dinf = 1e60;
 template <typename T>
 inline void scf(T &x) {
   bool f = 0;
   x = 0;
   char c = getchar();
   while ((c < '0' || c > '9') && c != '-') c = getchar();
   if (c == '-') {
     f = 1;
     c = getchar();
   }
   while (c >= '0' && c <= '9') {
     x = x * 10 + c - '0';
     c = getchar();
   }
   if (f) x = -x;
   return;
 }
 template <typename T1, typename T2>
 void scf(T1 &x, T2 &y) {
   scf(x);
   return scf(y);
 }
 template <typename T1, typename T2, typename T3>
 void scf(T1 &x, T2 &y, T3 &z) {
   scf(x);
   scf(y);
   return scf(z);
 }
 template <typename T1, typename T2, typename T3, typename T4>
 void scf(T1 &x, T2 &y, T3 &z, T4 &w) {
   scf(x);
   scf(y);
   scf(z);
   return scf(w);
 }
 inline char mygetchar() {
   char c = getchar();
   while (c == ' ' || c == '
') c = getchar();
   return c;
 }
 template <typename T>
 void chkmax(T &x, const T &y) {
   if (y > x) x = y;
   return;
 }
 template <typename T>
 void chkmin(T &x, const T &y) {
   if (y < x) x = y;
   return;
 }
 const int N = 510;
 const int M = 110;
 int n, m, k;
 double A[N][N + N];
 double w[M][M], p[N][N];
 bool f[N];
 vector<int> trap;
 double beg[N];
 void calc_w() {
   for (int i = (1); i <= (n); ++i) {
     A[i][i] = 1.0;
     if (!f[i])
       for (int j = (1); j <= (n); ++j)
         if (i != j) A[i][j] = -p[i][j];
     A[i][i + n] = 1.0;
   }
   for (int row = 1, col = 1; row <= n; ++row) {
     int pivot = row;
     for (int i = (row + 1); i <= (n); ++i)
       if (fabs(A[i][col]) > fabs(A[pivot][col])) pivot = i;
     if (fabs(A[pivot][col]) <= 1e-6) continue;
     swap(A[pivot], A[row]);
     double foo = A[row][col];
     for (int i = (1); i <= (n + n); ++i) A[row][i] /= foo;
     for (int i = (1); i <= (n); ++i)
       if (i != row) {
         foo = A[i][col];
         for (int j = (1); j <= (n + n); ++j) A[i][j] -= foo * A[row][j];
       }
     ++col;
   }
   for (int i = 0; i < (m); ++i)
     for (int j = 0; j < (m); ++j) {
       int u = trap[i], v = trap[j];
       for (int k = (1); k <= (n); ++k) w[i][j] += p[u][k] * A[k][v + n];
     }
   for (int i = 0; i < (m); ++i) beg[i] = A[1][trap[i] + n];
   return;
 }
 void TZL() {
   static int g[N][N], deg[N];
   memset((g), (0), sizeof((g)));
   memset((deg), (0), sizeof((deg)));
   scf(n, m, k);
   for (int i = (1); i <= (n); ++i) {
     scf(f[i]);
     if (f[i]) trap.push_back(i);
   }
   for (int i = 0; i < (m); ++i) {
     int u, v;
     scf(u, v);
     g[u][v]++;
     g[v][u]++;
     deg[u]++;
     deg[v]++;
   }
   m = (int)trap.size();
   for (int i = (1); i <= (n); ++i)
     for (int j = (1); j <= (n); ++j) p[i][j] = (1.0 * g[i][j]) / (1.0 * deg[i]);
   return calc_w();
 }
 struct mat {
   double num[M][M];
   mat() { memset((num), (0), sizeof((num))); }
   mat(int x) {
     memset((num), (0), sizeof((num)));
     for (int i = 0; i < (M); ++i) num[i][i] = x;
   }
   mat(double a[][M]) {
     for (int i = 0; i < (M); ++i)
       for (int j = 0; j < (M); ++j) num[i][j] = a[i][j];
   }
   double &operator()(int i, int j) { return num[i][j]; }
   double operator()(int i, int j) const { return num[i][j]; }
   friend mat operator*(const mat &a, const mat &b) {
     mat c;
     for (int i = 0; i < (M); ++i)
       for (int j = 0; j < (M); ++j)
         for (int k = 0; k < (M); ++k) c(i, j) += a(i, k) * b(k, j);
     return c;
   }
 } g;
 mat kiss_me(mat a, int n) {
   mat ret = mat(1);
   while (n) {
     if (n & 1) ret = ret * a;
     a = a * a;
     n >>= 1;
   }
   return ret;
 }
 void RANK1() {
   g = mat(w);
   g = kiss_me(g, k - 2);
   double ans = 0.0;
   for (int i = 0; i < (m); ++i) ans += beg[i] * g(i, m - 1);
   printf( .12f
 , ans);
   return;
 }
 int main() {
   TZL();
   RANK1();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m;
 long long dis[100010];
 vector<int> mom[100010];
 vector<pair<int, int> > vertex[100010];
 set<int> q;
 void readin() {
   scanf( dd , &n, &m);
   int u, v, c;
   for (int i = 0; i < m; ++i) {
     scanf( ddd , &u, &v, &c);
     vertex[u].push_back(make_pair(v, c));
     vertex[v].push_back(make_pair(u, c));
   }
   int cnt;
   for (int i = 1; i <= n; ++i) {
     scanf( d , &cnt);
     while (cnt--) {
       scanf( d , &v);
       mom[i].push_back(v);
     }
   }
 }
 void spfa() {
   int u, v, c, nt, sz;
   vector<int>::iterator low;
   memset(dis, -1, sizeof(dis));
   while (!q.empty()) q.clear();
   q.insert(1);
   dis[1] = 0;
   while (!q.empty()) {
     u = *q.begin();
     q.erase(u);
     if (u == n) continue;
     nt = dis[u];
     low = lower_bound(mom[u].begin(), mom[u].end(), nt);
     for (; low != mom[u].end(); low++) {
       if (*low == nt)
         nt++;
       else if (*low > nt)
         break;
     }
     sz = vertex[u].size();
     for (int i = 0; i < sz; ++i) {
       v = vertex[u][i].first;
       c = vertex[u][i].second;
       if (dis[v] == -1 || dis[v] > nt + c) {
         dis[v] = nt + c;
         q.insert(v);
       }
     }
   }
 }
 int main() {
   readin();
   spfa();
   printf( extra , dis[n]);
 }


#include <bits/stdc++.h>
 using namespace std;
 static const int INF = 500000000;
 template <class T>
 void debug(T a, T b) {
   for (; a != b; ++a) cerr << *a << ' ';
   cerr << endl;
 }
 int n;
 pair<pair<int, int>, int> es[5005];
 vector<pair<int, int> > g[5005];
 int size[5005];
 int cut[5005];
 int prep(int v, int p) {
   size[v] = 1;
   for (int i = 0; i < g[v].size(); ++i) {
     int to = g[v][i].first;
     if (to == p || cut[to]) continue;
     size[v] += prep(to, v);
   }
   return size[v];
 }
 int type;
 int cost[2], root[2], all[2];
 void dfs(int v, int p) {
   int maxi = 0;
   for (int i = 0; i < g[v].size(); ++i) {
     int to = g[v][i].first;
     if (to == p || cut[to]) continue;
     maxi = max(maxi, size[to]);
     dfs(to, v);
   }
   if (max(maxi, all[type] - size[v]) < cost[type]) {
     cost[type] = max(maxi, all[type] - size[v]);
     root[type] = v;
   }
 }
 long long int tot;
 int dfs2(int v, int p) {
   size[v] = 1;
   for (int i = 0; i < g[v].size(); ++i) {
     int to = g[v][i].first;
     if (to == p || cut[to]) continue;
     size[v] += dfs2(to, v);
     tot += size[to] * (all[type] - size[to]) * (long long int)g[v][i].second;
     tot += size[to] * (long long int)all[type ^ 1] * g[v][i].second;
   }
   return size[v];
 }
 int main() {
   scanf( d , &n);
   for (int i = 0; i < n - 1; ++i) {
     int a, b, c;
     scanf( ddd , &a, &b, &c);
     --a;
     --b;
     g[a].push_back(make_pair(b, c));
     g[b].push_back(make_pair(a, c));
     es[i] = make_pair(make_pair(a, b), c);
   }
   long long int ans = 1e18;
   for (int i = 0; i < n - 1; ++i) {
     int a = es[i].first.first, b = es[i].first.second;
     tot = 0;
     cost[0] = cost[1] = INF;
     type = 0;
     cut[b] = 1;
     all[0] = prep(a, b);
     all[1] = n - all[0];
     dfs(a, b);
     dfs2(root[0], -1);
     type = 1;
     cut[b] = 0;
     cut[a] = 1;
     all[1] = prep(b, a);
     dfs(b, a);
     dfs2(root[1], -1);
     cut[a] = 0;
     tot += all[0] * all[1] * (long long int)es[i].second;
     ans = min(ans, tot);
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   int t;
   cin >> t;
   while (t--) {
     vector<pair<int, int>> st, re;
     int a, b;
     int n;
     cin >> n;
     for (int i = 0; i < n; i++) {
       cin >> a >> b;
       st.emplace_back(a, b);
       re.emplace_back(b, a);
     }
     sort(st.begin(), st.end());
     sort(re.begin(), re.end());
     cout << max(st[n - 1].first - re[0].first, 0) <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const double eps = 1e-8;
 const double pi = acos(-1.0);
 struct Q {
   int a, b, c;
   Q(int a, int b, int c) : a(a), b(b), c(c) {}
   bool operator<(const Q& o) const {
     if (a == o.a) return c < o.c;
     return a < o.a;
   }
 };
 vector<pair<int, int> > ans;
 set<Q> q;
 int in[100000];
 int main() {
   int n, i, a, b;
   scanf( d , &n);
   for (i = 0; i < n; ++i) {
     scanf( dd , &a, &b);
     in[i] = a;
     if (a) q.insert(Q(a, b, i));
   }
   while (!q.empty()) {
     Q u = *(q.begin());
     q.erase(q.begin());
     int cur = u.c;
     ans.push_back(make_pair(u.b, u.c));
     in[u.b]--;
     in[u.c]--;
     u = *q.lower_bound(Q(in[u.b] + 1, 0, u.b));
     q.erase(u);
     u.a--;
     u.b ^= cur;
     if (u.a) q.insert(u);
   }
   printf( d
 , ans.size());
   for (i = 0; i < ans.size(); ++i)
     printf( d d
 , ans[i].first, ans[i].second);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int pos[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
 int n;
 char s[510][510];
 int v[510][510];
 vector<pair<int, int> > vec, ans;
 int operator*(const pair<int, int> &a, const pair<int, int> &b) {
   return a.first * b.second - a.second * b.first;
 }
 pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) {
   return make_pair(a.first - b.first, a.second - b.second);
 }
 pair<int, int> stk[250010];
 int main() {
   while (1) {
     ans.clear();
     scanf( d , &n);
     if (n == 0) break;
     for (int i = n; i >= 1; i--) scanf( s , s[i] + 1);
     for (int i = 1; i <= n; i++)
       for (int j = 1; j <= n; j++) v[i][j] = s[i][j] - '0';
     vec.clear();
     for (int i = 1; i <= n; i++) {
       for (int j = 1; j <= n; j++) {
         int cnt = 0;
         for (int k = -1; k <= 0; k++) {
           for (int l = -1; l <= 0; l++) {
             cnt += v[i + k][j + l];
           }
         }
         if (cnt == 1) {
           if (v[i][j] == 1)
             vec.push_back(make_pair(i, j));
           else if (v[i - 1][j] == 1)
             vec.push_back(make_pair(i - 2, j));
           else if (v[i][j - 1] == 1)
             vec.push_back(make_pair(i, j - 2));
           else
             vec.push_back(make_pair(i - 2, j - 2));
         }
       }
     }
     for (auto &x : vec) swap(x.first, x.second);
     sort(vec.begin(), vec.end());
     int top = 0;
     for (auto &x : vec) {
       while (top > 1 && (stk[top] - stk[top - 1]) * (x - stk[top]) >= 0) top--;
       stk[++top] = x;
     }
     for (int i = 1; i <= top; i++) ans.push_back(stk[i]);
     reverse(vec.begin(), vec.end());
     top = 0;
     for (auto &x : vec) {
       while (top > 1 && (stk[top] - stk[top - 1]) * (x - stk[top]) >= 0) top--;
       stk[++top] = x;
     }
     for (int i = 2; i < top; i++) ans.push_back(stk[i]);
     printf( d
 , ans.size());
     for (auto &x : ans) printf( d d
 , x.first, x.second);
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC target( avx2 )
 #pragma GCC optimization( O3 )
 #pragma GCC optimization( unroll-loops )
 using namespace std;
 const int mod = 1e9 + 7;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t;
   cin >> t;
   while (t--) {
     long long n, m, a, b, i, j;
     cin >> n;
     deque<long long> dq, tmp;
     long long ar[n], ans[n];
     set<long long> s;
     for (i = 0; i < n; i++) {
       cin >> a;
       ar[a - 1] = i;
       ans[i] = 0;
     }
     a = n, b = 0;
     for (i = 0; i < n; i++) {
       a = min(a, ar[i]);
       b = max(b, ar[i]);
       if (b - a == i) ans[i] = 1;
     }
     for (i = 0; i < n; i++) cout << ans[i];
     cout << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   long long n, p, b = 0;
   cin >> n >> p;
   vector<long long> v;
   for (int i = 0; i < n; ++i) {
     string s;
     cin >> s;
     if (s ==  half ) {
       v.push_back(0);
     } else
       v.push_back(1), b++;
   }
   reverse(v.begin(), v.end());
   long long at = 0;
   for (int i = 0; i < n; ++i) {
     at *= 2;
     at += v[i];
   }
   cout << (at * p) - (b * p / 2) << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAX = 1005;
 vector<int> v[MAX];
 int dp[105][MAX];
 int main() {
   ios::sync_with_stdio(false);
   int n, t;
   cin >> n >> t;
   for (int i = 0; i < n; i++) {
     int t, p;
     cin >> t >> p;
     v[t].push_back(p);
   }
   for (int i = 0; i < MAX; i++) {
     sort(v[i].begin(), v[i].end());
     v[i].push_back(0);
     reverse(v[i].begin(), v[i].end());
     for (int j = 1; j < v[i].size(); j++) v[i][j] += v[i][j - 1];
   }
   for (int i = 1; i <= t; i++)
     for (int j = 1; j < MAX; j++)
       for (int k = 0; k < min((int)v[i].size(), j + 1); k++)
         dp[i][j] =
             max(dp[i][j], dp[i - 1][min(MAX - 1, (j - k) * 2)] + v[i][k]);
   cout << dp[t][1] << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long M = 7e2 + 5;
 const long long mod = 1e9 + 7;
 char sz[M];
 long long a[M], js;
 inline long long read() {
   register long long x = 0, y = 1;
   register char c = getchar();
   while (!isdigit(c)) {
     if (c == '-') y = 0;
     c = getchar();
   }
   while (isdigit(c)) {
     x = x * 10 + (c ^ 48);
     c = getchar();
   }
   return y ? x : -x;
 }
 long long f[M][M][10];
 long long dfs(long long pos, long long limit, long long sum, long long l) {
   if (!pos) return !sum  mod;
   if (!limit && ~f[pos][sum][l]) return f[pos][sum][l]  mod;
   long long up = limit ? a[pos] : 9;
   long long cnt = 0;
   for (long long i = 0; i <= up; i++)
     cnt = (cnt + dfs(pos - 1, limit && i == up, sum - (i >= l), l))  mod;
   if (!limit) f[pos][sum][l] = cnt;
   return cnt  mod;
 }
 signed main() {
   scanf( s , sz + 1);
   memset(f, -1, sizeof(f));
   long long len = strlen(sz + 1);
   for (long long i = 1; i <= len; i++) a[i] = sz[len - i + 1] - '0';
   a[0] = 0;
   for (long long i = 1; i <= 9; i++)
     for (long long j = 1, puz = 1; j <= len;
          j++, puz = (10ll * puz + 1ll)  mod)
       js = (js + dfs(len, 1, j, i) * puz  mod)  mod;
   printf( lld
 , js);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, m;
   cin >> n >> m;
   int A[n][m], B[n][m], C[n][m];
   vector<int> a, b;
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < m; j++) {
       cin >> A[i][j];
       a.push_back(A[i][j]);
     }
   }
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < m; j++) {
       cin >> B[i][j];
       b.push_back(B[i][j]);
     }
   }
   sort(a.begin(), a.end());
   sort(b.begin(), b.end());
   for (int i = 0; i < a.size(); i++) {
     if (a[i] != b[i]) {
       cout <<  NO  << endl;
       return 0;
     }
   }
   if (n >= m) {
     for (int i = 0; i < n; i++) {
       long long x = 0;
       for (int j = 0; j < min(i + 1, m); j++) {
         x ^= (long long)(A[i - j][j] ^ B[i - j][j]);
       }
       if (x) {
         cout <<  NO  << endl;
         return 0;
       }
     }
     for (int i = 0; i < m - 1; i++) {
       long long x = 0;
       for (int j = 1; j + i < m; j++) {
         x ^= (long long)(A[n - j][j + i] ^ B[n - j][j + i]);
       }
       if (x) {
         cout <<  NO  << endl;
         return 0;
       }
     }
   } else {
     for (int i = 0; i < m; i++) {
       long long x = 0;
       for (int j = 0; j < min(i + 1, n); j++) {
         x ^= (long long)(A[j][i - j] ^ B[j][i - j]);
       }
       if (x) {
         cout <<  NO  << endl;
         return 0;
       }
     }
     for (int i = 0; i < n - 1; i++) {
       long long x = 0;
       for (int j = 1; j + i < n; j++) {
         x ^= (long long)(A[j + i][m - j] ^ B[j + i][m - j]);
       }
       if (x) {
         cout <<  NO  << endl;
         return 0;
       }
     }
   }
   cout <<  YES  << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, q;
 int x[100100], y[100100];
 bool ans[100100];
 int par[100100], sz[100100];
 int distToPar[100100];
 int getpar(int now) { return (par[now] == now) ? now : getpar(par[now]); }
 bool getdist(int now) {
   bool ret = (par[now] == now) ? 0 : (getdist(par[now]) ^ distToPar[now]);
   return ret;
 }
 stack<pair<pair<int, int>, bool> > prevStat;
 map<pair<int, int>, int> mp;
 vector<pair<pair<int, int>, pair<int, int> > > opSeg;
 vector<pair<int, int> > add[400400];
 void addSeg(int tl, int tr, pair<int, int> val, int l, int r, int k) {
   if (tl > r || l > tr) return;
   if (tl <= l && r <= tr) {
     add[k].push_back(val);
     return;
   }
   int mid = (l + r) >> 1;
   addSeg(tl, tr, val, l, mid, k + k);
   addSeg(tl, tr, val, mid + 1, r, k + k + 1);
 }
 bool isBipar = 1;
 void addEdge(pair<int, int> now) {
   int u = now.first, v = now.second;
   int pu = getpar(u), pv = getpar(v);
   if (pu == pv) {
     prevStat.push(make_pair(make_pair(-1, -1), isBipar));
     if ((getdist(u) ^ getdist(v)) == 0) {
       isBipar = 0;
     }
     return;
   }
   if (sz[pu] > sz[pv]) swap(u, v), swap(pu, pv);
   prevStat.push(make_pair(make_pair(pu, sz[pu]), isBipar));
   distToPar[pu] = getdist(u) ^ getdist(v) ^ 1;
   par[pu] = pv;
   sz[pv] += sz[pu];
 }
 void undo() {
   int pos = prevStat.top().first.first, presz = prevStat.top().first.second,
       preIsBipar = prevStat.top().second;
   prevStat.pop();
   if (pos >= 0) {
     sz[pos] = presz;
     sz[par[pos]] -= sz[pos];
     par[pos] = pos;
   }
   isBipar = preIsBipar;
 }
 void solve(int l, int r, int k) {
   for (int i = 0; i < (int)add[k].size(); i++) {
     addEdge(add[k][i]);
   }
   if (l == r) {
     ans[l] = isBipar;
   } else {
     int mid = (l + r) >> 1;
     solve(l, mid, k + k);
     solve(mid + 1, r, k + k + 1);
   }
   for (int i = 0; i < (int)add[k].size(); i++) undo();
 }
 int main() {
   ios::sync_with_stdio(false);
   cin >> n >> q;
   for (int i = 0; i < q; i++) {
     cin >> x[i] >> y[i];
     x[i]--, y[i]--;
     if (x[i] > y[i]) swap(x[i], y[i]);
   }
   for (int i = 0; i < n; i++) par[i] = i, sz[i] = 1;
   for (int i = 0; i < q; i++) {
     pair<int, int> now = make_pair(x[i], y[i]);
     if (!mp.count(now) || mp[now] < 0) {
       mp[now] = i;
     } else {
       opSeg.push_back(make_pair(make_pair(mp[now], i), now));
       mp[now] = -1;
     }
   }
   for (map<pair<int, int>, int>::iterator it = mp.begin(); it != mp.end();
        it++) {
     if (it->second >= 0) {
       opSeg.push_back(make_pair(make_pair(it->second, q), it->first));
     }
   }
   for (int i = 0; i < (int)opSeg.size(); i++) {
     addSeg(opSeg[i].first.first, opSeg[i].first.second - 1, opSeg[i].second, 0,
            q - 1, 1);
   }
   solve(0, q - 1, 1);
   for (int i = 0; i < q; i++) cout << (ans[i] ?  YES  :  NO ) << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   string s;
   cin >> s;
   int count = 0;
   for (int i = 0; i < n - 1; i++) {
     if (s[i] == s[i + 1]) {
       count++;
     }
   }
   cout << count;
 }


#include <bits/stdc++.h>
 using namespace std;
 stringstream ans;
 int final_sum;
 string print_line(string a0) {
   int S = 0;
   for (int i = 0; i < a0.size() - 1; i++) {
     int digit = a0[i] - '0';
     S += digit;
     ans << digit <<  + ;
   }
   int digit = a0[a0.size() - 1] - '0';
   S += digit;
   ans << digit << endl;
   final_sum = S;
   return to_string(S);
 }
 void print289(string a0) { print_line(print_line(print_line(a0))); }
 void print999(string a0, int S, int offset = 0) {
   ans.str(  );
   int i = 0;
   int nz = 0;
   int dt = 0;
   int ddd = 0;
   while (i < offset) {
     ans << a0[i] <<  + ;
     dt = 10 * dt + a0[i] - '0';
     ddd += a0[i] - '0';
     i++;
   }
   for (i += 1; i < a0.size() - 1; i += 2) {
     int a = a0[i - 1] - '0';
     int b = a0[i] - '0';
     int dt = 10 * a + b - a - b;
     S += dt;
     ans << a << b <<  + ;
     if (S >= 1000) break;
   }
   if (S < 1000 && i < a0.size()) {
     int a = a0[i - 1] - '0';
     int b = a0[i] - '0';
     int dt = 10 * a + b - a - b;
     S += dt;
     ans << a << b;
   }
   i++;
   for (i; i < a0.size() - 1; i++) ans << a0[i] <<  + ;
   for (i; i < a0.size(); i++) ans << a0[a0.size() - 1];
   ans << endl;
   print_line(print_line(to_string(S)));
 }
 bool is_close(int S) {
   if (S == 0) return true;
   int div = 1;
   while (S / div > 0) div *= 10;
   if (S * 10 == div) return true;
   return div - S < 1000;
 }
 bool is_mega_close(int S) {
   if (S == 0) return true;
   int div = 1;
   while (S / div > 0) div *= 10;
   if (S * 10 == div) return true;
   return S - (div / 10) < 100;
 }
 void print(string a0, int S, int offset = 0) {
   ans.str(  );
   int i = 0;
   int nz = 0;
   int dt = 0;
   int ddd = 0;
   while (i < offset) {
     ans << a0[i] <<  + ;
     dt = dt * 10 + a0[i];
     ddd += a0[i] - '0';
     i++;
   }
   if (!is_close(S)) {
     for (i += 2; i < a0.size() - 2; i += 3) {
       int a = a0[i - 2] - '0';
       int b = a0[i - 1] - '0';
       int c = a0[i] - '0';
       int dt = 100 * a + 10 * b + c - a - b - c;
       S += dt;
       ans << a << b << c <<  + ;
       if (is_close(S)) break;
     }
     if (i < a0.size() - 2) i++;
   }
   if (!is_mega_close(S))
     for (i += 2; i < a0.size() - 2; i += 3) {
       int a = a0[i - 2] - '0';
       int b = a0[i - 1] - '0';
       int c = a0[i] - '0';
       int dt = 9 * a;
       S += dt;
       ans << a << b <<  +  << c <<  + ;
       if (is_mega_close(S)) break;
     }
   if (i >= a0.size() - 2)
     i -= 2;
   else
     i++;
   for (i; i < a0.size() - 1; i++) ans << a0[i] <<  + ;
   for (i; i < a0.size(); i++) ans << a0[a0.size() - 1];
   ans << endl;
   print_line(print_line(to_string(S)));
 }
 int main() {
   int n;
   cin >> n;
   string a0;
   cin >> a0;
   int S = 0;
   for (int i = 0; i < a0.size(); i++) {
     int digit = a0[i] - '0';
     S += digit;
   }
   if (S < 199) {
     print289(a0);
     cout << ans.str();
     return 0;
   }
   if (S < 1000) {
     print999(a0, S);
     int k = 1;
     while (final_sum > 9 && k < 2) print999(a0, S, k++);
     if (false && n == 155096) {
       cout << k << endl;
       cout << final_sum << endl;
       return 0;
     }
     cout << ans.str();
     return 0;
   }
   print(a0, S);
   int k = 1;
   while (final_sum > 9 && k < 3) print(a0, S, k++);
   cout << ans.str();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename T>
 inline T read() {
   T s = 0, f = 1;
   char ch = getchar();
   while (!isdigit(ch)) {
     if (ch == '-') f = -1;
     ch = getchar();
   }
   while (isdigit(ch)) {
     s = (s << 3) + (s << 1) + ch - 48;
     ch = getchar();
   }
   return s * f;
 }
 template <typename T>
 inline void print(T x) {
   if (x < 0) putchar('-'), x = -x;
   if (x > 9) print(x / 10);
   putchar(x  10 + '0');
 }
 const int N = 2e5 + 100;
 const int mod = 1e9 + 7;
 long long h[N], w[N], sum[N];
 struct Segment {
   static const int maxn = 2e5 + 100;
   struct star {
     long long lsum, rsum, sum;
   } s[maxn << 2];
   void pushup(int node, int l, int r) {
     int mid = l + r >> 1;
     s[node].lsum =
         max(s[node << 1].lsum, h[l] + sum[mid - 1] - sum[l - 1] +
                                    s[node << 1 | 1].lsum - h[mid + 1] + w[mid]);
     s[node].lsum = max(s[node].lsum, h[l] + h[mid + 1] + sum[mid] - sum[l - 1]);
     s[node].rsum =
         max(s[node << 1 | 1].rsum,
             h[r] + sum[r - 1] - sum[mid] + s[node << 1].rsum - h[mid] + w[mid]);
     s[node].rsum = max(s[node].rsum, h[r] + h[mid] + sum[r - 1] - sum[mid - 1]);
     s[node].sum = max(s[node << 1].rsum + s[node << 1 | 1].lsum - h[mid] -
                           h[mid + 1] + w[mid],
                       max(s[node << 1].sum, s[node << 1 | 1].sum));
     s[node].sum = max(s[node].sum, max(s[node].lsum, s[node].rsum));
     s[node].sum = max(s[node].sum, h[r] + h[l] + sum[r - 1] - sum[l - 1]);
     s[node].sum = max(
         s[node].sum, max(s[node << 1].rsum - h[mid] + h[mid + 1] + w[mid],
                          s[node << 1 | 1].lsum - h[mid + 1] + h[mid] + w[mid]));
     s[node].sum = max(s[node].sum, h[mid] + h[mid + 1] + w[mid]);
   }
   void build(int node, int l, int r) {
     if (l == r) {
       s[node].lsum = s[node].rsum = h[l];
       s[node].sum = 0;
       return;
     }
     int mid = l + r >> 1;
     build(node << 1, l, mid);
     build(node << 1 | 1, mid + 1, r);
     pushup(node, l, r);
   }
   star query(int node, int l, int r, int L, int R) {
     if (L == l && R == r) {
       return s[node];
     }
     int mid = l + r >> 1;
     if (R <= mid)
       return query(node << 1, l, mid, L, R);
     else if (L > mid)
       return query(node << 1 | 1, mid + 1, r, L, R);
     else {
       star lnode = query(node << 1, l, mid, L, mid);
       star rnode = query(node << 1 | 1, mid + 1, r, mid + 1, R);
       star now;
       now.lsum = max(lnode.lsum, h[L] + sum[mid - 1] - sum[L - 1] + rnode.lsum -
                                      h[mid + 1] + w[mid]);
       now.lsum = max(now.lsum, h[L] + h[mid + 1] + sum[mid] - sum[L - 1]);
       now.rsum = max(rnode.rsum, h[R] + sum[R - 1] - sum[mid] + lnode.rsum -
                                      h[mid] + w[mid]);
       now.rsum = max(now.rsum, h[R] + h[mid] + sum[R - 1] - sum[mid - 1]);
       now.sum = max(lnode.rsum + rnode.lsum - h[mid] - h[mid + 1] + w[mid],
                     max(lnode.sum, rnode.sum));
       now.sum = max(now.sum, max(now.lsum, now.rsum));
       now.sum = max(now.sum, h[L] + h[R] + sum[R - 1] - sum[L - 1]);
       now.sum = max(now.sum, max(lnode.rsum - h[mid] + h[mid + 1] + w[mid],
                                  rnode.lsum - h[mid + 1] + h[mid] + w[mid]));
       now.sum = max(now.sum, h[mid] + h[mid + 1] + w[mid]);
       return now;
     }
   }
 } tree;
 int main() {
   int n = read<int>(), m = read<int>();
   for (int i = 1; i <= n; ++i) {
     w[i] = read<long long>();
     w[i + n] = w[i];
     sum[i] = sum[i - 1] + w[i];
   }
   for (int i = 1; i <= n; ++i) {
     h[i] = read<long long>();
     h[i] = h[i] + h[i];
     h[i + n] = h[i];
   }
   for (int i = n + 1; i <= n + n; ++i) {
     sum[i] = sum[i - 1] + w[i];
   }
   tree.build(1, 1, n + n);
   for (int i = 1; i <= m; ++i) {
     int l = read<int>(), r = read<int>();
     int lc, rc;
     if (r >= l)
       lc = r + 1, rc = l + n - 1;
     else
       lc = r + 1, rc = l - 1;
     printf( lld
 , tree.query(1, 1, n + n, lc, rc).sum);
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m, a[1001000], cnt[1001000], z[1001000];
 int main() {
   ios::sync_with_stdio(false);
   memset(cnt, 0, sizeof(cnt));
   memset(z, 0, sizeof(z));
   cin >> n >> m;
   for (int i = 1; i <= n; i++) {
     cin >> a[i];
     if (a[i] <= m) cnt[a[i]]++;
   }
   int ans = 0, flag = 0;
   for (int i = 1; i <= m; i++) {
     if (cnt[i]) {
       for (int k = 1; k * i <= m; k++) z[k * i] += cnt[i];
     }
   }
   for (int i = 1; i <= m; i++) {
     if (z[i] > ans) {
       ans = z[i];
       flag = i;
     }
   }
   cout << (flag == 0 ? 1 : flag) <<     << ans << endl;
   for (int i = 1; i <= n; i++) {
     if (flag  a[i] == 0 && flag != 0) cout << i <<    ;
   }
   cout << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 signed long long int n, m, k, x, y;
 signed long long int ct[3], myct;
 int main() {
   cin >> n >> m >> k >> x >> y;
   signed long long int f1, q, val, rem = k;
   if (n == 1) {
     f1 = m;
     q = rem / f1;
     rem -= q * f1;
     myct = q;
     ct[1] = q;
     ct[2] = q;
     if (y <= rem) myct++;
     if (rem != 0) ct[1]++;
     cout << ct[1] <<     << ct[2] <<     << myct <<
 ;
     return 0;
   } else if (n == 2) {
     f1 = 2 * m;
     q = rem / f1;
     rem -= q * f1;
     myct = q;
     ct[1] = ct[2] = q;
     if (((x - 1) * m + y) <= rem) myct++;
     if (rem != 0) ct[1]++;
     cout << ct[1] <<     << ct[2] <<     << myct <<
 ;
     return 0;
   }
   f1 = ((n - 2) * m * 2) + (2 * m);
   q = rem / f1;
   rem -= q * f1;
   ct[0] = 2 * q;
   ct[1] = q;
   ct[2] = q;
   int grp = -1;
   if (x == 1) {
     myct = q;
     grp = 1;
   } else if (x == n) {
     myct = q;
     grp = 2;
   } else {
     myct = 2 * q;
     grp = 0;
   }
   int stp = 0;
   if (rem > 0 && rem <= m) {
     ct[1]++;
     if (((x - 1) * m + y) <= rem) myct++;
   } else if (rem > m && rem <= (n - 1) * m) {
     ct[0]++;
     ct[1]++;
     if (((x - 1) * m + y) <= rem) myct++;
   } else if (rem > (n - 1) * m && rem <= n * m) {
     ct[0]++;
     ct[1]++;
     stp = 3;
     if (rem == n * m) ct[2]++;
     if (((x - 1) * m + y) <= rem) myct++;
   } else if (rem > n * m && rem <= f1) {
     ct[0] += 2;
     ct[1]++;
     ct[2]++;
     myct++;
     stp = 4;
     if (x == 1 || x == n) {
     } else {
       rem -= n * m;
       val = (n - x - 1) * m + y;
       if (val <= rem) myct++;
     }
   }
   signed long long int mini = ct[0], maxi = ct[0];
   for (int i = 1; i < 3; i++) {
     mini = min(mini, ct[i]);
     maxi = max(maxi, ct[i]);
   }
   cout << maxi <<     << mini <<     << myct <<
 ;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, mncnt = 1000000000, cnt;
   string a;
   string c =  ACTG ;
   cin >> n >> a;
   for (int i = 0; i <= n - 4; i++) {
     cnt = 0;
     string b = a.substr(i, 4);
     for (int j = 0; j < 4; j++) {
       int x = c[j] - 'A';
       int y = b[j] - 'A';
       if (abs(y - x) <= 13)
         cnt += abs(y - x);
       else
         cnt += 26 - (abs(y - x));
     }
     mncnt = min(mncnt, cnt);
   }
   cout << mncnt << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct data {
   int x, h, p;
 } a[100005];
 int n, x[100005], kq[100005], st[4 * 100005];
 void update(int id, int l, int r, int p, int v) {
   if (l > p || r < p) return;
   if (l == p && l == r) {
     st[id] = v;
     return;
   }
   int m = (l + r) >> 1;
   update(id << 1, l, m, p, v);
   update((id << 1) + 1, m + 1, r, p, v);
   st[id] = max(st[id << 1], st[(id << 1) + 1]);
 }
 int getmax(int id, int l, int r, int d, int c) {
   if (l > c || r < d) return 0;
   if (l >= d && r <= c) return st[id];
   int m = (l + r) >> 1;
   return max(getmax((id << 1), l, m, d, c),
              getmax((id << 1) + 1, m + 1, r, d, c));
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin >> n;
   for (int i = 1; i <= n; ++i) {
     cin >> a[i].x >> a[i].h;
     a[i].p = i;
     a[i].h = a[i].x + a[i].h - 1;
   }
   sort(a + 1, a + n + 1, [](data a, data b) { return a.x < b.x; });
   for (int i = n; i >= 1; --i) {
     x[i] = a[i].x;
     int pos = upper_bound(x + i + 1, x + n + 1, a[i].h) - x - 1;
     int t = getmax(1, 1, n, i + 1, pos);
     if (t < i) t = i;
     kq[a[i].p] = t - i + 1;
     update(1, 1, n, i, t);
   }
   for (int i = 1; i <= n; ++i) cout << kq[i] << ' ';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int mas[1010][1010];
 int main() {
   int N, K;
   cin >> N >> K;
   for (int i = 1; i <= N; i++) {
     int k = 0;
     for (int j = 1; j <= N; j++) {
       if (k == K)
         break;
       else if (i == j)
         continue;
       else if (mas[j][i] || mas[i][j])
         continue;
       else {
         mas[i][j] = 1;
         k++;
       }
     }
     if (k < K) {
       cout << -1 << endl;
       return 0;
     }
   }
   int cnt = 0;
   for (int i = 1; i <= N; i++) {
     for (int j = 1; j <= N; j++) {
       if (mas[i][j]) cnt++;
     }
   }
   cout << cnt << endl;
   for (int i = 1; i <= N; i++) {
     for (int j = 1; j <= N; j++) {
       if (mas[i][j]) cout << i <<     << j << endl;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, m, k, mod = 1e9 + 7;
 map<long long, long long> mp;
 string s;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   srand(time(0));
   cin >> n >> k;
   vector<long long> a(n + 2);
   vector<long long> b(k + 2);
   for (long long i = 1; i <= n; ++i) cin >> a[i], a[i] -= i;
   a[0] = -2e9;
   a[n + 1] = 2e9;
   b[k + 1] = n + 1;
   for (long long i = 1; i <= k; ++i) cin >> b[i];
   long long ans = 0;
   for (long long i = 0; i <= k; ++i) {
     long long l = b[i];
     long long r = b[i + 1];
     if (a[l] > a[r]) {
       cout << -1;
       exit(0);
     }
     vector<long long> v;
     for (long long j = l + 1; j < r; ++j) {
       if (a[j] > a[r] || a[j] < a[l]) continue;
       auto x = upper_bound(v.begin(), v.end(), a[j]);
       if (x == v.end())
         v.push_back(a[j]);
       else
         *x = a[j];
     }
     ans += r - l - 1 - v.size();
   }
   cout << ans;
 }


#include <bits/stdc++.h>
 using namespace std;
 int N, K, M, S;
 int arr[500000];
 int raito[500005];
 int seen[500005];
 int bucket[500005];
 int shift[500005];
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cin >> M >> K >> N >> S;
   for (int i = 0; i < M; i++) {
     cin >> arr[i];
   }
   int t;
   for (int i = 0; i < S; i++) {
     cin >> t;
     bucket[t]++;
   }
   for (int i = 0; i < 500005; i++) seen[i] = -1;
   for (int i = M - 1; i >= 0; i--) {
     raito[i] = seen[arr[i]];
     seen[arr[i]] = i;
   }
   int maxima = 0;
   for (int i = 0; i < 500005; i++) {
     if (bucket[i] == 0) continue;
     int cur = seen[i];
     int p = 1;
     while (cur != -1 && p < bucket[i]) {
       cur = raito[cur];
       p++;
     }
     if (cur == -1) {
       cout << -1;
       return 0;
     }
     shift[i] = cur;
     maxima = max(maxima, cur);
   }
   vector<int> adj;
   for (int i = 0; i < M;) {
     int total = i / K + 1 + ((M - 1) - (maxima + 1) + 1) / K;
     if (total >= N) {
       int extra = K - S;
       for (int j = i; j <= maxima; j++) {
         if (extra <= 0 && bucket[arr[j]] == 0) {
           adj.push_back(j + 1);
         } else if (bucket[arr[j]] == 0) {
           extra--;
         } else {
           bucket[arr[j]]--;
         }
       }
       cout << adj.size() <<
 ;
       for (int j = 0; j < adj.size(); j++) {
         cout << adj[j] <<    ;
       }
       return 0;
     }
     if (i + 1 == M) break;
     int pp = 0;
     if (bucket[arr[i]] != 0) {
       shift[arr[i]] = raito[shift[arr[i]]];
       maxima = max(maxima, shift[arr[i]]);
       if (shift[arr[i]] == -1) {
         cout << -1;
         return 0;
       }
     }
     i++;
   }
   cout << -1;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = 400010;
 int n;
 int fa[MAXN][21];
 int dep[MAXN];
 int LCA(int x, int y) {
   if (dep[x] < dep[y]) swap(x, y);
   for (int i = 20; i >= 0; i--) {
     if (dep[x] - (1 << i) >= dep[y]) {
       x = fa[x][i];
     }
   }
   if (x == y) return x;
   for (int i = 20; i >= 0; i--) {
     if (fa[x][i] != fa[y][i]) {
       x = fa[x][i];
       y = fa[y][i];
     }
   }
   return fa[x][0];
 }
 int main() {
   scanf( d , &n);
   int L, R;
   L = R = 1;
   int mx = 0;
   int p;
   for (int i = 2; i <= n; i++) {
     scanf( d , &p);
     fa[i][0] = p;
     dep[i] = dep[p] + 1;
     for (int j = 1; j <= 20; j++) {
       fa[i][j] = fa[fa[i][j - 1]][j - 1];
     }
     int z = LCA(i, L);
     int ans1 = dep[i] + dep[L] - 2 * dep[z];
     z = LCA(i, R);
     int ans2 = dep[i] + dep[R] - 2 * dep[z];
     if (ans1 > ans2 && ans1 > mx) {
       mx = ans1;
       R = i;
     }
     if (ans2 >= ans1 && ans2 > mx) {
       L = i;
       mx = ans2;
     }
     if (i == n)
       printf( d
 , mx);
     else
       printf( d  , mx);
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 #pragma GCC optimize( Ofast,no-stack-protector )
 #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )
 #pragma GCC optimize( unroll-loops )
 long long fun(long long n, long long m, long long mid) {
   long long val = 0;
   for (long long i = 1; i <= n; i++) val += min(m, (mid - 1) / i);
   return val;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   ;
   long long tst = 1;
   for (long long tt = 1; tt <= tst; tt++) {
     long long n, m, k;
     cin >> n >> m >> k;
     long long l = 1, r = (n * m) + 1;
     while (l < r) {
       long long mid = (l + r) / 2;
       if (fun(n, m, mid) < k)
         l = mid + 1;
       else
         r = mid;
     }
     cout << l - 1 << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long gcd(long long a, long long b) { return b ? gcd(b, a  b) : a; }
 long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
 int main() {
   long long a, b;
   while (cin >> a >> b) {
     long long suma = 0, sumb = 0;
     long long ca = 0, cb = 0;
     long long limit = lcm(a, b);
     long long now = 0, prev = 0;
     while (now <= limit) {
       if (now  b != 0 || (now  a == 0 && a > b)) {
         suma += now - prev;
       } else {
         sumb += now - prev;
       }
       prev = now;
       now = min(a * (ca + 1), b * (cb + 1));
       if (now  a == 0) ca++;
       if (now  b == 0) cb++;
     }
     cout << (suma == sumb ?  Equal  : suma > sumb ?  Dasha  :  Masha ) << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, k, dp[2000 + 10][2000 + 10];
 bool v[2000 + 10][2000 + 10];
 vector<int> vec[2000 + 10];
 int solve(int curr, int kk) {
   if (kk > k) return 0;
   if (kk == k) return 1;
   if (v[curr][kk]) return dp[curr][kk];
   for (int i = 0; i < vec[curr].size(); i++) {
     dp[curr][kk] += (solve(vec[curr][i], kk + 1))  1000000007;
     dp[curr][kk] = 1000000007;
   }
   v[curr][kk] = true;
   return dp[curr][kk];
 }
 int main() {
   ios::sync_with_stdio(false), cin.tie(0);
   cin >> n >> k;
   for (int i = 1; i <= n; i++) {
     for (int j = i; j <= n; j += i) {
       if (!(j  i)) vec[i].push_back(j);
     }
   }
   cout << solve(1, 0) <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int a[100005];
 int dp[302][100005];
 int main() {
   ios::sync_with_stdio(0);
   int n, q;
   cin >> n;
   for (int i = 1; i <= n; ++i) cin >> a[i];
   cin >> q;
   memset(dp, 0, sizeof(dp));
   for (int k = min(300, n); k >= 1; --k) {
     for (int i = n; i >= 1; --i) {
       if (i + a[i] + k > n)
         dp[k][i] = 1;
       else
         dp[k][i] = 1 + dp[k][i + a[i] + k];
     }
   }
   while (q--) {
     int p, k;
     cin >> p >> k;
     if (k <= 300)
       cout << dp[k][p] << endl;
     else {
       int ans = 0;
       while (p <= n) {
         p = p + a[p] + k;
         ans++;
       }
       cout << ans << endl;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, ans = 0, minm;
 long long A[10 * 100000 + 6];
 unordered_map<long long, long long> M;
 long long pos, neg, cc = 0, k = 0;
 int main() {
   scanf( lld , &n);
   for (int i = 1; i <= n; ++i) {
     scanf( lld , &A[i]);
     M[A[i] - i]++;
     ans += abs(A[i] - i);
     if (A[i] <= i)
       neg++;
     else
       pos++;
   }
   minm = ans;
   for (long long i = 1, j = n; i <= n - 1; ++i, --j) {
     if (A[j] - j - cc <= 0)
       --neg;
     else
       --pos;
     ans -= abs(A[j] - j - cc);
     ans += A[j];
     ++pos;
     M[A[j] + cc]++;
     M[A[j] - j]--;
     ++cc;
     ans -= pos;
     ans += neg;
     pos -= M[cc];
     neg += M[cc];
     if (ans <= minm) {
       minm = ans;
       k = i;
     }
   }
   printf( lld lld
 , minm, k);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main(int argc, const char* argv[]) {
   int cases;
   cin >> cases;
   while (cases--) {
     int num;
     scanf( d , &num);
     vector<pair<int, int> > coords;
     pair<int, int> z(0, 0);
     coords.push_back(z);
     for (int i = 0; i < num; ++i) {
       int x, y;
       scanf( dd , &x, &y);
       coords.push_back({x, y});
     }
     sort(coords.begin(), coords.end());
     string out;
     bool ok = true;
     for (int i = 1; i <= num; ++i) {
       int diffx = coords[i].first - coords[i - 1].first;
       int diffy = coords[i].second - coords[i - 1].second;
       if (diffx < 0 || diffy < 0) {
         ok = false;
         break;
       }
       while (diffx--) out += 'R';
       while (diffy--) out += 'U';
     }
     if (ok) {
       cout <<  YES  << endl;
       cout << out << endl;
     } else {
       cout <<  NO  << endl;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int M = 110;
 int a[M];
 int main() {
   int n, cnt = 0;
   scanf( d , &n);
   for (int i = 1; i <= n; i++) {
     scanf( d , a + i);
     if (a[i]  2 == 0) cnt++;
   }
   if (n  2 == 0) {
     printf( No
 );
     return 0;
   }
   if (a[1]  2 == 0 || a[n]  2 == 0) {
     printf( No
 );
     return 0;
   } else {
     printf( Yes
 );
     return 0;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 T mulmod(T a, T b) {
   if (b == 0) return 0;
   if (b == 1) return a;
   T x = mulmod(a, b >> 1);
   x = (x + x)  1000000007;
   if (b & 1) x = (x + a)  1000000007;
   return x;
 }
 template <class T>
 T larger(T a, T b) {
   return (a > b ? a : b);
 }
 template <class T>
 T smaller(T a, T b) {
   return (a < b ? a : b);
 }
 template <class T>
 T gcd(T a, T b) {
   if (b == 0) return a;
   return gcd(b, a  b);
 }
 template <class T>
 T lcm(T a, T b) {
   return (a * b) / gcd(a, b);
 }
 template <class T>
 string converter(T n) {
   stringstream x;
   x << n;
   return x.str();
 }
 template <class T>
 T pw(T a, T b) {
   if (b == 0) return 1;
   T x = pw(a, b >> 1);
   x = mulmod(x, x);
   if (b & 1) x = mulmod(x, a);
   return x;
 }
 template <class T1>
 void deb(T1 e1) {
   cout << e1 << endl;
 }
 template <class T1, class T2>
 void deb(T1 e1, T2 e2) {
   cout << e1 <<     << e2 << endl;
 }
 template <class T1, class T2, class T3>
 void deb(T1 e1, T2 e2, T3 e3) {
   cout << e1 <<     << e2 <<     << e3 << endl;
 }
 template <class T1, class T2, class T3, class T4>
 void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
   cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;
 }
 template <class T1, class T2, class T3, class T4, class T5>
 void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
   cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;
 }
 template <class T1, class T2, class T3, class T4, class T5, class T6>
 void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
   cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6
        << endl;
 }
 void letsgo() {
   long long int a, b, x, n;
   cin >> a >> b >> n >> x;
   if (a == 1) {
     cout << (x + (n  1000000007 * b)  1000000007)  1000000007;
     return;
   }
   long long int aN = pw(a, n);
   long long int ans = (aN * x)  1000000007;
   long long int z = ((aN - 1 + 1000000007)  1000000007 * b)  1000000007;
   z = (z * pw(a - 1, 1000000007 - 2ll))  1000000007;
   cout << (ans + z)  1000000007;
 }
 int main() {
   letsgo();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 0x3f3f3f3f;
 const double eps = 1e-8;
 const double PI = acos(-1.0);
 const int maxn = 200 + 10;
 char str[maxn];
 struct TwoSat {
   int n;
   vector<int> G[maxn * 2];
   bool mark[maxn * 2];
   int S[maxn * 2], c;
   bool isv[maxn];
   int sz;
   bool dfs(int x) {
     if (mark[x ^ 1]) return false;
     if (mark[x]) return true;
     if (x / 2 < xi) {
       int id = str[x / 2] - 'a';
       if (isv[id] != (x & 1)) return false;
       tmp[x / 2] = str[x / 2];
     } else if (x / 2 == xi) {
       int t = get_min(str[xi] - 'a', (x & 1) ? true : false);
       if (t == -1) return false;
       tmp[x / 2] = t + 'a';
     } else {
       int t = get_min(-1, (x & 1) ? true : false);
       if (t == -1) return false;
       tmp[x / 2] = t + 'a';
     }
     mark[x] = true;
     S[c++] = x;
     for (int i = 0; i < G[x].size(); i++)
       if (!dfs(G[x][i])) return false;
     return true;
   }
   void init(int n, char *s) {
     this->n = n;
     for (int i = 0; i < n * 2; i++) G[i].clear();
     memset(mark, false, sizeof(mark));
     sz = strlen(s);
     for (int i = 0; i < sz; i++) isv[i] = s[i] == 'V' ? true : false;
   }
   void add_clause(int x, int xval, int y, int yval) {
     x = x * 2 + xval;
     y = y * 2 + yval;
     G[x ^ 1].push_back(y);
     G[y ^ 1].push_back(x);
   }
   int get_min(int pos, bool c) {
     for (int i = pos + 1; i < sz; i++) {
       if (c == isv[i]) return i;
     }
     return -1;
   }
   char ans[maxn], tmp[maxn];
   int xi;
   void solve() {
     bool OK = false;
     for (int pos = 0; pos <= n; pos++) {
       for (int x = 0; x <= 1; x++) {
         xi = pos;
         bool ok = false;
         memset(mark, false, sizeof(mark));
         strcpy(tmp, str);
         if (pos < n) {
           int t = get_min(str[pos] - 'a', (x & 1) ? true : false);
           if (t == -1) continue;
           tmp[pos] = t + 'a';
         }
         for (int i = pos + 1; i < n; i++) tmp[i] = 'a';
         c = 0;
         for (int i = 0; i < n; i++) {
           int x1 = (i << 1) | (isv[tmp[i] - 'a']);
           if (!dfs(x1)) {
             ok = true;
             break;
           }
         }
         if (n == 200) {
         }
         if (ok) continue;
         OK = true;
         tmp[n] = 0;
         if (ans[0] == 0)
           strcpy(ans, tmp);
         else if (strcmp(tmp, ans) < 0)
           strcpy(ans, tmp);
       }
     }
     if (OK)
       printf( s
 , ans);
     else
       printf( -1
 );
   }
 } sat;
 int main() {
   int n, m;
   while (~scanf( s , str)) {
     scanf( dd , &n, &m);
     sat.init(n, str);
     for (int i = 0, x, y, xval, yval; i < m; i++) {
       char t1[5], t2[5];
       scanf( dsds , &x, t1, &y, t2);
       xval = t1[0] == 'V' ? 1 : 0;
       yval = t2[0] == 'V' ? 1 : 0;
       --x;
       --y;
       sat.add_clause(x, xval ^ 1, y, yval);
     }
     scanf( s , str);
     sat.solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int thien, n, tt, h;
 string s;
 int main() {
   cin >> tt;
   for (int ii = 1; ii <= tt; ii++) {
     cin >> n;
     thien = 0;
     h = 0;
     for (int i = 1; i <= n; i++) {
       cin >> s;
       if (s.length()  2 != 0) thien++;
       for (int j = 0; j < s.length(); j++)
         if (s[j] == '1') h++;
     }
     if (h  2 != 0 && thien == 0)
       cout << n - 1 << endl;
     else
       cout << n << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 300010;
 int p1[maxn], p2[maxn], q[maxn];
 int main() {
   int n, m;
   scanf( dd , &n, &m);
   for (int i = 0; i < n; i++) {
     scanf( d , &p1[i]);
     p1[i]--;
     p2[p1[i]] = i;
     q[i] = n;
   }
   for (int i = 0; i < m; i++) {
     int x, y;
     scanf( dd , &x, &y);
     x--;
     y--;
     x = p2[x];
     y = p2[y];
     if (x > y) swap(x, y);
     q[x] = min(q[x], y);
   }
   int r = n - 1;
   long long ans = 0;
   for (int i = n - 1; i >= 0; i--) {
     r = min(q[i] - 1, r);
     ans += r - i + 1;
   }
   printf( lld
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, a[200001];
 const double esl = 1e-11;
 double cal(double x) {
   double t = 0;
   double ans = 0;
   for (int i = 1; i <= n; i++) {
     if (t + a[i] - x < 0) {
       ans = max(ans, t);
       t = 0;
     } else {
       t += ((double)a[i] - x);
       ans = max(ans, t);
     }
   }
   ans = max(ans, t);
   double t1 = 0;
   for (int i = 1; i <= n; i++) {
     if (t1 + a[i] - x > 0) {
       ans = max(ans, -t1);
       t1 = 0;
     } else {
       t1 += ((double)a[i] - x);
       ans = max(ans, -t1);
     }
   }
   ans = max(ans, -t1);
   return ans;
 }
 int main() {
   scanf( d , &n);
   for (int i = 1; i <= n; i++) {
     scanf( d , &a[i]);
   }
   double l = -(1e5);
   double r = 1e5;
   for (int i = 1; i <= 500; i++) {
     double d = (2.0 * l + r) / 3;
     double c = (2.0 * r + l) / 3;
     if (cal(d) > cal(c)) {
       l = d;
     } else
       r = c;
   }
   printf( .10f , cal(l));
   return 0;
 }


#include <bits/stdc++.h>
 const int N = 5e4 + 10;
 int n, m;
 std::vector<char> a[N];
 int sx[N], sy[N];
 int main() {
   int T;
   scanf( d , &T);
   while (T--) {
     scanf( dd , &n, &m);
     for (int i = 1; i <= n; ++i) {
       a[i].resize(m + 2);
       getchar();
       for (int j = 1; j <= m; ++j) scanf( c , &a[i][j]);
     }
     int cnt_x = 0, cnt_y = 0, p_x = 1, p_y = 1;
     for (int i = 1; i <= n; ++i) {
       int sum = 0;
       for (int j = 1; j <= m; ++j) sum += (a[i][j] == '*');
       sx[i] = sum;
     }
     for (int i = 1; i <= m; ++i) {
       int sum = 0;
       for (int j = 1; j <= n; ++j) sum += (a[j][i] == '*');
       sy[i] = sum;
     }
     int ans = 0x3f3f3f3f;
     for (int i = 1; i <= n; ++i)
       for (int j = 1; j <= m; ++j) {
         int now = n + m - sx[i] - sy[j];
         if (a[i][j] == '.') --now;
         ans = std::min(ans, now);
       }
     printf( d
 , ans);
     for (int i = 1; i <= n; ++i) a[i].clear(), sx[i] = 0;
     for (int i = 1; i <= m; ++i) sy[i] = 0;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 auto clk = clock();
 mt19937_64 rang(
     chrono::high_resolution_clock::now().time_since_epoch().count());
 void test_case() {
   long long int n;
   cin >> n;
   long long int a[n + 1];
   long long int t = -1, b = -1, c = -1;
   for (long long int i = 1; i <= n; i++) {
     cin >> a[i];
   }
   for (long long int i = 2; i <= n - 1; i++) {
     for (long long int j = i - 1; j >= 1; j--) {
       if (a[j] < a[i]) {
         t = j;
         break;
       }
     }
     for (long long int j = i + 1; j <= n; j++) {
       if (a[j] < a[i]) {
         c = j;
         break;
       }
     }
     if (t != -1 && c != -1) {
       b = i;
       break;
     }
     t = -1, c = -1;
   }
   if (b != -1) {
     cout <<  YES  << endl;
     cout << t <<     << b <<     << c << endl;
   } else
     cout <<  NO  << endl;
 }
 signed main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   srand(chrono::high_resolution_clock::now().time_since_epoch().count());
   cout << fixed << setprecision(10);
   long long int t = 1;
   cin >> t;
   while (t--) {
     test_case();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long nthRoot(long long A, long long N) {
   float xPre = rand()  10;
   float eps = 1e-3;
   float delX = LLONG_MAX;
   float xK;
   while (delX > eps) {
     xK = ((N - 1.0) * xPre + (float)A / pow(xPre, N - 1)) / (float)N;
     delX = abs(xK - xPre);
     xPre = xK;
   }
   return ceil(xK);
 }
 int main() {
   long long n;
   cin >> n;
   char a[] = {'c', 'o', 'd', 'e', 'f', 'o', 'r', 'c', 'e', 's'};
   long long in = 0, num;
   num = nthRoot(n, 10);
   if (pow(num, 10) < n) num++;
   for (int i = 0; i <= 10; i++) {
     if (pow(num - 1, i) * pow(num, 10 - i) >= n) {
       in = i;
     } else
       break;
   }
   if (in * (num - 1) + (10 - in) * num - 10 < n - 1) {
     for (int i = 0; i < in; i++) {
       long long t = num - 1;
       while (t--) cout << a[i];
     }
     for (int i = in; i < 10; i++) {
       long long t = num;
       while (t--) cout << a[i];
     }
   } else {
     for (int i = 0; i < 10; i++) cout << a[i];
     long long t = n - 1;
     while (t--) cout << a[9];
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 inline void amin(T& a, const T& b) {
   if (a > b) a = b;
 }
 template <class T>
 inline void amax(T& a, const T& b) {
   if (a < b) a = b;
 }
 template <class T>
 inline void rv(vector<T>& v, int n) {
   vector<T>(n).swap(v);
   for (int i = 0; i < (n); i++) cin >> v[i];
 }
 inline void rv(int* v, int n) {
   for (int i = 0; i < (n); i++) scanf( d , &v[i]);
 }
 inline void rv(long long* v, int n) {
   for (int i = 0; i < (n); i++) scanf( lld , &v[i]);
 }
 inline vector<int> rvi(int n) {
   vector<int> v(n);
   for (int i = 0; i < (n); i++) scanf( d , &v[i]);
   return v;
 }
 inline vector<long long> rvl(int n) {
   vector<long long> v(n);
   for (int i = 0; i < (n); i++) scanf( lld , &v[i]);
   return v;
 }
 inline vector<string> rvs(int n) {
   vector<string> v(n);
   for (int i = 0; i < (n); i++) scanf( s , &v[i]);
   return v;
 }
 template <class T>
 inline void readvv(vector<vector<T>>& v, int m, int n) {
   vector<vector<T>>(m).swap(v);
   for (int i = 0; i < (m); i++) readv(v[i], n);
 }
 inline void pvi(vector<int>& v) {
   for (int i = 0; i < (v.size()); i++) printf( d  , v[i]);
   printf(
 );
 }
 inline void pvl(vector<long long>& v) {
   for (int i = 0; i < (v.size()); i++) {
     printf( lld  , v[i]);
   }
   printf(
 );
 }
 inline void pvs(vector<string>& v) {
   for (int i = 0; i < (v.size()); i++) {
     printf( s
 , v[i].c_str());
   }
 }
 int main() {
   long long n;
   long double s;
   cin >> n >> s;
   vector<vector<long long>> g(n);
   for (int i = 0; i < (n - 1); i++) {
     long long u, v;
     cin >> u >> v;
     g[u - 1].push_back(v - 1);
     g[v - 1].push_back(u - 1);
   }
   long double leaves = 0, two = 2;
   for (int i = 0; i < (n); i++) {
     if (g[i].size() == 1) leaves++;
   }
   cout << setprecision(20) << endl;
   cout << ((two * s) / leaves) << endl;
   return 0;
 }


#include  bits/stdc++.h
 using namespace std;
 #define all(x) x.begin(),x.end()
 #define pb push_back
 #define ff first
 #define ss second
 #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define ar array
 #define int long long
 #define F(i,a,b) for(i=a;i<b;++i)
 #define RF(i,b,a) for(i=b;i>=a;--i)
 #define NL cout<<
 ;
 #define INF LONG_LONG_MAX
 #define pii pair<int,int>
 #define vi vector<int>

 typedef long long ll;
 typedef long double ld;
 const ll mod=1e9+7;
 bool comp(ll a,ll b)
 {
 	return a<b;
 }
 ll fpow(ll a, ll b) {

 	ll res=1;
 	while(b) {
 		if(b&1)
 			res=(res*a);
 		a=(a*a);
 		b>>=1;
 	}
 	return res;
 }

 ll minm(ll a,ll b){
 	if(a<b) return a;
 	return b;
 }

 ll maxm(ll a,ll b){
 	if(a>b){ return a;}
 	else return b;
 }

 int PHI(int k){
 	// This is Euler's Totient Function.
 	//This function returns no. of coprime numbers to N in range [1,2,....,N]

 	  int ans=k;
 	  for(int i=2;i*i<=k;++i){
 	  	if(ki==0){
 	  		ans-=ans/i;
 	  		while(ki==0){
 	  			k/=i;
 	  		}
 	  	}
 	  }
      if(k>1) ans-=ans/k;
      return ans;

 }

 void solve(){

    int n,i;
    cin >> n;

    vector<pii>ecells;
    vector<pii>ocells;

    for(i=1;i<=n;i++){
    	for(int j=1;j<=n;j++){
    		if((i+j)2){
    			ocells.pb({i,j});
    		}
    		else ecells.pb({i,j});
    	}
    }

    // 1 even
    // 2,3 odd
    // if not possible ie all odd are filled, fill 2,3 in even

    int cnt=0;

    while(cnt<n*n){
    	int a; cin >> a;

    	if(a==1){
    		 // try to fill 2 in odd cell
    		 // if not possible , fill 3 in even
    		 if(ocells.empty()){
    		 	cout<< 3  <<ecells.back().ff<<   <<ecells.back().ss<<endl;
    		 	ecells.pop_back();
    		 }

    		 else{
    		 	cout<< 2  <<ocells.back().ff<<   <<ocells.back().ss<<endl;
    		 	ocells.pop_back();
    		 }
    		 ++cnt;
    	}

    	else if(a==2){
    		// fill 1 in even , if possible
    		if(!ecells.empty()){
    			cout<< 1  <<ecells.back().ff<<   <<ecells.back().ss<<endl;
    			ecells.pop_back();
    		}

    		else{
    			// fill 3 in ocells
    			cout<< 3  <<ocells.back().ff<<   <<ocells.back().ss<<endl;
    			ocells.pop_back();
    		}
    		cnt++;
    	}
    	else{
    		// fill 1 in even if possible
    		if(!ecells.empty()){
    			cout<< 1  <<ecells.back().ff<<   <<ecells.back().ss<<endl;
    			ecells.pop_back();
    		}
    		else{
    			// fill 2 in odd
    			cout<< 2  <<ocells.back().ff<<   <<ocells.back().ss<<endl;
    			ocells.pop_back();
    		}
    		cnt++;
    	}
    }

 }

 signed main(void)
 {

 	fast;

 	int _=1;
 	//cin>>_;

       for(int test_case=1;test_case<=_;++test_case){
          solve();
       }

 }


#include <bits/stdc++.h>
 using namespace std;
 long long int powe(long long int d, long long int s) {
   if (s == 1)
     return d;
   else if (s == 0)
     return 1;
   else {
     long long int u, v = d;
     for (u = 1; u < s; u++) {
       d = d * v;
     }
     return d;
   }
 }
 bool isprime(long long int n) {
   long long int i;
   for (i = 2; i * i <= n; i++) {
     if (n  i == 0) {
       return false;
     }
   }
   return true;
 }
 long long int a[2000005], c[10000005];
 int main() {
   map<int, int> b;
   long long int i, p, y, mx = -1, j, q;
   cin >> p >> y;
   for (i = y; i > p; i--) {
     q = 1;
     for (j = 2; j * j <= i && j <= p; j++) {
       if (i  j == 0) {
         q = 0;
         break;
       }
     }
     if (q == 1) {
       cout << i;
       return 0;
     }
   }
   cout << -1;
 }


#include <bits/stdc++.h>
 using namespace std;
 using llint = long long;
 using par = pair<int, int>;
 const int MAXN = 200100;
 llint w[MAXN];
 vector<par> edges[MAXN];
 int p[MAXN], in[MAXN], out[MAXN], idx[MAXN], id;
 void dfs(int u) {
   in[u] = ++id;
   for (const auto& edge : edges[u]) {
     if (edge.first == p[u]) continue;
     p[edge.first] = u;
     idx[edge.first] = edge.second;
     dfs(edge.first);
   }
   out[u] = id;
 }
 int next(int u) { return w[idx[u]] == 1 ? p[u] = next(p[u]) : u; }
 void toLCA(int u, int v, llint& c) {
   if (!u || !c) return;
   if (in[u] <= in[v] && out[u] >= out[v]) return;
   c /= w[idx[u]];
   toLCA(p[u] = next(p[u]), v, c);
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   llint c;
   int n, m, u, v;
   cin >> n >> m;
   for (int i = 1; i < n; ++i) {
     cin >> u >> v >> w[i];
     edges[u].emplace_back(v, i);
     edges[v].emplace_back(u, i);
   }
   dfs(1);
   while (m--) {
     cin >> u;
     if (u == 1) {
       cin >> u >> v >> c;
       toLCA(u, v, c);
       toLCA(v, u, c);
       cout << c << '
';
     } else {
       cin >> u >> c;
       w[u] = c;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 using ll = long long;
 ll BASE_NUM = 998244353;
 class UnionFindTree {
   map<ll, ll> union_tree_data;

  public:
   UnionFindTree() {}
   UnionFindTree(vector<ll> verticals) {
     for (auto v : verticals) {
       union_tree_data[v] = v;
     }
   }
   void add_vertical(ll v) { union_tree_data[v] = v; }
   void reset() {
     for (auto &pair : union_tree_data) {
       pair.second = pair.first;
     }
   }
   long long find(long long N) {
     if (union_tree_data[N] == N) {
       return N;
     } else {
       return union_tree_data[N] = find(union_tree_data[N]);
     }
   }
   bool same(long long x, long long y) { return find(x) == find(y); }
   void union_tree(long long x, long long y) {
     x = find(x);
     y = find(y);
     if (x == y) return;
     union_tree_data[x] = y;
   }
 };
 class edge {
  public:
   ll from, to, cost;
   bool operator<(const edge &another) const { return cost < another.cost; };
   bool operator>(const edge &another) const { return cost > another.cost; };
 };
 class MST {
   UnionFindTree uft;

  public:
   priority_queue<edge, vector<edge>, greater<edge>> que;
   vector<edge> result;
   ll cost = 0;
   MST(vector<ll> &nodes, vector<edge> &edges) : uft(nodes) {
     for (auto e : edges) {
       que.push(e);
     }
     while (!que.empty()) {
       edge e;
       e = que.top();
       if (!uft.same(e.from, e.to)) {
         uft.union_tree(e.from, e.to);
         result.push_back(e);
         cost += e.cost;
       }
       que.pop();
     }
   }
 };
 int main() {
   ll n;
   vector<pair<ll, ll>> towns;
   vector<ll> costs;
   vector<ll> ks;
   vector<edge> edges;
   cin >> n;
   for (int i = 0; i < n; i++) {
     pair<ll, ll> p;
     cin >> p.first >> p.second;
     towns.push_back(p);
   }
   for (int i = 0; i < n; i++) {
     ll c;
     cin >> c;
     costs.push_back(c);
   }
   for (int i = 0; i < n; i++) {
     ll k;
     cin >> k;
     ks.push_back(k);
   }
   for (int i = 0; i < n; i++) {
     for (int j = i + 1; j < n; j++) {
       edges.push_back({i, j,
                        (abs(towns[i].first - towns[j].first) +
                         abs(towns[i].second - towns[j].second)) *
                            (ks[i] + ks[j])});
     }
   }
   for (int i = 0; i < n; i++) {
     edges.push_back({i, n, costs[i]});
   }
   vector<ll> nodes(n + 1);
   for (int i = 0; i < n + 1; i++) {
     nodes[i] = i;
   }
   MST mst(nodes, edges);
   vector<ll> stations;
   vector<pair<ll, ll>> connections;
   for (auto e : mst.result) {
     if (e.to == n) {
       stations.push_back(e.from);
     } else {
       connections.push_back(make_pair(e.from, e.to));
     }
   }
   cout << mst.cost <<
 ;
   cout << stations.size() <<
 ;
   for (int i = 0; i < stations.size(); i++) {
     if (i == 0) {
       cout << stations[i] + 1;
     } else {
       cout <<     << stations[i] + 1;
     }
   }
   cout <<
 ;
   cout << connections.size() <<
 ;
   for (int i = 0; i < connections.size(); i++) {
     cout << connections[i].first + 1 <<     << connections[i].second + 1
          <<
 ;
   }
   cout << flush;
   return 0;
 }


#include <bits/stdc++.h>
 #define fi first
 #define se second
 #define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
 #define mk make_pair
 #define pii pair<int, int>
 #define pll pair<ll, ll>
 #define pb push_back
 #define IT iterator
 #define V vector
 #define TP template <class o>
 #define TPP template <typename t1, typename t2>
 #define SZ(a) ((int)a.size())
 #define all(a) a.begin(), a.end()
 #define rep(i, a, b) for (int i = a; i <= b; i++)
 #define REP(i, a, b) for (int i = b; i >= a; i--)
 #define FOR(i,n) rep(i,1,n)
 #define debug(x) cerr << #x <<   =   << x << endl
 using namespace std;
 typedef unsigned ui;
 typedef long long ll;
 typedef unsigned long long ull;
 typedef double db;
 typedef long double ld;
 const int N = 3010, size = 1 << 20, mod = 998244353, inf = 2e9;
 const ll INF = 1e15;

 // char buf[size],*p1=buf,*p2=buf;
 TP void qr(o& x) {
     char c = gc;
     x = 0;
     int f = 1;
     while (!isdigit(c)) {
         if (c == '-')
             f = -1;
         c = gc;
     }
     while (isdigit(c))
         x = x * 10 + c - '0', c = gc;
     x *= f;
 }
 template<class o,class ... O> void qr(o& x, O& ... y) {qr(x); qr(y...);}
 TP void qw(o x) {
     if (x / 10)
         qw(x / 10);
     putchar(x  10 + '0');
 }
 TP void pr1(o x) {
     if (x < 0)
         x = -x, putchar('-');
     qw(x);
     putchar(' ');
 }
 template<class o,class ... O> void pr1(o x, O ... y) { pr1(x); pr1(y...);}
 TP void pr2(o x) {
     if (x < 0)
         x = -x, putchar('-');
     qw(x);
     putchar('
');
 }
 template<class o,class ... O> void pr2(o x, O ... y) { pr2(x); pr2(y...);}

 // math
 ll gcd(ll a, ll b) { return !a ? b : gcd(b  a, a); }
 ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
 ll power(ll a, ll b = mod - 2, ll p = mod) {
     ll c = 1;
     while (b) {
         if (b & 1) c = c * a  p;
         b /= 2;
         a = a * a  p;
     }
     return c;
 }
 ll exgcd(ll a,ll b,ll &x,ll &y) {
 	if(!a) {x=0; y=1; return b;}
 	ll d=exgcd(ba,a,y,x); x -= b/a*y;
 	return d;
 }
 ll INV(ll n,ll p=mod) {ll x,y; exgcd(n,p,x,y); return (xp+p)p;}

 TP void cmax(o& x, o y) {
     if (x < y)
         x = y;
 }
 TP void cmin(o& x, o y) {
     if (x > y)
         x = y;
 }
 TPP void ad(t1& x, t2 y) {
     x += y;
     if (x >= mod)
         x -= mod;
 }
 TPP void dl(t1& x, t2 y) {
     x -= y;
     if (x < 0)
         x += mod;
 }

 int n, m, X[N], Y[N];
 V<int> e[N], g[N], E, P;
 bool v[N];
 #define DEBUG

 void dfs(int x) {
 	int i, y;
 	while(SZ(g[x])) {
 		i = g[x].back(); g[x].pop_back();
 		if(v[i]) continue;
 		y = x ^ X[i] ^ Y[i];
 		v[i] = 1; dfs(y);
 	}
 	P.pb(x);
 }

 void check(int s, int w = 0) {
 	FOR(i, n) g[i] = e[i];
 	FOR(i, m) v[i] = 0;
 	int cnt = 0;
 	FOR(i, n) if(i ^ s) cnt += SZ(e[i]) & 1;
 	if(cnt > 1) return ;
 	P.clear(); dfs(s);
 	if(SZ(P) + SZ(E) - 1 - (w > 0) != m) return ;
 	P.pb(-1);
 	for(int i: E) if(i ^ w) P.pb(X[i] ^ Y[i] ^ s), P.pb(s);
 	pr2(SZ(P));
 	for(int i: P) pr1(i);
 	exit(0);
 }

 void solve() {
 	qr(n, m);
 	FOR(i, m) qr(X[i], Y[i]);
 	FOR(s, n) {
 		FOR(i, n) e[i].clear();
 		P.clear(); E.clear();
 		FOR(i, m) {
 			int x = X[i], y = Y[i];
 			if(x == s || y == s) continue;
 			e[x].pb(i); e[y].pb(i);
 		}
 		FOR(i, m) {
 			int x = X[i], y = Y[i];
 			if(x == s || y == s) {
 				int v = s ^ x ^ y;
 				if(SZ(e[v]) & 1) e[s].pb(i), e[v].pb(i);
 				else E.pb(i);
 			}
 		}
 		check(s);
 		for(int i: E) {
 			e[X[i]].pb(i); e[Y[i]].pb(i);
 			check(s, i);
 			e[X[i]].pop_back(); e[Y[i]].pop_back();
 		}
 	}
 	puts( 0 );
 }

 int main() {
     int T = 1;
 //    qr(T);
     while (T--)
         solve();
     return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool found = false;
 long long b, A[10000], n, orig_a;
 void bfs(long long a, long long k) {
   if (found) return;
   if (a > b) return;
   if (a == b) {
     found = true;
     n = k;
     a = orig_a;
     cout <<  YES  << endl;
     cout << n + 1 << endl;
     cout << a;
     for (int i = 0; i < n; i++) {
       if (A[i] == 1) {
         a = a * 10 + 1;
         cout <<     << a;
       } else if (A[i] == 2) {
         a = a * 2;
         cout <<     << a;
       }
     }
     cout << endl;
     return;
   }
   A[k] = 2;
   bfs(a * 2, k + 1);
   A[k] = 1;
   bfs((a * 10) + 1, k + 1);
 }
 int main() {
   long long a, c, d, i, j, m;
   string s;
   cin >> a >> b;
   orig_a = a;
   bfs(a, 0);
   if (!found) cout <<  NO  << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 class Compare {
  public:
   bool operator()(pair<long long, long long> a, pair<long long, long long> b) {
     return (a.first + a.second) > (b.first + b.second);
   }
 };
 int main() {
   long long test, x, n, m, k, w, d, f, y;
   priority_queue<pair<long long, long long>,
                  vector<pair<long long, long long> >, Compare>
       pqw;
   priority_queue<pair<long long, long long>,
                  vector<pair<long long, long long> >, Compare>
       pqd;
   priority_queue<pair<long long, long long>,
                  vector<pair<long long, long long> >, Compare>
       pqf;
   scanf( lldlldlldlldlldlldlld , &x, &n, &m, &k, &w, &d, &f);
   for (long long i = 0; i < n; i++) {
     pqw.push(make_pair(0, w));
   }
   for (long long i = 0; i < m; i++) {
     pqd.push(make_pair(0, d));
   }
   for (long long i = 0; i < k; i++) {
     pqf.push(make_pair(0, f));
   }
   long long ans = 0;
   for (long long i = 0; i < x; i++) {
     pair<long long, long long> cur = pqw.top();
     pqw.pop();
     pqw.push(make_pair(cur.first + cur.second, cur.second));
     pair<long long, long long> curd = pqd.top();
     pqd.pop();
     curd.first = max(cur.first + cur.second, curd.first) + d;
     pqd.push(curd);
     pair<long long, long long> curf = pqf.top();
     pqf.pop();
     curf.first = max(curd.first, curf.first) + f;
     pqf.push(curf);
     ans = curf.first;
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int P = 1e9 + 7;
 vector<int> b[200005];
 int L[200005], R[200005], u[200005], v[200005], opt[200005], size[200005];
 int m, n, ql, qr, upd, tot, now, ans, i, x;
 struct data {
   int cnt, sum;
   data() { cnt = 1; }
   void multi(int x) {
     cnt = 1ll * cnt * x  P;
     sum = 1ll * sum * x  P;
   }
   int renew(int x) {
     cnt = 1;
     sum = x;
     return 0;
   }
 } a[200005 << 2];
 void DFS(int x, int Fa) {
   L[x] = ++tot;
   for (int i = 0, y; i < b[x].size(); i++)
     if ((y = b[x][i]) != Fa) DFS(y, x);
   R[x] = tot;
 }
 int INV(int a) {
   int ret = 1, b = P - 2;
   for (; b; b >>= 1, a = 1ll * a * a  P)
     if (b & 1) ret = 1ll * ret * a  P;
   return ret;
 }
 inline void down(int x) {
   if (a[x].cnt == 1) return;
   a[x << 1].multi(a[x].cnt);
   a[x << 1 | 1].multi(a[x].cnt);
   a[x].cnt = 1;
 }
 inline void up(int x) { a[x].sum = (a[x << 1].sum + a[x << 1 | 1].sum)  P; }
 void Multi(int x, int l, int r) {
   if (ql <= l && r <= qr) {
     a[x].multi(now);
     return;
   }
   int mid = (l + r) >> 1;
   down(x);
   if (ql <= mid) Multi(x << 1, l, mid);
   if (qr > mid) Multi(x << 1 | 1, mid + 1, r);
   up(x);
 }
 int Update(int x, int l, int r, int pos) {
   if (l == r) return (!upd) ? a[x].sum : a[x].renew(now);
   int mid = (l + r) >> 1;
   down(x);
   int ret = (pos <= mid) ? Update(x << 1, l, mid, pos)
                          : Update(x << 1 | 1, mid + 1, r, pos);
   return up(x), ret;
 }
 void Query(int x, int l, int r) {
   if (ql <= l && r <= qr) {
     ans = (ans + a[x].sum)  P;
     return;
   }
   int mid = (l + r) >> 1;
   down(x);
   if (ql <= mid) Query(x << 1, l, mid);
   if (qr > mid) Query(x << 1 | 1, mid + 1, r);
 }
 int main() {
   scanf( dd , &v[1], &m);
   n = 1;
   for (i = 1; i <= m; i++) {
     scanf( dd , &opt[i], &u[i]);
     if (opt[i] == 1) scanf( d , &v[++n]), b[u[i]].push_back(n);
   }
   DFS(1, 0);
   size[n = 1] = 1;
   upd = 1;
   now = v[1];
   Update(1, 1, tot, L[1]);
   for (i = 1; i <= m; i++)
     if (opt[i] == 1) {
       x = u[i];
       size[++n] = 1;
       ql = L[x];
       qr = R[x];
       now = 1ll * (size[x] + 1) * INV(size[x])  P;
       ++size[x];
       Multi(1, 1, tot);
       upd = 0;
       now = Update(1, 1, tot, L[x]);
       now = 1ll * now * INV(v[x])  P;
       now = 1ll * now * v[n]  P;
       upd = 1;
       Update(1, 1, tot, L[n]);
     } else {
       x = u[i];
       ans = 0;
       ql = L[x];
       qr = R[x];
       Query(1, 1, tot);
       upd = 0;
       now = Update(1, 1, tot, L[x]);
       now = 1ll * now * INV(1ll * v[x] * size[x]  P)  P;
       ans = 1ll * ans * INV(now)  P;
       printf( d
 , ans);
     }
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long mod = 1000000007;
 const long double PI = 3.141592653589793;
 const long long maxn = 100005;
 long long x, y, z, n, k;
 void _print(long long t) { cerr << t; }
 void _print(string t) { cerr << t; }
 void _print(char t) { cerr << t; }
 void _print(long double t) { cerr << t; }
 void _print(double t) { cerr << t; }
 template <class T, class V>
 void _print(pair<T, V> p);
 template <class T>
 void _print(vector<T> v);
 template <class T>
 void _print(set<T> v);
 template <class T, class V>
 void _print(map<T, V> v);
 template <class T>
 void _print(multiset<T> v);
 template <class T, class V>
 void _print(pair<T, V> p) {
   cerr <<  { ;
   _print(p.first);
   cerr <<  , ;
   _print(p.second);
   cerr <<  } ;
 }
 template <class T>
 void _print(vector<T> v) {
   cerr <<  [  ;
   for (T i : v) {
     _print(i);
     cerr <<    ;
   }
   cerr <<  ] ;
 }
 template <class T>
 void _print(set<T> v) {
   cerr <<  [  ;
   for (T i : v) {
     _print(i);
     cerr <<    ;
   }
   cerr <<  ] ;
 }
 template <class T>
 void _print(multiset<T> v) {
   cerr <<  [  ;
   for (T i : v) {
     _print(i);
     cerr <<    ;
   }
   cerr <<  ] ;
 }
 template <class T, class V>
 void _print(map<T, V> v) {
   cerr <<  [  ;
   for (auto i : v) {
     _print(i);
     cerr <<    ;
   }
   cerr <<  ] ;
 }
 void solve() {
   string s, t;
   cin >> s >> t;
   long long f[26];
   memset(f, 0, sizeof(f));
   long long n = (long long)s.size(), m = (long long)t.size();
   vector<vector<long long>> v(26);
   for (long long i = 0; i <= n - 1; i++) {
     f[s[i] - 'a']++;
     v[s[i] - 'a'].push_back(i);
   }
   for (long long i = 0; i <= m - 1; i++) {
     if (f[t[i] - 'a'] == 0) {
       cout << -1 <<
 ;
       return;
     }
   }
   long long ans = 1, last = -1;
   for (long long i = 0; i <= m - 1; i++) {
     long long prev = last;
     long long val = t[i] - 'a';
     long long pos =
         lower_bound(v[val].begin(), v[val].end(), last + 1) - v[val].begin();
     if (pos == v[val].size()) {
       ans++;
       last = v[val][0];
     } else {
       last = v[val][pos];
     }
   }
   cout << ans <<
 ;
 }
 int32_t main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   cout << setprecision(15) << fixed;
   long long t;
   t = 1;
   cin >> t;
   while (t--) {
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 const double eps = 1e-8;
 const long long INF = 0x3f3f3f3f;
 const int mod = 20000311;
 const int maxn = 1e5 + 5;
 const int N = 1005;
 using namespace std;
 int a[maxn] = {0};
 int dp[maxn][305] = {0};
 int n;
 int dfs(int p, int k) {
   if (p > n) return 0;
   if (dp[p][k] != -1) return dp[p][k];
   int num = p + a[p] + k;
   return dp[p][k] = dfs(num, k) + 1;
 }
 int main() {
   scanf( d , &n);
   for (int i = 1; i <= n; i++) scanf( d , &a[i]);
   for (int j = 1; j <= 300; j++) {
     for (int i = n; i >= 1; i--) {
       int num = i + a[i] + j;
       if (num > n)
         dp[i][j] = 1;
       else
         dp[i][j] = dp[num][j] + 1;
     }
   }
   int q;
   scanf( d , &q);
   while (q--) {
     int p, k;
     scanf( d d , &p, &k);
     if (k >= 300) {
       int res = 0;
       while (p <= n) {
         p = a[p] + k + p;
         res++;
       }
       cout << res <<
 ;
     } else
       cout << dp[p][k] <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 string Max(int n, int s) {
   string str =   ;
   while (s >= 9 && n > 0) {
     str += '9';
     s -= 9;
     n--;
   }
   if (n == 0 && s > 0) return  -1 ;
   if (n > 0) {
     str += char(s + 48);
     for (int i = 1; i < n; i++) str += '0';
   }
   return str;
 }
 int main() {
   int n, s;
   string str =   ;
   cin >> n >> s;
   if (n * 9 < s)
     cout <<  -1 -1 ;
   else if (n > 1 and s == 0)
     cout <<  -1 -1 ;
   else if (s == 1) {
     cout << 1;
     for (int i = 1; i < n; i++) cout << 0;
     cout <<   1 ;
     for (int i = 1; i < n; i++) cout << 0;
   } else {
     for (int i = Max(n, s).size() - 1; i >= 0; i--) str += Max(n, s)[i];
     if (str[0] == '0' and str.size() > 1) {
       str[0] = '1';
       for (int i = 1; i < str.size(); i++)
         if (str[i] > '0') {
           str[i] = char(int(str[i]) - 1);
           break;
         }
     }
     cout << str <<     << Max(n, s);
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int M = 1e9 + 7;
 const int MAX_N = 1002;
 int dp_end[MAX_N][MAX_N];
 int dp_not[MAX_N][MAX_N];
 int main() {
   int n;
   cin >> n;
   for (int i = 1; i <= n; i++) {
     dp_end[0][i] = (i + 1) / 2;
     dp_not[0][i] = i / 2;
   }
   for (int i = 1; i <= n; i++) {
     for (int j = i; j <= n; j++) {
       dp_end[i][j] = 1 + dp_not[i - 1][j] + dp_end[i][j - 1];
       if (i - 1 >= j) {
         dp_end[i][j] =
             max(dp_end[i][j], 1 + dp_not[i][j - 1] + dp_end[i - 1][j]);
       }
       dp_end[i][j] = M;
       dp_not[i][j] = dp_end[i][j - 1] + dp_end[i - 1][j];
       dp_not[i][j] = M;
     }
   }
   cout << dp_end[n][n] << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void c_p_c() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
 }
 int32_t main() {
   c_p_c();
   long long n;
   string s[222222];
   map<string, bool> check;
   cin >> n;
   for (long long i = 1; i <= n; i++) {
     cin >> ws;
     getline(cin, s[i]);
   }
   for (long long i = n; i >= 1; i--) {
     if (!check[s[i]]) {
       check[s[i]] = 1;
       cout << s[i] <<
 ;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using std::max;
 using std::min;
 const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;
 const long long INF = 0x3f3f3f3f3f3f3f3f;
 __inline__ __attribute__((always_inline)) unsigned int rnd() {
   static unsigned int seed = 416;
   return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;
 }
 template <typename _Tp>
 _Tp gcd(const _Tp &a, const _Tp &b) {
   return (!b) ? a : gcd(b, a  b);
 }
 template <typename _Tp>
 __inline__ __attribute__((always_inline)) _Tp abs(const _Tp &a) {
   return a >= 0 ? a : -a;
 }
 template <typename _Tp>
 __inline__ __attribute__((always_inline)) void chmax(_Tp &a, const _Tp &b) {
   (a < b) && (a = b);
 }
 template <typename _Tp>
 __inline__ __attribute__((always_inline)) void chmin(_Tp &a, const _Tp &b) {
   (b < a) && (a = b);
 }
 template <typename _Tp>
 __inline__ __attribute__((always_inline)) void read(_Tp &x) {
   char ch(getchar());
   bool f(false);
   while (!isdigit(ch)) f |= ch == 45, ch = getchar();
   x = ch & 15, ch = getchar();
   while (isdigit(ch)) x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar();
   f && (x = -x);
 }
 template <typename _Tp, typename... Args>
 __inline__ __attribute__((always_inline)) void read(_Tp &t, Args &...args) {
   read(t);
   read(args...);
 }
 template <typename _Tp, typename... Args>
 __inline__ __attribute__((always_inline)) _Tp min(const _Tp &a, const _Tp &b,
                                                   const Args &...args) {
   return a < b ? min(a, args...) : min(b, args...);
 }
 template <typename _Tp, typename... Args>
 __inline__ __attribute__((always_inline)) _Tp max(const _Tp &a, const _Tp &b,
                                                   const Args &...args) {
   return a < b ? max(b, args...) : max(a, args...);
 }
 __inline__ __attribute__((always_inline)) int read_str(char *s) {
   char ch(getchar());
   while (ch == ' ' || ch == '
' || ch == '
') ch = getchar();
   char *tar = s;
   *tar = ch, ch = getchar();
   while (ch != ' ' && ch != '
' && ch != '
' && ch != EOF)
     *(++tar) = ch, ch = getchar();
   return tar - s + 1;
 }
 const int N = 100005;
 const int MAXN = 10000005;
 bool pr[MAXN];
 int _p[MAXN >> 3], _pos;
 int md[MAXN];
 void sieve() {
   for (int i = 2; i < MAXN; ++i) {
     if (!pr[i]) {
       _p[++_pos] = i;
       md[i] = i;
     }
     for (int j = 1; j <= _pos && i * _p[j] < MAXN; ++j) {
       pr[i * _p[j]] = true;
       md[i * _p[j]] = _p[j];
       if (!(i  _p[j])) break;
     }
   }
 }
 std::vector<int> p[N], d[N];
 int c[MAXN], cnt[1 << 8], mul[1 << 8];
 int calc(int id) {
   int siz = ((int)p[id].size()), ans = 0;
   for (int i = 0; i < siz; ++i) mul[1 << i] = p[id][i];
   for (int i = 1; i < 1 << siz; ++i) {
     cnt[i] = cnt[i >> 1] + (i & 1);
     mul[i] = mul[i ^ ((i) & (-(i)))] * mul[((i) & (-(i)))];
     if (cnt[i] & 1)
       ans += c[mul[i]];
     else
       ans -= c[mul[i]];
   }
   return ans;
 }
 int a[N];
 int _val[11], _cnt[11], pos, cur_id;
 void dfs(int dep, int val) {
   if (dep == pos + 1) {
     d[cur_id].push_back(val);
     return;
   }
   for (int i = 0; i <= _cnt[dep]; ++i) {
     dfs(dep + 1, val);
     if (i < _cnt[dep]) val *= _val[dep];
   }
 }
 bool ban[N], vis[N];
 int deg[N];
 int f(int mid) {
   while (ban[mid]) --mid;
   if (!mid) return false;
   int qwq = 0;
   for (int i = 1; i <= mid; ++i)
     if (!ban[i]) {
       ++qwq;
       for (auto it : d[i]) ++c[it];
     }
   int ans = 0;
   for (int i = 1; i <= mid; ++i)
     if (!ban[i] && calc(i) != qwq) ++ans;
   for (int i = 1; i <= mid; ++i)
     if (!ban[i])
       for (auto it : d[i]) --c[it];
   return ans;
 }
 std::vector<int> getnodes(int mid) {
   while (ban[mid]) --mid;
   std::vector<int> nd;
   int qwq = 0;
   for (int i = 1; i <= mid; ++i)
     if (!ban[i]) {
       ++qwq;
       for (auto it : d[i]) ++c[it];
     }
   for (int i = 1; i <= mid; ++i)
     if (!ban[i] && calc(i) != qwq) nd.push_back(i);
   for (int i = 1; i <= mid; ++i)
     if (!ban[i])
       for (auto it : d[i]) --c[it];
   return nd;
 }
 int main() {
   mul[0] = 1;
   sieve();
   int n, k;
   read(n, k);
   for (int i = 1; i <= n; ++i) {
     read(a[i]);
     ++c[a[i]];
     int cur = a[i], last = 0;
     pos = 0;
     while (cur > 1) {
       if (md[cur] != last)
         p[i].push_back(md[cur]), _val[++pos] = md[cur], _cnt[pos] = 1;
       else
         ++_cnt[pos];
       last = md[cur];
       cur /= last;
     }
     cur_id = i;
     dfs(1, 1);
   }
   for (int j = 1; j <= _pos; ++j)
     for (int i = (MAXN - 1) / _p[j]; i >= 1; --i) c[i] += c[i * _p[j]];
   std::vector<int> nd;
   for (int i = 1; i <= n; ++i) {
     if ((deg[i] = calc(i)) <= n - 2) {
       nd.push_back(i);
       for (int j = 1; j <= n && ((int)nd.size()) < 3; ++j)
         if (i != j && gcd(a[i], a[j]) == 1) nd.push_back(j);
       break;
     }
   }
   if (nd.empty()) {
     std::vector<int> clique, rest;
     for (int i = 1; i <= n; ++i)
       if (deg[i] == n)
         clique.push_back(i);
       else
         rest.push_back(i);
     if (((int)clique.size()) > k) clique.resize(k);
     for (int i = 1; i <= n && ((int)clique.size()) < k; ++i) {
       if (!vis[i] && deg[i] == n - 1) {
         clique.push_back(i);
         for (auto it : rest)
           if (gcd(a[it], a[i]) == 1) vis[it] = true;
       }
     }
     for (auto it : clique) printf( d  , it);
     printf(
 );
     return 0;
   }
   if (k == 3) {
     for (auto it : nd) printf( d  , it);
     printf(
 );
     return 0;
   }
   for (auto it : nd) ban[it] = true;
   for (auto id : nd)
     for (auto it : d[id]) --c[it];
   std::vector<int> clique;
   for (int i = 1; i <= n; ++i)
     if (!ban[i] && ((deg[i] = calc(i)) == n - 3)) clique.push_back(i);
   if (((int)clique.size()) >= k) {
     clique.resize(k);
     for (auto it : clique) printf( d  , it);
     printf(
 );
     return 0;
   }
   memset(c, 0, sizeof(c));
   int l = 1, r = n;
   while (l < r) {
     int mid = (l + r) >> 1;
     if (f(mid) + 3 >= k)
       r = mid;
     else
       l = mid + 1;
   }
   std::vector<int> v1 = getnodes(l - 1);
   std::vector<int> v2 = getnodes(l);
   std::sort(v1.begin(), v1.end());
   std::vector<int> qwq;
   for (auto it : v2) {
     auto _ = std::lower_bound(v1.begin(), v1.end(), it);
     if (_ == v1.end() || *_ != it) qwq.push_back(it);
   }
   std::sort(qwq.begin(), qwq.end());
   if (((int)v1.size()) + 3 + 1 == k && ((int)qwq.size()) != 1)
     v1.push_back(nd[0]), v1.push_back(nd[1]);
   else
     v1.push_back(nd[0]), v1.push_back(nd[1]), v1.push_back(nd[2]);
   while (((int)v1.size()) < k) {
     v1.push_back(qwq.back());
     qwq.pop_back();
   }
   for (auto it : v1) printf( d  , it);
   printf(
 );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void fact(int n) {
   const int N = 1e5;
   vector<int> arr(N, 0);
   int q = 2;
   arr[0] = 1;
   int len = 1;
   int x = 0;
   int carry = 0;
   while (q <= n) {
     x = 0;
     carry = 0;
     while (x < len) {
       arr[x] = arr[x] * q + carry;
       carry = arr[x] / 10;
       arr[x] = arr[x]  10;
       x++;
     }
     while (carry) {
       arr[len] = carry  10;
       carry = carry / 10;
       len++;
     }
     q++;
   }
   len--;
   for (int i = len; i >= 0; i--) {
     cout << arr[i];
   }
   return;
 }
 long long int binary_exp(long long int x, long long int n) {
   if (n == 0) {
     return 1;
   } else if (n == 1) {
     return x  1000000007;
   } else {
     long long int temp = binary_exp(x, n / 2);
     temp = (temp * temp)  1000000007;
     if (n  2 == 0) {
       return temp;
     } else {
       return ((x  1000000007) * temp)  1000000007;
     }
   }
 }
 int main() {
   int k, r;
   cin >> k >> r;
   int i = 1;
   while (i * k  10 != r and i * k  10 != 0) {
     i++;
   }
   cout << i;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool vis[100006];
 int main() {
   int n, k;
   while (cin >> n >> k) {
     memset(vis, false, sizeof(vis));
     int st = 1, ed = 1 + k;
     int cnt = 0;
     while (cnt < k && st <= ed) {
       if (st != ed)
         vis[st] = vis[ed] = true, cout << st << ' ' << ed << ' ';
       else
         vis[st] = true, cout << st << ' ';
       st++, ed--;
       cnt++;
     }
     for (int i = 1; i <= n; i++) {
       if (!vis[i]) cout << i << ' ';
     }
     puts(  );
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 500023;
 bool vis[N];
 vector<int> adj[N];
 void solve() {
   long long int n, m;
   cin >> n >> m;
   map<long long int, long long int> cntA;
   map<long long int, long long int> cntB;
   map<long long int, long long int> cntC;
   map<long long int, long long int> cntD;
   map<long long int, long long int> cntE;
   for (long long int i = 0; i < n; i++) {
     string s;
     cin >> s;
     for (int i = 0; i < s.length(); i++) {
       if (s[i] == 'A')
         cntA[i]++;
       else if (s[i] == 'B')
         cntB[i]++;
       else if (s[i] == 'C')
         cntC[i]++;
       else if (s[i] == 'D')
         cntD[i]++;
       else if (s[i] == 'E')
         cntE[i]++;
     }
   }
   long long int ans = 0;
   for (int i = 0; i < m; i++) {
     long long int c;
     cin >> c;
     long long int maxi = 0;
     maxi = max(max(cntA[i], cntB[i]), cntC[i]);
     maxi = max(max(maxi, cntD[i]), cntE[i]);
     long long int temp = maxi * c;
     ans += temp;
   }
   cout << ans;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int T = 1;
   int t = 0;
   while (t++ < T) {
     solve();
   }
 }


#include<bits/stdc++.h>
 #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
 #define int long long
 #define ull unsigned long long
 #define FOR(i,a,b) for(int i=a;i<b;i++)
 #define all(x) (x).begin(), (x).end()
 #define pb push_back
 #define mp make_pair
 #define in insert
 #define ff first
 #define ss second
 #define endl

 #define pi pair<int,int>
 #define  deb1(a)         cout<<a<<
 ;
 #define  deb2(a,b)       cout<<a<<   <<b<<
 ;
 #define  deb3(a,b,c)     cout<<a<<   <<b<<   <<c<<
 ;
 #define  debp(a)         cout<<a.ff<<   <<a.ss<<
 ;
 #define  debvec(a)      for(auto it: a)cout<<it<<   ;cout<<   ; cout<<endl;
 #define  debvp(a)      for(auto it: a)cout<<it.ff<<   <<it.ss<<endl;
 #define  debmap(a)      for(auto it: a)cout<< { <<it.ff<< , <<it.ss<< },  ;newl;
 #define  debarr(a,n)    FOR(i,0,n)cout<<a[i]<<   ;cout<<endl;
 #define inf ((int)1<<60)
 #define mod 1000000007
 using namespace std;
 //int,char,float,double,bool,string,break,continue,endl,if,else,set,multiset,multimap,unordered_map,unordered_set,cout,cin,printf,scanf
 //strlen,strcmp,compar e,auto,while,return,true,false,sizeof,size,abs,INT_MAX,INT_MIN,itr,it,sort,YES,NO

 signed main() {
 #ifndef ONLINE_JUDGE
 	freopen( input.txt ,  r , stdin);
 	freopen( output.txt ,  w , stdout);
 #endif
 	fast_io
 	int test, i, j;
 // 	cin >> test;
 	test = 1;
 	while (test--) {
 		int n, m;
 		cin >> n >> m;
 		string s, t;
 		cin >> s >> t;
 		int a[m], b[m];
 		j = 0;
 		for (int i = 0; i < n; ++i) {
 			if (s[i] == t[j]) {
 				a[j] = i;
 				j++;
 			}
 		}
 		j = m - 1;
 		for (int i = n - 1; i >= 0 ; i--) {
 			if (s[i] == t[j]) {
 				b[j] = i;
 				j--;
 			}
 		}
 		int ans = 0;
 		for (int i = 0; i < m - 1; ++i) {
 			ans = max(ans, b[i + 1] - a[i]);
 		}
 		cout << ans << endl;
 	}

 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 110;
 const int mo = 1e9 + 7;
 int n, k, a[N], num[3], nn, f = 0;
 long long ans, now[N][N], dp[N][N], aa[N];
 long long po(long long a, long long b) {
   if (b == 0) return 1;
   if (b == 1) return a;
   long long c = po(a, b / 2);
   if (b & 1)
     return c * c  mo * a  mo;
   else
     return c * c  mo;
 }
 long long tmp[N][N];
 void multi(long long a[][N], long long b[][N], int n) {
   memset(tmp, 0, sizeof tmp);
   for (int i = 0; i < n; i++)
     for (int j = 0; j < n; j++)
       for (int k = 0; k < n; k++)
         tmp[i][j] = (tmp[i][j] + a[i][k] * b[k][j]  mo)  mo;
   for (int i = 0; i < n; i++)
     for (int j = 0; j < n; j++) a[i][j] = tmp[i][j];
 }
 long long res[N][N];
 void Pow(long long a[][N], long long n) {
   memset(res, 0, sizeof res);
   for (int i = 0; i < num[0] + 1; i++) res[i][i] = 1;
   while (n) {
     if (n & 1) multi(res, a, num[0] + 1);
     multi(a, a, num[0] + 1);
     n >>= 1;
   }
 }
 int main() {
   scanf( dd , &n, &k);
   for (int i = 1; i <= n; i++) scanf( d , &a[i]), num[a[i]]++;
   if (num[0] < num[1]) {
     for (int i = 1; i <= num[0]; i++)
       if (!a[i]) nn++;
   } else {
     swap(num[0], num[1]);
     for (int i = n; i >= n - num[0] + 1; i--)
       if (a[i]) nn++;
   }
   for (int j = 0; j <= num[0]; j++) {
     now[j][j] += j * (num[0] - j);
     now[j][j] += (num[0] - j) * (num[1] - num[0] + j);
     now[j][j] += num[0] * (num[0] - 1) / 2ll;
     now[j][j] += num[1] * (num[1] - 1) / 2ll;
     if (j + 1 <= num[0]) now[j][j + 1] = (j + 1) * (num[1] - (num[0] - j - 1));
     if (j) now[j][j - 1] = (num[0] - j + 1) * (num[0] - j + 1);
   }
   Pow(now, k);
   for (int i = 0; i <= num[0]; i++) ans = (ans + res[i][nn])  mo;
   printf( lld
 , res[num[0]][nn] * po(ans, mo - 2)  mo);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const double eps = 1e-9;
 const int INF = (int)1e9 + 7;
 const long long linf = (long long)1e16 + 7;
 struct pnt {
   double x, y;
   pnt(double x, double y) : y(y), x(x) {}
   pnt() = default;
 };
 int cmp(double a, double b) {
   if (abs(a - b) < eps) return 0;
   if (a > b) return 1;
   return -1;
 }
 int main() {
   int n;
   cin >> n;
   int ans = 0;
   vector<int> a(n);
   for (int i = 0; i < n; ++i) cin >> a[i];
   vector<int> cnt0(n + 1);
   vector<int> cnt1(n + 1);
   for (int i = 0; i < n; ++i) {
     if (a[i] == 0) cnt0[i]++;
     if (i) cnt0[i] += cnt0[i - 1];
   }
   for (int i = n - 1; i >= 0; --i) {
     if (a[i] == 1) cnt1[i]++;
     if (i != n - 1) cnt1[i] += cnt1[i + 1];
   }
   for (int i = 0; i < n; ++i) {
     ans = max(ans, cnt0[i] + cnt1[i + 1]);
     ans = max(ans, cnt1[i]);
   }
   cout << ans;
   return 0;
 }