#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>

using namespace std;

// #define DEBUG

namespace {
#ifdef DEBUG
    const int kDebug = true;
#else
    const int kDebuf = false;
#endif
}  // namespace

const int mod = (int)1e9 + 7;

struct Rational {
    operator int() { return x; }

    Rational() {
        this->x = 0;
#ifdef DEBUG
        this->rawValue = 0;
#endif
    }
    Rational(int x) {
        this->x = (mod + x % mod) % mod;
#ifdef DEBUG
        this->rawValue = x;
#endif
    }

    Rational operator * (int rh) {
        Rational res((this->x * 1ll * ((mod + rh % mod) % mod)) % mod);
#ifdef DEBUG
        res.rawValue = this->rawValue * rh;
#endif
        return res;
    }

    Rational operator * (Rational rh) {
        Rational res((this->x * 1ll * rh.x) % mod);
#ifdef DEBUG
        res.rawValue = this->rawValue * rh.rawValue;
#endif
        return res;
    }

    Rational operator += (Rational rh) {
        this->x = (this->x + 0ll + rh.x) % mod;
#ifdef DEBUG
        this->rawValue += rh.rawValue;
#endif
        return *this;
    }

    Rational operator = (int x) {
        this->x = (mod + x % mod) % mod;
#ifdef DEBUG
        this->rawValue = x;
#endif
        return *this;
    }

    Rational operator / (int x) {
        Rational res(this->x * 1ll * reverse(x) % mod);
#ifdef DEBUG
        res.rawValue = this->rawValue / x;
#endif
        return res;
    }

#ifdef DEBUG
    double rawValue;
#endif
private:
    int x;

    int reverse(int x) {
        x = (mod + x % mod) % mod;
        return binPow(x, mod - 2);
    }

    int binPow(int x, int p) {
        if (!p) return 1;
        if (p & 1) return binPow(x, p - 1) * 1ll * x % mod;
        x = binPow(x, p >> 1);
        return x * 1ll * x % mod;
    }
};

template <class T>
struct Matrix {
    static Matrix<T> unit(int size) {
        Matrix<T> res(size, size);
        for (int i = 0; i < size; ++i)
            res[i][i] = 1;
        return res;
    }

    int rows, cols;
    vector < vector <T> > arr;

    Matrix <T>(int rows, int cols) {
        this->rows = rows;
        this->cols = cols;
        arr.clear();
        for (int i = 0; i < rows; ++i) {
            vector <T> tmp(cols);
            arr.push_back(tmp);
        }
    }

    Matrix <T> operator * (Matrix<T> rh) {
        Matrix <T> lh = *this;
        assert(lh.cols == rh.rows);
        int commonSize = lh.cols;

        Matrix <T> res(lh.rows, rh.cols);
        for (int i = 0; i < lh.rows; ++i)
            for (int j = 0; j < rh.cols; ++j)
                for (int k = 0; k < commonSize; ++k)
                    res[i][j] += lh[i][k] * rh[k][j];

        return res;
    }

    vector <T>& operator [] (int index) {
        return arr[index];
    }
};

template <class T>
Matrix<T> binPow(Matrix<T> m, int p) {
    assert(m.rows == m.cols);
    int size = m.rows;

    if (!p) return Matrix<T>::unit(size);
    if (p & 1) return binPow(m, p - 1) * m;
    m = binPow(m, p >> 1);
    return m * m;
}

const int maxn = (int)1e2 + 10;
int a[maxn];

int main() {
    int n, k;
    cin >> n >> k;
    int cntOnes = 0, cntZeros = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i]) cntOnes++;
        else cntZeros++;
    }

    int max_ = max(cntOnes, cntZeros);
    int min_ = min(cntOnes, cntZeros);
    if (min_ == 0)
    {
        cout << 1 << endl;
        return 0;
    }

    int badZeros = 0;
    for (int i = 0; i < n; ++i) {
        if (i >= cntZeros)
            break;
        badZeros += a[i] == 1;
    }

    int size = min_ + 1;
    Matrix<Rational> initial(1, size);
    initial[0][badZeros] = 1;

    Matrix<Rational> step(size, size);
    for (int i = 0; i <= min_; ++i) {
        if (i < min_)
            step[i + 1][i] = (i + 1) * (i + 1);
        if (i > 0)
            step[i - 1][i] = (max_ - i + 1) * (min_ - i + 1);
        step[i][i] =
            (i * (min_ - i) + i * (max_ - i) + min_ * (min_ - 1) / 2 + max_ * (max_ - 1) / 2);
    }

#ifdef DEBUG
    cout << (Rational(2) * 1 * 1 / n).rawValue << endl;
    for (int i = 0; i <= min_; ++i)
        for (int j = 0; j <= min_; ++j) {
            cout << "step[" << i << "][" << j << "]=";
            printf("%.7lf\n", step[i][j].rawValue);
            cout << endl;
        }
#endif
    step = binPow<Rational>(step, k);
#ifdef DEBUG
    for (int i = 0; i <= min_; ++i)
        for (int j = 0; j <= min_; ++j)
            cout << "step[" << i << "][" << j << "]=" << step[i][j].rawValue << endl;
#endif

    Matrix<Rational> answer = initial * step;
    Rational sum = 0;
    for (int i = 0; i <= min_; ++i)
        sum += answer[0][i];
#ifdef DEBUG
    cout << answer[0][0].rawValue << endl;
    cout << sum << endl;
#endif
    cout << answer[0][0] / sum << endl;
    return 0;
}

// CodeForces


