//try 10
    #pragma GCC optimize("O3")
    #include <bits/stdc++.h>
    // #include <ext/pb_ds/assoc_container.hpp>
    // using namespace __gnu_pbds;
    // gp_hash_table<int, int> mapka;

    using namespace std;
    #define PB push_back
    #define MP make_pair
    #define LL long long
    #define int LL
    #define FOR(i,a,b) for(int i = (a); i <= (b); i++)
    #define RE(i,n) FOR(i,1,n)
    #define REP(i,n) FOR(i,0,(int)(n)-1)
    #define R(i,n) REP(i,n)
    #define VI vector<int>
    #define PII pair<int,int>
    #define LD long double
    #define FI first
    #define SE second
    #define st FI
    #define nd SE
    #define ALL(x) (x).begin(), (x).end()
    #define SZ(x) ((int)(x).size())

    template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
    template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

    template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
    template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
      while(*sdbg!=',')cerr<<*sdbg++;
      cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
    }

    template<class T> ostream &operator<<(ostream& os, vector<T> V) {
      os << "["; for (auto vv : V) os << vv << ","; return os << "]";
    }
    template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
      return os << "(" << P.st << "," << P.nd << ")";
    }

    #ifdef LOCAL
    #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
    #else
    #define debug(...) (__VA_ARGS__)
    #define cerr if(0)cout
    #endif

    const int MAX = 1e6 + 5;
    int np[MAX];
    int koszt[MAX];
    int n,k;
    int ilepom[MAX],ile[MAX];
    const int inf = 1e18;
    int licz(){
      set<PII> secik;
      for(int i = 3; i<=n; i++){
        if(ile[i] == 0)
          secik.insert({koszt[i],i});
      }
      int res = 0;
      R(_,k){
        if(secik.empty())return inf;
        PII pom = *secik.begin();
        debug(pom);
        res += pom.FI;
        secik.erase(secik.begin());
        for(int j = 2; j * pom.SE <= n; j++){
          int i = j * pom.SE;
          koszt[i] -= pom.FI;
          ile[i]--;
          if(ile[i] == 0)
            secik.insert({koszt[i],i});
        }
      }
      return res;
    }
    int32_t main() {
      ios_base::sync_with_stdio(0);
      cin.tie(0);
      cout << fixed << setprecision(11);
      cerr << fixed << setprecision(6);
      cin >> n >> k;
      for(int i = 3; i <= n; i++){
        for(int j = 2; i * j <= n; j++){
          ilepom[i*j] ++;
        }
      }
      R(i,n + 1){
        koszt[i] = (i%2 ? i - 1 : inf);
        ile[i] = (i % 2 ? ilepom[i] : inf);
      }
      int res1 = licz() + 1;
      R(i,n + 1){
        koszt[i] = i - (i % 2 ? 1 : 2);
        ile[i] = ilepom[i];
      }
      int res2 = licz() + 2;
      debug(res1,res2);
      cout << min(res1,res2) << "\n";
    }


/// https://en.wikipedia.org/wiki/Prime-counting_function
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e2 + 5, M = 1e5 + 5, MX = 1e7 + 5;

int n, x, y, dp[N][M], mem[MX];
bool used[MX];
vector < int > primes;

int phi(int m, int n){
    if(n == 0){
        return m;
    }
    if(primes[n - 1] >= m){
        return 1;
    }
    if(m < M && n < N){
        return dp[n][m];
    }
    return phi(m, n - 1) - phi(m / primes[n - 1], n - 1);
}

int rec(int m){
    if(m < MX){
        return mem[m];
    }
    int s2 = sqrtl(m), s3 = cbrtl(m);
    int n = rec(s3);
    int ans = phi(m, n) + n - 1;
    for(int i = n; primes[i] <= s2; i++){
        ans -= rec(m / primes[i]);
        ans += rec(primes[i]);
        ans -= 1;
    }
    return ans;
}

main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    for(int i = 2; i < MX; i++){
        mem[i] = mem[i - 1];
        if(!used[i]){
            mem[i] += 1;
            primes.push_back(i);
            for(int j = i * i; j < MX; j += i){
                used[j] = true;
            }
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            if(!i){
                dp[i][j] = j;
            }
            else{
                dp[i][j] = dp[i - 1][j] - dp[i - 1][j / primes[i - 1]];
            }
        }
    }
    cin >> n;
    long long ans = 0;
    for(int i = 0; i < primes.size(); i++){
        int x = primes[i], y = n / x;
        if(x * x > n){
            break;
        }
        ans += rec(y) - rec(x);
    }
    for(int i = 0; i < primes.size(); i++){
        int x = primes[i];
        if(x * x * x > n){
            break;
        }
        ans++;
    }
    cout << ans;
}


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

typedef long long i64;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;

template<typename T>
inline T read(){
    T x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

#define rdi read<int>
#define rdi64 read<i64>
#define fi first
#define se second
#define pb push_back
#define mp make_pair

const int N=7,INF=0x3f3f3f3f;
constexpr int pw5[N]={1,5,25,125,625,3125,15625};

int n,m,a[N],b[N],c[N][N];
int f[N][pw5[N-1]];

int main(){
#ifdef LOCAL
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
    n=rdi(),m=rdi();
    for(int i=1;i<=n;i++) a[i]=rdi();
    for(int i=1;i<=m;i++) b[i]=rdi();
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++) c[i][j]=rdi();

    memset(f,0x3f,sizeof(f));

    int stat=0;
    for(int i=1;i<=m;i++) stat+=pw5[i-1]*b[i];
    f[0][stat]=0;

    for(int i=1;i<=n;i++){
        static int sum[(1<<N)+1];
        for(int j=0;j<(1<<m);j++){
            sum[j]=0;
            for(int k=1;k<=m;k++) sum[j]+=(j>>(k-1)&1)*c[i][k];
        }

        for(int j=0;j<pw5[m];j++){
            if(f[i-1][j]>=INF) continue;
            for(int k=0;k<(1<<m);k++){
                function<void(int,int,int,int)> dfs = [&](int x,int stat,int s,int rest){
                    if(x>m){
                        if(!rest) f[i][stat]=min(f[i][stat],f[i-1][j]+sum[k]);
                        return;
                    }
                    int cap=stat/pw5[x-1]%5;
                    if(!(s>>(x-1)&1)) cap=0;
                    for(int i=0;i<=min(cap,rest);i++)
                        dfs(x+1,stat-pw5[x-1]*i,s,rest-i);
                };
                dfs(1,j,k,a[i]);
            }
        }
    }
    int ans=*min_element(f[n],f[n]+pw5[m]);
    cout<<(ans>=INF?-1:ans)<<endl;
    return 0;
}


#include <windows.h>
#include <iostream>
#define for32(i,n,x) for(int i=0;i<n;i+=x)
#define for64(i,n,x) for(long long i=0;i<n;i+=x)
using namespace std;
void fastIo(){	ios_base::sync_with_stdio(false);	cin.tie(NULL);}
int main(){
	//fastIo();
	double Vp,Vd,t,f,c;
	cin >> Vp >> Vd >> t >> f >> c;
	Vp = Vp / (3600.0);
	Vd = Vd /(3600.0);
	t = t * 60 * 60;
	f = f * 60 * 60;
	int bijous = 0;
	double dDist = 0,qDist = Vp * t;
	while(qDist < c){
		if(dDist >= qDist){
			double dragH = (dDist / Vd);
			dDist = 0;
			qDist += (Vp) * (f + dragH);
			bijous++;
		}
		else{
			dDist += Vd;
			qDist += Vp;
		}
	}
	cout<<bijous;

}


#include "iostream"
#include "string"

using namespace std;

int main(){
    int d[2];
    int arr[2][9];
    string s;
    getline(cin,s);
    d[0] = atoi(s.c_str());
    getline(cin,s);
    if ((d[0] == 0) && (s == "0")){
        cout<<"OK";
        return 0;
    }

    if (s[0] == '0'){
        cout<<"WRONG_ANSWER";
    return 0;
    } else d[1] = atoi(s.c_str());

    int nn[2];
    for (int i=0;i<2;i++){
        int j = 0;
        while (d[i] > 0){
            arr[i][j] = d[i] % 10;
            d[i] /= 10;
            j++;
        }
        nn[i] = j;
    }

    int n;
    if (nn[0] == nn[1])
        n = nn[0]; else
    {
        cout<<"WRONG_ANSWER";
        return 0;
    }

    for (int i=0;i<2;i++)
        for (int j=0;j<n/2;j++){
            int z = arr[i][j];
            arr[i][j] = arr[i][n-j-1];
            arr[i][n-j-1] = z;
        }

    for (int i=0;i<n;i++){
        int mini = i;
        for (int j=i+1;j<n;j++)
            if (!((i == 0) && (arr[0][j] == 0)) && (arr[0][j] < arr[0][mini]))
                mini = j;
        int z = arr[0][mini];
        arr[0][mini] = arr[0][i];
        arr[0][i] = z;
    }

    bool right = true;
    for (int i=0;i<n;i++)
        if (arr[0][i] != arr[1][i])
            right = false;

    if (right)
        cout<<"OK"; else cout<<"WRONG_ANSWER";

    return 0;
}


// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

string s;

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	cin>>s;
	char m=*max_element(s.begin(),s.end());
	rep(i,sz(s))if(s[i]==m)cout<<m;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;
ll tab[55];
bool cmp(int a,int b)
{
    return (a>b);
}
int main()
{
    //freopen("in","r",stdin);
    ll n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>tab[i];

    sort(tab,tab+n);
    for(int i=0; i<n-1; i++)
    {
        if (tab[i]==tab[i+1])
        {
            tab[i]=0;
        }

    }
    sort(tab,tab+n,cmp);

    bool test=false;
    int i=0;
    while(!test && tab[i+2]!=0)
    {
        if (tab[i]==(tab[i+1]+1) )
        {
            if (tab[i]==(tab[i+2]+2))
            {
                test=true;
            }

        }
        i++;
    }

    if (test)
        cout<<"YES";
    else
        cout<<"NO";

    return 0;
}


#include <iostream>
#include <algorithm>

int main() {
	int n, m;

	std::cin >> n >> m;

	if (std::min(n, m) % 2) {
		std::cout << "Akshat" << '\n';
	} else {
		std::cout << "Malvika" << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define popb pop_back
#define forr(x,y) for(ll i=x;i<=y;i++)

void solve(){
    ll n, k, sum1=0, sum2=0;
    cin>>n>>k;

    if(n<k){
        sum1= k-1;
        sum2= n;
    }
    else{
        sum1 = n-1;
        sum2 = k;

    }
    cout<<sum1<<" "<<sum2<<endl;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

//Code begins here

    ll t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <algorithm>
#include <cstring>
#include <string>
#include <sstream>

using namespace std;
typedef long long int64;

char buf[1<<16];
int p=0, l=0;

void _readbuf() {
    cin.read(buf, 1 << 16);
    l = cin.gcount();
    p = 0;
}

bool _eof() {
    if (p < l) return false;
    _readbuf();
    return p == l;
}

char _nextc() {
    if (p < l) return buf[p++];
    if (cin.eof()) throw 1;
    _readbuf();
    if (p < l) return buf[p++];
    throw 2;
}

string nexttoken() {
    string s="";

    while (!_eof()) {
        char c = _nextc();
        if (c == ' ' || c == '\r' || c == '\n' || c == '\t') continue;
        s += c;
        while (!_eof()) {
            c = _nextc();
            if (c == ' ' || c == '\r' || c == '\n' || c == '\t') break;
            s += c;
        }
        break;
    }

    return s;
}

string nextline() {
    string s = "";

    while (!_eof()) {
        char c = _nextc();
        if (c == '\r' || c == '\n') continue;
        s += c;
        while (!_eof()) {
            c = _nextc();
            if (c == '\r' || c == '\n') break;
            s += c;
        }
        break;
    }

    return s;
}

int nextint() {
    string s = nexttoken();
    if (s == "") throw 3;
    bool minus = s[0] == '-';
    int64 res = 0;
    for (size_t i = minus?1:0; i < s.length(); i++)
    {
        if (s[i]<'0' || s[i]>'9') throw 4;
        res = 10 * res + s[i]-'0';
    }
    if (minus) res = -res;
    if (res > 2147483647LL || res < -2147483648LL) throw 5;
    return (int)res;
}

int64 nextlong() {
    string s = nexttoken();
    if (s == "") throw 3;
    bool minus = s[0] == '-';
    int64 res = 0;
    for (size_t i = minus ? 1 : 0; i < s.length(); i++)
    {
        if (s[i]<'0' || s[i]>'9') throw 4;
        res = 10 * res + s[i] - '0';
    }
    if (minus) res = -res;
    return res;
}

double nextdouble() {
    string s = nexttoken();
    if (s == "") throw 5;
    double res = 0;
    bool minus = s[0] == '-';
    bool haveDigits = false;
    bool decimalSeparatorFound = false;
    size_t i;
    for (i = minus ? 1 : 0; i < s.length(); i++)
    {
        if (s[i] == '.' || s[i]==',') {
            decimalSeparatorFound = true;
            ++i;
            break;
        }
        if (s[i] < '0' || s[i] > '9') throw 7;
        res = 10 * res + s[i] - '0';
        haveDigits = true;
    }
    if (decimalSeparatorFound) {
        int64 p = 0, q = 1;
        int len = 0;
        for (; i < s.length(); i++)
        {
            if (s[i] < '0' || s[i] > '9') throw 8;
            haveDigits = true;

            if (++len < 17) {
                p = 10 * p + s[i] - '0';
                q *= 10LL;
            }
        }
        if (len > 0) {
            res += (double)p / q;
        }
    }
    if (!haveDigits) {
        throw 9;
    }
    return minus ? -res : res;
}

void solve() {
    int n = nextint();
    string s = nexttoken();

    int res = 0;

    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = i; j < n; j++)
        {
            int x = 0, y = 0;
            for (size_t k = i; k <= j; k++)
            {
                if (s[k] == 'U') ++y;
                if (s[k] == 'D') --y;
                if (s[k] == 'L') ++x;
                if (s[k] == 'R') --x;
            }
            if (x == 0 && y == 0)
                ++res;
        }
    }

    printf("%d\n", res);
}

int main()
{
#ifdef GAMER34
    freopen("input.txt", "r", stdin);
#endif

    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    cout.precision(10);

    solve();

    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,x,count=0;
    cin>>n>>x;
    for(ll i=1;i*i<=x;i++)
    {
        if(x%i==0 && i<=n && (x/i)<=n )
            if(i==(x/i)) count++;
            else count+=2;
    }
    cout<<count;
    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include<math.h>

using namespace std;

typedef long long ll;

int clearr(int n) {
    int a = 0;
    int b = 1;
    while(n!=0)
    {
        if (n%10!=0)
        {
            a += (n%10)*b;
            b *= 10;
        }
        n /= 10;
    }
    return a;
}

int main()
{
    int a, b, c;
    cin >> a >> b;
    c = a + b;
    a = clearr(a);
    b = clearr(b);
    c = clearr(c);
    if (a+b==c) cout << "YES";
    else cout << "NO";
}


#include<bits/stdc++.h>
#define int long long
#define double long double
#define pb push_back
#define sp ' '
#define endl '\n'
#define fi first
#define se second
using namespace std;
const int mod=1e9+7;
const int N=1e5+7;
const double pi=acos(-1);
vector<int> ans;
signed main()
{
int p,k;   cin>>p>>k;
ans.pb(p%k);
if(p<k) return cout<<"1\n"<<p,0;
int cur=p/k;
cur*=(-1);
while(cur >= k || cur<0)
{
	int tem=(cur+k*abs(cur))%k;
	ans.pb(tem);
	cur=(tem-cur)/k;
}
if(cur>0) ans.pb(cur);

cout<<ans.size()<<endl;

for(int i=0;i<ans.size();++i) cout<<ans[i]<<" ";
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <hash_map>
#include <hash_set>
#include <vector>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iterator>
using namespace std;
#define mems(arr, val) memset(arr, val, sizeof(arr))
#define forn(it, from, to) for(int it = from; it < to; ++it)
#define all(A) (A).begin(), A.end()
#define mp(a, b) make_pair(a, b)
typedef unsigned long long LL;

int D[41][41];
int A[41][41];
int rec(int a, int b, int c, int d)
{
	if (c < a || d < b) return 0;
	int result = 0;
	if (c >= a && D[c - 1][d] == -1 && A[c - 1][d] == 1)
	{
		D[c - 1][d] = rec(a, b, c - 1, d);
	}

	if (d >= b && D[c][d - 1] == -1 && A[c][d - 1] == 1)
	{
		D[c][d - 1] = rec(a, b, c, d - 1);
	}

	return D[c - 1][d] + D[c][d - 1] + A[c][d];
}

int main()
{
#ifdef MY_SOL
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	LL w, m, k;
	LL ans = 0;
	cin>>w>>m>>k;
	vector<LL> A;
	LL cur = 10;
	forn(i, 0, 17)
	{
		A.push_back(cur);
		cur *= 10;
	}

	int curdeg = 0;
	while (w > 0)
	{
		if (A[curdeg] > m)
		{
			LL tmp = (A[curdeg] - m) * (curdeg + 1) * k;
			if (tmp > w)
			{
				ans += (w) / ((curdeg + 1) * k);
				cout<<ans;
				return 0;
			}
			else
			{
				w -= (A[curdeg] - m) * (curdeg + 1) * k;
				ans += (A[curdeg] - m);
				m = A[curdeg];
				curdeg++;
			}
		}
		else
		{
			curdeg++;
		}
	}
	cout<<ans;
    return 0;
}


#include<iostream>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include<cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <sstream>
//#define lp(i,n)    for(int i=0;(int)i<n;++i)
typedef long long ll;
using namespace std;
const int MAX = 1000000000 + 9;
//freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
void fast()
{
	std::ios_base::sync_with_stdio(0);
}
int main()
{

	int n;
	cin >> n;
	vector<int> num;
	int a = 1;
	num.push_back(a);
	for (int i = 1;i <= 9;i++)
	{
		a = a << 2;
		int y = 1;
		y = y << i;
		//cout << bitset<32>(a) << "   " << bitset<32>(y) << endl;
		a = (a | y);
		num.push_back(a);

	}
	int ans = 0;
	for (int i = 0;i <num.size();i++)
	{
		if (n%num[i] == 0)
			ans = num[i];

	}
/*	cout << endl << endl;
	for (int i = 0;i <num.size();i++)
	{
	//	cout <<bitset<32>( num[i] )<< endl;	}
	//cout << endl << endl;
	*/cout << ans << endl;

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

struct Node {
    int a[4];
};

bool vis[4][4][4][4];

void set_vis(const Node& no) {
    vis[no.a[0]][no.a[1]][no.a[2]][no.a[3]] = true;
}

bool get_vis(const Node& no) {
    return vis[no.a[0]][no.a[1]][no.a[2]][no.a[3]];
}

int main() {
    Node s, t;
    char g[8];
    scanf("%s %s", g, g+2);
    for (int i = 0; i < 4; i++) {
        if (g[i] == 'X')
            s.a[i] = 3;
        else
            s.a[i] = g[i] - 'A';
    }
    scanf("%s %s", g, g+2);
    for (int i = 0; i < 4; i++) {
        if (g[i] == 'X')
            t.a[i] = 3;
        else
            t.a[i] = g[i] - 'A';
    }
    memset(vis, 0, sizeof(vis));
    queue<Node> q;
    set_vis(s);
    q.push(s);
    while (!q.empty()) {
        Node no = q.front();
        q.pop();
        for (int k = 0; k < 4; k++) {
            if (no.a[k] == 3) {
                swap(no.a[k], no.a[k^1]);
                if (!get_vis(no)) {
                    set_vis(no);
                    q.push(no);
                }
                swap(no.a[k], no.a[k^1]);
                swap(no.a[k], no.a[k^2]);
                if (!get_vis(no)) {
                    set_vis(no);
                    q.push(no);
                }
                swap(no.a[k], no.a[k^2]);
            }
        }
    }
    puts(get_vis(t) ? "YES" : "NO");
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector<long long>     VLL;
typedef vector< VI >    VVI;
typedef long long int   LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))

#define din(n) int n; scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define llin(n) long long n; scanf("%lld",&n)
#define llout(n) printf("%lld\n",n)
#define strin(s,l) char s[l]; scanf("%s",s)
#define strout(n) printf("%s\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl '\n'

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
bool cmpManh(const std::pair<long long,long long>& l, const std::pair<long long,long long>& r)  {
return ((llabs(l.F) + llabs(l.S)) < (llabs(r.F) + llabs(r.S)));
}

int gcd(int a, int b){
if (a == 0) return b; return gcd(b%a, a);
}

int main(void)
{
	string s;
	cin>>s;
	LL n = 0;
	LL sz = s.size();
	for (int i = 0; i < sz-1; ++i)
	{
		n += s[i]-'0';
		if(i!=sz-2) n *= 10;
		/* code */
	}
	// LL n =  - '0';
	// trace(n);
	char c = s[sz-1];
	LL ans = ((n-1)/4)*16;
	if(n%2==0){
		ans += 7;
	}
	if(c=='f') ans+=1;
	if(c=='e') ans+=2;
	if(c=='d') ans+=3;
	if(c=='c') ans+=6;
	if(c=='b') ans+=5;
	if(c=='a') ans+=4;
	llout(ans);

    return(0);
}


#include<iostream>
using namespace std;
long long n,m;
int main()
{
    cin>>n>>m;
    while(n&&m)
        if(n>=2*m)n%=2*m;
        else if(m>=2*n)m%=2*n;
        else break;
    cout<<n<<' '<<m<<endl;
    return 0;
}


#include <bits/stdc++.h>
#include <chrono>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*............................................................................*/
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/* find_by_order(x) give iterator of the index x
   order_by_key(x) give the position where x will be placed*/
#define int long long
#define lop(i,a,b,c) for (int i=a;i<b;i+=c)
#define rlop(i,a,b,c) for (int i=a-1;i>=b;i-=c)
#define prii pair <int,int>
#define PB push_back
#define S second
#define F first
#define all(x) x.begin(),x.end()
#define vvii vector < vector < int > >
#define vii vector <int>
#define count_1(x) __builtin_popcount(x)
#define cn(a) scanf("%lld",&a);
#define cn_vl(arr,n) lop(i,0,n,1){scanf("%lld",arr+i);}
#define shw_vl(arr,n) lop(i,0,n,1){printf("%lld ",arr[i]);}printf("\n");
#define shw(CON) cout << &("NO\0YES"[3 * CON]) << '\n';
const int MAX=3e5+10;
const int mod=1e9+7;
/*......................................................................*/

void solve(){
	int n,m;cn(n)cn(m)
	queue <prii> q;
	q.push({m,0});
	int cs=0;
	map <int,int> mp;
	mp[m]=1;
	while (!q.empty())
	{
		auto a=q.front();q.pop();
		string s=to_string(a.F);
		int sz=s.size();
		if (sz==n)
		{
			printf("%lld\n",a.S);return;
		}
		cs=max(cs,sz);
		int arr[10];memset(arr,0,sizeof(arr));
		for (auto x:s)
		{
			int ch=x-'0';
			arr[ch]=1;
		}
		int cn=0;
		rlop (i,10,2,1)
		{
			if (arr[i])
			{
				if (!mp.count(a.F*i)){q.push({a.F*i,a.S+1});mp[a.F*i]=1;}
				cn++;
			}
		}
	}
	printf("-1\n");
}
int32_t main(){
	int t;t=1;
	// cin>>t;
	for (int ie=1;ie<=t;ie++){
		// printf("Case #%d: ",ie);
		auto t_1=chrono::high_resolution_clock::now();
		solve();
		auto t_2=chrono::high_resolution_clock::now();
		// cout <<". Elapsed (ms): " << chrono::duration_cast<chrono::milliseconds>(t_2 - t_1).count() << endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
#include<algorithm>

int main()
{
    int a, b;
    cin >> a >> b;
    int x, y;
    int c1 = 0, c2 = 0, c3 = 0;

    for (int i = 6; i > 0; i--)
    {
        x = max(i, a) - min(i, a);
        y = max(i, b) - min(i, b);

        if (x < y)
            c1++;
        else{
            if (x>y)
                c2++;
            else c3++;
        }

    }
    cout << c1 << " " << c3 << " " << c2;

}


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

struct ponto{
	long long int x, y;
	ponto() {}
	ponto(long long int _x, long long int _y){
		x = _x;
		y = _y;
	}
	//soma de vetores
	ponto operator+(const ponto & p){
		return ponto(x + p.x, y + p.y);
	}
	//subtracao de vetores
	ponto operator-(const ponto & p){
		return ponto (x - p.x, y - p.y);
	}
	//produto escalar
	//se =0 entao angulo = 90
	//se <0 entao angulo <90
	//se >0 entao angulo >90
	long long int operator* (const ponto & p){
		return x * p.x + y * p.y;
	}
	//produto vetorial
	//se >0 entao  angulo < 180
	//se <0 entao angulo >180
	//se 0 entao angulo = 0 ou =180
	long long int operator^(const ponto & p){
		return x * p.y - y * p.x;
	}
	long long int operator~(){
		return x * x + y * y;
	}
};

int main()
{
	ponto a, b, c;
	//ler os pontos
	cin >> a.x >> a.y;
	cin >> b.x >> b.y;
	cin >> c.x >> c.y;
	//montar os vetores
	ponto vetor1 = b - a;
	ponto vetor2 = c - b;

	long long int teste = vetor1 ^ vetor2;

	if(teste == 0)cout << "TOWARDS" << endl;
	else if(teste > 0)cout << "LEFT" << endl;
	else cout << "RIGHT" << endl;
}


#include <stdio.h>

int n,par[105];
bool vis[105];
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main(){
	int ans=1;
	scanf("%i",&n);
	for(int i=1;i<=n;i++)scanf("%i",&par[i]);
	for(int j=1;j<=n;j++){
		if(vis[j])continue;
		bool valid=0;
		int pos=par[j];
		for(int k=1;k<=n+2;k++){
			vis[pos]=1;
			if(pos==j){
				valid=1;
				int fpb=gcd(ans,(k&1)?k:k/2);
				ans=(ans*((k&1)?k:k/2))/fpb;
				break;
			}
			pos=par[pos];
		}
		if(!valid){
			printf("-1\n");
			return 0;
		}
	}
	printf("%i\n",ans);
}


#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define ppi pair<int,pair<int,int> >
#define fr first
#define sc second
#define PI acos(-1)
#define mp make_pair

using namespace std;

#define sim template < class c

#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int n;
ll pr[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
ll ans = 1e18 + 100;
const ll Limit = 4e18;

void so(int i = 0,ll sum = 1,ll num = 1){
    if(i == 10){
        if(sum == n)ans = min(ans , num);
        return ;
    }
    if(sum > n)return;
    ll x = 1;
    for(int j = 0;j<64;j++){
        if(j == 0)
        {
            so(i + 1,sum , num);
            continue;
        }
        if(Limit / x > pr[i] ){
            x = x * pr[i];
            if(Limit / x > num)
                so(i + 1,sum * (j + 1),num * x);
            else break;
        }
        else break;
    }
    return ;
}

int main()
{
    cin >> n;
    so();
    assert(ans != 1e18 + 100);
    while(ans < 0 || ans > 1e18){
        new int[100101];
    }
    cout << ans << '\n';

    return 0;
}


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

#define scanfd1(x) scanf("%d", &x)
#define scanfd2(x,y) scanf("%d %d", &x, &y)
#define scanfd3(x,y,z) scanf("%d %d %d", &x, &y, &z)
#define scanfd4(x,y,z,w) scanf("%d %d %d %d", &x, &y, &z, &w)

#define scanfll1(x) scanf("%lld", &x)
#define scanfll2(x,y) scanf("%lld %lld", &x, &y)
#define scanfll3(x,y,z) scanf("%lld %lld %lld", &x, &y, &z)
#define scanfll4(x,y,z,w) scanf("%lld %lld %lld %lld", &x, &y, &z, &w)

#define fr(i,n) for(int i=0;i<(n);i++)
#define frr(i,a,b) for(int i=(a);i<=(b);i++)
#define frrs(i,a,b) for(int i=(a);i>=(b);i--)
#define VAR(a,b) __typeof(b) a=b
#define frit(it,c) for(VAR(it,(c).begin());it!=(c).end();it++)

typedef long long ll;
typedef long double ld;

#define pb push_back

#define all(a) a.begin(),a.end()

#define fi first
#define se second
typedef pair<int,int> pii;

#define PI acos(-1)
#define MOD 1000000007

//LONG_LONG_MAX
//-DBL_MAX

#define prin(a) cout << #a << " = " << (a) << endl

int main(){
	int mat[5][5];

	fr(i,4){
			scanfd4(mat[i][0],mat[i][1],mat[i][2],mat[i][3]);
	}

	bool ped[5];

	fr(i,4) ped[i] = 0;
	//fr(i,4) prin(ped[i]); //novo code

	fr(i,4){//mat[x][0] left
		if(mat[i][0]){
			ped[i] = 1;
			ped[(i-1+4)%4] = 1;
		}
	}

	fr(i,4){//mat[x][1] s
		if(mat[i][1]){
			ped[i] = 1;
			ped[(i+2+4)%4] = 1;
		}
	}

	fr(i,4){//mat[x][2] s
		if(mat[i][2]){
			ped[i] = 1;
			ped[(i+1+4)%4] = 1;
		}
	}

	//prin(mat[0][3]);

	/*if(mat[0][1]){
		fr(i,4){
			prin(ped[i]);
		}
	}*/

	fr(i,4){
		if(mat[i][3] and ped[i]){
			//prin(i);
			cout << "YES" << endl;
			return 0;
		}
	}

	cout << "NO" << endl;

	return 0;
}


#include<bits/stdc++.h>
 using namespace std;
 int main()
 {
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a;
    int b;
    cin >> a >> b;
    vector<int> q;
    vector<int> w;
    while(a>0)
    {
      q.push_back(a%10);
      a/=10;
    }
    while(b>0)
    {
      w.push_back(b%10);
      b/=10;
    }
    int c=q.size();
    int d=w.size();
    if(c>d)
    {
       for(int i=0;i<(c-d);i++)
       {
          w.push_back(0);
          //cout << 0;
       }
    }
    else if(d>c)
    {
       for(int i=0;i<(d-c);i++)
       {
          q.push_back(0);
          //cout << 0;
       }
    }
    int e=q[0];
    int r=w[0];
    for(int i=0;i<q.size();i++)
    {
       if(e<q[i])
       {
          e=q[i];
       }
       if(r<w[i])
       {
          r=w[i];
       }
    }
    int t=max(e,r)+1;
    int ans1=0;
    vector<int> as;
    for(int i=0;i<q.size();i++)
    {
       int y=q[i]+w[i]+ans1;
       as.push_back(y%t);
       //cout << q[i] + w[i] + ans1 << endl;
       ans1=(y/t);
    }
    //cout << ans1 << endl;
    if(ans1==0)
    {
      cout << as.size();
    }
    else
    {
      cout << as.size()+1;
    }
    return 0;
 }
 //s[i].size()
 //a=tolower(a) делает char переменную a маленькой,
//a=toupper(a), делает char переменную a большой
/*

 /*  %с – одиночный символ
     %d – десятичное целое число со знаком
     %f – число с плавающей точкой (десятичное представление)
     %s – строка символов (для строковых переменных)
     %u – десятичное целое без знака
     %% - печать знака процента
     printf(“Ваш возраст = %d, Ваш вес = %f”, age, weigth);
     */

/* if((j<n-abs(i-n/2)) and j>=abs(i-n/2))
          {
             cout << "D";
          }
          else
          {
             cout << "*";
          }*/


#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

ll l,r;
int num[10],keep[10];
vector<int> lv,rv;

inline bool any(int l,int r) {
    for (int i=l;i<=r;i++) {
        if (num[i]>0) return true;
    }
    return false;
}

bool dfs(int idx,bool lf,bool rf) {
    if (idx==rv.size()) return true;
    int l=lv[idx],r=rv[idx];
    if (lf&&rf) {
        if (l==r) {
            if (num[l]>0) {
                num[l]--;
                if (dfs(idx+1,1,1)) return true;
                num[l]++;
            }
            return false;
        }
        if (any(l+1,r-1)) return true;
        if (num[l]>0) {
            num[l]--;
            if (dfs(idx+1,1,0)) return true;
            num[l]++;
        }
        if (num[r]>0) {
            num[r]--;
            if (dfs(idx+1,0,1)) return true;
            num[r]++;
        }
        return false;
    } else {
        if (lf) {
            if (any(l+1,9)) return true;
            if (num[l]>0) {
                num[l]--;
                if (dfs(idx+1,1,0)) return true;
                num[l]++;
            }
            return false;
        }
        if (rf) {
            if (any(0,r-1)) return true;
            if (num[r]>0) {
                num[r]--;
                if (dfs(idx+1,0,1)) return true;
                num[r]++;
            }
            return false;
        }
    }
    return false;
}

int ans=0;
void go(int idx,int rem) {
    if (idx==10) {
        memcpy(num,keep,sizeof(keep));
        num[0]+=rem;
        if (dfs(0,1,1)) ans++;
        return;
    }
    for (int i=0;i<=rem;i++) {
        keep[idx]=i;
        go(idx+1,rem-i);
    }
}

int main()
{
    scanf("%lld%lld",&l,&r);

    while (l>0) {
        lv.pb(l%10);
        l/=10;
    }
    while (r>0) {
        rv.pb(r%10);
        r/=10;
    }
    while (lv.size()<rv.size()) lv.pb(0);
    reverse(lv.begin(),lv.end());
    reverse(rv.begin(),rv.end());

    go(1,lv.size());
    printf("%d\n",ans);
}


#include <ctime>

#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <set>
#include <map>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef double lf;

const int maxn = 8, inf = 1000000000;

int n, p[maxn], order[maxn], ans = inf;
ll data[maxn];
vector<ll> fact[maxn], tmp[maxn];

inline int matchSubseq(vector<ll> &a, vector<ll> &b)
{
	for (size_t i = 0, ptr = 0; i < a.size(); i++, ptr++)
	{
		while (ptr < b.size() && b[ptr] != a[i]) ptr++;
		if (ptr >= b.size()) return -1;
	}
	return b.size() - a.size();
}

void rec(int k)
{
	if (k == n)
	{
		int curans = 0, alone = 0;
		for (int i = 0; i < n; i++) tmp[i].clear();
		for (int i = n - 1; i >= 0; i--)
		{
			int v = order[i];
			sort(tmp[i].begin(), tmp[i].end());
			int x = matchSubseq(tmp[i], fact[v]);
			if (x == -1) return;
			if (fact[v].size() == 1) curans++;
			else curans += x + 1;
			if (p[i] == -1) alone++;
			else
				for (size_t j = 0; j < fact[v].size(); j++)
					tmp[p[i]].pb(fact[v][j]);
		}
		if (alone > 1) curans++;
		ans = min(ans, curans);
		return;
	}
	for (p[k] = -1; p[k] < k; p[k]++)
		rec(k + 1);
}

inline bool cmp(int a, int b)
{
	return fact[a].size() > fact[b].size();
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    cin >> n;
    for (int i = 0; i < n; i++)
    {
		cin >> data[i];
		ll tmp = data[i];
		for (ll x = 2; x * x <= tmp; x++)
			while (tmp % x == 0) tmp /= x, fact[i].pb(x);
		if (tmp != 1) fact[i].pb(tmp);
		order[i] = i;
	}
	sort(order, order + n, cmp);
	rec(0);
	printf("%d\n", ans);
    return 0;
}


#include<iostream>
#include<string.h>
#include<stdio.h>
#include<string>

using namespace std;

// Returns the product of digits of number x
int product(int x)
{
	int prod = 1;
	while (x) {
		prod *= (x % 10);
		x /= 10;
	}
	return prod;
}

// This function returns the number having
// maximum product of the digits
int findNumber(int l, int r)
{
	// Converting both integers to strings
	string a = to_string(l);
	string b = to_string(r);

	// Let the current answer be r
	int ans = r;
	for (int i = 0; i < b.size(); i++) {
		if (b[i] == '0')
			continue;

		// Stores the current number having
		// current digit one less than current
		// digit in b
		string curr = b;
		curr[i] = ((curr[i] - '0') - 1) + '0';

		// Replace all following digits with 9
		// to maximise the product
		for (int j = i + 1; j < curr.size(); j++)
			curr[j] = '9';

		// Convert string to number
		int num = 0;
		for (auto c : curr)
			num = num * 10 + (c - '0');

		// Check if it lies in range and its product
		// is greater than max product
		if (num >= l && product(ans) < product(num))
			ans = num;
	}

	return ans;
}

// Driver Code
int main()
{
	int l = 1, n;
	cin >> n;
	cout << product(findNumber(l, n));
	//system("pause");
	return 0;
}

//#include<iostream>
//#include<cmath>
//using namespace std;
//
//
//int productDigit(int n) {
//	int pro = 1;
//	while (n> 0) {
//		pro *= n % 10;
//		n /= 10;
//	}
//	return pro;
//}
//
//int numofDigit(int n) {
//	int num = 0;
//	while (n > 0) {
//		num++;
//		n /= 10;
//	}
//	return num;
//}
//
//int maxProduct(int n) {
//	if (n <= 9)
//		return n;
//	int lastDigit,tmp=n;
//	int num = pow(10,numofDigit(n) - 1);
//	bool find = false;
//	int max = 0;
//	int rel;
//	while (find==false)
//	{
//		lastDigit = n % 10;
//		rel = productDigit(n);
//		if (rel > max) {
//			max = rel;
//		}
//		if (lastDigit == 9 && rel != 0) {
//			if (rel > max)
//			max = rel;
//			find = true;
//		}
//		n--;
//	}
//	n++;
//	int count = 0;
//
//	while (count!=num)
//	{
//		rel = productDigit(n);
//		if (rel > max) {
//			max = rel;
//		}
//		count += 10;
//		n-=10;
//	}
//	return max;
//}
//
//
//int main() {
//	int n;
//	cin >> n;
//	cout << maxProduct(n);
//	system("pause");
//	return 0;
//}


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

long long x , y , z , i , j , n , m , k , s1 , s2 , mod , r , N , maxx , minn ;
double w , v , q , h , hh , ww1 , ww2 ;
long long a [ 100045 ] ;
long long b [ 100045 ] ;
string s ;
map < long long , long long > mm ;

int main() {
    scanf ( "%lld%lld%lld" , & x , & y , & n ) ;
    if ( y <= n ) {
        k = __gcd ( x , y ) ;
        printf ( "%lld/%lld" , x / k , y / k ) ;
        exit (0) ;
    }
    s1 = -1 ;
    for ( i = 1 ; i <= n ; i ++ ) {
       j = i * x / y ;
       if ( abs ( i * x - j * y ) > abs ( i * x - ( j + 1 ) * y ) ) j ++ ;
       if( s1 == -1 || abs ( s2 * x - s1 * y ) * i > abs ( i * x - j * y ) * s2 ) {
           s1 = j ;
           s2 = i ;
       }
    }
    printf ( "%lld/%lld" , s1 , s2 ) ;
}


#include<bits/stdc++.h>
using namespace std;
map<string,int>a;
int main()
{
	a["January"]=1,a["February"]=2,a["March"]=3,a["April"]=4,a["May"]=5,a["June"]=6,a["July"]=7,a["August"]=8,a["September"]=9,a["October"]=10,a["November"]=11,a["December"]=12;
	int n,k;
	string s;cin>>s>>n;
	k=(a[s]+n)%12;
	if(k==1)cout<<"January";
	if(k==2)cout<<"February";
	if(k==3)cout<<"March";
	if(k==4)cout<<"April";
	if(k==5)cout<<"May";
	if(k==6)cout<<"June";
	if(k==7)cout<<"July";
	if(k==8)cout<<"August";
	if(k==9)cout<<"September";
	if(k==10)cout<<"October";
	if(k==11)cout<<"November";
	if(k==0)cout<<"December";
	cout<<endl;
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define ll long long int

int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll n;
    int m;
    cin>>n>>m;
    int rem[100001]={0};
    int flag=1;
    while(flag)
    {
        rem[n%m]++;
        if(rem[n%m]>1)
            flag = 0;
        n+=(n%m);
        if(n%m==0)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


#include<vector>
#include<set>
#include<list>
#include<map>
///Sortedorder    (Slow)
///Randomorder   (fast)
#include<iostream>
#include<string>
#include<bits/stdc++.h>
#define all(c) c.begin(), c.end()
# define lli long long int
#include<string>
#define vec vector<lli>
#define M 1000000007

using namespace std;
vector<lli>dp(1000000,-1);
int main()
{

    lli n;
    cin>>n;
    lli i;
    lli c=0;
    vector<lli>v;
    lli no_of_digits=0;
    lli k=n;
    while(k>0)
    {

        no_of_digits++;
        k=k/10;

    }

    lli f=n-(no_of_digits*2)*9-1;

    if(f<0)
        f=0;

    for(i=f;i<=n;i++)
    {

        lli sum=i;
        lli x=i;
        while(x>0)
        {

            sum=sum+(x%10);
            x=x/10;

        }
        if(sum==n)
        {

            c++;
            v.push_back(i);
        }

    }
    cout<<c<<"\n";
    for(i=0;i<v.size();i++)
    {
        cout<<v[i]<<"\n";
    }

}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    long long int l,r,ans=0,expof2,expof3;
    cin>>l>>r;

    for(expof2=1;expof2<=r;expof2*=2)
    {
        for(expof3=1;expof3<=r;expof3*=3)
        if(expof3*expof2<=r&&expof2*expof3>=l)
        ans++;
    }
    cout<<ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int M = 4;
const int K = 13;
const int N = K * (1 << M) + 1;
const int MOD = 1000000007;

inline int add(int u, int v) {
    return (u += v) >= MOD ? u - MOD : u;
}

inline int sub(int u, int v) {
    return (u -= v) < 0 ? u + MOD : u;
}

inline int mul(int u, int v) {
    return (long long)u * v % MOD;
}

struct Matrix {
    int a[N][N];

    Matrix(int diag = 0) {
        memset(a, 0, sizeof a);
        for (int i = 0; i < N; i++) a[i][i] = diag;
    }

    int* operator [] (int u) {
        return a[u];
    }

    Matrix operator * (Matrix &u) const {
        Matrix res;
        for (int k = 0; k < N; k++) {
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    res[i][j] = add(res[i][j], mul(a[i][k], u[k][j]));
                }
            }
        }
        return res;
    }

    Matrix operator ^ (int v) const {
        Matrix res(1);
        Matrix u = *this;
        while (v) {
            if (v & 1) res = res * u;
            u = u * u;
            v >>= 1;
        }
        return res;
    }

    void debug(int n) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) cout << a[i][j];
            cout << endl;
        }
        cout << endl;
    }
};

int n, m, k;

int encode(int u, int mask) {
    return (u << m) + mask;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k >> m;
    Matrix b;
    for (int i = 0; i <= k; i++) {
        for (int mask = 0; mask < (1 << m); mask++) {
            int id = encode(i, mask);
            int id2 = encode(i, (mask << 1) & ((1 << m) - 1));
            b[id][id2] = 1;
            if (i < k) {
                id2 = encode(i + 1, (mask << 1) & ((1 << m) - 1) | 1);
                b[id][id2] = __builtin_popcount(mask) + 1;
            }
        }
    }
    Matrix a;
    a[0][0] = 1;
    // b.debug((k + 1) << m);
    Matrix c = b ^ n;
    // c.debug((k + 1) << m);
    c = a * c;
    // c.debug((k + 1) << m);
    int res = 0;
    for (int mask = 0; mask < (1 << m); mask++) {
        res = add(res, c[0][encode(k, mask)]);
    }
    cout << res << endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int k, n, s, p;
    cin >> k >> n >> s >> p;
    cout << ((n + s - 1) / s * k + p - 1) / p;
    return 0;
}


#include<cstdio>
#include<fstream>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<bitset>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<cstring>
#include<ctime>
#include<cstdlib>

#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define dbg(x) (cout<<#x<<" = "<<(x)<<endl)

using namespace std;

int n,i,j,k,l,a,b,lim,known,totalknown,sol,cate,cnt;

string s;

map<string,int> m;

set<int> color[10],number[10];

vector<pii> v;

bitset<10> A,B;

int main()
{
    //freopen("test.in","r",stdin);
    //freopen("test.out","w",stdout);

    cin.sync_with_stdio(false);

    cin>>n;

    for(i=1; i<=n; i++)
    {
        cin>>s;

        if(m[s]) continue;

        m[s]=1;

        if(s[0]=='R') a=1;
        else if(s[0]=='G') a=2;
        else if(s[0]=='B') a=3;
        else if(s[0]=='Y') a=4;
        else a=5;

        b=s[1]-'0';

        color[a].insert(b);
        number[b].insert(a);

        v.pb(mp(a,b));
    }

    lim=1<<5;
    sol=1<<30;

    for(i=0; i<lim; i++)
        for(j=0; j<lim; j++)
        {
            A=B=0;
            totalknown=0;
            cate=0;

            for(k=0; k<5; k++)
            {
                if((1<<k)&i) A[k+1]=1,cate++;
                if((1<<k)&j) B[k+1]=1,cate++;
            }

            for(l=0; l<v.size(); l++)
            {
                known=0;
                a=v[l].first;
                b=v[l].second;

                if(A[a])
                {
                    cnt=0;
                    for(auto it:color[a])
                        if(B[it]) cnt++;
                    if(cnt>=color[a].size()-1) known=1;
                }

                if(B[b])
                {
                    cnt=0;
                    for(auto it:number[b])
                        if(A[it]) cnt++;
                    if(cnt>=number[b].size()-1) known=1;
                }

                totalknown+=known;
            }

            if(totalknown>=v.size()-1) sol=min(sol,cate);
        }

    cout<<sol;

    return 0;
}


#include <bits/stdc++.h>]
typedef long long LL;
using namespace std;

LL n,m,L,R;
const LL mod=998244353;
LL pow(LL p,LL k){
    LL ans=p,ret=1;
    while (k!=0){
        if (k%2==1) ret=ret*ans%mod;
        ans=ans*ans%mod;
        k/=2;
    }
    return ret;
}
int main()
{
	cin>>n>>m>>L>>R;
    if (L==R){
        printf("1");return 0;
    }
    LL k1=R/2;
    if (L>0) k1-=(L-1)/2;
    LL k2=(R-L+1)-k1;
    LL ans1=pow((k1+k2),n*m);
    LL ans2=pow((k1-k2),n*m);
    //printf("%lld %lld\n",ans1,ans2);
    if (n*m%2==0) cout<<((ans1+ans2+mod)%mod*((mod+1)/2LL))%mod<<endl;
    else cout<<pow((k1+k2),n*m)<<endl;
    return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
#define sz(a) (int)(a.size())
#define set(a,b) memset(a,b,sizeof(a))
#define let(x,a) __typeof(a) x(a)
#define rep(i, begin, end) for (ll i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) (v).begin(),(v).end()
#define sll(x) { scanf("%lld",&x); }
#define si(x) { scanf("%d",&x); }
#define slf(x) { scanf("%lf",&x); }
#define pll(x) { printf("%lld\n",x); }
#define pi(x) { printf("%d\n",x); }
#define tcases() long long testcases; cin>>testcases ; while(testcases--)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " = " << arg1<<" | ";__f(comma+1, args...);
}

#else
#define trace(...)
#endif

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<long long,long long> pll;
typedef vector<long long> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;

const ll mod=1000000007;
//-----------------------------------------------------------------------------------------------------------------------------------------------//

int main()
{
//	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	ll s,x,z,y,ans=0,one=1;
	sll(s);sll(x);

	s=s-x;
	if(s<0 || s%2!=0)
	{
		cout<<0<<endl;
		return 0;
	}

	s/=2;
	z=s;
	y=x;
	rep(i,0,64)
	{
		ll p=z&1;
		ll r=y&1;
		if(p==1 and r==1)
		{
			cout<<0<<endl;
			return 0;
		}
		z>>=1;
		y>>=1;
		ans+=r;
	}
	if(s!=0)
		cout<<(one<<ans)<<endl;
	else
	{
		cout<<(one<<ans)-2<<endl;
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int dec_bits( long long num ){
	int b = 0;
	for(; num; num /= 10, b++ );
	return b;
}
long long dec_pow( int pow ){
	long long val = 1;
	for(; pow; pow --, val *= 10 );
	return val;
}
long long weight( long long num ){
	return ( ( ( dec_pow( dec_bits( num ) )-1 )-num) * num );
}
int main(){
	int l, r;
	long long mid;
	cin >> l >> r;
	mid = (dec_pow( dec_bits( r ) )-1)/2;
	if( l < mid && mid < r ){
		cout << weight( mid ) << endl;
	}else{
		cout << max( weight(l), weight(r) ) << endl;
	}
	return 0;
}
/****** PCCA -Wed Aug 03 02:52:19 GMT 2011 *******/


#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<stack>
using namespace std;
#define fo(a,b) for(int i = a;i<b;i++)
#define fori(i,n) for(int i=0;i<n;i++)
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define N 501
#define mp make_pair
#define NMAX 200007
//#define x first
//#define y second
typedef pair<int, int> pii;
typedef vector<int> arr1D;
typedef vector<arr1D> arr2D;
void Arr2DInit(arr2D &a, int n, int m)
{
	a.resize(n);
	for (int i = 0; i < n; i++)
		a[i].resize(m);
}
template<class T>
T minn(T a, T b)
{
	return a < b ? a : b;
}
template<class T>
T maxx(T a, T b)
{
	return a > b ? a : b;
}
///////////////////////////// Le Chi Nhin 17CTT5 HCMUS /////////////////////////////////////////////
//const int dx[] = { -1,0,1,1,1,0,-1,-1 };
//const int dy[] = { 1,1,1,0,-1,-1,-1,0 };
///////////////////////////// I love U (KLy) //////////////////////////////////////////////////////
///////////////////////////// in the moments //////////////////////////////////////////////////////
//
const int dx[] = { 0,0,1,-1 };
const int dy[] = { 1,-1,0,0 };
string direct = "UDRL";

char a[501][501];
int main()
{
	//
	int n;
	cin >> n;
	if (n == 2)
		cout << 2;
	else cout << 1;
	//system("pause");
}


#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
  int n; char a[100];
  cin >> n;
  scanf("%s", a);
  int cnt = 0;
  for(int i = 0; i < n; i++) {
    if(a[i] == '1') cnt++;
    else {cout << cnt; cnt = 0;}
  }
  cout << cnt << endl;
  return 0;
}


///INCLUDE
#include<algorithm>
#include<iostream>
#include<fstream>
#include<cstring>
#include<cstdio>
///INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RIV(n, m, k, l) scanf("%d%d%d%d", &n, &m, &k, &l)
#define RFI(n) scanf("%lf", &n)
#define RFII(n, m) scanf("%lf%lf", &n, &m)
#define RFIII(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)
#define RFIV(n, m, k, l) scanf("%lf%lf%lf%lf", &n, &m, &k, &l)
#define RS(s) scanf("%s", s)
///OUTPUT
#define PI(n) printf("%d\n", n)
#define PIS(n) printf("%d ", n)
#define PS(s) printf("%s\n", s)
#define PSS(s) printf("%s ", s)
///LOOP
#define REP(i, n) for(int i = 0; i < n; i++)
#define FF(i, a, b) for(int i = a; i < b; i++)
#define FFF(i, a, b) for(int i = a; i <= b; i++)
#define FD(i, a, b) for(int i = a - 1; i >= b; i--)
#define FDD(i, a, b) for(int i = a; i >= b; i--)
#define CLR(a, b) memset(a, b, sizeof(a))
#define CPY(a, b) memcpy(a, b, sizeof(a))

using namespace std;

typedef long long LL;

const int MOD = 1000;
const int INFI = 1e9;
const int N = 1111;
const int M = 11;
const int move[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};

ofstream fout("out.txt");
ifstream fin("in.txt");

int main()
{
    int a, b, c, d;
    double e;
    while(RIV(a, b, c, d) != EOF)
    {
        if(c - b == d - c && b - a == c - b)
        {
            PI(d + b - a);
            continue;
        }
        if(b * b == a * c && c * c == b * d)
        {
            e = double(d * b) / double(a);
            if(e == int(e))PI(int(e));
            else PI(42);
            continue;
        }
        PI(42);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef ONLINE_JUDGE
#define OJ 1
#else
#define OJ 0
#endif

#define dd				double
#define ll 				long long
#define pb 				push_back
#define mp 				make_pair
#define X				first
#define Y				second
#define forn( i, n ) 	for( ll i = 0; i < (ll) (n); i ++ )
#define endl 			'\n'

#define TIMESTAMP fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock()/CLOCKS_PER_SEC)

struct __s { __s() {
		//srand( time( NULL ) );
		//freopen( "input.txt", "r", stdin ); freopen( "output.txt", "w", stdout );
		if( OJ ) { ios_base::Init i; cin.sync_with_stdio( 0 ); cin.tie( 0 ); }
	} ~__s() {
		if( !OJ ) TIMESTAMP;
		ll n; cin >> n;
	}
} __S;

int main( void ) {
	ll x;
	cin >> x;
	ll y = abs( x ) % 360;
	if( x >= 0 ) {
		if( y <= 45 || y >= 315 )
			cout << 0 << endl;
		else if( y <= 135 )
			cout << 1 << endl;
		else if( y <= 225 )
			cout << 2 << endl;
		else if( y < 315 )
			cout << 3 << endl;
	} else {
		if( y <= 45 || y >= 315 )
			cout << 0 << endl;
		else if( y >= 225 )
			cout << 1 << endl;
		else if( y >= 135 )
			cout << 2 << endl;
		else if( y > 45 )
			cout << 3 << endl;
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

#define X first
#define Y second

#define add push_back
typedef long long ll;
typedef pair<int, int> Point;
typedef pair<float, float> PointF;
typedef pair<double, double> PointD;

int main() {
    ios::sync_with_stdio(false);

    long long l1, r1, l2, r2, k;
    cin >> l1 >> r1 >> l2 >> r2 >> k;
    long long ans = min(r1, r2) - max(l1 - 1, l2 - 1);
    if (max(l1, l2) <= k && min(r1, r2) >= k) {
        ans = max((long long)0, ans - 1);
    } else {
        ans = max((long long)0, ans);
    }

    cout << ans << endl;

#ifdef _DEBUG
    system("pause");
#endif
    return 0;
}


/* DHUOJ solution #343263 @ 2018-07-06 20:17:08.805 */

#include <bits/stdc++.h>
#define ll long long
#define INF 0x7fffffff
#define inf 0x7fffffffffffffff
#define ms(a,val) memset((a),(val),(sizeof(a)))
#define sqr(x) ((x)*(x))

using namespace std;

pair<int,int> a[15],b[15];
set<int> ans,store[15];

int main(){
    int n,m,x,y;
    while(cin>>n>>m){
        for(int i=0;i<n;i++){
            cin>>x>>y;
            a[i]=make_pair(min(x,y),max(x,y));
        }
        for(int i=0;i<m;i++){
            cin>>x>>y;
            b[i]=make_pair(min(x,y),max(x,y));
        }
        int flag=0,sum=0;
        for(int i=0;i<n;i++){
            set<int> dict;
            for(int j=0;j<m;j++){
                if(a[i]==b[j])continue;
                if(a[i].first==b[j].first||a[i].first==b[j].second){
                    dict.insert(a[i].first);
                    if(store[j].size()==1&&*store[j].begin()!=a[i].first){
                        flag=1;
                        break;
                    }
                    store[j].insert(a[i].first);
                }
                if(a[i].second==b[j].second||a[i].second==b[j].first){
                    dict.insert(a[i].second);
                    if(store[j].size()==1&&*store[j].begin()!=a[i].second){
                        flag=1;
                        break;
                    }
                    store[j].insert(a[i].second);
                }
            }
            if(dict.size()>1){
                flag=1;
                break;
            }
            else if(dict.size()==1){
                ans.insert(*dict.begin());
                sum++;
            }
        }
        if(flag)cout<<-1<<endl;
        else if(ans.size()==1)cout<<*ans.begin()<<endl;
        else cout<<0<<endl;

        //dict.clear();
    }
    return 0;
}


// A.cpp: определяет точку входа для консольного приложения.
//

#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>

#define fr(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define fd(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define be(m) (m).begin(),(m).end()
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef double d;
typedef vector<int> vi;
typedef vector<d> vd;
typedef vector <string> vs;
typedef stack<int> si;
typedef stack<string> ss;
typedef map<string,int> msi;
typedef map<int,int> mii;
typedef list<int> li;
typedef list<string> ls;
typedef pair<int,int> pii;
typedef pair<string,string> pss;
typedef vs::iterator vs_it;
typedef msi::iterator msi_it;
typedef mii::iterator mii_it;
typedef li::iterator li_it;
typedef ls::iterator ls_it;

const int e9=1000*1000*1000;
const ll e18=(ll)e9*(ll)e9;
const d pi=3.1415926535;

void pV(int num){cout << num << " ";}
int ri(){int x;scanf("%d",&x);return x;}
d rd(){d x;scanf("%lf",&x);return x;}
ll rll(){ll x;scanf("%lld",&x);return x;}
string rs(){string x;cin >> x;return x;}
string rsf(){string s;char c; while(c=getchar()){if(c>=65 && c<=90 || c>='a' && c<='z')s+=c;else break;}return s;}
void wi(int x){printf("%d ",x);}
void wd(d x){printf("%lf ",x);}
void wll(ll x){printf("%lld ",x);}
void ws(string x){cout << x << " ";}

int main()
{
    vs mas(3);
    int r=0,p=0,s=0;
    fr(i,0,2)
    {
        mas[i]=rs();
        if (mas[i]=="rock")
            r++;
        if (mas[i]=="paper")
            p++;
        if (mas[i]=="scissors")
            s++;
    }
    if (r==2 && p==1 || r==1 && s==2 || p==2 && s==1)
    {
        string search="";
        if (r==2 && p==1)
            search="paper";
        if (r==1 && s==2)
            search="rock";
        if (p==2 && s==1)
            search="scissors";
        fr(i,0,2)
            if (mas[i]==search)
            {
                if (i==0)
                    ws("F");
                if (i==1)
                    ws("M");
                if (i==2)
                    ws("S");
                return 0;
            }
    }
    ws("?");
    return 0;
}


/* You got a dream , you gotta protect it . */
/* Sometimes you win , sometimes you learn . */
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lp(i , N) for(ll i = 0; i < ll (N) ; i++)
#define debug(x) cout<<" [ " << #x << " is: " << x << " ] "<<endl;
using namespace std;
typedef long long ll;
typedef long double ld;
const long double EPS = 1e-6;
const long double pi = acos(-1);
ll toLL(string x){
    stringstream ss;
    ss << x;
    ll t;
    ss >> t;
    return t;
}
int main(){
    FAST
    string s , K = "";
    cin >> s;
    for(ll i = (s.size()) - 1; i >= 0; i--){
        if(s[i] == 'e'){
            s.pop_back();
            break;
        }
        K+=s[i];
        s.pop_back();
    }
    reverse(K.begin() , K.end());
    ll k = toLL(K) , x = 2 , cnt = s.size() - 2;
    ll r = k;
    cout << s[0];
    for(ll i = 2 , j = 0; i < s.size() && j < k; i++ , j++){
        cout << s[i];
        x = i + 1;
        cnt--;
        r--;
    }
    if(s.substr(2) == "0" && k == 0) return 0;
    else if(cnt > 0)cout << '.';
    cout << s.substr(x);
    while(r--) cout << 0;
    return 0;
}


#include <string>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <fstream>
#include <cassert>

using namespace std;

                                                                                #define int ll
const bool online_judge =
#ifdef ONLINE_JUDGE
  true
#else
  false
#endif
  ;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

typedef tuple<int,int> int2;
typedef tuple<int,int,int> int3;
typedef tuple<int,int,int,int> int4;

#define all(v)  (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb push_back
#define eb emplace_back
#define SZ(a) ((int)((a).size()))
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,n) for(int i = 1; i <= n; i++)
#define rep3(i,n) for(int i = n-1; i >= 0; i--)
#define tag(i,v) rep(i,SZ(v))
#define _trace(x) #x << " = " << (x)
#define trace(x)  { if(!online_judge) cerr << _trace(x) << endl; }
#define trace2(x,y) { if(!online_judge) cerr << _trace(x) << " " << _trace(y) << endl; }
#define trace3(x,y,z) { if(!online_judge) cerr << _trace(x) << " " << _trace(y) << " " << _trace(z) << endl; }
#define tracev(x) { if(!online_judge) { cerr << #x << " = "; tag(__i, x) { cerr << x[__i] << ","; } cerr << endl; } }
#define fst get<0>
#define snd get<1>
#define thd get<2>
#define divup(x,y) ((x)/(y)+!!((x)%(y)))
#define mp make_tuple
#define range(x,a,b) ((x) >= (a) && (x) <= (b))

const int inf = 1LL << 60;
int toInt(string s) {int res; stringstream ss; ss<<s; ss>>res; return res; }
string toString(int n) { stringstream ss; ss<<n; return ss.str(); }

int rdfs(int a, int b){
  if(a == 0 || b == 0)
    return inf;
  if(a == 1 && b == 1)
    return 0;

  if(a > b)
    return 1+rdfs(a-b,b);
  else
    return 1+rdfs(a,b-a);
}

void run() {

  /* entry point */

  int n;
  cin >> n;

  if(n == 1){
    cout << 0 << endl;
    return;
  }

  int ans = inf;

  for(int b = 1; b < n; b++){
    ans = min(ans, rdfs(n,b));
  }

  cout << ans << endl;

}

#undef int

int main(int argc, char *argv[]) {

  #if 0
  if(online_judge){
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
  }
  #endif

  run();

  return 0;

}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; ++i)
using namespace std;
const int N = 110, mod = 1e9 + 7;
int f[N][N][N], g[N][N][N], c[N][N];
bool F[N][N], G[N][N];
void init() { rep(i,0,N) { c[i][0] = c[i][i] = 1; rep(j,1,i - 1) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod; } }
inline void add(int &a, int b) { a += b; if (a > mod) a -= mod; }
int main() {
//	freopen("arrangement.in","r",stdin); freopen("arrangement.out","w",stdout);
	int n, m, K; scanf("%d%d%d",&n,&m,&K); init(); memset(F, false, sizeof(F)); memset(G, false, sizeof(G));
	int ans = 0;
	rep(t,1,m) {
		rep(i,1,n) rep(k,1,K) if (G[i][k]) memset(g[i][k], 0, sizeof(g[i][k])); memset(G, false, sizeof(G));
		if (t == 1) { rep(i,1,n) G[i][1] = g[i][1][i] = 1; }
		rep(i,1,n) rep(k,1,K) if (F[i][k]) {
			rep(j,1,n) if (f[i][k][j]) {
				int tmp;
				rep(t,j,n - i) if (c[t - 1][j - 1] <= K && (tmp = k * c[t - 1][j - 1]) <= K)
					add(g[i + t][tmp][t - j], f[i][k][j]) , G[i + t][tmp] = true;
				else break;
			}
		}
		swap(f, g), swap(F, G);
		rep(i,1,n) rep(k,1,K) if (f[i][k][0]) (ans += 1LL * f[i][k][0] * (m - t + 1) % mod) %= mod;
	}
	printf("%d\n",ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
const int N=100;
char a[N+1],b[N+1];
int aa,bb,aSize,bSize,dp[N][2];
//dp[i][j]表示a[1->aSize]和b[j->bSize]的最大匹配到b[?]
int main() {
  scanf("%d%d%s%s",&aa,&bb,a,b);
  aSize=strlen(a);
  bSize=strlen(b);
  for(int i=0; i<bSize; ++i) {
    int x=i,count=0;
    for(int j=0; j<aSize; ++j) {
      if(a[j]==b[x]) {
        ++x;
        if(x==bSize) {
          x=0;
          count++;
        }
      }
    }
    dp[i][0]=x;
    dp[i][1]=count;
  }
  int j=0,result=0;
  for(int i=0; i<aa; ++i) {
    result+=dp[j][1];
    j=dp[j][0];
  }
  result/=bb;
  printf("%d\n",result);
}


#include<bits/stdc++.h>
using namespace std;
int n,a;
int main()
{
      scanf("%d%d",&n,&a);
        if(a%2==0)
        {
            printf("%d\n",(n+2-a)/2);
        }
        else
        {
            printf("%d\n",(a+1)/2);
        }
    return 0;
}


#include <bits/stdc++.h>

#define fst first
#define snd second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define mp make_pair
#define sz size()
#define FORN( i , s , n ) for( int i = (s) ; i < (n) ; i++ )
#define FOR( i , n ) FORN( i , 0 , n )
#define FORIT( i , x ) for( typeof x.begin() i = x.begin() ; i != x.end() ; i++ )
#define trace(x)    cout << #x << ": " << x << endl;
#define trace2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define read ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

typedef long long int64;
typedef vector <int64> vi;
typedef pair <int64,int64> ii;
typedef vector <string> vs;
typedef vector <ii> vii;

map<int64,int> DP;

int64 fDP(int64 N){
	if (N<=0) return -1e9;
	if (N==1) return 0;
	if (N==2) return 1;
	if (DP.count(N)) return DP[N];
	int64 mi = N/2;
	int64 ans = 0;
	if ( abs(fDP(mi) - fDP(N-mi)) <= 1) 	ans = max( ans, max(fDP(mi) , fDP(N-mi)  ) + 1);
	if ( abs(fDP(mi+1) - fDP(N-mi-1)) <= 1) ans = max( ans, max(fDP(mi+1) , fDP(N-mi-1)) + 1);
	if ( N-mi-2 > 0 and abs(fDP(mi+2) - fDP(N-mi-2)) <= 1) ans = max( ans, max(fDP(mi+1) , fDP(N-mi-1)) + 1);
	return DP[N] = ans;
}

int main(){
	int64 N;
	vi F(2,1);
	while(F.back() < 1e18) F.pb ( F.back() + F[F.sz-2] );
	while(cin>>N){
		cout<<upper_bound(all(F), N) - F.begin() - 2<<endl;
	}
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 10;
typedef long long Long;
const int mod = 1e9 + 7;
Long arr[10];

int main()
{
    int x, y, n; scanf("%d%d%d", &x, &y, &n);
    arr[1] = x;
    arr[2] = y;
    arr[3] = y - x;
    arr[4] = -x;
    arr[5] = -y;
    arr[0] = -y+x;
    Long ans = arr[n%6];
    printf("%d\n", (ans%mod+mod)%mod);

    return 0;
}


#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <math.h>
#include <bitset>
#include <stack>
#include <queue>
#include <functional>
#include <complex>
#include <cstring>
#include <stdlib.h>
using namespace std;
#define endl '\n'
// #define exp 2.7182818284590452353602874713527
// #define pi acos(-1)
// typedef complex<double> comp;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
int dp[101][10001], tt[101][10001];
int ncr[101][101];
int M = 1e9+7;
int expo(int a, int b)
{
    int res = 1;
    while(b > 0)
    {
        if(b%2 == 1)
            res = (res*a)%M;
        b >>= 1;
        a = (a*a)%M;
    }
    return res;
}
void solve()
{
    int n, m, k;
    cin >> n >> m >> k;
    ncr[0][0] = 1;
    ncr[1][0] = ncr[1][1] = 1;
    for(int i = 2;i <= n;i++)
    {
        ncr[i][0] = 1;
        for(int j = 1;j <= i;j++)
        {
            ncr[i][j] = ncr[i-1][j-1] + ncr[i-1][j];
            if(ncr[i][j] >= M)
                ncr[i][j] -= M;
        }
    }
    for(int i = 0;i <= k;i++)
    {
        dp[n][i] = 0;
        if(i <= n)
            dp[n][i] = expo(ncr[n][i], m/n);
    }
    for(int i = n-1;i > 0;i--)
        for(int kk = 0;kk <= k;kk++)
            tt[i][kk] = expo(ncr[n][kk], m/n + (i <= m%n));
    for(int i = n-1;i > 0;i--)
    {
        for(int j = 0;j <= k;j++)
        {
            dp[i][j] = 0;
            for(int kk = 0;kk <= min(n, j);kk++)
            {
                dp[i][j] += (tt[i][kk]*dp[i+1][j-kk])%M;
                if(dp[i][j] >= M)
                    dp[i][j] -= M;
            }
        }
    }
    cout << dp[1][k];
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double t1 = clock();
    int t;
    t = 1;
    // cin >> t;
    // while(t--)
    for(int i = 1;i <= t;i++)
    {
        // cout << "Case #" << i << ": ";
        solve();
    }
    cerr << setprecision(10) << (clock()-t1)/CLOCKS_PER_SEC << "\n";
    return 0;
}


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

typedef pair<int, int> pii;

template <typename T> void sortv(std::vector<T> &v) {
	sort(v.begin(), v.end());
}

int disaresta(vector<pii> &inter1, vector<pii>& inter2) {
	sortv(inter1);
	sortv(inter2);

	int c1 = 0, c2 = 0;
	int mc1 = 0, mc2 = 0;
	int ret = 0;
	while (c1 < (int)inter1.size() || c2 < (int)inter2.size()) {
		if (c2 == (int)inter2.size() || (c1 < (int)inter1.size() && inter1[c1].first < inter2[c2].first)) {
			mc1 = max(mc1, inter1[c1].second);
			ret = max(ret, min(mc1,mc2) - inter1[c1].first + 1);
			c1++;
		}
		else {
			mc2 = max(mc2, inter2[c2].second);
			ret = max(ret, min(mc1,mc2) - inter2[c2].first + 1);
			c2++;
		}
	}

	return ret;
}

void split(vector<pii>& inter, int split_pos) {
	vector<pii> nw;
	for (pii p : inter) {
		if (split_pos <= p.second) {
			if (p.first < split_pos) nw.emplace_back(p.first, split_pos-1);
			if (p.second > split_pos) nw.emplace_back(max(1, p.first - split_pos), p.second - split_pos);
		}
		else {
			nw.push_back(p);
		}
	}

	inter.clear();
	sortv(nw);
	for (int i = 0; i < (int)nw.size(); i++) {
		while (!inter.empty() && inter.back().first == nw[i].first ) inter.pop_back();
		if (inter.empty() || inter.back().second < nw[i].second) inter.push_back(nw[i]);
	}
}

void solve() {
	int l1,r1,l2,r2;
	scanf("%d %d %d %d", &l1, &r1, &l2, &r2);

	vector< pii > inter1, inter2;
	inter1.emplace_back(l1,r1);
	inter2.emplace_back(l2,r2);

	int ans = 0;
	for (int let = 30; let >= 1; let--) {
		ans = max(ans, disaresta(inter1, inter2));
		int pos = (1<<(let-1));
		split(inter1,pos);
		split(inter2,pos);
	}

	printf("%d\n", ans);
}

int main() {
    solve();
}


#include <iostream>

using namespace std;

int main() {
    int n, max = 0;
    cin>>n;
    int arr[n];
    int answer[n];
    answer[0] = -1;

    for (int i=0; i<n; ++i) {
        cin>>arr[i];
        answer[i] = 0;
    }

    for (int i=1; i<n; ++i) {
        if (arr[i]-arr[i-1] == 1) {
            if (i != n-1 || arr[i] == 1000 || arr[i-answer[i-1] - 1] == 1) {
                answer[i] = answer[i-1] + 1;
            }
        } else {
            if (arr[i-answer[i-1] - 1] != 1) {
                --answer[i-1];
            }
        }
    }

    for (int i=1; i<n; ++i) {
        max = (answer[i]>max)? answer[i] : max;
    }

    cout<<max;
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

  ll n,k,m,D;
  cin>>n>>k>>m>>D;
  ll ans = 0;

  for (ll d=1; d<=D; d++) {
    // (d-1)*k*x + x <= n. optimal # of candies to get if we do d rounds
    // first d-1 rounds everyone gets x. then we give x to Arkady and throw the rest away.
    if (d-1>0 && k > (n-1)/(d-1)) continue; // prevent overflow when doing k*(d-1)

    ll x = min(n / (k*(d-1) + 1), m);
    if (x == 0) continue;
    ans = max(ans, x*(d-1)+x);
  }

  cout<<ans<<endl;
  return 0;
}


#include <bits/stdc++.h>
#include<vector>
using namespace std;
int main()
{
    int n,m,i,j,sum=1,b=0,k=0;
    vector<int>v;
    scanf("%d%d",&n,&m);
    if(m==0)
    {
        printf("YES\n");
        return 0;
    }
    if(n==2&&m==0)
    {
        printf("YES\n");
        return 0;
    }
    else if(n==2&&m!=0)
    {
        printf("NO\n");
        return 0;
    }
    int arr[n]= {0};
    for(i=2; i<n; i++)
    {
        for(j=i*i; j<n; j+=i)
            arr[j-1]=1;
    }
    for(i=1; i<n; i++)
    {
        if(arr[i-1]==0)
            v.push_back(i);
    }
    for(i=0; i<v.size(); i++)
    {
        for(j=0; j<i; j++)
        {
            sum=sum+v[j]+v[j+1];
            if(sum==v[i])
            {
                b++;
                if(b==m)
                {
                    k=1;
                    printf("YES\n");
                    return 0;
                }
            }
            sum=1;
        }
        if(k==1)
            break;
    }
    int c=v.size()-1;
    int d=sqrt(double(c));
    for(i=2;i<d;i++)
    {
        if(c%i==0)
        {
           k=2;
           break;
        }
    }
    if(k==2)
        printf("NO\n");
    else
    {
        b++;
        if(b==m)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


#include<iostream>
using namespace std;
int a[10][10],f;
int main()
{
    for(int i=1;i<=2;i++)
        for(int j=1;j<=3;j++)
            cin>>a[i][j];
    for(int i=1;i<=3;i++)
        if(a[1][i]==a[2][i]){f=1;break;}
    cout<<(f?"YES\n":"NO\n");
    return 0;
}


#include <bits/stdc++.h>
#define ld long double

using namespace std;
int a[200],b[200],c[200],d[200], ans,x,n,tot;
int main() {
    cin>>n>>x;
    for (int i=1;i<=n;++i) {
        scanf("%d",&d[i]);
        if (d[i]&1) a[i]=a[i-1]+1,b[i]=b[i-1]; else a[i]=a[i-1],b[i]=b[i-1]+1;
    }
    for (int i=2;i<=n;i+=2) {
        if (a[i]==b[i]) {
            c[++tot]=abs(d[i]-d[i+1]);
        }
    }
    tot--;
    sort(c+1,c+1+tot);
    int i=0;
    while (ans+c[i+1]<=x&&i<tot) {
        i++;
        ans+=c[i];
    }
    printf("%d\n",i);
    return 0;
}


#include<bits/stdc++.h>
#include<string>
#define ll long long
#define ld long double
#define llu unsigned long long int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define gll(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define mod 1000000007
#define pi 3.1415926535897
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("B-small-attempt0.in", "r", stdin);freopen("output.txt", "w", stdout);
    //std::cout << std::setprecision(9);
    //std::cout << std::fixed;
    ll n,m,a,b;
    cin>>n>>m>>a>>b;
    ll ans=0;
    ll x=b-a,y=a%m,z=b%m;
    if(y==0)
        y=m;
    if(z==0)
        z=m;
    //cout<<x<<" "<<y<<" "<<z<<endl;
    if(a==b)
    {
        cout<<1;
        return 0;
    }
    if(m==1)
    {
        cout<<1;
        return 0;
    }
    if((a%m==1 || a==1) && (b==n || b%m==0))
    {
        cout<<1;
        return 0;
    }
    if(a%m!=0 && a/m==b/m)
    {
        cout<<1;
        return 0;
    }
    if(a%m!=0 && b/m-a/m==1 && b%m==0)
    {
        cout<<1;
        return 0;
    }
    else if(a%m==0 && a/m==b/m)
    {
        cout<<2;
        return 0;
    }
    if(b/m-a/m==1 && a%m!=0)
    {
        cout<<2;
        return 0;
    }
    if(a%m==1 || a==1)
    {
        cout<<2;
        return 0;
    }
    if(y-1==z)
    {
        cout<<2;
        return 0;
    }
    if(b%m==0 || b==n)
    {
        cout<<2;
        return 0;
    }
    cout<<3;
}


#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<deque>
#include<map>
#include<set>
#include<stack>
#include <numeric>
#include <functional>
//#include<bits/stdc++.h>
//#include<unordered_map>
#define ll long long
#define ms(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x & -x
#define bug cout<<"----acac----"<<endl
#define IOS ios::sync_with_stdio(false), cin.tie(0),cout.tie(0)
using namespace std;
const int maxn = 2e5 + 50;
const int inf = 1e9+5;
const int mod = 1e9 + 7;
int main()
{
    int n;
    cin>>n;
    int k1,k2;
    cin>>k1;
    deque<int>q1,q2;
    for(int i=0;i<k1;i++)
    {
        int x;
        cin>>x;
        q1.push_back(x);
    }
    cin>>k2;
    for(int i=0;i<k2;i++)
    {
        int x;
        cin>>x;
        q2.push_back(x);
    }
    int ans=0,flage=0;
    while(ans<10000)
    {
        int x=q1.front();
        int y=q2.front();
        q1.pop_front();
        q2.pop_front();
        if(x>y)
        {
            q1.push_back(y);
            q1.push_back(x);
        }
        if(x<y)
        {
            q2.push_back(x);
            q2.push_back(y);
        }
        ans++;
        if(q1.empty())
        {
            flage=2;
            break;
        }
        if(q2.empty())
        {
            flage=1;
            break;
        }
    }
    if(ans==10000)
    {
        printf("-1\n");
    }
    else
    {
        printf("%d ",ans);
    }
    if(flage==1)printf("1\n");
    else if(flage==2)printf("2\n");
    return 0;
}


#include<set>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<utility>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define Inf (1<<30)
#define LL long long
#define MOD 2520
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int MM=2520;
LL bit[20];
LL dp[20][MOD][2][2][2][2][2][2][2][2];
LL n,m;
///                       2       3        4      5      6        7       8       9
LL DP(int a,int c,bool cc,bool dd,bool ee,bool ff,bool gg,bool hh,bool ii,bool jj,bool flag)
{
    LL ans=0;
    if(a==0){
        if(!cc&&c%2!=0)return 0;
        if(!dd&&c%3!=0)return 0;
        if(!ee&&c%4!=0)return 0;
        if(!ff&&c%5!=0)return 0;
        if(!gg&&c%6!=0)return 0;
        if(!hh&&c%7!=0)return 0;
        if(!ii&&c%8!=0)return 0;
        if(!jj&&c%9!=0)return 0;return !flag;
    }
    if(!flag&&dp[a][c][cc][dd][ee][ff][gg][hh][ii][jj]!=-1)
        return dp[a][c][cc][dd][ee][ff][gg][hh][ii][jj];
    int en=flag?bit[a]:9;
    for(int k=0;k<=en;k++)
        ans+=DP(a-1,(c*10+k)%MOD,cc&&k!=2,dd&&k!=3,ee&&k!=4,ff&&k!=5,gg&&k!=6,hh&&k!=7,ii&&k!=8,jj&&k!=9,flag&&k==en);
    if(!flag)dp[a][c][cc][dd][ee][ff][gg][hh][ii][jj]=ans;
    return ans;
}
LL calc(LL n)
{
    int L=0;
    while(n>0)
    {
        bit[++L]=n%10;
        n/=10;
    }
    return DP(L,0,1,1,1,1,1,1,1,1,1);
}
int main()
{
    int T;
    //freopen("D:\\o.txt","r",stdin);
    scanf("%d",&T);
    memset(dp,-1,sizeof(dp));
    while(T--)
    {
        scanf("%lld%lld",&n,&m);
        LL temp1=calc(m+1);
        LL temp2=calc(n);
        printf("%lld\n",temp1-temp2);
    }
    return 0;
}


#include <cstdio>
#include <vector>
using namespace std;

typedef vector<int> Row;
typedef vector<Row> Mat;

const int inf = 2e9 +7;

Mat operator * (Mat &a, Mat &b) {
    Mat r (a.size(), Row(b[0].size(), inf));
    for(int i = 0; i < a.size(); i++) {
        for(int j = 0; j < b[0].size(); j++) {
            for(int k = 0; k < b.size(); k++) {
                if(a[i][k] != inf and b[k][j] != inf) {
                    r[i][j] = min(r[i][j], a[i][k] + b[k][j]);
                }
            }
        }
    }
    return r;
}

int n, m;
int a[20], b[20];

int main() {
    scanf("%d %d", &n, &m);
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    for(int i = 0; i < n; i++) scanf("%d", &b[i]);
    Mat I (n+1, Row(n+1, inf));
    for(int i = 0; i <= n; i++) I[i][i] = 0;
    Mat X = I;
    for(int t = 0; t < n; t++) {
        Mat Y = I;
        for(int i = 0; i <= n; i++) {
            for(int j = 0; j <= n; j++) {
                Y[i][j] = j == i+1? b[t]: j == i-1? a[t]: inf;
            }
        }
        X = Y*X;
    }
    Mat Z = I;
    for(int x = 1; x <= m; x*=2, X = X*X) {
        if(x & m) {
            Z = Z*X;
        }
    }
    Mat A (n+1, Row(1, inf));
    A[0][0] = 0;
    printf("%d\n", (Z*A)[0][0]);
}


#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cstdio>
#include<cmath>
#define inf 0x3f3f3f3f
using namespace std;
const int MOD = 1000000007;
int main(){

	int n,x,pos,maxnum,minnum,left,right,middle;
	long long ans=1;
	cin>>n>>x>>pos;
	maxnum=n-x,minnum=x-1;
	left=0,right=n;
	while(left<right){
		middle=(left+right)/2;
		if(middle<pos){
			ans=ans*minnum%MOD;
			minnum--;
			left=middle+1;
		}else if(middle>pos){
			ans=ans*maxnum%MOD;
			maxnum--;
			right=middle;
		}else{
			left=middle+1;
		}
	}
	for(int i=1;i<=maxnum+minnum;i++){
		ans=ans*i%MOD;
	}
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
#define PII pair <int, int>
#define PB push_back
#define MP make_pair
#define fi first
#define se second
#define LL long long
const int maxn = 100005;
int n, m;
set < pair <PII, int> > S;
set < PII > SS;
string c;
/*
 *  1     3
 *
 *  4     2
*/
int main() {
    int i, j;
    int x, y;
    cin >> n >> m >> x >> y >> c;
    int dir;
    if(c == "DR") dir = 2;
    else if(c == "UR") dir = 3;
    else if(c == "DL") dir = 4;
    else dir = 1;
    int tot = 1;
    int sum = (m+1)/2+(m+(n&1))/2+(n+1)/2+(n+(m&1))/2
            -1 - (m&1) - (n&1) - ((n&1)==(m&1));
    LL ans = 1;
//  printf("sum = %d\n", sum);
    S.insert( MP(MP(x, y), dir));
    SS.insert(MP(x, y));
    bool flag = 0;
    while(1) {
    //    printf("x = %d y = %d dir = %d\n", x, y, dir);
     //   printf("ans = %d tot = %d\n", ans, tot);
        if(dir == 1) {
            int cnt = min(x-1, y-1);
            ans += cnt;
            y -= cnt;
            x -= cnt;
            if(x==1 && y == 1) dir = 2;
            else if(x==1) dir = 4;
            else if(y==1) dir = 3;
        }
        else if(dir == 2) {
            int cnt = min(m-y, n-x);
            ans += cnt;
            x += cnt;
            y += cnt;
            if(x==n&&y==m) dir = 1;
            else if(x==n) dir = 3;
            else if(y==m) dir = 4;
        }
        else if(dir == 3) {
            int cnt = min(x-1,m-y);
            ans += cnt;
            x -= cnt;
            y += cnt;
            if(x==1&&y==m) dir = 4;
            else if(x==1) dir = 2;
            else if(y==m) dir = 1;
        }
        else {
            int cnt = min(n-x, y-1);
            ans += cnt;
            x += cnt;
            y -= cnt;
            if(x==n&&y==1) dir = 3;
            else if(x==n) dir = 1;
            else if(y==1) dir = 2;
        }
        PII pp = MP(x, y);
        if(!SS.count(pp)) {
            SS.insert(pp);
            tot++;
        }
        if(tot == sum) break;
        if(S.count(MP(pp, dir))) { flag = 1; break; }
        S.insert(MP(pp, dir));

    }
    if(flag) puts("-1");
    else cout << ans << endl;
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
#define ll long long
using namespace std;
ll num[100500];
int main()
{
	ll n,k;
	num[1]=1;
	for(int i=2;i<=100400;i++)
	{
		num[i]=num[i-1]+i;
	}
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)
	{
		if(num[i]+i==n+k)
		{
			printf("%lld",n-i);
			break;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define fu(x) (((x)&1)?-1:1)
#define add(a,b) a=((a)+(b))%mod
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define mod 998244353
#define Mod 998244351
#define ll long long
//#define file
using namespace std;

int n,K,i,j,k,l,ii;
int a[51];
ll C[2001][2001],jc[2001],Jc[2001];
ll f[51][2001][51];
ll ans,p0,p1,Len,LEN,L;

ll qpower(ll a,int b) {ll ans=1; while (b) {if (b&1) ans=ans*a%mod;a=a*a%mod;b>>=1;} return ans;}
ll E(ll p,ll a,ll b) {return p*qpower(qpower(1-b,a+1),Mod)%mod;} //p*x^a*e^b

int main()
{
	#ifdef file
	freopen("CF1477F.in","r",stdin);
	#endif

	scanf("%d%d",&n,&K);
	fo(i,1,n) scanf("%d",&a[i]),Len+=a[i];LEN=qpower(Len,Mod);

	C[0][0]=1;
	fo(i,1,2000)
	{
		C[i][0]=C[i][i]=1;
		fo(j,1,i-1) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	jc[0]=1;
	fo(i,1,2000) jc[i]=jc[i-1]*i%mod;
	Jc[2000]=qpower(jc[2000],Mod);
	fd(i,2000-1,0) Jc[i]=Jc[i+1]*(i+1)%mod;

	f[0][0][0]=1;
	fo(l,1,n)
	{
		L=a[l],ii=(L-1)/K;
		fo(i,0,ii)
		{
			p0=qpower((L-i*K)*LEN%mod,i)*fu(i)*Jc[i]%mod;
			if (i)
			p1=qpower((L-i*K)*LEN%mod,i-1)*fu(i)*Jc[i-1]%mod;
			fo(j,0,Len)
			{
				fo(k,0,l-1)
				if (f[l-1][j][k])
				{
					add(f[l][j+i][k],f[l-1][j][k]*p0);
					if (i)
					add(f[l][j+i][k+1],f[l-1][j][k]*p1);
				}
			}
		}
	}
	fo(j,0,Len) fo(k,0,n) f[n][j][k]=-f[n][j][k];
	add(f[n][0][0],1);
	assert(!f[n][0][0]);

	fo(j,0,Len) fo(k,0,n) if (f[n][j][k])
	add(ans,E(f[n][j][k],j-k,(Len-j*K)*LEN%mod)*jc[j-k]);
	printf("%lld\n",(ans+mod)%mod);

	fclose(stdin);
	fclose(stdout);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str1[]= {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"};
    int num;
    string str;
    cin>>num>>str;
    int i;
    for(i=0; i<8; i++)
    {
        if(str1[i].size()==num)
        {
            int j;
            for(j=0; j<num; j++)
            {
                if(str[j]=='.')
                    //  cout<<str[j]<<" "<<endl;
                    continue;
                if(str[j]==str1[i][j])
                    //cout<<str1[i][j]<<" ";
                    continue;
                else
                    break;
            }
            if(j==num)
            {
                //cout<<j<<endl;
                cout<<str1[i]<<endl;
                break;
            }
        }
    }
    return 0;
}
/* J j nam ase ami alada ekta strig ey rakhsi.. tar pore ami check korsi j str1 er i-th element ki test case er number er soman ki na..  */
/* jodi soman hoy taile ami loop ey dukbo..tarpor j string ta cin korsi oita jodi dot(.)otoba str1 er [i][j] tomo j charecter ta ase oitar soman hole continue korbo  */
/* ar na hole break.. sob sese j dekbo puro puri loop complete korse ki na ,,, pore jodi j test nisi oitar soman length jodi j hoy taile just str1 print dibo*/


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

int read() {
	int ans = 0, flag = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') flag = - flag; ch = getchar();}
	while(ch >= '0' && ch <= '9') {ans = ans * 10 + ch - '0'; ch = getchar();}
	return ans * flag;
}
const int MOD = 1000000007;
int qpow(int a, int b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = 1ll * ans * a % MOD;
		a = 1ll * a * a % MOD;
		b >>= 1;
	}
	return ans;
}
int n, m;
int main() {
	n = read(); m = read();
	printf("%d\n", 1ll * qpow(2 * (n + 1), m) * (n + 1 - m) % MOD * qpow(n + 1, MOD - 2) % MOD);
	return 0;
}


#include <stdio.h>
#include<math.h>
int main()
{
    int k,a,b,ans=0,c,d,t;
    scanf("%d%d%d",&k,&a,&b);
    if(a<b)
    {
        t=a;
        a=b;
        b=t;
    }
    if(a<k&&b<k)
    {
        ans=-1;
    }
    else if( a%k==0  )
    {

            ans=a/k+b/k;

    }
    else
    {
        if(b>=k)
            ans=a/k+b/k;
        else
            ans=-1;
    }
    printf("%d\n",ans);
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
char t;
long long a=0,ans,f=0;
int main()
{
	while(cin>>t&&++f)
		if(t=='A'||t=='E'||t=='I'||t=='O'||t=='U'||t=='Y')
			ans=max(ans,f-a),a=f;
	cout<<max(ans,f+1-a);
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
using namespace std;
#define FR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,c,n) for(int (i)=(c);(i)<(n);(i)++)
#define REP(it,v,cont) for(cont::iterator (it)=(v).begin();(it)!=(v).end();++(it))
#define CLR(a,c) memset((a),(c),sizeof (a))
#define ALL(v) (v).begin(),(v).end()
#define EPS 1e-9
#define SQR(a) ((a)*(a))
typedef long long  ll;
typedef unsigned long long  ull;
typedef long double lld;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef pair<ll,ll> PLL;

double getme(double x,double a)
{
    if(x>=0 && x<=a) return x;
    int k=floor(x/a);
    return k%2?a-(x-k*a):x-k*a;
}
int main()
{
    //freopen("a.in","r",stdin);
    double a,b,m;
    double vx,vy,vz;
    double x,y,z;
    cin>>a>>b>>m;
    cin>>vx>>vy>>vz;
    x=a/2;y=m;z=0;
    double t=-y/vy;
    x=x+t*vx;z=z+t*vz;
    x=getme(x,a);
    z=getme(z,b);
    cout<<fixed<<setprecision(10);
    cout<<x<<" "<<z<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 8 + 5;
const int MAXL = 5 + 5;
const int mod = 998244353;

inline void add_mod(int &a,int b){ a+=b; if(a>=mod) a-=mod;}

const int M = 8 * 4 + 1;
const int N = 5 * M;

struct Matrix
{
	int a[N][N];
	Matrix(void){ clear();}
	inline void clear(void){ memset(a,0,sizeof(a));}
	inline int* operator [] (const int x){ return a[x];}
	inline const int* operator [] (const int x) const { return a[x];}
	inline Matrix operator * (const Matrix &b) const
	{
		Matrix res;
		for(int k=0; k<N; ++k)
			for(int i=0; i<N; ++i)
				for(int j=0; j<N; ++j)
					res[i][j] = (res[i][j] + (ll)a[i][k] * b[k][j]) %mod;
		return res;
	}
};

inline int get_id(int x,int y,int z)
{
	return M * (x - 1) + (y? (y - 1) * 4 + z: 0);
}
inline int get_id(int x,int yz){ return M * (x-1) + yz;}

char s[MAXN][MAXL];
int len[MAXN];

inline bool is_ok(int x,int l,int y)
{
	for(int i=len[x]-l+1,j=1; i<=len[x] && j<=len[y]; ++i,++j)
		if(s[x][i] != s[y][j]) return 0;
	return 1;
}

int main(void)
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; ++i)
		scanf("%s",s[i]+1), len[i] = strlen(s[i]+1);

	Matrix mat;
	for(int i=2; i<=5; ++i)
		for(int j=0; j<M; ++j)
			mat[get_id(i-1,j)][get_id(i,j)] = 1;
	for(int i=1; i<=n; ++i)
		for(int j=1; j<len[i]; ++j)
			for(int k=1; k<=n; ++k) if(is_ok(i,j,k))
			{
				int more = min(j, len[k]), ii, jj;
				if(j == len[k]) ii = jj = 0;
				else if(j < len[k]) ii = k, jj = len[k] - j;
				else ii = i, jj = j - len[k];

				add_mod(mat[get_id(5, ii, jj)][get_id(5-more+1, i, j)], 1);
			}
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=n; ++j) if(is_ok(i,len[i],j))
		{
			int more = min(len[i], len[j]), ii, jj;
			if(len[i] == len[j]) ii = jj = 0;
			else if(len[i] < len[j]) ii = j, jj = len[j] - len[i];
			else ii = i, jj = len[i] - len[j];

			add_mod(mat[get_id(5, ii, jj)][get_id(5-more+1, 0)], 1);
		}

	Matrix res;
	for(int i=0; i<N; ++i) res[i][i] = 1;
	while(m)
	{
		if(m&1) res=res*mat;
		mat=mat*mat; m>>=1;
	}

	printf("%d",res[get_id(5,0)][get_id(5,0)]);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (2 * (a[0] + a[1]) <= a[2])cout << a[0] + a[1] << endl;
	else cout << (a[0] + a[1] + a[2]) / 3 << endl;
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
int hp1,atk1,def1;
int hp2,atk2,def2;
int h,a,d;
int main(){
    // judge();
	read(hp1);read(atk1);read(def1);
	read(hp2);read(atk2);read(def2);
	read(h);read(a);read(d);
	int ans=1e9;
	rep(hp,hp1,5000)rep(atk,atk1,200)rep(def,def1,100){
		int cost=h*(hp-hp1)+a*(atk-atk1)+d*(def-def1);
		if(cost>ans)continue;
		if(atk<=def2)continue;
		int r=hp2/(atk-def2)+(hp2%(atk-def2)!=0);
		if(hp-(atk2-def)*r<=0)continue;
		ans=min(ans,cost);
	}cout<<ans;
    return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>

template<typename T>
struct Point
{
    Point(T x = 0, T y = 0) : x(x), y(y) {}

    template<typename TT>
    Point<TT> to() const {
        return Point<TT>(x, y);
    }

    Point& operator -= (const Point& o)
    {
        x -= o.x;
        y -= o.y;
        return *this;
    }

    T norm2() const
    {
        return x * x + y * y;
    }

    double norm() const
    {
        return sqrt(static_cast<double>(norm2()));
    }

    Point<double> normalize() const
    {
        auto d = norm();
        return Point<double>(x / d, y / d);
    }

    Point rot() const
    {
        return Point(-y, x);
    }

    T x, y;
};

template<typename T>
Point<T> operator - (Point<T> a, const Point<T>& b)
{
    return a -= b;
}

template<typename T>
Point<T> operator * (const Point<T> &a, double k)
{
    return Point<T>(a.x * k, a.y * k);
}

const int N = 3;
const double EPS = 1e-9;

int n, r[N], parent[N];
Point<int> p[N];

template<typename T>
T sqr(T x)
{
    return x * x;
}

int find(int u)
{
    if (parent[u] != u) {
        parent[u] = find(parent[u]);
    }
    return parent[u];
}

int count(const std::vector<Point<double>>& ps)
{
    int result = 0;
    for (size_t i = 0; i < ps.size(); ++ i) {
        size_t j = 0;
        while (std::abs(ps[i].x - ps[j].x) > EPS || std::abs(ps[i].y - ps[j].y) > EPS) {
            j ++;
        }
        result += i == j;
    }
    return result;
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++ i) {
        scanf("%d%d%d", &p[i].x, &p[i].y, r + i);
        parent[i] = i;
    }
    int result = n + 1;
    std::vector<Point<double>> ps;
    for (int i = 0; i < n; ++ i) {
        std::vector<Point<double>> cps;
        for (int j = 0; j < n; ++ j) {
            if (i == j) {
                continue;
            }
            int d2 = (p[j] - p[i]).norm2();
            if (d2 < sqr(r[i] - r[j]) || sqr(r[i] + r[j]) < d2) {
                continue;
            }
            if (find(i) != find(j)) {
                result --;
                parent[find(i)] = find(j);
            }
            // r[i]^2 - r[j]^2 + d^2 = 2 * d * x
            double x = 0.5 * (d2 + sqr(r[i]) - sqr(r[j])) / sqrt(d2);
            double h = sqrt(std::max(sqr(r[i]) - sqr(x), 0.0));
            Point<double> nv = (p[j] - p[i]).normalize() * -1;
            Point<double> q = p[i].to<double>() - nv * x;
            cps.push_back(q - nv.rot() * h);
            if (d2 < sqr(r[i] + r[j])) {
                cps.push_back(q - nv.rot() * -h);
            }
        }
        result += count(cps);
        for (auto&& p : cps) {
            ps.push_back(p);
        }
    }
    result -= count(ps);
    printf("%d\n", result);
}


#include<iostream>
using namespace std;
int fun(int n) {
	int x = 0;
	while (n) {
		x += n % 10;
		n /= 10;
	}
	return x;
}
int main() {
	int n;
	cin >> n;
	while ( fun(n) % 4 )
		n++;
	cout << n;
	return 0;
}


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

typedef long long LL;
const int mod = 1e9 + 7;
const int maxn = 4005;
int n;
int bell[maxn][maxn];
int c[maxn][maxn];

void get_c(){ //递推求组合数C(i,j)
	for(int i = 0; i <= 4000; i++) c[i][0] = 1;

	for(int i = 1; i <= 4000; i++)
		for(int j = 1; j <= i; j++) c[i][j] = (c[i-1][j-1] + c[i-1][j]) % mod;
}

void get_bell(){  //贝尔三角形递推贝尔数，其中第一列(每行首项)即为贝尔数b[i]
	bell[0][0] = 1;
	for(int i = 1; i <= 4000; i++){
		bell[i][0] = bell[i-1][i-1];
		for(int j = 1; j <= i; j++) bell[i][j] = (bell[i][j-1] + bell[i-1][j-1]) % mod;
	}
}

int main(){
	get_c();
	get_bell();
	scanf("%d", &n);
	int ans = 0;
	for(int i = 0; i < n; i++) ans = (ans + (LL)c[n][i]*bell[i][0] % mod) % mod;
	cout << ans << endl;
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=100010;
ll t;
int n,m,s,nd,rt,tot,to[N][50];
struct Tr{ int ls,rs,v,sz,d; }v[N<<8];
struct P{ int x,y; };

int jump(ll x,ll y){
	if (x<=m) x+=y; else x-=y;
	return (x%n+n-1)%n+1;
}

void upd(int x){ v[x].sz=v[v[x].ls].sz+v[v[x].rs].sz+1; v[x].d=max(v[v[x].ls].d,v[v[x].rs].d)+1; }
int get(int k){ v[++nd]=(Tr){0,0,k,1,1}; return nd; }
void dfs(int x){ if (v[x].ls) dfs(v[x].ls); to[++tot][0]=v[x].v; if (v[x].rs) dfs(v[x].rs); }
void Print(int x){ if (v[x].ls) Print(v[x].ls); printf("%d ",v[x].v); if (v[x].rs) Print(v[x].rs); }

int merge(int x,int y){
	if (!x || !y){ v[++nd]=v[x|y]; return nd; }
	int p=++nd;
	if (1ll*rand()*(v[x].sz+v[y].sz)<1ll*v[x].sz*RAND_MAX)
		{ v[p]=v[x]; v[p].rs=merge(v[p].rs,y); upd(p); return p; }
	else{ v[p]=v[y]; v[p].ls=merge(x,v[p].ls); upd(p); return p; }
}

P split(int x,int k){
	if (!x) return (P){0,0};
	P t; int p=++nd; v[p]=v[x];
	if (k<=v[v[x].ls].sz){ t=split(v[p].ls,k); v[p].ls=t.y; upd(p); return (P){t.x,p}; }
		else{ t=split(v[p].rs,k-v[v[x].ls].sz-1); v[p].rs=t.x; upd(p); return (P){p,t.y}; }
}

void build(){ rt=nd=0; rep(i,1,n) rt=merge(rt,get(to[i][0])); }

int main(){
	scanf("%d%d%d",&n,&m,&s); cin>>t;
	for (; t%n; t--) s=jump(s,t); t/=n;
	rep(i,1,n) to[i][0]=i; build();
	rep(i,1,n-1){
		int lst=rt;
		if (m+i<=n){ P a=split(lst,m+i),b=split(a.x,i); rt=b.y; }
			else{ P a=split(lst,i),b=split(a.x,m+i-n); rt=merge(a.y,b.x); }
		if (m+1-i>0){ P a=split(lst,n-i),b=split(a.x,m-i); rt=merge(rt,b.y); }
			else{ P a=split(lst,m+n-i),b=split(a.x,n-i); rt=merge(rt,merge(a.y,b.x)); }
		if (v[rt].d>200) tot=0,dfs(rt),build();
	}
	tot=0; dfs(rt);
	rep(j,1,49) rep(i,1,n) to[i][j]=to[to[i][j-1]][j-1];
	for (int j=49; ~j; j--) if (t&(1ll<<j)) s=to[s][j];
	printf("%d\n",s);
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	string s, p = "", a;
	cin >> s;
	int l = s.size();
	if (l % 2 == 0) {
		p += s[(l / 2 - 1)];
		int i = 0;
		while (true)
		{
			++i;
			if ((l / 2 - 1) + i < l)
				p += s[(l / 2 - 1) + i];
			else break;
			if ((l / 2 - 1) - i >= 0)
				p += s[(l / 2 - 1) - i];
			else break;
		}
	}
	else {
		p += s[(l / 2)];
		int i = 0;
		while (true)
		{
			++i;
			if ((l / 2) + i < l)
				p += s[(l / 2) + i];
			else break;
			if ((l / 2) - i >= 0)
				p += s[(l / 2) - i];
			else break;
		}
	}
	cout << p;
    return 0;
}