//New_Year_And_Hurry
#include<bits/stdc++.h>
#define lb lower_bound
using namespace std;
int main()
{
    int n,k,m;cin>>n>>k;
    m=240-k;
    vector<int> v(n);v.at(0)=5;
    for(int i=1;i<n;i++) v.at(i)=((i+1)*5+v.at(i-1));
    int a=lb(v.begin(),v.end(),m)-v.begin();
    if(v.at(a)==m) cout<<a+1;
    else cout<<a;
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main()
{
    int n;
    cin>>n;
    getchar();
    char c=getchar();
    int cnt=0;
    vector <int>g;
    int temp=0;
    while (c!=EOF)
    {
        if (c=='W')
        {
            c=getchar();
            continue;
        }
        while (c!=EOF && c=='B')
        {
            temp++;
            c=getchar();
        }

        g.push_back(temp);
        cnt++;
        temp=0;
    }

    cout<<cnt<<endl;

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


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define soja(i,a,n) for(int i=a;i<=n;i++)
#define ulta(i,n,a) for(int i=n;i>=a;i--)
#define pb push_back
int main()
{
    ll n,m,k,t;
    cin>>n>>m>>k;
    vector<pair<int,int>>p;
    soja(i,1,n)
    {
        p.pb({i,1});
    }
    soja(i,2,m)
    {
        p.pb({n,i});
    }
    soja(i,1,n-1)
    {
        if(i%2!=0)
        {
            ulta(j,m,2)
            {
                p.pb({n-i,j});
            }
        }
        else
        {
            soja(j,2,m)
            {
                p.pb({n-i,j});
            }
        }
    }
    t=p.size();
    cout<<p[k%t].first<<" "<<p[k%t].second<<endl;
    return 0;
    }


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

int main() {
	ios_base::sync_with_stdio(false);
	long long n,m;
	cin>>n>>m;
	vector<long long> divisors;
	if(m==1){cout<<n*n<<endl; return 0;}

	for(long long i=0;i<=2*(n*n);i+=m)
	{

		if(i%m==0 &&i!=0)
		{

			divisors.push_back(i);
		}
	}
	long long cnt=0;
	for(int i=0;i<divisors.size();i++)
	{

		for(long long j=1;j<=n;j++)
		{
			if(divisors[i]-(j*j)<=0)continue;
			long long num2=divisors[i]-(j*j);
			long long reminsqrt=sqrt(num2);
			if(reminsqrt>n)continue;
			if((reminsqrt*reminsqrt)==(divisors[i]-(j*j)))
			{  cnt++;

			   //cout<<reminsqrt<<" "<<j<<" "<<divisors[i]<<endl;
			}
		}
	}
	cout<<cnt;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;

#define LL __int64
#define inf 0x3fffffff
#define M 100

int a[M];

int main()
{
    int i,n, m;
    while(scanf("%d%d", &n, &m) != EOF)
    {
        for(i = 1; i<=m; i++)
            scanf("%d", &a[i]);

        sort(a+1, a+m+1);

        int ans = a[m] - a[1];
        if(n == m)
        {
            printf("%d\n",ans);
            continue;
        }
        for(i = 1; i+n-1<=m; i++)
        {
            ans = min(ans, a[i+n-1] - a[i]);
        }
        printf("%d\n",ans);
    }
    return 1;
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>

using namespace std;

#define ff(i,x,y) for(int i = (x);i < (y);++i)
#define rep(i,n) ff(i,0,n)
#define st(v) sort(v.begin(),v.end())
#define st2(v,f) sort(v.begin(),v.end(),f)
#define rvs(v) reverse(v.begin(),v.end())
#define cnt(v,n) count(v.begin(),v.end(),n)
#define pb push_back
bool myfunction (int i,int j) { return (i<j); }
#define fact(x) for(i=x-1;i>0;i--){x=x*i;}
#define MP make_pair
#define F first
#define S second
#define LL long long
#define ULL unsigned long long
#define VI vector<int>
#define VVI vector<VI>

typedef pair<int,int> PII;
typedef pair<PII,int> PIII;

#ifdef LOCAL
ifstream in("in.txt");
#else
istream &in = cin;
#endif

int n;
bool adj[1501][1501];
int vtx[1501];
vector<bool> chk;
vector <PIII> points;
vector <PII> res;

int dfs(int node)
{
	int cnt = 0;
	chk[node] = true;
	for(int i = 1;i <= n;++i)
		if(!chk[i] && adj[node][i])
			cnt += dfs(i);
	vtx[node] = cnt+1;
	return vtx[node];
}

void go(int s, int r, int root, vector<PIII> ps, vector<bool> c)
{
	int min_y = INT_MAX, min_i = -1;
	for(int i = s;i <= r;++i) if(!c[i] && ps[i].F.S < min_y) {min_y = ps[i].F.S; min_i = i;}
	c[min_i] = true;
	res.push_back(MP(ps[min_i].S,root));
	for(int i = 1;i <= n;++i) if(adj[root][i]) {
		vector<PIII> nps(1);
		vector<bool> nchk;
		while(nps.size() < vtx[i]+1) {
			if(!c[s]) nps.push_back(ps[s]);
			++s;
		}
		adj[i][root] = false;
		nchk.resize(nps.size(),false);
		go(1,nps.size()-1,i,nps,nchk);
	}
}

int main()
{
	in >> n;
	rep(i,n+1) rep(j,n+1) adj[i][j] = false;
	points.resize(n+1);
	chk.resize(n+1,false);
	memset(vtx,0,sizeof(vtx));

	rep(i,n-1) {
		int a, b;
		in >> a >> b;
		adj[a][b] = adj[b][a] = true;
	}

	rep(i,n) {
		int x, y;
		in >> x >> y;
		points[i+1] = MP(MP(x,y),i+1);
	}

	dfs(1);

	sort(points.begin()+1,points.end());
	rep(i,n+1) chk[i] = false;

	go(1,n,1,points,chk);

	st(res);

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

	return 0;
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
//#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 300010;
const int K = 400;
template <typename T, typename C>
class mcmf {
  public:
  static constexpr T eps = (T) 1e-9;
  struct edge {
    int from;
    int to;
    T c;
    T f;
    C cost;
  };
  vector< vector<int> > g;
  vector<edge> edges;
  vector<C> d;
  vector<int> q;
  vector<bool> in_queue;
  vector<int> pe;
  int n;
  int st, fin;
  T flow;
  C cost;
  mcmf(int _n, int _st, int _fin) : n(_n), st(_st), fin(_fin) {
    assert(0 <= st && st < n && 0 <= fin && fin < n && st != fin);
    g.resize(n);
    d.resize(n);
    in_queue.resize(n);
    pe.resize(n);
    flow = 0;
    cost = 0;
  }
  void clear_flow() {
    for (const edge &e : edges) {
      e.f = 0;
    }
    flow = 0;
  }

  void add(int from, int to, T forward_cap, T backward_cap, C cost) {
    assert(0 <= from && from < n && 0 <= to && to < n);
    g[from].push_back((int) edges.size());
    edges.push_back({from, to, forward_cap, 0, cost});
    g[to].push_back((int) edges.size());
    edges.push_back({to, from, backward_cap, 0, -cost});
  }
  bool expath() {
    fill(d.begin(), d.end(), numeric_limits<C>::max());
    q.clear();
    q.push_back(st);
    d[st] = 0;
    in_queue[st] = true;
    int beg = 0;
    bool found = false;
    while (beg < (int) q.size()) {
      int i = q[beg++];
      if (i == fin) {
        found = true;
      }
      in_queue[i] = false;
      for (int id : g[i]) {
        const edge &e = edges[id];
        if (e.c - e.f > eps && d[i] + e.cost < d[e.to]) {
          d[e.to] = d[i] + e.cost;
          pe[e.to] = id;
          if (!in_queue[e.to]) {
            q.push_back(e.to);
            in_queue[e.to] = true;
          }
        }
      }
    }
    if (found) {
      T push = numeric_limits<T>::max();
      int v = fin;
      while (v != st) {
        const edge &e = edges[pe[v]];
        push = min(push, e.c - e.f);
        v = e.from;
      }
      v = fin;
      while (v != st) {
        edge &e = edges[pe[v]];
        e.f += push;
        edge &back = edges[pe[v] ^ 1];
        back.f -= push;
        v = e.from;
      }
      flow += push;
      cost += push * d[fin];
    }
    return found;
  }

  pair<T, C> max_flow_min_cost() {
    while (expath()) {
    }
    return make_pair(flow, cost);
  }
};
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, m, k, c, d;
    cin >> n >> m >> k >> c >> d;
    int t = k * (n - 1);
    mcmf < int, int > g(t * n + 2, t * n, t * n + 1);
    for (int i = 0; i < t; i++){
        g.add(i * n, t * n + 1, 100, 0, c * i);
        for (int j = 0; j < n; j++){
            if (i + 1 < t)
            g.add(i * n + j, (i + 1) * n + j, 100, 0, 0);
        }
    }
    for (int i = 1; i <= k; i++){
        int x;
        cin >> x;
        g.add(t * n, x - 1, 1, 0, 0);
    }
    for (int i = 1; i <= m; i++){
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        for (int j = 0; j < t - 1; j++){
            int v1 = j * n + u;
            int v2 = (j + 1) * n + v;
            for (int q = 0; q < k; q++){
                if (q == 0) g.add(v1, v2, 1, 0, d);
                else if (q == 1) g.add(v1, v2, 1, 0, 4 * d);
                else   g.add(v1, v2, 1, 0, d * (2 * q + 1));
            }
            v1 = j * n + v;
            v2 = (j + 1) * n + u;
            for (int q = 0; q < k; q++){
                if (q == 0) g.add(v1, v2, 1, 0, d);
                else if (q == 1) g.add(v1, v2, 1, 0, 4 * d);
                else   g.add(v1, v2, 1, 0, d * (2 * q + 1));
            }
        }
    }
    cout << (g.max_flow_min_cost()).S;
}


#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<fstream>
#include<sstream>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;

const int N = 1e3+9;

int a[N];
int main() {
    int i, j, n, q, L, R, x;
    while(scanf("%d", &n)) {
        scanf("%d", &x);
        for(i=0; i<n; ++i) {
            scanf("%d", a+i);
        }
        int ans=0;
        for(i=0; i<n-1; ++i) {
            ans=max(ans, a[i]-a[i+1]-x);
        }
        printf("%d\n", ans);
    }
    return 0;
}


//scnucjh
#include <iostream>
using namespace std;

const int maxn = 100005;
int phi[maxn];

int main() {
#ifndef ONLINE_JUDGE
    freopen("data.txt", "r", stdin);
#endif
    int n,k;
    cin>>n>>k;
    if(k==3) { cout<<3<<endl; return 0;}
    for(int i=1;i<maxn;i++) phi[i]=i;
    for(int i=2;i<maxn;i++) {
        if(phi[i]==i) {
            for(int j=i;j<maxn;j+=i) phi[j]=phi[j]/i*(i-1);
        }
    }
    sort(phi,phi+maxn);
    long long ans=0;
    for(int i=0;i<=k+2;i++) ans+=phi[i];
    cout<<ans<<endl;
    return 0;
}


/*
Algorithm&&Data Structure:Implementation
Source: Codeforces Round #136 (Div. 2) Little Elephant and Numbers
*/
#define _CRT_SECURE_NO_WARNINGS
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<iostream>
#include<stdlib.h>
#include<set>
#include<string>
#include<vector>
using namespace std;
#define maxn 200010
int N;
string a = "";
char isshow[256];
bool is[1000000010];
void tostr(int i)
{
    if (i >= 0 && i < 10)
    {
        a = i + '0';
        return;
    }
    tostr(i / 10);
    a += (i % 10 + '0');
}
int main()
{
    cin >> N;
    tostr(N);
    string Nt = a;
    for (int i = 0; i < Nt.length(); i++)
        isshow[Nt[i]] = true;
    string t = "";
    int ans = 1;
    if (N == 1)
        cout << 1 << endl;
    else
    {
        if (isshow['1'])
            ans++;
        for (int i = 2; i <= sqrt(N*1.0); i++)
        {
            for (int j = i; j <= N / 2; j += i)
            {
                if (N%j == 0&&!is[j])
                {
                    is[j] = true;
                    a = "";
                    tostr(j);
                    int len = a.length();
                    for (int k = 0; k < len; k++)
                    {
                        if (isshow[a[k]])
                        {
                            ans++;
                            break;
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long  n,count0=0;
    cin>>n;
    long long  v[n+1],a[n+1],k=1;
    for(long long  i=1;i<=n;i++)
    {
        cin>>v[i];
        if(v[i]==0)count0++;
        else a[k]=v[i],k++;
    }
    sort(a+1,a+n+1);
    long long  count=0,maxi;
    long long  i=k;
    while(i>2){
          maxi=1;
        for(long long  j=i-1;j>=1;j--)
        {
            maxi=max(maxi,(j-a[j]+1));
        }
        count++;
        i=maxi;
    }
    cout<<max(count,count0);
}


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std ;
const long long MAXN = 1e17 + 5 ;
long long vis[1000005] ;
int cnt ;
void print()
{
    cnt = 0 ;
    long long i ;
    for(i = 3 ; i <= MAXN ; i ++)
    {
        vis[cnt] = i ;
        if(cnt == 34)
        break ;
        cnt ++ ;
        i *= 3 ;
    }
}
int main()
{
   // print() ;
    long long n ;
    while (cin >> n)
    {
        if(n % 3 != 0)
        {
            cout << n / 3 + 1 << endl ;
        }
        else
        {
            int j ;
            int pan = 0 ;
            for(j = 0 ; j <= cnt ; j ++)
            {
                if(vis[j] == n)
                {
                    printf("1\n") ;
                    pan = 1 ;
                    break ;
                }
            }
            if(pan == 0)
            {
                for(j = 0 ; j <= cnt ; j ++)
                {
                    if(n % vis[j] != 0)
                    {
                        cout << n / vis[j] + 1 << endl ;
                        break ;
                    }
                }
            }
        }
    }
    return 0 ;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <time.h>
#include <math.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for (LL i=0; i<n; i++)
#define FOR(i,x,y) for (LL i=x; i<=y; i++)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))

class figur
{
public:
	int x,y;
};
bool isin(int a, int b,int x)
{
	if (x>a && x<b) return 1;
	if (x<a && x>b) return 1;
	return 0;
}
bool Is(figur a1, figur b1, figur tmp, figur k1)
{
	bool f=0;
	if ( (a1.x==tmp.x && !isin(a1.x,tmp.x,k1.x) ) || ( a1.y==tmp.y && !isin(a1.y,tmp.y,k1.y) ) ) f=1;
	if ( (b1.x==tmp.x && !isin(b1.x,tmp.x,k1.x) ) || ( b1.y==tmp.y && !isin(b1.y,tmp.y,k1.y ) ) ) f=1;
	/*if (k1.x==tmp.x-1 && k1.y==tmp.y+1) f=1;
	if (k1.x==tmp.x-1 && k1.y==tmp.y) f=1;
	if (k1.x==tmp.x-1 && k1.y==tmp.y-1) f=1;
	if (k1.x==tmp.x && k1.y==tmp.y-1) f=1;

	if (k1.x==tmp.x+1 && k1.y==tmp.y-1) f=1;
	if (k1.x==tmp.x+1 && k1.y==tmp.y) f=1;
	if (k1.x==tmp.x+1 && k1.y==tmp.y+1) f=1;
	if (k1.x==tmp.x && k1.y==tmp.y+1) f=1;*/
	if (sqrt(double( (tmp.x-k1.x)*(tmp.x-k1.x)+(tmp.y-k1.y)*(tmp.y-k1.y)) ) < sqrt(2.1) ) f=1;

	return f;
}
int main()
{
	figur a1,b1,k1,k2;
	char arr[15];
	//scanf("%s",&arr);
	gets(arr);
	a1.x=arr[0]-'a'+1;
	a1.y=arr[1]-'1'+1;
	b1.x=arr[3]-'a'+1;
	b1.y=arr[4]-'1'+1;
	k1.x=arr[6]-'a'+1;
	k1.y=arr[7]-'1'+1;
	k2.x=arr[9]-'a'+1;
	k2.y=arr[10]-'1'+1;
	bool fl=false;
	if (a1.x==k2.x || a1.y==k2.y) fl=1;
	if (b1.x==k2.x || b1.y==k2.y) fl=1;
	if ( (a1.x==k2.x && !isin(a1.x,k2.x,k1.x) ) || ( a1.y==k2.y && !isin(a1.y,k2.y,k1.y) ) ) f=1;
	if ( (b1.x==k2.x && !isin(b1.x,k2.x,k1.x) ) || ( b1.y==k2.y && !isin(b1.y,k2.y,k1.y ) ) ) f=1;
	if (!fl) {printf("OTHER"); return 0;}
	if(k2.x!=1 && k2.y!=1)
	{
		figur tmp;
		figur lade;
		bool f=false;
		tmp.x=k2.x-1;
		tmp.y=k2.y-1;
		if (tmp.x==a1.x && tmp.y== a1.y) {lade=a1; a1.x=10; a1.y=10;}
		if (tmp.x==b1.x && tmp.y== b1.y) {lade=b1; b1.x=10; b1.y=10;}
		f=Is(a1,b1,tmp,k1);
		if (!f) {printf("OTHER"); return 0;}
		if (a1.x==10) a1=lade;
		if (b1.x==10) b1=lade;
	}
	if(k2.x!=1)
	{
		figur tmp;figur lade;
		bool f=false;
		tmp.x=k2.x-1;
		tmp.y=k2.y;
		if (tmp.x==a1.x && tmp.y== a1.y) {lade=a1; a1.x=10; a1.y=10;}
		if (tmp.x==b1.x && tmp.y== b1.y) {lade=b1; b1.x=10; b1.y=10;}
		f=Is(a1,b1,tmp,k1);
		if (!f) {printf("OTHER"); return 0;}
		if (a1.x==10) a1=lade;
		if (b1.x==10) b1=lade;
	}
	if(k2.x!=1 && k2.y!=8)
	{
		figur tmp;figur lade;
		bool f=false;
		tmp.x=k2.x-1;
		tmp.y=k2.y+1;
		if (tmp.x==a1.x && tmp.y== a1.y) {lade=a1; a1.x=10; a1.y=10;}
		if (tmp.x==b1.x && tmp.y== b1.y) {lade=b1; b1.x=10; b1.y=10;}
		f=Is(a1,b1,tmp,k1);
		if (!f) {printf("OTHER"); return 0;}
		if (a1.x==10) a1=lade;
		if (b1.x==10) b1=lade;
	}
	if(k2.y!=8)
	{
		figur tmp;figur lade;
		bool f=false;
		tmp.x=k2.x;
		tmp.y=k2.y+1;
		if (tmp.x==a1.x && tmp.y== a1.y) {lade=a1; a1.x=10; a1.y=10;}
		if (tmp.x==b1.x && tmp.y== b1.y) {lade=b1; b1.x=10; b1.y=10;}
		f=Is(a1,b1,tmp,k1);
		if (!f) {printf("OTHER"); return 0;}
		if (a1.x==10) a1=lade;
		if (b1.x==10) b1=lade;
	}
	if(k2.x!=8 && k2.y!=8)
	{
		figur tmp;figur lade;
		bool f=false;
		tmp.x=k2.x+1;
		tmp.y=k2.y+1;
		if (tmp.x==a1.x && tmp.y== a1.y) {lade=a1; a1.x=10; a1.y=10;}
		if (tmp.x==b1.x && tmp.y== b1.y) {lade=b1; b1.x=10; b1.y=10;}
		f=Is(a1,b1,tmp,k1);
		if (!f) {printf("OTHER"); return 0;}
		if (a1.x==10) a1=lade;
		if (b1.x==10) b1=lade;
	}
	if(k2.x!=8)
	{
		figur tmp;figur lade;
		bool f=false;
		tmp.x=k2.x+1;
		tmp.y=k2.y;
		if (tmp.x==a1.x && tmp.y== a1.y) {lade=a1; a1.x=10; a1.y=10;}
		if (tmp.x==b1.x && tmp.y== b1.y) {lade=b1; b1.x=10; b1.y=10;}
		f=Is(a1,b1,tmp,k1);
		/*printf("%d %d\n",tmp.x,tmp.y);
		printf("%d %d\n",a1.x,a1.y);
		printf("%d %d\n",b1.x,b1.y);*/
		if (!f) {printf("OTHER"); return 0;}
		if (a1.x==10) a1=lade;
		if (b1.x==10) b1=lade;
	}
	if(k2.x!=8 && k2.y!=1)
	{
		figur tmp;figur lade;
		bool f=false;
		tmp.x=k2.x+1;
		tmp.y=k2.y-1;
		if (tmp.x==a1.x && tmp.y== a1.y) {lade=a1; a1.x=10; a1.y=10;}
		if (tmp.x==b1.x && tmp.y== b1.y) {lade=b1; b1.x=10; b1.y=10;}
		f=Is(a1,b1,tmp,k1);
		if (!f) {printf("OTHER"); return 0;}
		if (a1.x==10) a1=lade;
		if (b1.x==10) b1=lade;
	}
	if(k2.y!=1)
	{
		figur tmp;figur lade;
		bool f=false;
		tmp.x=k2.x;
		tmp.y=k2.y-1;
		if (tmp.x==a1.x && tmp.y== a1.y) {lade=a1; a1.x=10; a1.y=10;}
		if (tmp.x==b1.x && tmp.y== b1.y) {lade=b1; b1.x=10; b1.y=10;}
		f=Is(a1,b1,tmp,k1);
		if (!f) {printf("OTHER"); return 0;}
		if (a1.x==10) a1=lade;
		if (b1.x==10) b1=lade;
	}
	printf("CHECKMATE");

	//printf("%d",b1.y);
	//cin.get();cin.get();

}


#include<bits/stdc++.h>
#define ll long long
#define sec second
#define fir first
using namespace std;
int main(){
	ll x,fr=1,c4=0,c7=0,fr4=0;
	string s;
	cin>>s;
	for(ll i=0;i<s.length();i++){
		if(s[i]=='4')c4++;
		else if(s[i]=='7')c7++;
		else if(fr){
			if(s[i]>'7')fr=0,fr4=1;
		}
	}

		for(ll i=0;i<s.length();i++){
			if(fr4&&s[i]=='4')s[i]='7',c7++,c4--,fr4=0;
			if(s[i]!='4'&&s[i]!='7')
				if((s.length()/2-c7))s[i]='7',c7++;
				else s[i]='4',c4++;
		}
	cout<<s;

}


#pragma comment(linker, "/stack:100000000")

#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <cassert>
#include <queue>

using namespace std;

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()

const int MOD = 1000000009;

vector <string> s;
set <string> pr;
vector <string> P;
vector <vector <int> > nxt;
vector <vector <int> > fs;
int dp[1001][1001][101]; //length, cover, prefix

char get(char c) {
	switch (c) {
		case 'A': return '0';
		case 'C': return '1';
		case 'G': return '2';
		case 'T': return '3';
		default: return 0;
	}
}

bool endsWith(string s, string t) {
	if (sz(s) < sz(t)) return false;
	for (int i = sz(s) - sz(t), j = 0; i < sz(s); i++, j++) {
		if (s[i] != t[j]) return false;
	}
	return true;
}

void add(int &a, int b) {
	a += b;
	if (a > MOD) a -= MOD;
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, m;
	cin >> n >> m;
	s.resize(m);
	REP(i, m) {
		cin >> s[i];
		REP(j, sz(s[i])) s[i][j] = get(s[i][j]);
	}
	pr.insert("");
	REP(i, sz(s)) {
		string t;
		REP(j, sz(s[i])) {
			t += s[i][j];
			pr.insert(t);
		}
	}
	P = vector <string>(all(pr));
	nxt.resize(sz(P));
	fs.resize(sz(P));
	REP(i, sz(P)) {
		string str = P[i];
		for (char c = '0'; c <= '3'; c++) {
			string t = str + c;
			int id = -1;
			REP(j, sz(P)) {
				if (endsWith(t, P[j]) && (id == -1 || sz(P[j]) > sz(P[id]))) {
					id = j;
				}
			}
			nxt[i].push_back(id);
			id = -1;
			REP(j, sz(s)) {
				if (endsWith(t, s[j]) && (id == -1 || sz(s[j]) > sz(s[id]))) {
					id = j;
				}
			}
			fs[i].push_back(id);
		}
	}
	memset(dp, 0, sizeof(dp));
	dp[0][0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= i; j++) {
			for (int k = 0; k < sz(P); k++) {
				if (sz(P[k]) <= i) {
					REP(c, 4) {
						int x = fs[k][c];
						if (x != -1 && i - sz(s[x]) + 1 <= j) {
							add(dp[i + 1][i + 1][nxt[k][c]], dp[i][j][k]);
						} else {
							add(dp[i + 1][j][nxt[k][c]], dp[i][j][k]);
						}
					}
				}
			}
		}
	}
	int res = 0;
	REP(i, sz(P)) add(res, dp[n][n][i]);
	printf("%d\n", res);
	return 0;
}


/*
  ID: nigo1
  LANG: C++
  TASK: B
*/
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <stack>

#define pf printf
#define sf scanf
#define TIME pf("%f", (double)clock()/CLOCKS_PER_SEC);

using namespace std;

int N, DD, MM, YY;
int pos, b[3], a[3], used[3];

bool is_date (int BD, int BM, int BY) {
    if (BM > 12) return 0;
    if (BY > YY) return 0;

    int max_days = 0;
    switch (BM) {
        case 1 : max_days = 31;
                 break;
        case 2 : max_days = BY%4 ? 28 : 29;
                 break;
        case 3 : max_days = 31;
                 break;
        case 4 : max_days = 30;
                 break;
        case 5 : max_days = 31;
                 break;
        case 6 : max_days = 30;
                 break;
        case 7 : max_days = 31;
                 break;
        case 8 : max_days = 31;
                 break;
        case 9 : max_days = 30;
                 break;
        case 10 : max_days = 31;
                 break;
        case 11 : max_days = 30;
                 break;
        case 12 : max_days = 31;
                 break;
    }
    if (BD > max_days) return 0;

    return 1;
}

bool check (int BD, int BM, int BY) {
    if (YY - BY < 18) return 0;
    if (YY - BY > 18) return 1;

    if (MM > BM) return 1;
    if (MM < BM) return 0;

    if (DD >= BD) return 1;

    return 0;
}

int permute () {
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++)
            for (int k = 0; k < 3; k++)
                if (i != j and i != k and j != k) {
                    int D = b[i], M = b[j], Y = b[k];
                    if (is_date (D, M, Y)) {
                        if (YY % 4 and M == 2 and D == 29) M = 3, D = 1;
                        if (check (D, M, Y)) {
                            //cout << D << " " << M << " " << Y << endl;
                            return 1;
                        }
                }
    return 0;
}
int main()
{
	//freopen ("B.in", "r", stdin);
	//freopen ("B.out", "w", stdout);

    sf ("%d.%d.%d\n", &DD, &MM, &YY);
    //cout << DD << " " << MM << " " << YY << endl;
    sf ("%d.%d.%d\n", &b[0], &b[1], &b[2]);

    if (permute ()) pf ("YES\n");
    else pf ("NO\n");
}


#include <iostream>

using namespace std;

int main()
{
    int k=0 , n=0 , w=1 , sol=0;
    cin>>k>>n>>w;

    w=w*(w+1)/2;
    sol=w*k-n;
    if(sol>=0)
    {
        cout<<sol;
    }

}


#include <iostream>

using namespace std;

int main()
{
    int n,k,t=0;
    cin >> n >> k;
    while (1)
    {
        if (t==n)break;
        if (k%5==0 && ((k/5)+t)==n)break;
        if (k%4==0 && ((k/4)+t)==n)break;
        if (k%3==0 && ((k/3)+t)==n)break;
        else
        {
            k-=2;
            t++;
        }
    }
    cout << t ;
    return 0;
}
//Okasha


#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<complex>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<cmath>
#include<bitset>
#include<functional>

using namespace std;
typedef unsigned long long ull;
typedef  long long ll;
typedef vector<int> vec;
typedef pair<int,int> ii;
typedef vector<ii> vecii;
typedef vector<int>::iterator it;
const ll oo = 1e9;
const ll EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll mod2 = (mod-1);

int Do(int m){
	while(m > 9){
		int total = 0;
		while(m != 0){
			total += m%10;
			m/=10;
		}
		m = total;
	}

	return m;
}
int main(){
	//freopen("in.txt","r",stdin);

	int n;
	cin>>n;
	vec a[10];
	for(int i=1; i<=n; i++){
		a[Do(i)].push_back(i);
	}

	int total = 0;
	for(int i=1; i<=9; i++)
		for(int j=1; j<=9; j++){

			int k = Do(i*j);
			for(int t1 = 0; t1<a[i].size(); t1++)
				for(int t2 = 0; t2<a[j].size(); t2++)
					for(int t3 = 0; t3<a[k].size(); t3++)
					{
						int o = a[i][t1];
						int oo = a[j][t2];
						int ooo = a[k][t3];

						if(o*oo != ooo)
							++total;
					}
		}

		cout<<total<<endl;
}


#include <stdio.h>
#include <assert.h>

int output_year_figure[4];

void carry(void);
bool compare(void);

int main()
{
	int input_year = 0;
	int err = scanf("%d", &input_year);
	/*
	if(err != 1) {
		printf("Input year error!\n");
		assert(0);
	}
	*/
	/* Input year range: 1000 ~ 9000. */
	if(input_year < 1000 || input_year > 9000) {
		printf("Input year is out of range!\n");
		assert(0);
	}

	/* Get four numbers of the input year. */
	output_year_figure[3] = input_year / 1000;
	input_year -= (1000 * output_year_figure[3]);
	output_year_figure[2] = input_year / 100;
	input_year -= (100 * output_year_figure[2]);
	output_year_figure[1] = input_year / 10;
	input_year -= (10 * output_year_figure[1]);
	output_year_figure[0] = input_year;

	bool need_to_calc = true;
	while(need_to_calc) {
		if(output_year_figure[3] == output_year_figure[2]) {
			output_year_figure[2]++;
			carry();
			need_to_calc = !compare();
		}
		else if(output_year_figure[3] == output_year_figure[1] \
			|| output_year_figure[2] == output_year_figure[1]) {
				output_year_figure[1]++;
				carry();
				need_to_calc = !compare();
		}
		else {
			output_year_figure[0]++;
			carry();
			need_to_calc = !compare();
		}
	}

	int output_year = output_year_figure[3] * 1000 + output_year_figure[2] * 100 \
		+ output_year_figure[1] * 10 + output_year_figure[0];
	printf("%d\n", output_year);
}

void carry(void)
{
	if(output_year_figure[0] == 10) {
		output_year_figure[0] = 0;
		output_year_figure[1]++;
		if(output_year_figure[1] == 10) {
			output_year_figure[1] = 0;
			output_year_figure[2]++;
			if(output_year_figure[2] == 10) {
				output_year_figure[2] = 0;
				output_year_figure[3]++;
			}
		}
	}
	else if(output_year_figure[1] == 10) {
		output_year_figure[1] = 0;
		output_year_figure[2]++;
		if(output_year_figure[2] == 10) {
			output_year_figure[2] = 0;
			output_year_figure[3]++;
		}
	}
	else if(output_year_figure[2] == 10) {
		output_year_figure[2] = 0;
		output_year_figure[3]++;
	}
}

bool compare(void)
{
	if(output_year_figure[3] == output_year_figure[2])
		return false;
	if(output_year_figure[3] == output_year_figure[1])
		return false;
	if(output_year_figure[3] == output_year_figure[0])
		return false;
	if(output_year_figure[2] == output_year_figure[1])
		return false;
	if(output_year_figure[2] == output_year_figure[0])
		return false;
	if(output_year_figure[1] == output_year_figure[0])
		return false;
	return true;
}


#include<iostream>
#include<vector>

using namespace std;

string arr[12]={"C", "C#" , "D" , "D#" , "E" , "F" , "F#" , "G" , "G#", "A", "B", "H"};

int found(string c1 , string c2)
{
    bool found=false , first=false , second= false;
    int i=0 , count1=0 , count2=0;
    while(!found)
    {
        if(i > 11)
            i=0;

        if(arr[i] == c1)
        {
            first=true;

            //cout<<"///////////////////////////////////////////////////////////////////////"<<endl;
        }

        else if(arr[i]!=c2 && first)
            count1++;

        else if(arr[i]==c2 && first)
        {
            count1++;
            break;
        }
        i++;
    }
    //cout<<"tHIs cout "<<count1<<endl;
    if(count1==3 || count1==4)
        return count1;

    return -1;
}

int fun(int x1 , int x2)
{
    if(x1==4 && x2==3)
    {
        cout<<"major"<<endl;
        return 0;
    }

    else if(x1==3 && x2==4)
    {
        cout<<"minor"<<endl;
        return 0;
    }

    return 1;

}

int main()
{

    string c1 , c2 , c3;
    cin>>c1>>c2>>c3;

    int x1 = found(c1 , c2);
    int x2 = found(c2 , c3);
    if(!fun(x1,x2))
        return 0;

    int x3 = found(c2 , c1);
    int x4 = found(c1 , c3);
    if(!fun(x3,x4))
        return 0;

    int x5 = found(c3 , c2);
    int x6 = found(c2 , c1);
    if(!fun(x5,x6))
        return 0;

    int x7 = found(c3 , c1);
    int x8 = found(c1 , c2);
    if(!fun(x7,x8))
        return 0;

    int x9 = found(c2 , c3);
    int x10 = found(c3 , c1);
    if(!fun(x9,x10))
        return 0;

    int y = found(c1 , c3);
    int x = found(c3 , c2);
    if(!fun(y,x))
        return 0;

    cout<<"strange"<<endl;

    //cout<<count1<<" "<<count2<<endl;

    return 0;
}


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

int main(){
    int n,h,m;
    cin>>n>>h>>m;
    int l,r,x;
    //vector <int> res;
    map <int,int> mp;
    for(int i=1;i<=n;i++){
        mp[i] = INT_MAX;
    }
    for(int i=0;i<m;i++){
        cin>>l>>r>>x;
        if(x<mp[l]){
            mp[l] = x;
        }
        if(x<mp[r]){
            mp[r] = x;
        }
    }

    int result = 0;
    for(int i=1;i<=n;i++){
        if(mp[i]==INT_MAX){
            mp[i] = h;
        }

        result += mp[i]*mp[i];
    }

    //for(int i=1;i<=n;i++){
    //    cout<<mp[i]<<endl;
    //}
    cout<<result<<"\n";

}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;

const int maxn = 80 + 5;
const int INF = 1 << 29;

ll dp[maxn][maxn][maxn][2];
int a[maxn], b[maxn], c[maxn];
char s[maxn];

void upmin(int &a, int b)
{
    a = min(a, b);
}

int main()
{
    int n;
    scanf("%d%s", &n, s + 1);
    int cnt1 = 0, cnt2 = 0, cnt3 = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(s[i] == 'V') a[++cnt1] = i;
        else if(s[i] == 'K') b[++cnt2] = i;
        else c[++cnt3] = i;
    }
    memset(dp, 0x3f, sizeof(dp));
    dp[0][0][0][0] = 0;
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 0; j <= cnt1; ++j)
        {
            for(int k = 0; k <= cnt2; ++k)
            {
                for(int l = 0; l < 2; ++l)
                {
                    int m = i - j - k;
                    if(i - j - k <= cnt3)
                    {
                        int p = upper_bound(a + 1, a + j + 1, c[m]) - a - 1, q = upper_bound(b + 1, b + k + 1, c[m]) - b - 1;
                        upmin(dp[i][j][k][0], dp[i - 1][j][k][l] + abs(c[m] + j - p + k - q - i));
                    }
                    if(j < cnt1)
                    {
                        int p = upper_bound(b + 1, b + k + 1, a[j + 1]) - b - 1, q = upper_bound(c + 1, c + m, a[j + 1]) - c - 1;
                        upmin(dp[i][j + 1][k][1], dp[i - 1][j][k][l] + abs(a[j + 1] + k - p + m - 1 - q - i));
                    }
                    if(k < cnt2 && l != 1)
                    {
                        int p = upper_bound(c + 1, c + m, b[k + 1]) - c - 1, q = upper_bound(a + 1, a + j + 1, b[k + 1]) - a - 1;
                        upmin(dp[i][j][k + 1][0], dp[i - 1][j][k][l] + abs(b[k + 1] + m - 1 - p + j - q - i));
                    }
                }
            }
        }
    }
    printf("%I64d\n", min(dp[n][cnt1][cnt2][0], dp[n][cnt1][cnt2][1]));
    return 0;
}


#include<bits/stdc++.h>
#define ld long double
#define ll long long
#define fre  freopen("papaya.in", "r", stdin);
#define open freopen("papaya.out", "w", stdout);
#define el else
#define mm95 cin.tie(0);ios::sync_with_stdio(0);cout.tie(0);
using namespace std;
 ll a[10][10],ans,fl=0,i=0;
int main(){
    ll n,m;
    mm95
    fre open
     cin>>n>>m;
     for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>a[i][j];
     ll x=1,y=1;
     ans+=a[x][y];
     a[x][y]=0;
        while(true){
        if(a[x+1][y]>=a[x-1][y] and a[x+1][y]>=a[x][y+1] and a[x+1][y]>=a[x][y-1] and fl==0)x++,fl=1;
        if(a[x-1][y]>=a[x+1][y] and a[x-1][y]>=a[x][y+1] and a[x-1][y]>=a[x][y-1] and fl==0)x--,fl=1;
        if(a[x][y+1]>=a[x][y-1] and a[x][y+1]>=a[x+1][y] and a[x][y+1]>=a[x-1][y] and fl==0)y++,fl=1;
        if(a[x][y-1]>=a[x][y+1] and a[x][y-1]>=a[x+1][y] and a[x][y-1]>=a[x-1][y] and fl==0)y--,fl=1;
        ans+=a[x][y];
        fl=0;
        if(x==n and y==m){
        break;
//        cout<<"s"<<endl;
        }
        a[x][y]=0;
     }
//     for(int i=1;i<=n;i++)
//     {
//         for(int j=1;j<=m;j++)cout<<a[i][j]<<" ";
//         cout<<endl;
//     }
      cout<<ans<<endl;
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,q,i;
    cin>>n>>q;
    vector<string>v[6];
    for(i=1;i<=q;i++)
    {
        string s;char ch;
        cin>>s>>ch;
        v[ch-'a'].push_back(s);
    }

    queue<string>que;
    for(auto x: v[0]) que.push(x);
    while(!que.empty()&&(que.front().size()<n))
{
	string current=que.front();
	que.pop();

	int x=current[0];
	current.erase(current.begin());
	for(auto j: v[x-'a'])
	{
		string temp= j+current;
		que.push(temp);
	}

}

cout<<q.size()<<endl;
}


#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

int main(){
    int n;
    cin >> n;
    int ans;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        if(x > 0){
            ans+=x;
        }else{
            anx-=x;
        }
    }
    cout << ans;
    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

ll n;
ll l[5], r[5];
ll divi= 1;
long double res= 0.0;
long double f[10005][35], g[10005][35];

int main(){
    cin >> n;
    for(ll i=0;i<n;i++){
        cin >> l[i] >> r[i];
        divi*= (r[i]-l[i]+1);
    }

    for(ll x=1;x<=10000;x++){
        for(ll mask=1;mask<(1LL<<n)-1;mask++){
            f[x][mask]= 0.0; g[0][mask]= 0.0;
            for(ll mask2=1;mask2<(1LL<<n);mask2++){
                if((mask|mask2)!=mask) continue;
                bool have= false; ll cost= 1LL;
                for(ll i=0;i<n;i++){
                    if((mask2&(1LL<<i))!=0){
                        if(l[i]>x || x>r[i]){
                            have= true; break;
                        }
                    }
                    else if((mask&(1LL<<i))!=0){
                        cost*= max(0LL, min(x,r[i]+1)-l[i]);
                    }
                }
                if(!have) f[x][mask]+= (long double)(x*cost);
            }
            g[x][mask]= g[x-1][mask]+f[x][mask];
        }
    }

    for(ll x=1;x<=10000;x++){
        for(ll mask=1;mask<(1LL<<n);mask++){
            ll cost= 1LL, cnt= 0; bool have= false;
            for(ll i=0;i<n;i++){
                if((mask&(1LL<<i))!=0){
                    if(l[i]>x || x>r[i]){
                        have= true; break;
                    }
                    cnt++;
                }
                else cost*= max(0LL,min(x,r[i]+1)-l[i]);
            }
            if(!have){
                if(cnt>=2) res= res+ (long double)(x*cost)/(long double)divi;
                else res= res+ g[x-1][(1<<n)-1-mask]/(long double)divi;
            }
        }
    }

    cout.precision(9);
    cout << fixed << res << "\n";

    return 0;
}


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

typedef long double ld;
typedef unsigned long long ll;
const int N = 1e4 + 100;

ll n, l[N], r[N], dp[N];
ld sum, s;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	s = 1;
	for (int i = 0; i < n; i++) {
		cin >> l[i] >> r[i];
		s *= r[i] - l[i] + 1;
	}
	for (int mask = 1; mask < (1 << n); mask++) {
		for (int big = 0; big < N; big++) {
			dp[big] = 1;
			for (int i = 0; i < n; i++)
				if((mask & (1 << i)) == 0) {
					if(l[i] > big)
						dp[big] = 0;
					else if(r[i] <= big)
						dp[big] *= r[i] - l[i] + 1;
					else
						dp[big] *= big - l[i] + 1;
				}
			ld X, S;
			ll L = 1, R = N;
			for (int i = 0; i < n; i++)
				if(mask & (1 << i))
					R = min(R, r[i]), L = max(L, l[i]);
			if(R < L || R <= big)
				X = 0, S = 0;
			else if(L <= big + 1) {
				X = R - big;
				S = (big + 1 + R) * X / 2;
			}
			else {
				X = R - L + 1;
				S = (L + R) * (R - L + 1) / 2;
			}
			if(__builtin_popcount(mask) == 1)
				sum += big * (dp[big] - (big? dp[big - 1]: 0)) * X;
			else
				sum += (dp[big] - (big? dp[big - 1]: 0)) * (S);
		}
	}
	cout << fixed << sum / s;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    string ans="";
    if(s[0]=='h')
    {
        int i;
        ans="http://";
        for(i=4;i<s.size();i++)
        {
         if(s[i]=='r'&&s[i+1]=='u')
         break;
         ans+=s[i];
        }
        ans+=".ru/";
        i++;
        while(i<s.size())
        {
            ans+=s[i];
        }
        cout<<ans<<endl;
    }
    else
    {
             int i;
       ans="ftp://";
        for(i=3;i<s.size();i++)
        {
         if(s[i]=='r'&&s[i+1]=='u')
         break;
         ans+=s[i];
        }
        ans+=".ru/";
        i++;
        while(i<s.size())
        {
            ans+=s[i];
        }
        cout<<ans<<endl;

    }

    return 0;
}


#include <iostream>
#include<string>
using namespace std;
int main() {
	string s;
	cin >> s;
	string a = { s[0],s[1],s[2] }, b = { s[0],s[1],s[2],s[3] }, c = "://";
	if (a == "ftp") {
		s.insert(3, c);
	}
	else if (b == "http") {
		s.insert(4, c);
	}
	int u;
	for (int i = 2; i < s.max_size() - 2; i++) {
		if (s.find(".") != -1 && u != s.size() - 1 && s.substr(i - 2, 2) == "ru") {
			s.insert(i, "/");
			break;
		}
		if (s.substr(i - 2, 2) != "ru" && s.substr(i, 2) == "ru" && s.find(".") == -1 && s.substr(i - 2, 2) != "//") {
			s.insert(i, ".");
			u = i+2;
		}
	}
	cout << s;
	return 0;
}


/********   All Required Header Files ********/
#include <bits/stdc++.h>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define forn(i,n) for (int i = 0; i < n;i++)
#define all(cont) cont.begin(), cont.end()
#define pb push_back
#define mod ((int)1e9 + 7)
#define vicin(n,vipb) for(int i = 0; i < n;i++){ int rt; cin >> rt; vipb.push_back(rt);}
#define icin(a) int a; cin >> a
#define icin2(a,b) int a,b; cin >> a >> b
#define icin3(a,b,c) int a,b,c; cin >> a >> b >> c
#define fore(t) for(auto e:t) cout << e << " ";
#define fst first
#define sec second
#define int long long

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<pair<int,int>>> vvpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef map<int,int> mpii;
typedef map<string,int> mpsi;
typedef map<char,int> mpci;
typedef set<int> seti;
typedef multiset<int> mseti;

/****** Template of some basic operations *****/
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
/**********************************************/

/*** Global Variables ***/

/********************** cout << c << endl;**/

/*** Global functions ***/

int modu(int u){
    return ((u % mod) + mod) % mod;
}

int power(int x, int y, int p)
{
    int res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

/************************/

/********** Main()  function **********/
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	#endif

    int n,k;

    cin >> n >> k;

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

    if(k == 0){
        cout << modu(2*n);
        return 0;
    }

    int resultat = modu(n*power(2,k+1,mod) - power((int)2,k,mod) + 1);
    cout << resultat;

	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long LL;
LL gi () {
    LL ret=0; char ch=getchar();
    while((ch<'0' || ch>'9') && ch!='-') ch=getchar();
    char c=ch=='-'?getchar():ch;
    while(c>='0' && c<='9') ret=ret*10+c-'0',c=getchar();
    return ch=='-'?-ret:ret;
}
const int N = 610 + 10;
const int mo = 10007;
int n,len,f[N][N][N],G[N],r[N],g[N],e[N],alc;
char s[N];
struct Mat {
    int a[N][N];
} M,M1;
Mat operator * (const Mat &x, const Mat &y) {
    Mat ret = {0};
    for(int i=1;i<=alc;i+=1)
        for(int j=1;j<=alc;j+=1)
            if(x.a[i][j])
                for(int k=1;k<=alc;k+=1)
                    if(y.a[j][k]) (ret.a[i][k] += x.a[i][j] * y.a[j][k]) %= mo;
    return ret;
}
Mat ksm (Mat a, int b) {
    Mat ret = {0};
    for(int i=1;i<=alc;i+=1) ret.a[i][i] = 1;
    while(b) {
        if(b&1) ret = ret * a;
        a = a * a; b >>= 1;
    }
    return ret;
}
int main () {
    scanf("%s",s+1); len = strlen(s+1);
    n = gi() + len;
    f[1][len][0] = 1;
    for(int d=len-1;d>=0;d-=1)
        for(int i=1;i+d<=len;i+=1) {
            int j = i+d;
            for(int k=0;k<=len;k+=1)
                if(f[i][j][k]) {
                    if(s[i]==s[j]) {
                        if(i==j) (G[k] += f[i][j][k]) %= mo;
                        else if(i+1==j) (G[k] += f[i][j][k]) %= mo;
                        else (f[i+1][j-1][k] += f[i][j][k]) %= mo;
                    }
                    else {
                        (f[i+1][j][k+1] += f[i][j][k]) %= mo;
                        (f[i][j-1][k+1] += f[i][j][k]) %= mo;
                    }
                }
        }
    for(int i=1;i<len;i+=1) r[i] = ++alc, M.a[r[i]][r[i]] = 24;
    for(int i=2;i<len;i+=1) M.a[r[i-1]][r[i]] = 1;
    for(int i=1;i<=(len+1)/2;i+=1) g[i] = ++alc, M.a[g[i]][g[i]] = 25;
    for(int i=2;i<=(len+1)/2;i+=1) M.a[g[i-1]][g[i]] = 1;
    M.a[r[len-1]][g[1]] = 1;
    for(int i=1;i<=(len+1)/2;i+=1) e[i] = ++alc, M.a[g[i]][e[i]] = 1, M.a[e[i]][e[i]] = 26;
    M1 = ksm(M,(n+1)/2-1); M = ksm(M,(n+1)/2);
    LL ans = 0;
    for(int i=0;i<len;i+=1) {
        (ans += G[i] * M.a[len-i][e[(len-i+1)/2]]) %= mo;
    }
    if(n&1)
        for(int i=0;i<len;i+=1)
            if((len-i)%2 == 0) {
                (ans -= G[i] * M1.a[len-i][g[(len-i+1)/2]]) %= mo;
            }
    cout << (ans+mo)%mo;
    return 0;
}


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

typedef long long LL;

struct par { LL x, y; };

LL modu, period;

inline LL M (LL x, LL y) {
	LL r(0);
	y = (y % modu + modu) % modu;
	for (; y; y >>= 1, x = (x + x) % modu) if (y & 1) r = (r + x) % modu;
	return r;
}

par getFib (LL x) // (F[x], F[x + 1])
{
	if (x == 0) return (par){0, 1};
	par y;
	if (x & 1)
	{
		y = getFib(x - 1);
		return (par){y.y, (y.x + y.y) % modu};
	}
	else
	{
		y = getFib(x / 2);
		return (par){M(y.x, y.y * 2 - y.x), (M(y.x, y.x) + M(y.y, y.y)) % modu};
	}
}

int main ()
{
	LL cx; cin >> cx;
	vector<LL> vpre, vcur;
	modu = 10; period = 60;
//	cout << '#' << endl;
	for (int i = 0; i < period; ++i)
		if (getFib(i).x == cx % modu) vcur.push_back(i);
	for (int _ = 2; _ <= 13; ++_)
	{
//		cout << _ << endl;
		vpre = vcur;
		vcur.clear();
		modu *= 10;
		LL f = (_ <= 3) ? 5 : 10;
		for(typeof vpre.begin() x:vpre){}
		for (LL x : vpre) for (LL i = 0, j; i < f; ++i)
			if (getFib(j = x + i * period).x == cx % modu)
				vcur.push_back(j);
		period *= f;
	}
	if (vcur.size())
		cout << *min_element(vcur.begin(), vcur.end()) << endl;
	else
		cout << -1 << endl;
	return 0;
}


#include <iostream>
#include <cassert>
#include <vector>

#define dvs 100000000LL

using namespace std;

long long to_find, res;
long long mlt[2][2], tmp[2][2], mr[2][2];
long long period[14];

long long mult(const long long &p1, const long long &p2, const long long &md){
	long long a = p1 / dvs, b = p1 % dvs;
	long long c = p2 / dvs, d = p2 % dvs;
	long long tmp = (((dvs * dvs % md) * a  % md) * c % md + (dvs * d % md) * a % md + (dvs * b % md) * c % md + b * d % md) % md;
	return tmp;
}

long long number(const long long &pos, const long long &p){
	mlt = {{1, 1}, {1, 0}};
	mr = {{1, 0}, {0, 1}};
	long long cur = pos - 1;
	if(!pos)return 0;
	while(cur){
		if(cur % 2){
			for(int i = 0; i < 2; ++i)
				for(int j = 0; j < 2; ++j){
					tmp[i][j] = 0;
					for(int k = 0; k < 2; ++k)
						tmp[i][j] = (tmp[i][j] + mult(mr[i][k], mlt[k][j], p)) % p;
				}
			for(int i = 0; i < 2; ++i)
				for(int j = 0; j < 2; ++j)
					mr[i][j] = tmp[i][j];
			--cur;
		}
		cur >>= 1;
		for(int i = 0; i < 2; ++i)
			for(int j = 0; j < 2; ++j){
				tmp[i][j] = 0;
				for(int k = 0; k < 2; ++k)
					tmp[i][j] = (tmp[i][j] + mult(mlt[i][k], mlt[k][j], p)) % p;
			}
		for(int i = 0; i < 2; ++i)
			for(int j = 0; j < 2; ++j)
				mlt[i][j] = tmp[i][j];
	}
	return(mr[0][0]);
}

void init_per(){
	period[1] = 60;
	period[2] = 300;
	period[3] = 1500;
	for(int i = 4; i < 14; ++i)period[i] = period[i - 1] * 10;
}

inline void input_data(){cin >> to_find;}
inline void output_data(){cout << res << "\n";}

int calc(){
	res = -1;
	long long cur = 10000000000000LL;
	//long long cur = 100;
	init_per();
	vector< long long > sm;
	vector< long long > tmp;
	long long cur_n = 10, cur_mod = to_find % cur_n;
	if(!cur_mod)sm.push_back(0);
	if(cur_mod == 1){sm.push_back(1); sm.push_back(2);}
	int mp = 1, pr = 1, itr = 1;
	for(int i = 3; i <= 59; ++i){
		int tmp = (mp + pr) % cur_n;
		if(cur_mod == tmp)sm.push_back(i);
		pr = mp; mp = tmp;
	}
	//cerr << "go\n";
	while(cur_n != cur){
		//cerr << "cur_n = " << cur_n << "\n";
		long long prd = period[itr], next_prd = period[++itr];
		//cerr << prd << " is prd\n" << next_prd << " is next_prd\n";
		cur_n *= 10;
		cur_mod = to_find % cur_n;
		tmp.clear();
		long long now = 0;
		while(now < next_prd){
			for(int i = 0; i < sm.size(); ++i){
				long long nmb = number(sm.at(i) + now, cur_n);
				//cout << "nmb = " << nmb << "\n";
				if(nmb == cur_mod)tmp.push_back(sm.at(i) + now);
			}
			now += prd;
			//cerr << "now = " << now << "\n";
		}
		if(tmp.empty())return 0;
		sm = tmp;
	}
	res = sm.at(0);
	return 0;
}

int main(){
	input_data();
	calc();
	output_data();
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int)(2e9 + 0.5);
const int MAXN = 100100;

string s1, s2;
int mass[MAXN];

int main() {

    cin >> s1 >> s2;

    int l = 0, r = 0;
    for(l = 0; l < s2.size(); ++l) {
        if(r >= s1.size()) break;
        for(; r < s1.size(); ++r) {
            if(s1[r] == s2[l]) break;
        }
    }
    if(l == (int)s2.size()) {
        printf("automaton\n");
        exit(0);
    }
    for(int i = 0; i < (int)s1.size(); ++i) {
        ++mass[s1[i] - 'a'];
    }
    for(int i = 0; i < (int)s2.size(); ++i) {
        --mass[s2[i] - 'a'];
    }
    if((int)s1.size() == (int)s2.size()) {
        for(int i = 0; i < MAXN; ++i) {
            if(mass[i] != 0) {
                printf("need tree\n");
                exit(0);
            }
        }
        printf("array\n");
        exit(0);
    } else {
        for(int i = 0; i < MAXN; ++i) {
            if(mass[i] < 0) {
                printf("need tree\n");
                exit(0);
            }
        }
        printf("both\n");
    }
}


#include <iostream>
using namespace std;

void mSwap(int*a,int*b)
{
    *a=*a^*b;
    *b=*a^*b;
    *a=*a^*b;
}

void mSort (int* a, int*b, int* c)
{
    if (*a<*b)
    {
        mSwap(a,b);
    }
    if (*c>*a)
    {
        mSwap(a,c);
        mSwap(b,c);
    }
    else if(*c>*b)
    {
        mSwap(b,c);
    }
}

int main()
{
    unsigned int a, b, c, sum=0;
    cin>>a>>b>>c;
    mSort(&a,&b,&c);
    while(b>0)
    {
        if(b==c)
        {
            sum+=b;
            cout<<sum<<endl;
            return 0;
        }
        --a;
        --b;
        ++c;
        ++sum;
        mSort(&a,&b,&c);
    }
    cout<<sum<<endl;
   return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#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 <cstring>
#include <climits>
#include <cctype>
#include <cmath>

using namespace std;

#define ill long long
#define pii pair<ill,ill>
#define pb(x) push_back(x)
#define forall(i,a,n) for(ill i=(a); i < (n); i++)
#define forev(i, a, n) for(ill i = (a); i >= (n); i--)
#define fill(i,a) memset(i, a, sizeof(i))
#define V(x) vector<x>
#define vii vector<ill>
#define sii set<ill>
#define sz(a) a.size()
#define prnt(n) prillf("%d\n", n)
#define INF 1000000000
#define gc getchar_unlocked

#define foreach(v, c)  for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define S(n) scanf("%d", &n)
int main()
{
	ill x, y, z, k;
	cin >> x >> y >> z >> k;
	ill part = 1;
	while(k) {
		if(x >1) {
			k--;
			part<<=1;
			x--;
		}
		if(y >1 && k) {
			k--;
			part<<=1;
			y--;
		}
		if(z >1 && k) {
			k--;
			part<<=1;
			z--;
		}
	}
	cout << part <<endl;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long x, y, z, k, cx = 1, cy = 1, cz = 1;
    cin >> x >> y >> z >> k;
    cz = cy = cx = min(min(x - 1, y - 1), min(z - 1, (k / 3))) + 1;
    k -= 3 * (cx - 1);
    while(k > 0)
    {
        if((cx <= cy || cy == y) && (cx <= cz || cz == z) && cx < x)
            cx++;
        else if((cy <= cz || cz == z) && cy < y)
                cy++;
            else if(cz < z)
                    cz++;
        k--;
    }
    cout << cx * cy * cz << endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
const int MAX_N=100005;
struct Fly
{
    int x,y;
}F[MAX_N];
struct Land
{
    int a,b;
}L[MAX_N];
int main()
{
    int R,B;
    cin>>R>>B;
    for(int i=0;i<R;i++)
    {
        cin>>F[i].x>>F[i].y;
    }
    for(int j=0;j<B;j++)
    {
        cin>>L[j].x>>L[j].y;
    }
    if(R>B)
    {
        cout<<"No"<<endl;
        return 0;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main ()
{
  int sum = 0;
  int ans = 0;
  int n,s;
  cin>>n>>s;
  for(int i= 1;i<=n;i *= 2)
  {
    sum += i;
    if(sum >= n) ans = i,break;
  }
  cout<<ans<<endl;
  return 0;
}


#include <iostream>
#include <vector>

std::vector<int> digits(int x) {
	std::vector<int> answer;
	while(x) {
		answer.push_back(x % 10);
		x /= 10;
	}
	return answer;
}

int to_integer(std::vector<int> x_digits) {
	int answer = x_digits.back();
	for (int i = x_digits.size() - 2; i >= 0; i--) {
		answer *= 10;
		answer += x_digits[i];
	}
	return answer;
}

int main() {
	int x;
	std::cin >> x;
	std::vector<int> x_digits = digits(x);
	int first_digit = x_digits.back();
	bool is_max_sum = true;
	for (int i = 0; i < x_digits.size() - 1; i++) {
		if (x_digits[i] != 9) {
			is_max_sum = false;
		}
	}
	if (is_max_sum) {
		std::cout << x;
		return 0;
	}

	int answer = first_digit - 1;
	int curr_answer = answer;
	while (curr_answer <= x) {
		answer = curr_answer;
		curr_answer *= 10;
		curr_answer += 9;
	}

	std::vector<int> answer_digits = digits(answer);
	int max_answer = answer;
	for (int i = 0; i < answer_digits.size() - 1; i++) {
		std::vector<int> temp = answer_digits;
		temp[i]--;
		temp.back()++;
		int temp_int = to_integer(temp);
		if (temp_int <= x) {
			max_answer = temp_int;
			break;
		}
	}
	std::cout << max_answer;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n.m;
     cin>>n;
     m=n/2;
     cout<<m+1;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    int n=a.size(),i,j;
    if(n%2==0){
        j=(n/2)-1;
        cout<<a[j];
        i=1;
        while(1){
            j=(n/2)-1+i;
            cout<<a[j];
            if(j==n-1){
                break;
            }
            j=(n/2)-1-i;
            cout<<a[j];
            i++;
        }
    }
    else{
        j=n/2;
        cout<<a[j];
        i=1;
        if(j!=n-1){
            while(1){
                j=(n/2)+i;
                cout<<a[j];
                j=(n/2)+1;
                cout<<a[j];
                if(j==0){
                    break;
                }
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
/*ll mod=1000000+3;
  ll pow(ll x,ll y)
  {
  ll fans=1;
  while(y>0)
  {
  fans=(fans*x)%mod;
  x=(x*x)%mod;
  y=y>>1;
  }
  return fans%mod;
  }
  int main()
  {
  ios::sync_with_stdio(0);cin.tie(0);
  ll n,r;
  cin>>n>>r;
  ll ans=1;
  for(ll i=r+n;i>n;i--)
  {
  ans=(ans*i)%mod;
  }
  cout<<ans<<endl;
  ll fans=1;
  for(ll i=2;i<=r;i++)
  {
  fans=(fans*i)%mod;
  }
  ans=(ans*(pow(fans,mod-2)))%mod;
  cout<<ans-1<<endl;
  return 0;
  }*/
ll nCrModpDP(ll n, ll r, ll p)
{
    // The array C is going to store last row of
    // pascal triangle at the end. And last entry
    // of last row is nCr
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1; // Top row of Pascal Triangle

    // One by constructs remaining rows of Pascal
    // Triangle from top to bottom
    for (ll i = 1; i <= n; i++)
    {
        // Fill entries of current row using previous
        // row values
        for (ll j = min(i, r); j > 0; j--)

            // nCj = (n-1)Cj + (n-1)C(j-1);
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

// Lucas Theorem based function that returns nCr % p
// This function works like decimal to binary conversion
// recursive function.  First we compute last digits of
// n and r in base p, then recur for remaining digits
ll nCrModpLucas(ll n, ll r, ll p)
{
    // Base case
    if (r==0)
        return 1;

    // Compute last digits of n and r in base p
    ll ni = n%p, ri = r%p;

    // Compute result for last digits computed above, and
    // for remaining digits.  Multiply the two results and
    // compute the result of multiplication in modulo p.
    return (nCrModpLucas(n/p, r/p, p) * // Last digits of n and r
            nCrModpDP(ni, ri, p)) % p;  // Remaining digits
}
int main()
{
    ll n,r;
    cin>>n>>r;
    cout<<nCrModpLucas(n+r,r,1000000+3)-1<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,i,j,s1=0,s2=0,r;
    int a[35],b[35];
    cin>>n;
    for(i=0; i<n; i++)
    {cin>>a[i];
    s1+=a[i];
    }
    for(i=0; i<n; i++)
    {cin>>b[i];
    s2+=b[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    for(i=0; i<n; i++)
    {
        if(abs(a[i]-b[i])>1)
        {
            printf("NO\n");
            return 0;
        }
    }
    if(s2>s1)printf("NO\n");
    else printf("YES\n");
	return 0;
}


#include<iostream>
#include<cstdlib>
#include<vector>
#include<climits>
#include<cctype>
#include<map>
#include<list>
#include<cstdio>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<queue>
#include<fstream>
#include<sstream>
#include<set>
#include<iomanip>
#define L long long int
#define LD long double
#define pi 3.141592653589793238462643383
#define M 1000000007

using namespace std;

struct e
{
       LD t;
       string w;
};

bool com(struct e e1,struct e e2)
{
     return e1.t<e2.t;
}

int main()
{
    int tc=1,i,ln,m;
    LD x,y,z,a,b,m1,vx,vy,vz,t,tx,tz;
    while(tc--)
    {
              cin>>a>>b>>m1;
              cin>>vx>>vy>>vz;
              x=a/2;
              y=m1;
              z=0;
              /*ln=0;
              while(1)
              {
                  struct e t[5];
                  if(vx!=0)
                  t[0].t=(a-x)/vx;
                  else
                  t[0].t=1000000000.0;
                  t[0].w="x";
                  if(vx!=0)
                  t[1].t=-x/vx;
                  else
                  t[1].t=1000000000.0;
                  t[1].w="x";
                  if(vz!=0)
                  t[2].t=(b-z)/vz;
                  else
                  t[2].t=1000000000.0;
                  t[2].w="z";
                  if(vy!=0)
                  t[3].t=-y/vy;
                  else
                  t[3].t=1000000000.0;
                  t[3].w="y";
                  if(ln!=0&&vz!=0)
                  t[4].t=-z/vz;
                  else
                  t[4].t=1000000000.0;
                  t[4].w="z";
                  for(i=0;i<5;i++)
                  if(t[i].t<=0)
                  t[i].t=1000000000.0;
                  sort(t,t+5,com);
                  for(i=0;i<5;i++)
                  cout<<t[i].t<<" "<<t[i].w<<"\n";
                  if(t[0].w=="x")
                  {
                                 x=x+vx*t[0].t;
                                 y=y+vy*t[0].t;
                                 z=z+vz*t[0].t;
                                 vx=-vx;
                  }
                  else if(t[0].w=="z")
                  {
                                 x=x+vx*t[0].t;
                                 y=y+vy*t[0].t;
                                 z=z+vz*t[0].t;
                                 vz=-vz;
                  }
                  else
                  {
                                 x=x+vx*t[0].t;
                                 y=y+vy*t[0].t;
                                 z=z+vz*t[0].t;
                                 break;
                  }
                  ln++;
                  //cout<<x<<" "<<y<<" "<<z<<"\n";
              }*/
              t=abs(y/vy);
              tx=abs(2*a/vx);
              //cout<<tx<<"\n";
              m=(int)(t/tx);
              //cout<<tx<<"\n";
              tx=t-m*tx;
              //cout<<tx<<"\n";
              x=x+vx*tx;
              while(!(x>=0&&x<=a))
              {
                                  if(x>a)
                                  {
                                         x=a-(x-a);
                                  }
                                  if(x<0)
                                  {
                                         x=-x;
                                  }
              }
              if(vz!=0)
              {
              tz=abs(2*b/vz);
              m=(int)(t/tz);
              //cout<<tz<<"\n";
              tz=t-m*tz;
              //cout<<tz<<"\n";
              z=z+vz*tz;
              if(z>b)
              z=b-(z-b);
              }
              //cout<<x<<" "<<z<<"\n";
              //printf("%Lf %Lf\n",(LD)x,(LD)z);
              cout<<fixed;
              cout<< setprecision (12)<<x<<" "<<z<<"\n";
    }
    return 0;
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define mod 1000000000 + 7
using namespace std;
typedef long long ll;
const int N = 505;
ll dp[N],f[N],mod;
int n;
int main(){
	cin>>n;
	dp[0] = 1;
	for( int i = 1; i <= n; i++ ){
		memset(f,0,sizeof(f));
		for( int j = 0; j <= n; j++ )
			for( int k = 0; k+j <= n; k++ )
				f[j+k] = (f[j+k]+dp[j]*dp[k])%mod;
		memset(dp,0,sizeof(dp));
		for( int j = 0; j <= n; j++ )
			dp[j] = (f[j-1]+f[j+1]*(j+1)*j+f[j]*(2ll*j+1))%mod;
	}
	cout<<dp[1]<<endl;
	return 0;
}


#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
string s, s2;
cin>>s>>s2;
int n=0, m, sum=1, i=0, j;
j=s2.length();
while (j>=0){
if(s[i]!=s2[n]){
n++;
j--;
}
if(s[i]==s2[n]){
n++;
i++;
j--;
sum++;
}
}
if(sum>s2.length())
sum=s2.length();
cout<<sum;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<string>v;
void swap(char *x, char *y)
{
    char temp;
    temp = *x;
    *x = *y;
    *y = temp;
}
void permute(char *a, int l, int r)
{
   int i;
   if (l == r)
    {
        string s=a;
        v.push_back(s);
    }
   else
   {
       for (i = l; i <= r; i++)
       {
          swap((a+l), (a+i));
          permute(a, l+1, r);
          swap((a+l), (a+i)); //backtrack
       }
   }
}
int main()
{
   char a[101],b[101];
   cin>>a>>b;
   string str=b;
   long long x=atoi(str.c_str());
   int n=strlen(a);
   permute(a,0,n-1);
   long long ans=-1;
   for (int i=0;i<v.size();i++)
   {
       long long y=atoi(v[i].c_str());
       if (y<x)
       {
           if (y>ans)ans=y;
       }

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


#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
	scanf("%d",&n);
	for(int i=0;i*1234567<=n;i++)
	for(int j=0;j*123456<=n;j++)
	if(n%(i*1234567+j*123456)%1234==0){printf("YES\n");return 0;}
	printf("NO\n");
	return 0;
}


#include<iostream>
using namespace std;
int main(){ long long n,m,a,i;
 scanf("%lld %lld %lld",&n,&m,&a);
long long int total=n*m;
long long int tile=a*a;
long long int sum=0;
i=1;
if(tile>total){
  cout<<i;
  return i;}
while(total>sum){
  sum+=tile;
  if(sum==total){break;}
  ++i;
}

cout<<i<<endl;
}


#include <iostream>
using namespace std;
int main()
{
    long long int maxw, maxh, ratw, rath;
    cin >> maxw >> maxh >> ratw >> rath;
    for ( int i = min( ratw, rath ); i >= 1; i-- )
    {
        if ( ratw % i == 0 && rath % i == 0 )
        {
            ratw = ratw / i;
            rath = rath / i;
            i = 0;
        }
    }
    long long int timew = maxw / ratw, timeh = maxh / rath;
    cout << min( timew, timeh );
}


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

int main(void){
  int num_chars;
  cin >> num_chars;
  string theString;
  cin >> theString;
  char temp;
  int operations = 0;
  int longest = 1;
  for (size_t i = 0; i < num_chars; i++) {
    temp = theString[i];
    if(temp == theString[0]){
      bool willCopy = true;
      int length = 0;
      for (size_t j = 0; i + j < theString.length() && i!=0 && j < i; j++) {
        if(theString[i+j]!=theString[j]){
          willCopy = false;
        }
        length++;
      }
      if(willCopy && longest < length && j = i-1){
        longest = length;
      }
    }
  }
  cout << num_chars - (longest - 1) << endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
double a[10000], x, ans;
int n, k, y;

int main()
{
    cin >> n >> k;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        x += a[i];
    }
    y = round(x / n);
    for(ans = 0; y < k; ans++)
    {
        a[n] = k;
        n++;
        x += k;
        y = round(x / n);
    }
    cout << ans;
    return 0;
}


#include <cstdio>

int w, m;
bool dt;

bool f(int x, int l, int r)
{
    if( dt || (l && ( l == r )) ) return dt = true;
    if( x > w*m ) return false;
    return f(x*w, l+x, r) || f(x*w, l, r+x) || f(x*w, l, r);
}

int main()
{
    scanf("%d%d", &w, &m);
    puts( f(1, 0, m) ? "YES":"NO" );
}


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

int main() {
    int n,m;
    cin >> n >> m;
    if (n<m) {
        cout << -1 ;
        return 1;
    }

    int temp = m;
    n -=m;

    int count = (n/2)- (n/2)%m;
    temp += ((n/2)%m)*2 + n%2;
    if (temp > 2*m) count +=2*m;
    else if (temp >0) count += m;

    cout << count << endl;

 }


#include <bits/stdc++.h>

using namespace std;

typedef double db;
typedef long long ll;
typedef pair<ll, ll> pii;
const ll mINF = 1000 * 1000 * 1000 + 9;
const db ebs = 0.000001;

int main()
{
    /*
    freopen("", "r", stdin);
    freopen("", "w", stdout);
    */

    ll kol_vo, del;
    cin >> kol_vo >> del;
    vector<pair<ll, bool> > v;
    v.push_back({0, false});
    for(ll c=10; c<100; c++)
        if(c == (c%10)*10+c/10)v.push_back({c, true});
    ll j = 0, now = 1000, last = 10, p = 1;
    while(v.size()-p < kol_vo){
        ll dop = 0;
        for(ll c=j; c<v.size(); c++){
            for(ll i=0; i<=9; i++){
                if(i == 0){
                    v.push_back({i*now+v[c].first*(now/100LL)+i, false});
                    p++;
                }
                else v.push_back({i*now+v[c].first*(now/100LL)+i, true});
                dop++;
            }
        }
        j = last;
        last += dop;
        now*=100;
    }
    ll sum=0, n=0, c=0;
    while(n < kol_vo){
        if(v[c].second){
            sum += v[c].first;
            sum %= del;
            n++;
        }
        c++;
    }
    cout << sum;
    return 0;
}


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

int twoPows[8] = {2,4,8,16,32,64,128,256};

int findPow(int n){
	int answer;
	for (int i = n; i > 0; --i){
		for(int j = 0;j < 8;j++){
			if(i == twoPows[j]){
				return i;
			}
		}
	}
}

int calc(int n,int b){
	if(n == 2){
		return (b * 2) + 1;
	}
	int play = findPow(n);
	return calc(n - play / 2,b) + (play * b) + (play / 2);
}

int main(int argc, char const *argv[])
{
	//freopen("input.in","r",stdin);
	int n,b,q;
	cin>>n>>b>>q;
	cout<<calc(n,b)<<" "<<q*n<<endl;
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 75 + 2;
int dp[(1 << 20) + 2][maxn],a[maxn][maxn],ans,len;
char s[maxn];
int main(){

	scanf("%d",&len);
	scanf("%s",s + 1);
	for(int i = 0; i <= len; ++i){
		for(int j = i + 1; j <= len; ++j){
			a[i][j] = (a[i][j - 1] << 1) + s[j] - '0';
		}
	}
	int tmp = min(len,20);
	for(int i = 0; i < len; ++i) dp[0][i] = 1;
	int t = (1 << tmp);
	for(int i = 0; i < t; ++i){
		for(int j = 0; j < len; ++j){
			if(dp[i][j])
			for(int k = j + 1; k <= len + 1; ++k){
				if(a[j][k] && a[j][k] <= 20){
					dp[i | (1 << (a[j][k] - 1))][k] += dp[i][j];
					dp[i | (1 << (a[j][k] - 1))][k] %= mod;
				}
			}
		}
	}
	for(int i = 1; i <= tmp; ++i){
		for(int j = 1; j <= len; ++j){
			if(dp[(1 << i) - 1][j]){
				ans += dp[(1 << i) - 1][j];
				ans %= mod;
			}
		}
	}
	printf("%d\n",ans);

	return 0;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
ll a,b;
string str;
ll n;
int main(){
    cin >> a >> b;
    cin >> str;
    n = str.size();
    ll rx,ry;
    rx = 0;
    ry = 0;
    for(int i = 0; i < n; i++){
        if(str[i] == 'R'){
            rx++;
        }else if(str[i] == 'D'){
            ry--;
        }else if(str[i] == 'L'){
            rx--;
        }else if(str[i] == 'U'){
            ry++;
        }
        if(a == rx && b == ry){
            cout << "Yes" << endl;
            return 0;
        }
    }
    if((a == rx && b == ry )|| (a == 0 && b == 0)){
        cout << "Yes"<< endl;
        return 0;
    }
    if(rx == 0 && ry == 0){
        cout << "No" << endl;
        return 0;
    }
    int P,Q;
    P = -1;
    Q = -1;
    ll x,y;
    if(rx && ry){
        P = a/rx-100;
        Q = b/ry-100;
        x = rx*min(P,Q);
        y = ry*min(P,Q);
        for(int k = 0; k < 202; k++){
            for(int i = 0; i < n; i++){
                if(a == x && b == y){
                    cout << "Yes" << endl;
                    return 0;
                }
                if(str[i] == 'R'){
                    x++;
                }else if(str[i] == 'D'){
                    y--;
                }else if(str[i] == 'L'){
                    x--;
                }else if(str[i] == 'U'){
                    y++;
                }
                if(a == x && b == y){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }else if(rx == 0){
        Q = b/ry-100;
        x = rx*Q;
        y = ry*Q;
        for(int k = 0; k < 202; k++){
            for(int i = 0; i < n; i++){
                if(a == x && b == y){
                    cout << "Yes" << endl;
                    return 0;
                }
                if(str[i] == 'R'){
                    x++;
                }else if(str[i] == 'D'){
                    y--;
                }else if(str[i] == 'L'){
                    x--;
                }else if(str[i] == 'U'){
                    y++;
                }
                if(a == x && b == y){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }else if(ry == 0){
        P = a/rx-100;
        x = rx*P;
        y = ry*P;
        for(int k = 0; k < 202; k++){
            for(int i = 0; i < n; i++){
                if(a == x && b == y){
                    cout << "Yes" << endl;
                    return 0;
                }
                if(str[i] == 'R'){
                    x++;
                }else if(str[i] == 'D'){
                    y--;
                }else if(str[i] == 'L'){
                    x--;
                }else if(str[i] == 'U'){
                    y++;
                }
                if(a == x && b == y){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


//Md. Ahsan Kabir Shohagh
#include<bits/stdc++.h>
using namespace std;
#define sz 100000
#define pb(a) push_back(a)
#define ll long long
#define ull unsigned long long
#define fread freopen("input.txt","r",stdin)
#define fwrite freopen("output.txt","w",stdout)
#define inf (1LL<<29)
#define mem(abc,z) memset(abc,z,sizeof(abc))
#define PI acos(-1)
int dp[1150][105],v1,v2,t,d,mx;
int rec(int speed,int curTime,int val){
   //mx=max(mx,val);
   if(curTime>t || speed<0) return -inf;
   if(curTime==t){
     //if(speed==v2) cout<<speed<<" "<<curTime<<endl;
     return (speed==v2)?val:-inf;
   }
   int &ret=dp[val][curTime];
   if(ret!=-1) return ret;
   ret=0;
   for(int i=max(speed-d,1);i<=speed+d;i++){
      ret=max(ret,rec(i,curTime+1,i+val));
   }
   return ret;
}
int main(){
   int ans;
   //cout<<inf<<endl;
   mem(dp,-1);
   mx=0;
   cin>>v1>>v2>>t>>d;
   ans=rec(v1,1,v1);
   cout<<ans<<endl;
   return 0;
}
/*
100 100
100 10
*/


#include "library.h"
using namespace std;

int n,m;
int tt[61][61][61];
int agg[61][61];
int inv[150];
const int mod = 1000000007;

void solve()
{
    for (int i = 1; i <= 140; i++) inv[i] = modInv(i, mod);

    re(n,m);

    for (int ops = 0; ops <= n; ops++) {
        int mc = ops;
        tt[ops][0][0] = 1;
        for (int cutl = 0; cutl < ops; cutl++) {
            int cut = cutl+1;

            for (int toto = cutl*2; toto <= ops-1; toto++) {
                long long poss = 0;
                for (int left = cutl; left <= toto-cutl; left++) {
                    if (!tt[left][cutl][left]) break;
                    int right = toto-left;
                    long long right_poss = (2ll * agg[right][cutl+1] + tt[right][cutl][right]) % mod;
                    long long bposs = (tt[left][cutl][left] * right_poss) % mod;
                    poss = (bposs+poss)%mod;
                }

                for (int po = ops-toto-1; po >= 0; po--) {
                    for (int pc = mc-cut; pc >= 0; pc--) {
                        int lim = min( (mc-pc)/cut, (ops-po)/(toto+1) );

                        int comb = (poss * 1ll * tt[ops][pc][po]) % mod;

                        for (int hm = 1; hm <= lim; hm++) {
                            int& dest = tt[ops][pc + cut*hm][po + (toto+1)*hm];
                            dest = (dest + comb) % mod;

                            comb = (comb * 1ll * (poss+hm)) % mod;
                            comb = (comb * 1ll * inv[hm+1]) % mod;
                        }
                    }
                }
            }
        }

        for (int cut = ops; cut >= 0; cut--) {
            agg[ops][cut] = (tt[ops][cut][ops] + agg[ops][cut+1]) % mod;
        }
    }

    ps(tt[n][m-1][n]);
}


#define fi freopen("../../../../../Desktop/input.txt", "r", stdin);
#define fo freopen("../../../../../Desktop/output.txt", "w", stdout)
#define fio fi fo
#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
#define   max(a,b)     (a>b?a:b)
#define   min(a,b)     (a>b?b:a)
#define INF 99999999
typedef long long int ll;
const long long int N = 1000000000000005;
int n;
vector< ll >vi;

void pre() {
	for (int i = 1; i*8*1LL < N; i++)
		for (int j = 2; i*j*j*j*1LL < N; j++)vi.push_back(i*(j*j*j*1LL));
	sort<vector<ll>::iterator>(vi.begin(),vi.end());
}

int main()
{
	//fio;

	pre();
	cin >> n;

	//for (int i = 0; i < vi.size(); i++)cout << vi[i] << " ";
	//cout << "d";
	n--;

	if (n == 0)cout << vi[0];
	else {

		if (vi[n - 1] == vi[n] | vi[n] == vi[n + 1])cout << -1;
		else cout << vi[n];

	}
	//cin >> n;
	return 0;
}


// A. Keyboard.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s = "qwertyuiop", z = "asdfghjkl;", x = "zxcvbnm,./"; int c;
    char w; cin >> w;
    if (w == 'R')
    {
        c = -1;
    }
    else
        c = +1;

	string k, m; cin >> k; int q = 0;
	for (int i = 0; i < k.size(); i++)
	{

		{
			for (int j = 0; j < s.size(); j++)
			{
				if (k[i] == s[j])
				{
					m[i] = s[j +c];

					break;
				}
			}
            for (int f = 0; f < z.size(); f++)
            {
                if (k[i] == z[f])
                {
                   // cout << k[i] << " " << s[j] << "\n";
                    m[i] = z[f + c];

                    break;
                }
            }
            for (int d = 0; d < x.size(); d++)
            {
                if (k[i] == x[d])
                {
                    m[i] = x[d + c];
                    break;
                }
            }

		}

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


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <array>
#include <deque>
#include <string>
#include <forward_list>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
#include <iomanip>
#include <fstream>
#include <bitset>
#define Endl endl;
using namespace std;
typedef long long ll;
typedef long double ld;
ll n,m;
vector<int>g;
vector<int>h;
ll ans;
map<ll,ll>t;
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    //  ifstream fin("sight.in");
    //  ofstream fout("sight.out");
    cin>>n>>m;
    g.push_back(0);
    h.push_back(0);
    int r=0,t=0;
    for(int i=3; i; i+=6){
        g.push_back(i);
        r++;
        if(r==m){
            break;
        }
    }
    for(int i=2; i; i+=2){
        if(i%3==0){
            continue;
        }
        h.push_back(i);
        t++;
        if(t==n){
            break;
        }
    }

    for(int i=6; i<max(g[g.size()-1],h[h.size()-1]); i+=6){
        if(g[g.size()-1]>h[h.size()-1]){
            g.pop_back();
        }
        else{
            h.pop_back();
        }
    }

    cout<<max(g[g.size()-1],h[h.size()-1])<<endl;
}


#include<bits/stdc++.h>
#define INF 9223372036854775807LL//18446744073709551615LL
using namespace std;
  long long int xx,yy,ax,ay,bx,by,xs,ys,t;
vector< pair<  long long,  long long> >v;
//map<pair<  long long,   long long>,int>mp;
int size = 0;
struct node
{
	  long long x;
	  long long y;
	  long long t;
	int total;
	int mask;
};
int main()
{
	scanf("%lld %lld %lld %lld %lld %lld",&xx,&yy,&ax,&ay,&bx,&by);
	scanf("%lld %lld %lld",&xs,&ys,&t);
	v.push_back(make_pair(xx,yy));
	//mp[make_pair(xx,yy)] = 0;
	int flag = -1;
	for(int i=1;;i++)
	{
		  long long x = v[i-1].first;
		  long long y = v[i-1].second;
		if((INF-bx)/ax < x || (INF-by)/ay < y)
			break;
		v.push_back(make_pair(ax*x + bx, ay*y + by));
		//printf("%lld %lld\n",ax*x +bx , ay*y + by );
		//mp[make_pair(ax*x + bx, ay*y + by)] = i;
		if(ax*x + bx == xs && ay*y + by == ys  )
		{
			flag = i;
		}
		size++;
	}
	queue<node>q;
	if(flag == -1){
		q.push((node){xs,ys,0LL,0LL,0LL});
	}
	else
	{
		q.push((node){xs,ys,0LL,1LL,(1LL<<flag)});
	}
	int ans = 0;
	while(!q.empty())
	{
		node pp = q.front();
		q.pop();
		ans = max(pp.total,ans);
		for(int i=0; i<size; i++)
		{
			if( (pp.mask & (1LL<<i)) )
			{
				continue;
			}
			else
			{
				  long long newT = pp.t + abs(v[i].first - pp.x) + abs(v[i].second - pp.y);
				if( newT > t)
					continue;

				int newMask = (pp.mask | (1LL<<i));

				q.push((node){v[i].first,v[i].second,newT,pp.total+1, newMask});
			}
		}
	}
	printf("%d\n",ans );
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define all(x) x.begin(),x.end()
const int N =1e4+5;
ll M =1e9+7;
ll po (ll x, ll p)
{
  if(p==0)
    return 1;
  if(p%2==0)
    return po((x*x),p/2);
  else
  return (po(x,p-1)*x);
}
ll dp[20][1<<20][2];
string s1,s2;
int n;
ll rec(int idx,int msk,bool k)
{
  if(idx ==n)
    return 0;
  ll & ret = dp[idx][msk][k];
  if(ret!=-1)
    return ret;
  ret =-1;
  ll tmp;
  for(int i =0;i<n;i++)
  {
    if(idx==0 && s1[i]=='0')
      continue;
    if(1<<i & msk)
      continue;
    if(s1[i]==s2[idx])
    {
      tmp = rec(idx+1,msk| (1<<i),k);
      if(tmp!=-1)
       ret=max(ret,tmp+(po(10,n-idx-1)*(s1[i]-'0')));
    }
    if(s1[i]<s2[idx])
    {
      tmp = rec(idx+1,msk| (1<<i),1);
      if(tmp!=-1)
        ret=max(ret,tmp+(po(10,n-idx-1)*(s1[i]-'0')));
    }
    if(s1[i] > s2[idx])
      {
        if(k)
        {
          tmp = rec(idx+1,msk| (1<<i),k);
          if(tmp!=-1)
            ret=max(ret,tmp+(po(10,n-idx-1)*(s1[i]-'0')));
        }
      }

  }
  return ret;
}
int main()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #else
  #endif
  memset(dp,-1,sizeof dp);
  cin>>s1>>s2;
  sort(all(s1));
  n=s1.size();
  if(s1.size()<s2.size())
    cout<<s1<<endl;
  else
    cout<<rec(0,0,0)<<endl;

}


#include <bits/stdc++.h>

using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define repd(i, a, b) for(int i = (a); i > (b); i--)
#define forRev(it, a) for(__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define sz(a) (int)(a).size()
#define bc(n) __builtin_popcountll(n)

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int N = 1000000 + 7;
const int M = 9;
const int inf = 1e9 + 7;
const long long linf = 1e18 + 7;
const double pi = acos(-1);
const double eps = 1e-7;
const bool multipleTest = 0;

int lt[N], invlt[N];

int inverse(int x, int n){
    int r = n, newr = x;
    int t = 0, newt = 1;
    while (newr > 0){
        int q = r / newr;

        int tmp = newr;
        newr = r % newr;
        r = tmp;

        tmp = newt;
        newt = t - q * newt;
        t = tmp;
    }
    if (t < 0) t += n;
    return t;
}

int C(int n, int k) {
    return (ll) lt[n] * invlt[n - k] % inf * invlt[k] % inf;
}

ll pw(ll x, ll k) {
    if (!k) return 1;
    else if (k & 1) return pw(x, k - 1) * x % inf;
    ll tmp = pw(x, k / 2);
    return tmp * tmp % inf;
}

ii extended_eclid(int a, int b) {
    int s0 = 1, t0 = 0;
    int s1 = 0, t1 = 1;
    while (b > 0) {
        int q = a / b;
        int tmp = 0;
        tmp = s1; s1 = s0 - q * s1; s0 = tmp;
        tmp = t1; t1 = t0 - q * t1; t0 = tmp;
        tmp = b; b = a - q * b; a = tmp;
    }
    return mk(s0, t0);
}

void init() {
    lt[0] = invlt[0] = 1;
    rep(i, 1, N) {
        lt[i] = (ll) lt[i - 1] * i % inf;
        invlt[i] = inverse(lt[i], inf);
    }
}

ll dp[N][N];

ll F[N];

void solve() {
    init();
    int n, m;
    cin >> n >> m;
    ll res = pw(2 * (n + 1), m) * (n + 1 - m) % inf * inverse(n + 1, inf) % inf;
    cout << res << '\n';
}

int main() {
#ifdef _LOCAL_
    freopen("in.txt", "r", stdin);
    //    freopen("out.txt", "w", stdout);
#endif

    int Test = 1;
    if (multipleTest) {
        cin >> Test;
    }
    for(int i = 0; i < Test; ++i) {
        solve();
//        test();
    }

#ifdef _LOCAL_
    cout<<"\n" << 1.0 * clock() / CLOCKS_PER_SEC <<endl;
#endif
}


#include<bits/stdc++.h>
#define MAXN 50000050
using namespace std;
bool ok[MAXN];int su[MAXN];int tail=0,tail1=0;
int p,y;
int main()
{
	scanf("%d%d",&p,&y);
	for(register int i=1;i<=y;i++)ok[i]=1;
	ok[0]=ok[1]=0;tail=tail1=0;
	for(register int i=2;i<=y;i++)
	{
		if(ok[i])su[tail++]=i;
		if(i<=p&&ok[i]){tail1++;}
		for(register int j=0;j<tail1&&i*su[j]<=y;j++)//ֻ��<=p������ɸ
		{
			ok[i*su[j]]=0;
			if(i%su[j]==0)
			break;
		}
	}
	int ans=-1;
	if(tail!=0)for(int i=tail-1;i>=0;i--)if(su[i]>p){ans=su[i];break;}
	printf("%d\n",ans);
	return 0;
}


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

const int N=100100;

bool isPrime(int a){
    for(int i=2;i<=ceil(sqrt(a));i++){
        if(a%i==0) return false;
    }
    return true;
}
int main(){
    int a[3000]={2},sz=1,ans=0;
    for(int i=3;i<=3000;i++)
        if(isPrime(i)) a[sz++]=i;
    int num,count=0,c;
    cin>>num;
for(int i=1;i<=num;i++){
        count=0;
        for(int j=0;i>=a[j];j++){
            if(i%a[j]==0) count++;
            if(count==3) break;
        }
        if(count==2) ans++;
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define lld unsigned long long int
#define vec vector<lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
lld xyz(lld a, lld b)
{
    lld ans=1;
    lld i;
    for(i=1;i<=b;i++)
        ans*=a;
    return ans;
}
int main() {messi

        lld n,m,k,i,j,p,q,x,y,ans=0,cnt=0;string s;bool flag=false;
        cin>>x>>y;
		vec r,l;
		while(x>0){
			l.pb(x%2);
			x/=2;
		}
		while(y>0){
			r.pb(y%2);
			y/=2;
		}
		if(r.size()>l.size()){
				ans=1;
				for(j=1;j<=r.size();j++){
					ans*=2;
				}
				ans--;
			}
		else{
			vec rr;
			for(i=r.size()-1;i>=0;i--){
				if(flag==false){
					if(l[i]==1){
						if(r[i]==1)
							rr.pb(0);
						else
							rr.pb(1);
					}
					else{
						rr.pb(1);
						flag=true;
					}
				}
				else
					rr.pb(1);
			}
			k=0;ans=0;
			for(i=rr.size()-1;i>=0;i--){
				ans+=rr[i]*xyz(2,k);
				k++;
			}
		}
		cout<<ans<<endl;
	return 0;
}
/*  CODED BY:-
           __        __
 /\   /\  |__)  /\  |  \ |__| \ /  /\
/~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\

*/


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

int main()
{
	int w, b; cin >> w >> b;
	double ans = 0;

	vector<pair<double, pair<int, int> > > v;
	pair<double, pair<int, int> > love;
	love.first = 1; love.second.first = w; love.second.second = b;
	v.push_back(love);

	set<int> p;

	while(p.size() != v.size())
	{
		//cout << p.size() << ' ' << v.size() << '\n';
		for(int i = 0; i < v.size(); i++)
			if(p.find(i) == p.end())
			{
				double a = v[i].second.first;
				double b = v[i].second.second;
				//cout << a << ' ' << b << '\n';

				if(a >= 1)
				{
					double aux = a/(a+b);
					//cout << ans << ' ' << v[i].first * 	aux << '\n';
					ans += v[i].first * aux;
				}

				if(b-1 > 0)
				{
					double aux = b/(a+b);
					v[i].first *= aux;
					v[i].second.second--;
				}
				else
					p.insert(i);
			}

		int qtd = v.size();
		for(int i = 0; i < qtd; i++)
			if(p.find(i) == p.end())
			{
				double a = v[i].second.first;
				double b = v[i].second.second;

				double aux = b/(a+b);
				v[i].first *= aux;
				double old = v[i].first;

				v[i].second.second -= 1; b-=1;
				if(v[i].second.second > 0)
				{
					//if(v[i].second.first == 5 && v[i].second.second == 1)
						//cout << "hi\n";
					aux = b/(a+b);
					v[i].first *= aux;
					v[i].second.second -= 1;
					if(v[i].second.second < 0)
						p.insert(i);
				}
				else if(v[i].second.second == 0)
					p.insert(i);

				if(v[i].second.first > 1)
				{
					aux = a/(a+b);
					old *= aux;
					love.first = old;
					love.second.first = v[i].second.first-1;
					love.second.second = b;
					v.push_back(love);
				}

		}

	}

	printf("%.9lf\n", ans);

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define INF 2000000000
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>
#define si set<int>
#define msi map<string,int>
#define REP(i,a,b) for(int i=int(a);i<=int(b);i++)
#define TRvi(c,it) for(vi::iterator it=(c).begin();it!=(c).end();it++)
#define TRvii(c,it) for(vii::iterator it=(c).begin();it!=(c).end();it++)
#define TRmsi(c,it) for(msi::iterator it=(c).begin();it!=(c).end();it++)

using namespace std;

ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	ll p=power(a,b/2);
	p*=p;
	if(b%2)
		p*=a;
	return p;
}

int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ll n,s;
    cin >> n >> s;
    int ind=0;
    if(n<=s)
    {
    	cout << 0;
    	return 0;
    }
   	ll arr[19];
   	ll temp=n;
    while(ind<=18)
    {
    	arr[ind]=temp%10;
    	temp/=10;
    	ind++;
    }
    ll pre[19];
    ll no[19];
    pre[0]=0;
    ll prev=0;
   	temp=s;
    REP(i,1,17)
    {
    	prev*=10;
    	prev+=9;
    	no[i]=prev;
    	pre[i]=prev*9+pre[i-1];
    }
    int flag=0;
    ll sum=0;
    for(int i=18;i>=0;i--)
    {
    	if(i>0)
    	{
    		char ch='n';
	    	REP(j,0,9)
	    	{
	    		if(temp-j*no[i]<=pre[i-1])
	    		{
	    			sum+=j*power(10,i);
	    			temp-=j*no[i];
	    			ch='y';
	    			break;
	    		}
	    	}
	    	if(ch=='n')
	    	{
	    		cout << 0;
	    		return 0;
	    	}
	    }
	    else
	    {
	    	if(temp>0)
	    	{
	    		cout << 0;
	    		return 0;
	    	}
	    }
    }
   	cout << max(0,n-sum+1);
}


/*
    AABRA KA DABRA.. !!
*/
#include "bits/stdc++.h"
using namespace std;
typedef long double ld;
#define int long long
#define RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(i=0; i <n; i++)
#define repv(i,k,n) for(int i=k; i<=n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define endl '\n'
#define deb(x) cout<<#x<<" = "<<x<<endl
#define gcd __gcd
#define inf LLONG_MAX
#define minf LLONG_MIN
const int mod = (int)(1e9+7);

int power(int x,int n)
{
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}

int dx[]    =  {-1, 0, 1,  0, -1, -1, 1,  1};
int dy[]    =  { 0, 1, 0, -1, -1,  1, 1, -1};
const int maxn = 100005;

/*
    ╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩╦═╩═╦═╩═╦═╩═╦═╩═╦═╩╦═╩═╦═╩═╦═╩═╦═╩═╦═╩╦═╩═╦═╩═╦
*/

void solve()
{
    int n,i,j,k,m;
    int ar[4][4];
    rep(i,4)    rep(j,4)    cin>>ar[i][j];

    rep(i,4)
    {
        if(ar[i][3]==1)
        {
            if(!ar[i][0] && !ar[i][1] && !ar[i][2])
            {
                if(!ar[(i+2)%4][1] && !ar[(i+1)%4][0] && !ar[(i+3)%4][2])
                {
                    cout<<"NO";    exit(0);
                }
            }
        }
    }
    cout<<"YES";
}
signed main()
{
    RAGE;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int t=1;
    //  cin>>t;
    while(t--)
        solve();

    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename T>
void rin(T &t)
{t=0;int k=1;char c=getchar();while(!isdigit(c)){if(c=='-')k=-1;c=getchar();}while(isdigit(c)){t=t*10+c-'0';c=getchar();}t*=k;}
const int maxn=2e5+5;
vector<int>g[maxn];
int main()
{
	int n,k,MAX=0;
	cin>>n>>k;
	int x;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x>MAX)MAX=x;
		int cnt=0;
		while(x>=0)
		{
			g[x].push_back(cnt);
			x>>=1;
			cnt++;
		}
	}
	long long ans=0;
	for(int i=MAX;i>=0;i--)
	if(g[i].size()>=k)
	{
		sort(g[i].begin(),g[i].end());
		for(int j=0;j<k;j++)ans+=g[i][j];
		break;
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector <int> a;
int n;
int main()
{
    cin >>n;
    for (int i = 1 ; i <= n; ++i)
    {
       if (i > 9)
       {
           while(i)
           {
               a.push_back(i%10);
               i/=10;
           }
       }
       else a.push_back(i);
    }
    sort(a.begin(),a.end());
    for (int i = 0 ; i < a.size() ; ++i)
    {
        if (i == n-1)
           {
            cout << ++i << endl;
            break;
           }

    }
return 0;
}


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

vector< pair< pair< int, int >, int > > dis;
pair< pair< int, int >, int > x;
int n;

void dfs( pair< int, int >, int );

int main()
{
    cin >> n;
    pair< int, int > p;
    p.first = 1;
    p.second = 1;
    dfs( p, 0 );
    unsigned min = -1;
    for( unsigned i = 0; i < dis.size(); i++ )
        if( dis[i].first.first == n || dis[i].first.second == n )
            if( dis[i].second < min )
                min = dis[i].second;
    cout << min << endl;
    return 0;
}

void dfs( pair< int, int > p, int d )
{
    x.first = p;
    x.second = d;
    dis.push_back( x );
    if( p.first > n || p.second > n )
        return;
    p.first += p.second;
    dfs( p, d + 1 );
    p.first -= p.second;
    p.second += p.first;
    dfs( p, d + 1 );
}


#include<bits/stdc++.h>
#define ll long long
#define ios ios_base::sync_with_stdio(false)
#define pii pair<int, int>
#define fs first
#define sc second

using namespace std;

const ll INF=(1ll<<62)-1;
const int M=1e5+5;

ll s,s1;
int ar[101];
 int main()
    {
        ios;
        int n,ans;
        cin>>n;
        for(int i=0;i<n;i++){
                cin>>ar[i];
                s+=ar[i];
        }
        sort(ar,ar+n);

        int m=ar[n-1];

        for(int i=m;;i++)
        {
            for(int j=0;j<n;j++)
            {
                s1+=(m-ar[j]);
            }

            if(s1>=s)
            {
                ans=i;
                break;
            }
        }

        cout<<ans<<endl;
    }


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
const int mod = 1000000007;
int ca[2000009];
int powe(int x)
{
	int tmp=2ll,res=1ll;
	while(x)
	{
		if(x&1){
			res=(res*tmp)%mod;
		}tmp=(tmp*tmp)%mod;
		x>>=1;
	}return res;
}
int cal(int k)
{
	if(k==1||k==2) return 1;
	else if(k<=2000008&&ca[k]) return ca[k];
	int ans=(int)powe(k-1)-1;
	for(register int i=2;i<=sqrt(k);i++)
	{
		if(k%i==0){
			ans-=cal(k/i);
			ans+=mod;
			if(i*i!=k){
				ans-=cal(i);
				ans+=mod;
			}
			ans%=mod;
		}
	}
	return ca[k]=ans;
}
int x,y;
int main()
{
//	freopen("seq.in","r",stdin);	freopen("seq.out","w",stdout);
	ios::sync_with_stdio(0);
	cin>>x>>y;
	ca[1]=1;
	ca[2]=1;
	if(y%x){
		cout<<0;
		return 0;
	}
	cout<<cal(y/x);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

const int MAXK = 2005;
const int MAXT = 205;
const int mod = 1000000007;

int dp[2][MAXK*MAXT];
int cum[MAXK*MAXT];

int k,t;
int a,b;

int main(){
	scanf("%d %d %d %d",&a, &b, &k, &t);
	for(int i = 0; i<=(4*k*t); i++) dp[0][i] = 0;
	dp[0][2*k*t] = 1;
	for(int j = 0; j<=4*k*t; j++) dp[0][j] += dp[0][j-1];
	for(int i = 1; i<=2*t; i++){
		for(int j = 0; j<=4*k*t; j++){
			dp[i%2][j] = ((j!=0?dp[i%2][j-1]:0) + dp[(i+1)%2][min(j+k,4*k*t)] - (max(j-k,0)!=0?dp[(i+1)%2][max(j-k,0)-1]:0))%mod;
		}
	}
	int req = 2*t*k - (a - b);
	int ans;
	if(req>4*k*t) ans = 0;
	else ans = (dp[0][4*k*t] - dp[0][max(0,min(4*k*t,req))])%mod;
	if(ans<0) ans += mod;
	printf("%d\n", ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n,c=0,k=1;
    unordered_set<long long> st;
    cin>>n;
    if(n%2!=0 || n<=4)
    {
        cout<<"0";
        return 0;
    }
    n=n/2;
    n--;
    while(k!=n)
    {
       if(st.find(k)!=st.end() || st.find(n)!=st.end())
       break;
       if(st.find(k)==st.end() && st.find(n)==st.end())
       {st.insert(k);
       st.insert(n);
       }
       k++;
       n--;
    }
    cout<<k-1;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a,b[5],c[5],contb=0,contc=0;
    cin >> a;
    for(int i=0;i<a;i++){
        cin >> b[i];
    }
    for(int i=0;i<a;i++){
        cin >> c[i];
    }
    for(int i=0;i<a;i++){
        if(c[i]!=0){
            contc+=c[i];
            contb+=b[i];
        }
    }
    if(contc!=contb){cout << "No";}
    else{cout << "Yes";}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int Int;
int main(){
Int n,k;
cin>>n>>k;
if(k==1){
    cout<<n<<endl;
    return 0;
}
unordered_map<Int,bool> m;
Int ans=n;
Int mans=n;
Int selected=1;
Int bit=0;
Int temp=ans;
m[n]=1;
while(temp>0){
    temp=temp>>1;
    bit++;
}
bit=bit-2;
Int last=n-1;
while(selected<k){
temp=ans;
while(bit>=0&&((temp>>bit)&1)==1){
    bit--;
    temp=ans;
}
if(bit>=0){
    bool done=false;
    while(!done){
    if(bit>=0){
    while(last>0&&(m[last]==1||((last>>bit)&1==0))){
        last--;
    }
    if(last>0){
    ans=ans^last;
    if(ans>mans){
    mans=max(ans,mans);
    last--;
    done=true;
    selected++;
    m[last]=1;
    last=n-1;
    bit--;
    }else{
    ans=mans;
    last--;
    }
    }else{
    last=n-1;
    bit--;
    }
    }else{
    cout<<mans<<endl;
    return 0;
    }
    }
}else{
cout<<mans<<endl;
return 0;
}
}
cout<<mans<<endl;
return 0;
}