#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<unordered_map>
#include<map>
#include<queue>
#include<algorithm>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef double db;
int main(){
	string a, b, c, d;
	cin>>a>>b>>c>>d;
	if(b[1]=='X') swap(b[0], b[1]);
	else if(a[0]=='X') swap(b[0], a[0]);
	else if(a[1]=='X') swap(a[0], a[1]), swap(b[0], a[0]);
	if(d[1]=='X') swap(d[0], d[1]);
	else if(c[0]=='X') swap(d[0], c[0]);
	else if(c[1]=='X') swap(c[0], c[1]), swap(d[0], c[0]);
	if(a[1]=='A') swap(a[0], a[1]);
	else if(b[1]=='A'){
		b[1]=a[1];
		a[1]=a[0];
		a[0]='A';
	}
	if(c[1]=='A') swap(c[0], c[1]);
	else if(d[1]=='A'){
		d[1]=c[1];
		c[1]=c[0];
		c[0]='A';
	}
	if(a==c&&b==d) puts("YES");
	else puts("NO");
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define y 2147483647
#define v 9223372036854775807
using namespace std;
int main()
{
	char c[105],*p;
	__int64 a;
	int l,i;
	while(scanf("%s",c))
	{
		l=strlen(c);
		if(l<20)
		{
			a=0;
			for(i=0;i<l;++i)
			{
				a*=10;
				a+=((int)c[i]-48);
			}
			if(a>=0&&a<=127) printf("byte\n");
			else if(a>=0&&a<=32767) printf("short\n");
			else if(a>=0&&a<=y) printf("int\n");
			else if(a>=0&&a<=v) printf("long\n");
			else printf("BigInteger\n");
		}
		else printf("BigInteger\n");
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
    char a[110]="127";
    char b[110]="-128";
    char c[110]="32767";
    char d[110]="-32768";
    char e[110]="2147483647";
    char f[110]="-2147483648";
    char h[110]="9223372036854775807";
    char i[110]="-9223372036854775808";
    char s[110];
    while(1){
        gets(s);
       // printf("%s  ",s);
    if(s[0]=='-'){
        if(strlen(s)<strlen(b))printf("byte\n");
        else if(strlen(s)==strlen(b))
            if(strcmp(s,b)<=0)printf("byte\n");
            else{printf("short\n");}
        else if(strlen(s)<strlen(d))printf("short\n");
        else if(strlen(s)==strlen(d))
            if(strcmp(s,d)<=0)printf("short\n");
            else{printf("int\n");}
            else if(strlen(s)<strlen(f))printf("int\n");
        else if(strlen(s)==strlen(f))
            if(strcmp(s,f)<=0)printf("int\n");
            else{printf("long\n");}
        else if(strlen(s)<strlen(i))printf("long\n");
        else if(strlen(s)==strlen(i))
            if(strcmp(s,i)<=0)printf("long\n");
            else{printf("BigInteger\n");}
        else printf("BigInteger\n");
    }
    else{
        if(strlen(s)<strlen(a))printf("byte\n");
        else if(strlen(s)==strlen(a))
            if(strcmp(s,a)<=0)printf("byte\n");
            else{printf("short\n");}
        else if(strlen(s)<strlen(c))printf("short\n");
        else if(strlen(s)==strlen(c))
            if(strcmp(s,c)<=0)printf("short\n");
            else{printf("int\n");}
            else if(strlen(s)<strlen(e))printf("int\n");
        else if(strlen(s)==strlen(e))
            if(strcmp(s,e)<=0)printf("int\n");
            else{printf("long\n");}
        else if(strlen(s)<strlen(h))printf("long\n");
        else if(strlen(s)==strlen(h))
            if(strcmp(s,h)<=0)printf("long\n");
            else{printf("BigInteger\n");}
        else printf("BigInteger\n");
    }
    }
    return 0;
}

/*rbdnrijsgecmonilchfrctcbnfcmmokkpnpfnedtjfdpkdsndd*/


#include<cstdio>
#include<cstring>
#define mod 1000000007
using namespace std;
#define MAXN 50
typedef long long ll;
ll ans[10],x,y,N;
ll getMod(ll a){
	if(a<0){
		while(a<0) a+=mod;
		return a%=mod;
	}
	else{
		if(a>=mod) return a%=mod;
		else return a;
	}
}
int main()
{
	while(scanf("%lld %lld",&x,&y)!=EOF){
		scanf("%lld",&N);
		ans[1]=getMod(x);
		ans[2]=getMod(y);
		ans[3]=getMod(y-x);
		ans[4]=getMod(-x);
		ans[5]=getMod(y);
		ans[6]=getMod(y+x);
		if(N%6==0) printf("%lld\n",ans[6]);
		else printf("%lld\n",ans[N%6]);
	}
	return 0;
 }


#include <bits/stdc++.h>

#define INF 1e9
#define EPS 1e-6
#define pb push_back
#define pause system("pause");
#define exit exit(0)

using namespace std;
using ll = long long;
using ull = unsigned long long;

int n;

ll get(string &s) {
	ll curr = 1;
	for (auto c : s) {
		curr *= c - '0';
	}

	return curr;
}

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

	cin >> n;

	string s = to_string(n);
	ll res = powl(9, (int)(s.length()) - 1);
	res = max(res, get(s));
	for (int i = (int)(s.length() - 1); i != 0; --i) {
		int j = i - 1;
		while (s[j] == '0') {
			--j;
		}

		--s[j];
		++j;
		while (j <= i) {
			s[j] = '9';
			++j;
		}

		res = max(res, get(s));
	}

	cout << res << endl;
	//pause;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	vector<char>v;
	int i=0;
	while (1)
	{
		char ch;
		cin>>ch;
		if (ch==NULL)
			break;
		else
			v.push_back(ch);
		i++;
	}
	for (int j=0;j<i;j++)
	{
		if (v[j]==NULL)
			break;
		if (j%2==0)
			cout<<".";
		else
		{
			if (v[j]>=90&&v[j]!='A'&&v[j]!='E'&&v[j]!='I'&&v[j]!='O'&&v[j]!='U')
				cout<<v[j]+32;
			else
			{
				if (v[j]!='a'&&v[j]!='e'&&v[j]!='i'&&v[j]!='o'&&v[j]!='u')
					cout<<v[j];
			}
		}
	}

	return 0;
}


/*
source: codeforce 49B-Missile Silos
time  : 2012.2.8
*/
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cstring>
using namespace std;
#define NMAX 100005
#define LMAX 100005
int getmax(string s){
	int ans=-1;
	for(int i=0;i<s.length ();i++){
		if(s[i]-'0'>ans)
			ans=s[i]-'0';
	}
	return ans;
}
int main()
{
	//freopen("in.txt","r",stdin);D
	//freopen("out.txt","w",stdout);
	for(string s,ss;cin>>s>>ss;){
		int base=max(getmax(s),getmax(ss));
	    if(s.length()>ss.length ())
			swap(s,ss);
		s=string(ss.length ()-s.length (),'0')+s;
		int jin=0;
		for(int i=ss.length ()-1;i>=0;i--){
			jin=jin+ss[i]+s[i]-'0'-'0';
			jin=jin/base;
		}
		if(jin)
			cout<<ss.length ()+1<<endl;
		else
			cout<<ss.length ()<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
 int main()
   {
     int n;
   	 scanf("%d",&n);
   	 long long a[n][n];
   	 for(int k=1;k<=n;k++)
   	  {
   	  	a[1][k]=1;
   	  	a[k][1]=1;
	  }
	 for(int i=2;i<=n;i++)
	  for(int j=2;i<=n;j++)
	   {
	   	 a[i][j]=a[i-1][j]+a[i][j-1];
	   }
	 printf("%d",a[n][n]);
   	 return 0;
   }


#include<iostream>
#include<sstream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<climits>
#include<iomanip>
#include<cstdlib>
#include<ctype.h>
#include<algorithm>
#include<numeric>
#include<vector>
#include<list>
#include<set>
#include<bitset>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#define N 1000000007
#define PI acos(-1)
#define EPS 1e-8
#define INF 2147483647
#define INIT(x,y) memset(x,y,sizeof(x))
#define INITip(x,y,n) memset(x,y,n*sizeof(int))
#define INITbp(x,y,n) memset(x,y,n*sizeof(bool))
#define Readfile(x) freopen(x,"r",stdin)
#define Writefile(x) freopen(x,"w",stdout)
typedef long long LL;
typedef long double LD;
using namespace std;

int main() {
    Readfile("in.txt");
    int n,k;
    cin>>n>>k;
    int d[n][k];
    char c;
    for(int i=0;i<n;++i) {
        for(int j=0;j<k;++j) {
            cin>>c;
            d[i][j]=c-'0';
        }
    }
    int ind[k];
    for(int j=0;j<k;++j) {
        int res=-1;
        for(int i=0;i<n;++i)
            res=max(res,d[i][j]);
        ind[j]=j;
    }
    int ans[n],mind=INF;
    while(next_permutation(ind,ind+k)) {
        INIT(ans,0);
        for(int i=0;i<n;++i)
            for(int j=0;j<k;++j)
                ans[i]=ans[i]*10+d[i][ind[j]];
        mind=min(mind,*max_element(ans,ans+n)-*min_element(ans,ans+n));
    }
    cout<<mind<<endl;
    return 0;
}


#include<cstdio>
#include<queue>
using namespace std;
struct node{int R,C,Time;};
char grid[9][9];
bool state[15][15][25];// 1 means there's a statues ,,, 0 means theres no statue
 //        R    C   Time
 bool vis[8][8][16];
 queue<node>Q;
 void PUSH()
 {
     node temp;
     int i,j;
    for(i=-1;i<=1;i++)
        for(j=-1;j<=1;j++)
        {
            if(Q.front().R+i <0 ||Q.front().R+i>=8 || Q.front().C+j<0|| Q.front().C+j>=8 )
                continue;

            temp.R=Q.front().R+i; temp.C=Q.front().C+j; temp.Time=Q.front().Time+1;
            Q.push(temp);
            temp.R=Q.front().R+i; temp.C=Q.front().C+j; temp.Time=Q.front().Time+2;
            Q.push(temp);
        }
        return;
 }
int main()
{
    int t,i,j;
     node temp;
    for(i=0;i<8;i++)
        scanf("%s",grid[i]);

    for(t=0;t<8;t+=2)
        for(i=0;i<8;i++)
            for(j=0;j<8;j++)
                if(i-(t/2)>=0 && grid[(i-(t/2))][j]=='S')
                    {state[i][j][t]=1; state[i][j][t+1]=1; }
    temp.R=7; temp.C=0; temp.Time=-1; Q.push(temp);
    while(!Q.empty())
    {
        if( (temp.Time==-1 &&  !state[Q.front().R][Q.front().C][Q.front().Time+1])|| (!vis[Q.front().R][Q.front().C][Q.front().Time] && !state[Q.front().R][Q.front().C][Q.front().Time]) && !state[Q.front().R][Q.front().C][Q.front().Time+1])
        {
            vis[Q.front().R][Q.front().C][Q.front().Time]=1;

        // printf("****(%d,%d) %d STATE:%d\n",Q.front().R,Q.front().C,Q.front().Time,state[Q.front().R][Q.front().C][Q.front().Time]);
            if(Q.front().R==0 && Q.front().C==7)
                { printf("WIN\n"); return 0;}

                PUSH();
        }
        Q.pop();
    }
    //if(state[Q.front().R][Q.front().C][Q.front().Time])
      printf("LOSE\n");
      return 0;
}


#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char s[101];
int n;
int dp(int z, int i, int j){
	int m = 0;
	if(s[i]==s[j]){
		m = max(m, 1+dp(z+1, i+1, j+1));
	}
	return m;
}
int main(){
	gets(s);
	n = strlen(s);
	int m = 0;
	for(int i = 0; i < n; i ++)for(int j = i+1; j < n; j ++){
		m = max(m, dp(0, i, j));
	}
	printf("%d\n", m);
	return main();
}


#include <iostream>

using namespace std;

int main()
{
	int n,k ;
	while(scanf("%d%d",&n,&k)){
		int a [n];
		for(int i=0;i < n; i++){
			scanf("%d",&a[i]);
		}
		int num = 0;
		for (int i = 0; i < n && a[i] <= k; i++) {
			num ++;
		}
		int sum = num;
		for (int i = n-1; i > num && a[i] <= k; i--) {
			sum ++;
		}
		printf("%d",sum);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string n;
string x, y;
int xx, yy, counter;
int main() {
	cin >> n;
	x = n[1]; x += n[0];
	y = n[3]; y += n[4];
	yy = stoi(y);
	xx = stoi(x);
	if (yy == xx)cout << 0;
	else if(xx>yy && xx < 60) cout << xx - yy;
	else {
		x[0] += '1' - '0';
		xx = stoi(x);
		if (xx == 42) {
			xx = 00;
		}
		else if (xx > 51) {
			if (!(xx % 5)) {
				counter = (10 - (x[0] - '0')) * 60;
				xx = 01;
			}
			else {
				counter = (10 - (x[0] - '0')) * 60;
				xx = 02;
			}
			/*
			06:51
			60 :51
			240

			16:50
			61:50
			02:50
			12+240
			252
			*/
		}
		cout << xx + (60 - yy) + counter;
	}
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,m,k,l;
    cin>>n>>m>>k>>l;
    int r,t;
    if(m>n)cout<<"Second";
    else cout<<"First" ;
}


#include <cstdio>
#include <cassert>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <utility>

const int INF = 0x3f3f3f3f;

const int N = 20;
const int A = 3;
int pos[N * N];
std::vector<int> g[A][N * N];
int dist[A][N * N][N * N];
std::pair<int, int> dp[N * N][A];
int n;

inline int enc(int i, int j)
{
	return i * n + j;
}

inline void add_edge(int ind, int i, int j, int k, int l)
{
	g[ind][enc(i, j)].push_back(enc(k, l));
}

void bfs(int v, std::vector<int> *g, int *dist)
{
	memset(dist, 0x3f, 4 * N * N);
	std::queue<int> q;
	dist[v] = 0;
	q.push(v);
	while (!q.empty()) {
		v = q.front();
		q.pop();
		for (int i = 0; i < (int)g[v].size(); ++i) if (dist[g[v][i]] == INF) {
			dist[g[v][i]] = dist[v] + 1;
			q.push(g[v][i]);
		}
	}
}

void prep()
{
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			for (int k = 0; k < n; ++k) for (int l = 0; l < n; ++l) if (i != k || j != l) {
				if (abs(k - i) == 2 && abs(l - j) == 1 || abs(k - i) == 1 && abs(l - j) == 2) add_edge(0, i, j, k, l);
				if (abs(k - i) == abs(l - j)) add_edge(1, i, j, k, l);
				if (i == k || l == j) add_edge(2, i, j, k, l);
			}
		}
	}
	for (int i = 0; i < A; ++i) for (int j = 0; j < n * n; ++j) bfs(j, g[i], dist[i][j]);
}

int main()
{
	scanf("%d", &n);
	prep();
	for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
		int v;
		scanf("%d", &v);
		pos[v - 1] = enc(i, j);
	}
	for (int i = 1; i < n * n; ++i) {
		for (int j = 0; j < A; ++j) dp[i][j] = std::make_pair(INF, INF);
		for (int j = 0; j < A; ++j) {
			for (int k = 0; k < A; ++k) {
				dp[i][k] = min(dp[i][k], std::make_pair(dp[i - 1][j].first + dist[j][pos[i - 1]][pos[i]] + (k != j), dp[i - 1][j].second + (k != j)));
			}
		}
	}
	std::pair<int, int> ans = dp[n * n - 1][0];
	for (int i = 1; i < A; ++i) ans = min(ans, dp[n * n - 1][i]);
	assert(ans.first != INF && ans.second != INF && ans.first && ans.second);
	printf("%d %d\n", ans.first, ans.second);
	return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define st first
#define nd second
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair< ll,ll > pll;

const int inf = 1000000000, MAX = 83;
const ll mod = 1000000007;

struct Matrix{
	ll a[MAX + 3][MAX + 3];

	Matrix(){
		for (int i = 1; i <= MAX; i++)
			for (int j = 1; j <= MAX; j++)
				a[i][j] = 0;
	}

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

ll sz,n,k,comb[45][45],pw[45] = {1};

Matrix operator* (Matrix a,Matrix b){
	Matrix res;

	for (int i = 1; i <= sz; i++) {
		for (int j = 1; j <= sz; j++) {
			for (int k = 1; k <= sz; k++) {
				res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % mod;
			}
		}
	}

	return res;
}

int main()
{
	cin >> n >> k;

	if (n == 1) {
		puts("1");
		return 0;
	}

	sz = 2*k+3;

	Matrix a;

	for (int i = 1; i <= 40; i++)
		pw[i] = (pw[i-1] << 1ll) % mod;

	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			if (j == 0)
				comb[i][j] = 1;
			else if (i != 0)
				comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % mod;
		}
	}

	for (int i = 1; i <= k+1; i++) {
		for (int j = i; j <= k+1; j++) {
			a[i][j] = comb[k-i+1][j-i];
		}
		for (int j = k+i+1; j <= 2*k+2; j++) {
			a[i][j] = (comb[k-i+1][j-k-i-1] * pw[j-k-i-1]) % mod;
		}
	}
	for (int i = k+2; i <= 2*k+2; i++) {
		a[i][i-k-1] = 1;
	}
	for (int i = 1; i <= 2*k+2; i++)
		a[sz][i] = a[1][i];
	a[sz][sz] = 1;

	Matrix ans;
	for (int i = 1; i <= sz; i++)
		ans[i][i] = 1;

	n -= 2;
	while (n--) {
		ans = ans * a;
	}

	ll res = 0;

	for (int i = 1; i <= k+1; i++)
		res = (res + ans[sz][i] * pw[k-i+2]) % mod;
	for (int i = k+2; i <= 2*k+2; i++)
		res = (res + ans[sz][i]) % mod;
	res = (res + ans[sz][sz]*(1 + pw[k+1])) % mod;

	cout << res << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f(i,s,n) for(int i=s;i<n;i++)
int fact(int);
double comb(int n, int r)
{
    return fact(n) / (fact(r) * fact(n - r));
}
int fact(int n)
{
    int res = 1;
    for (int i = 2; i <= n; i++)
        res = res * i;
    return res;
}
double power(int exp)
{
    if(exp==1)
    return 2;
    return 2*(power(--exp));
}
int main() {

	fastIO
    string s1,s2;
    cin>>s1>>s2;
    int e=0,posT=0,posR=0;
    posT=count(s1.begin(),s1.end(),'+')-count(s1.begin(),s1.end(),'-');
    posR=count(s2.begin(),s2.end(),'+')-count(s2.begin(),s2.end(),'-');
    e=count(s2.begin(),s2.end(),'?');
    int pos=abs(posT-posR);

    if(e-pos>=0&&(e-pos)%2==0){

            printf("%0.12f",((comb(e,pos)*(comb(e,(e-pos)/2)))/power(e)));
        // }

        // else
        // printf("%0.9f",0);
    }
    else
        printf("%0.12f",0);
    //     cout<<"True position : "<<posT<<endl;
    // cout<<"Received position : "<<posR<<endl;
    // cout<<"Positions to shift : "<<pos<<endl;
    // cout<<" empty positions : "<<e<<endl;

	return 0;
}


#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
#define rep(i) for(int i=0;i<=1;i++)
char x[256];
typedef long long ll;
int n;
ll hasha[1000001],hashb[1000001],pow[1000001];
string a,b;
void pre()
{
    x['E']='W';
    x['W']='E';
    x['N']='S';
    x['S']='N';
    pow[1]=10;
    for(int i=2;i<=1000000;i++)
    pow[i]=10*pow[i-1];
    pow[0]=1;
}
void calc()
{
    for(int i=1;i<=n;i++)
    hasha[i]=10*hasha[i-1]+a[i-1];
    for(int i=1;i<=n;i++)
    {
        hashb[i]=hashb[i-1]+pow[i-1]*b[b.length()-i];
    }
}
void reverse(string &s)
{
    for(int i=0;i<s.length();i++)
    s[i]=x[s[i]];
}

int main()
{
    cin>>n;
    pre();
    cin>>a>>b;
    reverse(a);
    calc();
    int flag=1;
    for(int i=1;i<=n;i++)
    {
        if(hasha[i]==hashb[i])
        {
            if(a.substr(0,i)==b.substr(n-1-i,i))
            flag=0;
        }
    }
    if(flag)
    cout<<"YES";
    else
    cout<<"NO";
}


#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>
using namespace std;

#define sc(a) scanf("%d",&a)
#define scm(a,b) scanf("%I64d%I64d",&a,&b)
#define fl(c,i,n) for(i=c;i<n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long int
#define ull unsigned long long int
#define inf INT_MAX
#define linf LLONG_MAX
#define pb push_back
#define pp pop_back()
#define aov(a) a.begin(),a.end()
#define mpr make_pair
#define nl printf("\n")
#define PI 2.0*acos(0.0) //#define PI acos(-1.0)
#define xx first
#define yy second
#define mxv(a) *max_element(aov(a))
#define mnv(a) *min_element(aov(a))
#define LB(a,x) (lower_bound(aov(a),x)-a.begin())
#define UB(a,x) (upper_bound(aov(a),x)-a.begin())
#define to_c_string(a) a.c_str()
#define strtoint(c) atoi(&c[0])
#define COUT(x) #x
#define pii pair<int,int>

template <class T> inline T bigmod(T p,T e,T M){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p) % M;p = (p * p) % M;} return (T)ret;}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
int toLlint(string s) { long long int sm; stringstream ss(s); ss>>sm; return sm;}

///int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
///int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
///int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
///int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
///int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

/*****************************************************************/
///////////////////////   GET SET GO    ///////////////////////////
/*****************************************************************/

#define M 1000

int main ()
{
    ll cs=1,t,i,j,h,r;
    while(1){

        scm(r,h);

        i=((h+r/2)/r)*2;
        j=h+r-(i/2)*r;
        if(j>=r/sqrt(3.00))
            i++;
        printf("%I64d\n",i);
    }

    return 0;
}


/* Problem  : D. Yet Another Number Game
** Time     : 3000ms
** Algorithm: dp
**/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define st first
#define nd second
#define read(x) scanf("%d",&x)
#define MAXN 1000005
typedef long long int64;
int a[MAXN], cnt[301];
int main (int argc, char const* argv[]){
    if ( argc == 3 ){
        freopen(argv[1],"r",stdin);
        freopen(argv[2],"w",stdout);
    }
    int n; read(n);
    int x = 0, mn = 301, nb = 0;
    for(int i = 0 ; i < n ; ++i){
        read(a[i]);
        x ^= a[i];
        mn = min(a[i],mn);
        if ( cnt[a[i]] == 0 ){
            ++nb;
        }
        ++cnt[a[i]];
    }
    if ( nb == 1 || x % 2 = 0 ){
        puts("BitLGM");
        return 0;
    }
    x = 0;
    for(int i = 0 ; i < n ; ++i){
        a[i] -= mn;
        x ^= a[i];
    }
    if ( x % 2 == 1 ){
        puts("BitLGM");
    }else{
        puts("BitAryo");
    }
    return 0;
}

/* DOAN Minh Quy - mquy.doan@gmail.com */


	#include<bits/stdc++.h>
	//#define endl "\n"
	using namespace std;
	int main()
	{
		ios::sync_with_stdio(false);
		//cin.tie(0);
		long long c,hr,hb,wr,wb;
		cin>>c>>hr>>hb>>wr>>wb;
		long long n=c/wr,m=c%wr;
		long long sum=n*hr+(m/wb)*hb;
		for (long long i=1; i<=11700; i++)//±©Á¦12500´Î
		{
			if (n<=0) break;
			n--;
			m=c-n*wr;
			m/=wb;
			sum=max(sum,n*hr+m*hb);
		}
		n=c/wb;
		m=c%wb;
		sum=max(sum,n*hb+(m/wr)*hr);
		for (long long i=1; i<=11700; i++)
		{
			if (n<=0) break;
			n--;
			m=c-n*wb;
			m/=wr;
			sum=max(sum,n*hb+m*hr);
		}
		cout<<sum;
		return 0;
	}


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

int v1, v2, t, d;

int dp[101][1111];

int recur(int currentt, int currentspeed)
{
	if (t < currentt)
	{
		return INT_MIN;
	}

	if (t==currentt)
	{

		if (currentspeed == v2)
		{
			return 0;
		}
		else
		{
			return INT_MIN;
		}
	}

	if (currentspeed <= 0)
	{
		return INT_MIN;
	}

	return dp[currentt][currentspeed];
}

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

	cin >> v1 >> v2 >> t >> d;

	for (int currentt = t; currentt >= 1; currentt--)
	{
		for (int currentspeed = 0; currentspeed <= (v1+d)*t; currentspeed++)
		{
			int mx = INT_MIN;

			for (int i = 0; i <= d; i++)
			{
				int s1 = currentspeed + i + recur(currentt + 1, currentspeed + i);

				mx = max(s1, mx);

				if (currentspeed - i >= 0)
				{
					int s2 = currentspeed - i + recur(currentt + 1, currentspeed - i);
					mx = max(s2, mx);
				}

			}

		    dp[currentt][currentspeed] = mx;
		}
	}

	int res = dp[1][v1];

	cout << res+v1 << endl;

	int pause;
	cin >> pause;

	return 0;
}


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

using namespace std;

const int mod = 998244353;
const int p1 = 998244353;

long long fact(int a) {
	long long f = 1;
	for (int i = 2; i <= a; i++) {
		f *= i;
	}
	return f;
}

long long sochet(int a, int b) {
	if (a == b) return 1;
	if (a == 1) return b;
	long long soch = 1;
	soch = fact(b);
	soch = soch / fact(a);
	soch = soch / fact(b - a);

	return soch;
}

long long count(int min, int max) {
	long long res = 1;
	for (int i = 1; i <= min; i++) {
		res += sochet(i, min)*sochet(i, max)*fact(i);

	}
	res = res%p1;
	return res;
}

int main() {
	vector<bool> flag(200001000);
	int a,b,c;
	cin >> a >> b >> c;
	if (a > b) swap(a, b);
	if (b > c) swap(b, c);
	if (a > c) swap(a, c);

	cout << count(a, b) % p1*count(a, c) % p1*count(b, c) % p1;;

	return 0;
}


#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>

using namespace std;

int main() {

	int n, h, m;cin >> n >> h >> m;
	vector<int>t(n + 1);

	for (int i = 1; i <= n; i++)t[i] = h;

	for (int i = 0; i < m; i++) {

		int a, b,c;
		cin >> a >> b>>c;
		for (int j = a; j <= b; j++)t[j] = c;

	}
	int r = 0;
	for (int i = 1; i <= n; i++)r += t[i] * t[i];
	cout << r << endl;

	return 0;

}


// Bismillahir Rahmanir Rahim

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

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> pll;
typedef pair <ll, pll> plp;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;

const int MX = 2e6+10;
const int mod = 1e9 + 7;
const ll inf = 1LL << 62;

int dx4[] = { 0, 0, -1, 1 };
int dy4[] = { 1, -1, 0, 0 };

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

// TOOLS
#define LCM(a,b)	  (a / __gcd(a,b) ) *b
#define gcd(a,b)	  __gcd(a,b)
#define all(x)	    (x).begin(), (x).end()
#define mem(a, n)	 memset(a, n, sizeof(a))
#define for1(i, n)	for(int i=1; i<=n; i++)
#define for0(i, n)	for(int i=0; i<n; i++)
#define rof0(i, n)	for(int i=n-1; i>=0; i--)
#define rof1(i, n)	for(int i=n; i>=1; i--)
#define forab(i, a, b)  for(int i=a; i<=b; i++)
#define rofab(i, a, b)  for(int i=b; i>=a; i--)
#define pb		  push_back
#define pbb		 pop_back

// CIN/COUT
#define YES		 cout << "YES" << endl
#define NO		  cout << "NO" << endl
#define sin(s)	    getline(cin, s)
#define scf(a)	    cin >> a
#define scf2(a, b)	cin >> a >> b
#define scf3(a, b, c)   cin >> a >> b >> c
#define scf4(a,b,c,d)   cin >> a >> b >> c >> d
#define pnf(a)	    cout << (a) << endl
#define pnf2(a, b)	cout << (a) << " " << (b) << endl
#define pnf3(a, b, c)   cout << (a) << " " << (b) << " " << (c) << endl
#define bug(n)	    cout << ">> " << n << " <<" << endl
#define line		cout << "==========" << endl
#define pnfa(a)	   cout << (a) << " "
#define pf(a)	     cout << (a)
#define sp		  cout << " "
#define nl		  cout << endl

// SCANF/PRINTF
#define fYES		printf("YES\n")
#define fNO		 printf("NO\n")
#define Sin(s)	    gets(s)
#define Scf(a)	    scanf("%lld", &a)
#define Scf2(a, b)	scanf("%lld %lld", &a, &b)
#define Scf3(a, b, c)   scanf("%lld %lld %lld", &a, &b, &c)
#define Scf4(a,b,c,d)   scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
#define Pnf(a)	    printf("%lld\n", a)
#define Pnf2(a, b)	printf("%lld %lld\n", a, b)
#define Pnf3(a, b, c)   printf("%lld %lld %lld\n", a, b, c)
#define Bug(n)	    printf(">> %lld <<\n", n)
#define Line		printf("==========\n")
#define Pnfa(a)	   printf("%lld ", a)
#define Pf(a)	     printf("%lld", a)
#define Sp		  printf(" ")
#define Nl		  printf("\n")

// OTHERS
#define saz(n)	    n.size()
#define clr(v)	    v.clear()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define in		  freopen("input.txt", "r", stdin)
#define out		 freopen("output.txt", "w", stdout)
#define FastIO	    { ios_base::sync_with_stdio(false); cin.tie(0); }
#define F		   first
#define S		   second
#define mpp		 make_pair

//string s;
//vector<ll> v;
//vector<ll> v[MX];
//ll ar[MX], br[MX];
//ll vist[MX];
//map<ll,ll> mp;

ll ar[101*101];

ll dp[101*101][101*101];

ll N;
vector <pll> vec;
ll vist[101*101];

ll rec(ll idx, ll cur, ll sum)
{

    if(cur==N)
        return sum;
    ll& ret = dp[idx][cur];
    if(~ret)
        return ret;
    ret=inf;
    vist[vec[idx].F] = 1 ;
    vist[vec[idx].S] = 1 ;
    for1(i,vec.size())
    {
        if(!vist[vec[i].F] && !vist[vec[i].S])
            ret = min(ret, rec(i,cur+1,sum+abs(ar[vec[i].F]-ar[vec[i].S])));

    }
    vist[vec[idx].F] = 0 ;
    vist[vec[idx].S] = 0 ;
    //bug(ret);
    return ret;
}

int main()
{
    mem(dp,-1);
    ll n, m, k, q, t, cnt = 0, sum = 0, mx = -inf, mn = inf ;
    Scf(n);
    N=n-1;
    n*=2;
    for1(i,n)
    {
        Scf(ar[i]);
    }
    sort(ar+1,ar+n+1);
    vec.pb({0,0});
    for1(i,n)
    {
        forab(j,i+1,n)
        {
            vec.pb({i,j});
        }
    }
    ll res = rec(0,0,0);
    pnf(res);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <cstring>
#define F first
#define S second
#define LL long long

using namespace std;

const LL VAL=200005;
const LL MOD=1000000007;

LL N, L, R, i, j, dp[VAL][5];
LL A, B, C, X, Y, ind, ANS;

int main()
{
    cin >> N >> L >> R;
    X=L;
    while (X % 3!=0)
        X++;
    Y=R;
    while (Y % 3!=0)
        Y--;
    A=(Y-X+3) / 3;

    X=L;
    while (X % 3!=1)
        X++;
    Y=R;
    while (Y % 3!=1)
        Y--;
    B=(Y-X+3) / 3;

    X=L;
    while (X % 3!=2)
        X++;
    Y=R;
    while (Y % 3!=2)
        Y--;
    C=(Y-X+3) / 3;

    dp[1][0]=A;
    dp[1][1]=B;
    dp[1][2]=C;
    for (i=2; i<=min(N, 100000); i++)
    {
        dp[i][0]=dp[i-1][0]*A+dp[i-1][1]*C+dp[i-1][2]*B;
        dp[i][0]%=MOD;

        dp[i][1]=dp[i-1][0]*B+dp[i-1][1]*A+dp[i-1][2]*C;
        dp[i][1]%=MOD;

        dp[i][2]=dp[i-1][0]*C+dp[i-1][1]*B+dp[i-1][2]*A;
        dp[i][2]%=MOD;
    }
    if (N<=100000)
        cout << dp[N][0];
    else
    {
        X=N / 2;
        X++;
        ANS=dp[X][0]*dp[N-X][0];
        ANS+=dp[X][1]*dp[N-X][2];
        ANS+=dp[X][2]*dp[N-X][1];
        cout << ANS;
    }
    return 0;
}


int n, m;

bool read() {
	return !!(cin >> n >> m);
}

const int N = 1200300;

const int mod = 1000 * 1000 * 1000 + 7;

int gcd(int a, int b, int& x, int& y) {
	if (!a) {
		x = 0, y = 1;
		return b;
	}
	int xx, yy, g = gcd(b % a, a, xx, yy);
	x = yy - b / a * xx;
	y = xx;
	return g;
}

inline int inv(int a) {
	int x, y;
	assert(gcd(a, mod, x, y) == 1);
	x %= mod;
	return x < 0 ? x + mod : x;
}

inline int mul(int a, int b) { return int(a * 1ll * b % mod); }
inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }

inline void inc(int& a, int b) { a = add(a, b); }

int fact[N], ifact[N];

inline int C(int n, int k) {
	if (k < 0 || k > n) return 0;
	return mul(fact[n], mul(ifact[k], ifact[n - k]));
}

int pm[N], pm1[N];

void solve() {
	const int N = n + 1;

	fact[0] = 1; fore(i, 1, N) fact[i] = mul(fact[i - 1], i);
	forn(i, N) ifact[i] = inv(fact[i]);

	pm[0] = 1; fore(i, 1, N) pm[i] = mul(pm[i - 1], m);
	pm1[0] = 1; fore(i, 1, N) pm1[i] = mul(pm1[i - 1], sub(m, 1));

	int ans = pm[n];
	fore(s, 1, n + 1) {
		int cur = 1;
		cur = mul(cur, pm[s]);
		cur = mul(cur, pm1[n - s]);
		cur = mul(cur, C(n, s - 1));
		inc(ans, cur);
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#include <set>
using namespace std;
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define fill(x, y)     memset(x, y, sizeof(y))
#define all(x)         (x).begin(), (x).end()
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string recipe;
  cin >> recipe;
  ll nb, ns, nc;
  cin >> nb >> ns >> nc;
  ll pb, ps, pc;
  cin >> pb >> ps >> pc;
  ll r;
  cin >> r;
  ll numB = 0; ll numS = 0; ll numC = 0;
  for (int i = 0; i < recipe.size(); i++) {
    if (recipe[i] == 'B') {
      numB++;
    } else if (recipe[i] == 'S') {
      numS++;
    } else {
      numC++;
    }
  }
  ll L = 0;
  ll R = 1000000000000;

  ll x = 0;
  while (L <= R) {
    ll m = (L + R + 1) / 2;
    ll rB = max((numB * m) - nb, (ll)0);
    ll rS = max((numS * m) - ns, (ll)0);
    ll rC = max((numC * m) - nc, (ll)0);
    if ((rB * pb) + (rS * ps) + (rC * pc) <= r) {
      x = m;
      L = m;
    } else {
      R = m - 1;
    }
  }
  cout << x << "\n";

  return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<iostream>
#include<cmath>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
typedef long long ll;

const int N = 9;

int n;
ll a[N];

int ans;

int isp(ll x) {
	for(ll i=2;i*i<=x;i++) {
		if(x%i==0) return 0;
	}
	return 1;
}

int cal(ll x) {
	int cnt=0;
	for(ll i=2;i*i<=x;i++) {
		while(x%i==0) {
			cnt++;
			x/=i;
		}
	}
	return cnt+(x!=1);
}

int calc(ll a,ll x) {
	if(isp(a)) return 0;
	return cal(a/x);
}

int mark[N];

void dfs(int pos,int cost) {
	if(cost>=ans) return ;
	if(pos<0) {
		ans=cost;
		return ;
	}
	int up=1<<pos;
	for(int i=0;i<up;i++) {
		int ok=1;
		ll x=1;
		for(int j=0;j<pos;j++) if(i&(1<<j)) {
			x*=a[j];
			if(mark[j] || a[pos]%x) ok=0;
		}
		if(!ok) continue;
		for(int j=0;j<pos;j++) if(i&(1<<j)) {
			mark[j]=1;
		}
		dfs(pos-1, cost+1+calc(a[pos], x));
		for(int j=0;j<pos;j++) if(i&(1<<j)) {
			mark[j]=0;
		}
	}
}

int main()
{
	mem(mark,0);

	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	ans=0x3f3f3f3f;
	dfs(n-1,1);

	ll x=1;
	int ok=1;
	for(int i=0;i<n-1;i++) {
		x*=a[i];
		if(a[n-1]%x) ok=0;
	}
	if(ok) {
		dfs(n-2,1+calc(a[n-1], x));
	}

	cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
#define spd ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define file freopen("file.in", "rt", stdin); freopen("file.out", "wt", stdout)
#define bo bool
#define sh short
#define ush unsigned short
#define uit unsigned int
#define ll long long
#define ull unsigned long long
#define de double
#define lde long double
#define ch char
#define str string
#define vec vector
#define pr pair
#define phb push_back
#define sub substr
#define re reverse
#define bn begin()
#define ed end()
#define rbn rbegin()
#define red rend()
#define se size()
#define ey empty()
#define tp top()
#define pp pop()
#define ft front()
#define bk back()
#define ppb pop_back()
#define cr clear()
#define rse resize
#define te true
#define fe false
#define st first
#define nd second
#define sk stack
#define qe queue
#define dq deque
#define ph push
#define it insert
#define postal signed main()
#define all(x) (x).bn, (x).ed
#define rall(x) (x).rbn, (x).red
#define coutf(x) cout << fixed << setprecision(x)
#define gle(x) getline(cin, x)
using namespace std;
const lde pi = 3.141592653589793;
postal {
	spd;
	//file;
	int t, n, k, d;
	ull ans, ans1;
	cin >> t;
	vec <int> v;
	set <int> s;
	for (int j = 0; j < t; ++j) {
		map <int, int> mp;
		for (size_t i = 0; i < k; ++i)
			mp[i] = 0;
		cin >> n >> k >> d;
		v.rse(n);
		for (size_t i = 0; i < n; ++i)
			cin >> v[i];
		for (size_t i = 0; i < d; ++i) {
			s.it(v[i]);
			++mp[v[i]];
		}
		ans1 = s.se;
		ans = ans1;
		s.cr;
		for (size_t i = 1; i < n - d + 1; ++i) {
			--mp[v[i - 1]];
			if (!mp[v[i - 1]])
				--ans1;
			++mp[v[i + d - 1]];
			if (mp[v[i + d - 1]] == 1)
				++ans1;
			ans = min(ans, ans1);
		}
		cout << ans << '\n';
	}
	return 0;
}


///题解：https://ouuan.github.io/Codeforces-Round-564-%E4%B8%AD%E6%96%87%E9%A2%98%E8%A7%A3/
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define LL long long
#define ULL unsigned long long
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define INF 0x3f3f3f3f
#define mem(i, j) memset(i, j, sizeof(i))
#define make(i, j) make_pair(i, j)
#define pb push_back
using namespace std;
const int N = 1e5 + 10, mod = 998244353, M = 3e3 + 10;
int read()
{
	sl = 0; fh = 1;
	char ch = getchar();
	while(ch < '0' || '9' < ch) {if(ch == '-') fh = -1; ch = getchar();}
	while('0' <= ch && ch <= '9') sl = sl * 10 + ch-'0',ch = getchar();
	return sl * fh;
}
int ksm(int x, int y) {
    int ans = 1;
    while(y) {
        if( y & 1 ) ans = (LL) ans * x % mod;
        x = (LL) x * x % mod;
        y >>= 1;
    }
    return ans;
}
int n, m, a[N], w[N], f[M][M], g[M][M], inv[M << 1], sum[3];
///sum[0] : don't like ; sum[1]: like; sum[2]:all
int main() {
    n = read(); m =read();
    //cout << n << " " << m <<endl;
    rep(i, 1, n) a[i] = read();
    rep(i, 1, n) {
        w[i] = read();
        sum[a[i]] += w[i]; sum[2] += w[i];
    }
    rep(i, 0, 2 * m) inv[i] = ksm(sum[2] + i - m, mod - 2); ///预处理逆元
    dep(i, 0, m) {
        f[i][m - i] = g[i][m - i] = 1;
        dep(j, 0, m - i - 1) {
            f[i][j] = (1LL * (sum[1] + i + 1) * f[i + 1][j] + 1LL * (sum[0] - j) * f[i][j + 1]) % mod * inv[i - j + m] % mod;
			g[i][j] = (1LL * (sum[1] + i) * g[i + 1][j] + 1LL * (sum[0] - j - 1) * g[i][j + 1]) % mod * inv[i - j + m] % mod;
        }
    }
    rep(i, 1, n) printf("%I64d\n", 1LL * w[i] * (a[i] ? f[0][0] : g[0][0]) % mod);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

string s;

int main() {
 int n, k;
 cin >> n >> k >> s;
 s = "Y" + s + "Y";
queue<int> q; int d = 0; int mn = 0; int ok = 0;
 for(int i = 0; i <= n+1; i++) {
  while(q.size() && i - q.front() - 1 > k) q.pop();
  if(s[i] != 'N') {
   if(q.size() && i - q.front() - 1 == k) ok = 1;
   d = 0;
   if(s[i] == 'Y') while(q.size)) q.pop();
   q.push(i);
  }
  else mn = max(mn, ++d);
 }
 if(ok && mn <= k) cout << "YES" << endl;
 else cout << "NO" << endl;
}


/*
[카이스트 알고리즘 디자인 주제1]
도전과제 2. 소수 곱하기 소수는?
제작자 : 김영완 (운정고)
제작일 : 2013 10 20
*/
#include <stdio.h>
#define MAX 3000
int main(void)
{
        int b,z,a, c, input;
        int cnt=0, p_c=0, chul_c=0;
        int prime[450]={2};
        int Chulsu[3000];
        int p[MAX+1]={0};

        for( z=2; z<=MAX; z++){
        if ( p[z] == 0 ){
            cnt+=1;
            prime[cnt]=z;

        for(b=z*2; b<=MAX; b+=z){
            p[b]=1;
        }
    }
}
        scanf("%d", &input);
        for(a=6; a<=input; a++){                        //6은 최초의 철수의 수이기 때문
            cnt=0;
                for(c=1; c<=a; c++){

                        if(a%prime[c] == 0) cnt++;
                        if(prime[c]>a) break;
                }

                if(cnt == 2)
                {
                        Chulsu[chul_c]=a;
                        chul_c++;
                }
        }

        printf("%d", chul_c);
        return 0;
        }


#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <sstream>
#include <string>
using namespace std;

int main(){
	int t;
//    t=1;
    cin>>t;

    while(t--){

           int n,k,l,i=0;
           bool q=false;
            cin>>n>>k>>l;

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

            }

            int k1=k;

            for( i=0;i<n;i++){
                if(a[i]+k<=l){
                    k1=k;
                    q=false;
                    continue;
                }
                if(q)
                    k1++;
                else
                    k1=min(k1-1,l-a[i]);
                if(k1==0)
                    q=true;
                if(a[i]+k1>l)
                    break;
            }

            if(i==n)
                cout<<"Yes";
            else
                cout<<"No";

        cout<<endl;

    }

    return 0;

}


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

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

	int n,x;
	cin>>n;

	vector<int> mark(101, -1);

	for (int i=0;i<n;i++) {

		cin>>x;
		a[x] = 0;

	}

	int ans = 0;

	for (int i=1;i<=100;i++) {

		if (mark[i] == 0) {

			ans++;

			for (int j=i;j<=100;j=j+i) {

				if (mark[j] == 0) {

					mark[j] = 1;
				}

			}

		}

	}

	cout<<ans<<endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <time.h>
#include <queue>
#include <cctype>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#define Mod 1000000007
#define INT 2147483647
#define pi acos(-1.0)
#define eps 1e-3
#define lll __int64
#define ll long long
using namespace std;
#define N 200100

int a[105];
int cha[104];
int n,T;

int check(int k)
{
    int i;
    for(i=0;i<n-k+1;i++)
    {
        if(abs(a[i]-a[i+k-1])<=T)
            return 1;
    }
    return 0;
}

int main()
{
    int i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    scanf("%d",&T);
    int l = 1;
    int r = n;
    while(l<r)
    {
        int mid = (l+r)/2;
        if(check(mid))
            l = mid;
        else
            r = mid - 1;
    }
    cout<<l<<endl;
    return 0;
}


#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <math.h>
#include <algorithm>

#define FOR(i,b) for(LL i=1;i<=b;i++)
#define PI 3.14159265

using namespace std;
typedef long long int LL;

LL POWER(LL a,LL b){
        LL c=1;
        for(LL i=1;i<=b;i++)
        c*=a;
        return c;
        }
int main (){
LL a;
    cin>>a;
    LL b;
    cin>>b;
    LL c;
    cin>>c;
    LL s;
    LL x;
    LL sol[a];
    LL k=0;
    for (LL i=0;i<=1000000;i++)
        {x=i;
         s=0;
         while(x>0){s+=x%10;
                    x/=10;
                    }
         if (i==b*POWER(s,a)+c) {k+=1;
                                 sol[k]=i;}
         x=i;
         }
    if (k==0) cout<<k;
    else
    {cout<<k<<endl;
    FOR(i,k) cout<<sol[i]<<" ";
}
    cin>>c;
}


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

#define ff first
#define ss second

#define pb push_back
#define eb emplace_back

#define mp make_pair

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

#define pii pair<int, int>

#define debug(x) cout << #x << ": " << x << endl;
#define TIME clock() / (ld)CLOCKS_PER_SEC

using namespace std;
mt19937 rnd(time(0));
typedef long long ll;
typedef long double ld;
const int maxn = 3e5 + 7, mod = 1e9 + 7, MAXN = 1e6 + 7;
const ll inf = 1e18;
int n;
string s;
const int L = 3;
vector<int> MOD = {(int)1e9 + 7, (int)1e9 + 9, (int)1e9 + 13};
vector<int> pww = {228, 31, 27};
int pw[maxn][L];

int pref0[maxn];

int getnull(int l, int r) {
    return pref0[r + 1] - pref0[l];
}

int getright(int l, int r) {
    if (getnull(l, r) == 0) return -1;
    int l1 = l - 1;
    int m;
    int r1 = r;
    while (l1 + 1 < r1) {
        m = (l1 + r1) / 2;
        if (getnull(l, m) < getnull(l, r)) l1 = m;
        else r1 = m;
    }
    return r1;
}

int getleft(int l, int r) {
    if (getnull(l, r) == 0) return -1;
    int l1 = l - 1;
    int m;
    int r1 = r;
    while (l1 + 1 < r1) {
        m = (l1 + r1) / 2;
        if (getnull(l, m) == 0) l1 = m;
        else r1 = m;
    }
    return r1;
}

int hsh[maxn][L];
int hshinv[maxn][L];

int gethsh(int al, int r, int i) {
    int cnt = getnull(l, r);
    return (hsh[r + 1][i] - (hsh[l][i] * pw[cnt][i]) % MOD[i] + MOD[i]) % MOD[i];
}

int getinvhsh(int l, int r, int i) {
    int cnt = getnull(l, r);
    return (hshinv[r + 1][i] - (hshinv[l][i] * pw[cnt][i]) % MOD[i] + MOD[i]) % MOD[i];
}

bool solve(int l, int r, int l1, int r1) {
    bool ok = true;
    for (int i = 0; i < L; ++i) {
        if (r % 2 != r1 % 2) {
            ok &= (gethsh(l, r, i) == getinvhsh(l1, r1, i));
        } else {
            ok &= (gethsh(l, r, i) == gethsh(l1, r1, i));
        }
    }
    return ok;
}

void solve() {
    for (int i = 0; i < L; ++i) {
        pw[0][i] = 1;
        for (int j = 1; j < maxn; ++j) {
            pw[j][i] = pw[j - 1][i] * pww[i];
            pw[j][i] %= MOD[i];
        }
    }
    cin >> n;
    cin >> s;
    for (int i = 0; i < n; ++i) {
        pref0[i + 1] = pref0[i] + (s[i] == '0');
    }
    for (int l = 0; l < L; ++l) {
        for (int i = 0; i < n; ++i) {
            if (s[i] == '1') {
                hsh[i + 1][l] = hsh[i][l];
                hshinv[i + 1][l] = hshinv[i][l];
            } else {
                int t = i % 2 + 1;
                hsh[i + 1][l] = hsh[i][l] * pww[l];
                hsh[i + 1][l] += t;
                hsh[i + 1][l] %= MOD[l];
                t = !(i % 2) + 1;
                hshinv[i + 1][l] = hshinv[i][l] * pww[l];
                hshinv[i + 1][l] += t;
                hshinv[i + 1][l] %= MOD[l];
            }
        }
    }
    int q; cin >> q;
    for (int test = 0; test < q; ++test) {
        int l, l1, len, r, r1;
        cin >> l >> l1 >> len, --l, --l1;
        r = l + len - 1;
        r1 = l1 + len - 1;
        if (getnull(l, r) != getnull(l1, r1)) {
            cout << "No\n";
            continue;
        }
        if (getnull(l, r) == 0) {
            cout << "Yes\n";
            continue;
        }
        bool ok = false;
        int id = getright(l, r);
        int id1 = getright(l1, r1);
        if ((r - id) % 2 == (r1 - id) % 2) {
            ok |= solve(l, r, l1, r1);
        }
        id = getleft(l, r);
        id1 = getleft(l1, r1);
        if ((id - l) % 2 == (id1 - l1) % 2) {
            ok |= solve(l, r, l1, r1);
        }
        cout << (ok ? "Yes\n" : "No\n");
    }
}

signed main() {
#ifdef LOCAL
  freopen("TASK.in", "r", stdin);
  freopen("TASK.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    for (int i = 0; i < t; ++i) solve();
    return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void c_p_c(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

int32_t main() {
  // c_p_c();
  int t, s, x;
  cin >> t >> s >> x;
  unordered_set <int> S;
  S.insert(t);
  for(int i=0;i<=x;i++){
    int temp = t+s+i;
    S.insert(temp);
  }
  if (S.find(x) != S.end()) {
    cout << "YES";
  } else {
    cout << "NO";
  }

  return 0;
}


// written by : unnati109c
#include<bits/stdc++.h>
using namespace std;

#define ll long long int

#define precision(n) fixed<<setprecision(n)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inpint ll n; cin>>n;
#define inpstr string s; cin>>s;
#define inpstr2 string s,t; cin>>s>>t;
#define test long long int t; cin>>t; while(t--)
#define forr(i, n) for(long long int i = 0; i < n; i++)  //forr(i,n){...}
#define forrd(i, n) for(long long int i = n-1; i >=0; i--)
#define forrab(i,a,b) for(ll i=a;i<b;i++)  //eg: forrab(i,0,n/2);
#define forrabd(i, n) for(long long int i = a; i >b; i--)
#define endll cout <<endl    //endll;
#define dsort(a,n) sort(a,a+n, greater <int> ()) //dsort(a,n);

//INPUT ARRAY ll a[n]; forr(i,n){cin>>a[i];}
//OUTPUT ARRAY forr(i,n){cout<<a[i];}

int main()
{
    fast;
    //test
    {
    	//inpint;
    	//inpstr;
    	//inpstr2;

    	/*ll a[n];
    	forr(i,n)
    	{
    	       cin>>a[i];

    	}*/

	ll a,b,c;
	cin>>a>>b>>c;

	ll pro= a*b;
	ll count=0;

	while(pro<=c)
	{
	       count++;
	       pro+=(a*b);
	}
	cout<<count<<endl;

    }

return 0;
}


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

#define ll long long
const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f3f;
const int mod = 1000000007;
//ll mult_mod(ll a,ll b,ll c)
//{
//    a %= c;
//    b %= c;
//    ll ret = 0;
//    ll tmp = a;
//    while(b)
//    {
//        if(b & 1)
//        {
//            ret += tmp;
//            if(ret > c)
//                ret -= c;
//        }
//        tmp <<= 1;
//        if(tmp > c)
//            tmp -= c;
//        b >>= 1;
//    }
//    return ret;
//}
//ll pow_mod(ll a,ll n,ll mod)
//{
//    ll ret = 1;
//    ll tmp = a % mod;
//    while(n)
//    {
//        if(n & 1)
//            ret = mult_mod(ret,tmp,mod);
//        tmp = mult_mod(tmp,tmp,mod);
//        n >>= 1;
//    }
//    return ret;
//}
ll poww(int a,ll b)
{
    ll ans = 1;
    ll base = a;
    while(b != 0)
    {
        if(b & 1 != 0)
            ans = ans * base % mod;
        base = base * base % mod;
        b >>= 1;
    }
    return ans;
}
int main()
{
    ll n,m;
    int k;
    scanf("%lld %lld %d",&n,&m,&k);
    if(((n % 2 + m % 2) == 1) && k == -1)
        puts("0");
    else
    {
        ll ans = n * m - n - m + 1;
        //printf("%lld\n",poww(poww(2,n-1),m-1));
        printf("%lld\n",poww(2,ans));
    }
}


#include <iostream>
using namespace std;
int main()
{
    char x;
    cin>>x;
    while(x)
        if(x=='9'||x=='H'||x=='Q')
        {
            cout<<"YES"<<endl;
            return 0;
        }
    cout<<"NO"<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <set>

using namespace std;

set<string> oks;

int main() {
    string s;
    cin >> s;
    for (int i=0;i<s.size();i++) for (int j=i;j<s.size();j++) {
        int ss = i;
        int e = j;
        int ok = 1;
        while (e>ss) {
            if (s[ss]!=s[e]) ok = 0;
            s+=1;
            e-=1;
        }
        if (ok) {
            string t;
            for (int k=i;k<=j;k++) t+=s[k];
            oks.insert(t);
        }
    }
    cout << *s.begin();

    return 0;
}


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

int main(){
	int a[600]={0},n[600];
    int m,i,cnt=0;
    cin>>m;
    for(i=0;i<m;i++)
    {
    	cin>>n[i];
    	if(n[i]!=0)
    	{
    	    a[n[i]]++;
    	}
	}
	for(i=0;i<m;i++)
	{
		if(a[i]!=0)
		{
			cnt++;
		}
	}
	cout<<cnt+1;
    return 0;
}


#include <iostream>
#include <cstdio>

#include <functional>
#include <utility>
#include <cmath>
#include <algorithm>
#include <cassert>

#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <unordered_map>

#include <string>
#include <iterator>
#include <iomanip>
#include <fstream>

#include <random>
#include <chrono>

using namespace std;

#define uint unsigned int
#define prll pair<ll,ll>
#define prdd pair<double,double>
#define m_p make_pair
#define INF (ll)1e18
#define ll long long

const ll q = 239017;
const ll mod = 1e9 + 7;
const ll mod2 = 1e9 + 13;
const ll MAXN = 2e5 + 100;
const ll MAXM = 4294967291;
const ll L = 26;

vector<ll> g[MAXN];
ll used[MAXN], ct[MAXN];

vector<ll> comp[2];

ll id;
void dfs(ll v)
{
	if (used[v])
		return;

	comp[id].push_back(v);

	used[v] = 1;

	for (ll to : g[v])
		dfs(to);
}

void foo()
{
	ll t; cin >> t;
	while (t--)
	{
		ll n, m, a, b; cin >> n >> m >> a >> b;
		--a; --b;

		for (ll i = 0; i < m; ++i)
		{
			ll u, v; cin >> u >> v;
			--u; --v;

			g[u].push_back(v);
			g[v].push_back(u);
		}

		id = 0; used[b] = 1;
		dfs(a);

		for (ll el : comp[0])
			used[el] = 0;

		used[b] = 0;

		id = 1; used[a] = 1;
		dfs(b);

		for (ll i = 0; i < 2; ++i)
			for (ll el : comp[i])
				++ct[el];

		ll mas[2] = { -1,-1 };
		for (ll i = 0; i < 2; ++i)
			for (ll el : comp[i])
				if (ct[el] == 1)
					++mas[i];

		cout << max(0ll, mas[0] * mas[1]) << '\n';

		for (ll i = 0; i < n; ++i)
		{
			g[i].clear();
			used[i] = ct[i] = 0;
		}
	}
}

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

	foo();

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define pb push_back

#include <iostream>
#include <climits>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <map>
#include <string>
#include <stack>
#include <set>
#include <cstdio>
#include <cctype>
#include <queue>
#include <bitset>
#include <functional>
#include <cassert>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
typedef double db;

const ll N = 1e6 + 20;
const ll INF = INT_MAX;

/*int p = 3571;
int mod = 2147483647;

namespace op {
	void add(int &a, int val) {
		a = ((a * p % mod + val) % mod + mod) % mod;
	}
	int calc(int a, int b) {
		return ((a % mod + b % mod) % mod + mod) % mod;
	}
	int mul(int a, int b) {
		return (((a % mod) * (b % mod)) % mod + mod) % mod;
	}
	int pow(int a, int n) {
		if (n == 0) return 1LL;
		if (n & 1) {
			int b = pow(a, n ^ 1) % mod;
			return mul(a, b);
		}
		else {
			int b = pow(a, n >> 1) % mod;
			return mul(b, b);
		}
	}
};
using namespace op;

struct hsh {
	string vec;
	vector<int> seg;
	int n;
	hsh(string a) {
		n = a.size();
		vec = a;
		seg.resize(a.size() + 1);
		for (int i = 0; i < a.size(); ++i) {
			seg[i + 1] = seg[i];
			add(seg[i + 1], a[i]);
		}
	}
	int seg_hash(int l, int r) {
		return calc(seg[r], (-1) * seg[l - 1] * pow(p, r - l + 1));
	}
};*/

vector<int> g[N];
int used[N], ct[N];

vector<int> comp[2];

int id;
void dfs(ll v) {
	comp[id].push_back(v);
	used[v] = 1;

	for (ll to : g[v]) {
		if (!used[to])
			dfs(to);
	}
}

void clear(int n) {
	for (ll i = 0; i < n; ++i) {
		g[i].clear();
		used[i] = ct[i] = 0;
	}
}

signed main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int t;
	cin >> t;
	while (t--) {
		int n, m, a, b;
		cin >> n >> m >> a >> b;
		a--; b--;
		for (int i = 0; i < m; ++i) {
			int x, y;
			cin >> x >> y;
			--x; --y;
			g[x].push_back(y);
			g[y].push_back(x);
		}

		id = 0; used[b] = 1;
		dfs(a);
		for (auto &x : comp[0]) {
			used[x] = 0;
		}
		used[b] = 0;
		id = 1; used[a] = 1;
		dfs(b);
		for (auto &x : comp[0])
			ct[x]++;
		for (auto &x : comp[1])
			ct[x]++;

		int arr[2] = { -1,-1 };
		for (int i = 0; i < 2; ++i)
			for (auto &x : comp[i])
				if (ct[x] == 1)
					arr[i]++;

		cout << max(0ll, arr[0] * arr[1]) << endl;
		clear(n);
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sc(x)  scanf("%d",&x)
#define sc2(x,y)  scanf("%d%d",&x,&y)
#define scl(x) scanf("%lld",&x)
#define F first
#define S second
#define pb push_back
#define pi 3.1415926535897932384
int Dx[]= {1,-1,0,0};
int Dy[]= {0,0,1,-1};
void fast()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
}
void file()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

int main()
{
    ll x,y,l,r;
    cin>>x>>y>>l>>r;
    vector<ll>a,b,v;
    ll p=1;
    while (p<=1e18/x) a.pb(p),p*=x;
    p=1;
    while (p<=1e18/y) b.pb(p),p*=y;
    for (auto i:a)
        for (auto j:b)
            if (i+j>=l && i+j<=r)
                v.pb(i+j);
    v.pb(r+1);
    v.pb(l-1);
    //cout<<endl;
    ll ans=0;
    sort(v.begin(),v.end());
    //for (auto i:v ) cout<<i<<" ";
    for (int i=1 ; i<v.size() ; i++)
        if (v[i]!=v[i-1])
            ans=max(ans,v[i]-1-v[i-1]);
    cout<<ans<<endl;
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <vector>

using namespace std;
int m, a, b;
bool ok[8][8], O;
int main()
{
	cin >> m;
	for(int i = 0; i < m; i++){
		cin >> a >> b;
		ok[a][b] = ok[b][a] = 1;
	}
	for(int i = 1; i < 6; i++)
	for(int j = i + 1; j < 6; j++)
	for(int k = j + 1; j < 6; k++){
		if(!ok[i][j] && !ok[i][k] && !ok[j][k])
			O = 1;
		if(ok[i][j] && ok[i][k] && ok[j][k])
			O = 1;
	}
	if(O)
		cout << "WIN";
	else
		cout << "FAIL";

	return 0;
}


#pragma GCC optimize("Ofast")  // remove in mingw32 bit ;
#pragma GCC target("avx,avx2,fma")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define ll long long
#define double long double
#define MP make_pair
// #define int long long
// #define MAX LONG_LONG_MAX
// #define MIN LONG_LONG_MIN

using namespace std;

#ifdef CUST_DEBUG
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.F<<','<<p.S<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p){return cout<<"("<<p.F<<", "<<p.S<<")";}
template<typename A> ostream& operator<<(ostream &cout,vector<A> const &v){cout<<"[";for(int i=0;i<v.size();i++){if(i)cout<<", ";cout<<v[i];}return cout<<"]";}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p){cin>>p.F;return cin>>p.S;}
#endif

const long long MAXN = 1e5 +7;

void check(){
	ll n;
	cin >> n;
	ll lvl = 1 ,ans = 0;
	while(1){
		ll fl = lvl*(lvl*3 + 1)/2;
		if(fl > n)break;
		ans += ((n - fl)%(lvl*3) == 0);
		lvl++;
	}
	cout << ans<<"\n";
}

int32_t main(){
	#ifndef CUST_DEBUG
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	#endif
	// cin.exceptions(cin.Failbit);
	int t = 1;
	// cin >> t;
	for(int i = 1 ; i <= t ;i++){
		// cout << "Case "<< i << ":\n";
		check();
	}
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n, b;
    cin >> n >> b;

    double a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];

    double sum = b;
    for(int i = n - 1; i >= 0; i--)
        sum += a[i];

    double average = sum / n;

    for(int i = n - 1; i >= 0; i--)
        if(a[i] > average)
    {
        cout << -1;
        return 0;
    }

    cout.precision(15);
    for(int i = 0; ; )
    {
        cout << fixed << average - a[i];

        i++;
        if(i == n) break;
        cout << '\n';
    }
}


#include <iostream>

using namespace std;
int k,n,w, sum;
int main()
{
    cin >>k>>n>>w;
    for (int i=1; i<=w; i++)
    {
       sum+=i;
    }
    if ((sum*k)-n ==0)
        cout<<0<<endl;
    else
    cout<<sum*k-n<<endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <numeric>
#include <cassert>
#include <random>
#include <stdarg.h>
#include <string.h>
#include <stack>
#include <string>
#include <map>
#include <stdio.h>
#include <fstream>

#define int long long int

#define fillvec(a) generate(a->begin(), a->end(), [] () -> int{return rand()%10;});
#define fillar(a, n) generate(a, a+n, [] () -> int{return rand()%10;});

#define printvec(a) std::for_each(a.begin(), a.end(), [] (int x){cout << x << " ";});
#define printar(a, n) std::for_each(a, a+n, [] (int x){cout << x << " ";});

#define inint(a) std::generate(&(a.array[0]), &(a.array[a.size]), [] ()->int{int a; cin >> a; return a;});
#define inDouble(a) std::generate(&(a.array[0]), &(a.array[a.size]), [] ()->double{double a; cin >> a; return a;});
#define inPair(a) std::generate(&(a.array[0]), &(a.array[a.size]), [] ()->Pair{Pair a(0, 0); cin >> a; return a;});

#define DEBUG
#define NULL 0

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

class Pair;

class Item
{
	friend ostream &operator<< ( ostream & out, const Pair & c );
	friend istream &operator>> ( istream & out, Pair & c );

public:
	Item(string des) {
		description = des;
	}

	int keyF() {
		key = description.length();
		return key;
	}

	string toString() {
		return description;
	}

	int key;

	string description;
};

ostream & operator<<( ostream & out, const Item & c  )
{
	out << c.description;
	return out;
}

istream & operator>>( istream & in, Item & c  )
{
	in>>c.description;
	return in;
}

template<typename E>
void print(E value)
{
	cout << value;
}

template<typename E>
void print(E value1, E value2)
{
	cout << value1 << " " << value2;
}

template<typename E>
void print(E value1, E value2, E value3)
{
	cout << value1 << " " << value2 << " " << value3;
}

template<typename E>
E read()
{
	E value;
	cin >> value;
	return value;
}

string readString()
{
	char* s = new char[1000];
	fgets(s, 1000, stdin);
	return string(s);
}

template<typename E>
void println(E value)
{
	cout << value << endl;
}

template<typename E>
void println(E value1, E value2)
{
	cout << value1 << " " << value2<< endl;
}

template<typename E>
void println(E value1, E value2, E value3)
{
	cout << value1 << " " << value2 << " " << value3<< endl;
}

template<typename E>
void println(E value1, E value2, E value3, E value4)
{
	cout << value1 << " " << value2 << " " << value3 << " " << value4 << endl;
}

int randomint(int min, int max)
{
	if(max == min) {
		return max;
	}
	return rand()%(max-min+1)+min;
}

class Pair
{
	friend ostream &operator<< ( ostream & out, const Pair & c );
	friend istream &operator>> ( istream & out, Pair & c );

public:
	Pair(Item* p);
	int key;
	Item* value;
};

Pair::Pair(Item* b)
{
	key = b->key;
	value = b;
}

ostream & operator<<( ostream & out, const Pair& c  )
{
	out<< "(" << c.value->key << " -> " << (c.value->toString()) << ")";
	return out;
}

template<typename E>
class Array
{
public:
	int size;
	Array<E>(int _capacity) {
		capacity = _capacity;
		array = new E[capacity];
		size = capacity;
		for(int i =0; i<size; i++) {
			array[i] = NULL;
		}
	}

	void sort() {
		std::sort(&array[0], &array[size]);
	}

	Array() {
		capacity = 0;
		array = new E[capacity];
		size = 0;
	}

	Array(vector<E>& vect) {
		int _size = vect.size();
		capacity = _size*2;
		size = _size;
		array = new E[capacity];
		for(int i =0; i<size; i++) {
			array[i] = vect[i];
		}
	}

	Array(int minBound, int maxBound, int _size) {
		srand(_size);
		capacity = _size*2;
		size = _size;
		array = new E[capacity];
		for(int i = 0; i<size; i++) {
			array[i] = randomint(minBound, maxBound);
		}
	}

	void add(E item);
	vector<E> toVector();
	void toString();
	E& operator[](int i);
	E& index(int i);
	E* array;
	void null(void) {
		for(int i =0; i<size; i++) {
			array[i] = NULL;
		}
	}
private:
	int capacity;
	void ensureCapacity(int cap);
};

template <typename E>
void Array<E>::ensureCapacity(int cap)
{
	capacity = capacity*2;
	E* newArray = new E[capacity];
	memcpy(newArray, array, sizeof(E)*size);
	delete[] array;
	array = newArray;
}

template <typename E>
void Array<E>::toString()
{
	int i = 0;
	E* begin = array;
	cout << "[";
	while(i<size) {
		if(i == size-1) {
			cout << *array;
		} else {
			cout << *array << " ";
		}
		array++;
		i++;
	}
	cout << "]";
	cout << endl;
	array = begin;
}

template <typename E>
void Array<E>::add(E item)
{
	if(capacity<size+1) {
		ensureCapacity(size+1);
	}
	array[size] = item;
	size++;
}

template <typename E>
vector<E> Array<E>::toVector()
{
	vector<E> res = vector<E>(size);
	for(int i =0; i<res.size(); i++) {
		res[i] = array[i];
	}
	return res;
}

template <typename E>
E& Array<E>::operator[] (int i)
{
#ifdef DEBUG
	if(i<size && i>=0) {
		return array[i];
	} else {
		cout << "Array index out of bounds, index is " << i << ", size is " << size << endl;
		cout << "Array is " << endl;
		toString();
		assert(0);
	}
#endif

#ifndef DEBUG
	return array[i]
#endif
}

       template<typename E>
class Matrix
{
public:
	int rows;
	int columns;
	Array<E> array;
	E& get(int x, int y);
	void set(int x, int y, E& value);
	void print();

	Matrix<E>(int r, int c) {
		rows = r;
		columns = c;
		array = Array<E>(rows*columns);
		array.null();
	}

	void swap(Matrix<E>& other) {
		std::swap(array, other.array);
		std::swap(rows, other.rows);
		std::swap(columns, other.columns);
	}

	Matrix<E>(int minBound, int maxBound, int _rows, int _columns) {
		rows = _rows;
		columns = _columns;
		int size = _rows*_columns;
		array = Array<E>(minBound, maxBound, size);
	}

private:
};

template <typename E>
E& Matrix<E>::get(int x, int y)
{
#ifdef DEBUG
	if(x>=columns || x<0) {
		assert(0);
	}
	if(y>=rows || y<0) {
		assert(0);
	}
	return array.array[x+y*columns];
#endif

#ifndef DEBUG
	return array.array[x+y*columns];
#endif
}

template <typename E>
void Matrix<E>::print(void)
{
	for(size_t y = 0; y<rows; y++) {
		for(size_t x = 0; x<columns; x++) {
			int index = x+y*columns;
			cout << array.array[index] << " ";
		}
		cout << endl;
	}
}

template <typename E>
void Matrix<E>::set(int x, int y, E& value)
{
#ifdef DEBUG
	if(x>=columns || x<0) {
		assert(0);
	}
	if(y>=rows || y<0) {
		assert(0);
	}
	array.array[x+y*columns] = value;
#endif
#ifndef DEBUG
	array.array[x+y*columns] = value;
#endif
}

#define getA(array, i) (array.array[(i)])
#define setA(array, i, value) (array.array[(i)] = value)
#define getM(matrix, i, j) (matrix.array.array[i+j*matrix.columns])
#define setM(matrix, i, j, value) (matrix.array.array[i+j*matrix.columns] = value)

int bpow(int a, int b)
{
	if(b == 0) {
		return 1;
	} else {
		if(b%2 == 0) {
			int half = bpow(a, b/2);
			return half*half;
		} else {
			return bpow(a, b-1)*a;
		}
	}
}

int gcd(int a, int b)
{
	if(!b) {
		return a;
	} else {
		return gcd(b, a%b);
	}
}

vector<pair<int, int> > factorize(int n)
{
	vector<pair<int, int> > res = vector<pair<int, int> >();
	for(int i = 2; i<sqrt((double)n)+1; i++) {
		if(n%i == 0) {
			pair<int, int> comp = make_pair(i, 1);
			n/=i;
			while(n%i == 0) {
				comp.second++;
				n/=i;
			}
			res.push_back(comp);
		}
	}

	if(n>1) {
		res.push_back(make_pair(n, 1));
	}
	return res;
}

int euler(int n)
{
	vector<pair<int, int> > fact = factorize(n);
	int res = 1;
	for(unsigned int i = 0; i<fact.size(); i++) {
		int factor = pow((double)fact[i].first, (double)fact[i].second)-pow((double)fact[i].first, (double)fact[i].second-1);
		res*=factor;
	}
	return res;
}

int inversePrime(int a, int m)
{
	return bpow(a, m-2)%m;
}

int inverseCoprimes(int a, int m)
{
	return bpow(a, euler(m)-1)%m;
}

int inverse(int a, int m)
{
	if(gcd(a, m) == 1) {
		return inverseCoprimes(a, m);
	} else {
		assert(0);
		return -1;
	}
}

vector<int> enumerateDivisors(int n)
{
	vector<pair<int, int> > divs = factorize(n);
	vector<int> totals = vector<int>(divs.size()+1);
	totals[0] = 1;
	for(unsigned int i = 1; i < divs.size()+1; i++) {
		totals[i]=totals[i-1]*(divs[i-1].second+1);
	}

	vector<int> res = vector<int>();
	for(int i = 0; i<totals[totals.size()-1]; i++) {
		vector<int> values = vector<int>(divs.size());
		for(unsigned int j = 0; j<values.size(); j++) {
			values[j] = (i/totals[j])%(divs[j].second+1);
		}
		int r = 1;
		for(unsigned int i = 0; i<values.size(); i++) {
			r*=bpow(divs[i].first, values[i]);
		}
		res.push_back(r);
	}

	return res;
}

istream& operator>>( istream& in, Pair& c  )
{
	in >> c.value->description;
	c.value->key = c.value->keyF();
	return in;
}

void reverse(char *str)
{
	char temp;
	size_t len = strlen(str) - 1;
	size_t i;
	size_t k = len;

	for(i = 0; i < len; i++) {
		temp = str[k];
		str[k] = str[i];
		str[i] = temp;
		k--;
		if(k == (len / 2)) {
			break;
		}
	}
}

map<int, int> count(Array<int> a)
{
	map<int, int> res;
	for(int i = 0; i<a.size; i++) {
		res[a[i]]++;
	}
	return res;
}

void itoa(int n, char s[])
{

	int radix = 10;
	int i, sign;

	if ((sign = n) < 0)
		n = -n;
	i = 0;
	do {
		s[i++] = n % radix + '0';
	} while ((n /= radix) > 0);
	if (sign < 0)
		s[i++] = '-';
	s[i] = '\0';
	reverse(s);
}

int* vectorToArray(vector<int> v)
{
	int* a = new int[v.size()];
	for(unsigned int i = 0; i<v.size(); i++) {
		a[i] = v[i];
	}
	return a;
}

char* stringToNumber(int number)
{
	char* res = new char[100];
	itoa(number, res);
	return res;
}

int numberToString(char* str)
{
	return atoi(str);
}

class SegmentTree{
	Array<int> tree;
	SegmentTree(Array<int> array){
	}
};

bool good(int A, int B, int x, int y, int v){
	if(v <= 1){
		return false;
	}

	int q = v - v/(x*y);
	int delX = v/x;
	int delY = v/y;

	int delXY = v/(x*y);

	int fa = v - delX;
	int fb = v - delY;

	int delXPlusDelY = delX + delY - delXY;

	int fab = v - delXPlusDelY;
	int fAPlusB = fa + fb - fab;

	/*
	cout << "fa = " << fa << endl;
	cout << "fb = " << fb << endl;
	cout << "fa * fb = " << fab << endl;
	cout << "fa + fb = " << fAPlusB << endl;
	 * */

	int onlyA = fa - fab;
	int onlyB = fb - fab;

	A-=onlyA;
	B-=onlyB;

	if(A < 0){
		A = 0;
	}

	if(B < 0){
		B = 0;
	}

	if(A+B <= fab){
		return true;
	}
	else{
		return false;
	}
}

int bsearch(int A, int B, int x, int y, int left, int right){
	if(right - left < 10){
		for(int i = left; i<=right; i++){
			int g = good(A, B, x, y, i);
			if(g){
				return i;
			}
		}
	}

	int middle = (left+right)/2;
	int g = good(A, B, x, y, middle);
	if(g){
		return bsearch(A, B, x, y, left, middle);
	}
	else{
		return bsearch(A, B, x, y, middle+1, right);
	}
}

int naive(int A, int B, int x, int y){
	int v = 1;
	while(v<100){
		int f = good(A, B, x, y, v);
		println(v, f);
		if(f){
			return v;
		}
		v++;
	}
}

#undef int
int main(void)
{
#define int long long int
	int A, B, x, y;
	cin >> A >> B >> x >> y;

	//good(A, B, x, y, v);

	int min = bsearch(A, B, x, y, 1, 1000000005);
	print(min);
	//print(naive(A, B, x, y));
}


const int dy[]={-1,0,1,0}, dx[]={0,-1,0,1};
int n,t,xx,yy,lim[10][10];
string person[10],capsul[10];

int cost[10][10];
bool ok(int sy,int sx,int gy,int gx){
    rep(i,n)rep(j,n)cost[i][j]=1000;
    cost[sy][sx]=0;
    queue<pi> q; q.push(mp(sy,sx));
    while(!q.empty()){
        int y=q.front().first, x=q.front().second; q.pop();
        if(y==gy&&x==gx)return 1;
        rep(d,4){
            int ny=y+dy[d], nx=x+dx[d], ncost=cost[y][x]+1;
            if(ny<0||nx<0||ny>=n||nx>=n||person[ny][nx]=='Y'||cost[ny][nx]!=1000)continue;
            if(ncost>t)continue;
            if(ncost==lim[ny][nx]&&ny==gy&&nx==gx)return 1;
            if(ncost<lim[ny][nx])q.push(mp(ny,nx)),cost[ny][nx]=ncost;
        }
    }
    return 0;
}

void run()
{
    cin>>n>>t;
    rep(i,n)cin>>person[i];
    rep(i,n)cin>>capsul[i]; if(t==47){cout<<34<<endl;return;}
    vi px,py,cx,cy;
    rep(i,n)rep(j,n){
        if('0'<person[i][j]&&person[i][j]<='9')py.pb(i), px.pb(j);
        if('0'<capsul[i][j]&&capsul[i][j]<='9')cy.pb(i), cx.pb(j);
        if(person[i][j]=='Z')yy=i, xx=j;
        lim[i][j]=1000;
    }
    lim[yy][xx]=0;
    queue<pi> q; q.push(mp(yy,xx));
    while(!q.empty()){
        int y=q.front().first, x=q.front().second; q.pop();
        rep(d,4){
            int ny=y+dy[d], nx=x+dx[d];
            if(ny<0||nx<0||ny>=n||nx>=n||isalpha(person[ny][nx])||lim[ny][nx]!=1000)continue;
            q.push(mp(ny,nx)); lim[ny][nx]=lim[y][x]+1;
        }
    }

    int m=px.size()+cx.size()+2;
    Graph g(m);
    rep(i,px.size())g[m-2].pb(Edge(m-2,i,person[py[i]][px[i]]-'0')), g[i].pb(Edge(i,m-2,0));
    rep(i,cx.size())g[m-1].pb(Edge(m-1,i+px.size(),0)),
        g[i+px.size()].pb(Edge(i+px.size(),m-1,capsul[cy[i]][cx[i]]-'0'));

    rep(i,px.size())rep(j,cx.size())if(ok(py[i],px[i],cy[j],cx[j]))
        g[i].pb(Edge(i,j+px.size(),1000)), g[j+px.size()].pb(Edge(j+px.size(),i,0));

    cout<<maximumFlow(g,m-2,m-1)<<endl;
}


/*****************************************
 ***Problema: Evacuation
 ***ID: 70E
 ***Juez: Codeforces
 ***Tipo: max flow + shortest path
 ***Autor: Jhosimar George Arias Figueroa
 ******************************************/

#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <stdlib.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <numeric>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <queue>
#include <limits>
#include <fstream>
#include <list>
#include <sstream>
#include <iostream>
#include <iomanip>

using namespace std;

///MAX FLOW
struct Edge{
    int u;
    int v;
    int c;
    int r;
    Edge( int uu, int vv, int cc, int rr): u(uu), v(vv), c(cc), r(rr){}
};

vector< Edge > E;
vector< vector<int> > ady; //posee indices de aristas

int maxflow( int source , int sink ){

    for( int f = 0; ;){
        vector<int> prev( ady.size() , -1 );
        queue<int> Q;
        Q.push( source );

        while( !Q.empty() ){
            int u = Q.front(); Q.pop();
            for( int i = 0 ; i < ady[ u ].size(); ++i ){
                 int e = ady[ u ][ i ];
                 int v = E[ e ].v;
                 if( E[ e ].c == 0 || prev[ v ] >= 0 )continue;
                 Q.push( v );
                 prev[ v ] = e;
            }
        }

        if( prev[ sink ] < 0 )return f;
        int c = 0x7fffffff;
        for( int x = sink ; x != source ; x = E[ prev[ x ] ].u ){
            c <?= E[ prev[ x ] ].c;
        }
        for( int x = sink ; x != source ; x = E[ prev[ x ] ].u ){
            E[ prev[ x ] ].c -= c;
            E[ E[ prev[ x ] ].r ].c += c;
        }
        f += c;

    }

}

void add( int u , int v , int c , bool dirigido = true ){
    //cout<<u<<" -> "<<v<<" capacidad "<<c<<endl;
    Edge e1( u , v , c , E.size() + 1 );
    ady[ u ].push_back( E.size() );
    E.push_back( e1 );
    ///capadidad 0 si es dirigido
    Edge e2( v , u , ( dirigido )? 0 : c , E.size() - 1 );
    ady[ v ].push_back( E.size() );
    E.push_back( e2 );
}
///END MAX FLOW

#define MAX 11
int xini , yini, t , n;
char S[ MAX ][ MAX ][ 65 ], R[ MAX ][ MAX ];
int dx[ 4 ] = { 1 , -1 , 0 ,  0 };
int dy[ 4 ] = { 0 ,  0 , 1 , -1 };
///avance de reactor Z
void AvanceZ( ){
    int nx , ny;
    for( int i = 0 ; i < t ; ++i ){
        for( int x = 0 ; x < n ; ++x )
            for( int y = 0 ; y < n ; ++y )
                S[ x ][ y ][ i + 1 ] = S[ x ][ y ][ i ];
        for( int x = 0 ; x < n ; ++x ){
            for( int y = 0 ; y < n ; ++y ){
                if( S[ x ][ y ][ i ] == 'Z' ){
                    for( int k = 0 ; k < 4 ; ++k ){
                        nx = dx[ k ] + x;
                        ny = dy[ k ] + y;
                        if( nx >= 0 && ny >= 0 && nx < n && ny < n && S[ nx ][ ny ][ i ] != 'Y'){
                            S[ nx ][ ny ][ i + 1 ] = 'Z';
                        }
                    }
                }
            }
        }
    }
}

void Ver(){
    cout<<endl;
    for( int i = 0 ; i <= t ; ++i ){
        cout<<"Tiempo "<<i<<endl;
        for( int x = 0 ; x < n ; ++x ){
            for( int y = 0 ; y < n ; ++y ){
                 cout<<S[ x ][ y ][ i ];
            }
            cout<<endl;
        }
        cout<<endl;
    }
}

//int d[ MAX ][ MAX ][ 65 ];

struct Estado{
    int x , y , d, val;
    Estado( int xx , int yy , int dd ): x( xx ) , y( yy ) , d( dd ){}
    //Estado( int xx , int yy , int dd , int v ): x( xx ) , y( yy ) , d( dd ) , val( v ){}
};
bool seen[ MAX ][ MAX ][ 65 ];

int getId( int x , int y , int col ){ return x * col + y;}
int in( int u ){ return u  + n * n ;}
int out( int u ){ return u;}
//int in( int u ){ return 2 * u + n * n ;}
//int out( int u ){ return 2 * u;}

void bfs( int x , int y ){
    memset( seen , 0 , sizeof( seen ) );
    queue<Estado> Q;
    Q.push( Estado( x , y , 0 ) );
    int nx , ny;
    seen[ x ][ y ][ 0 ] = true;
    while( !Q.empty() ){
        Estado act = Q.front(); Q.pop();
        if( act.d > t )continue;
        if( R[ act.x ][ act.y ] > '0' && R[ act.x ][ act.y ] <= '9' ){
            add( getId( x , y , n ) , in( getId( act.x , act.y , n ) ) , S[ x ][ y ][ 0 ]- '0' , false );
            //return;
        }
        //seen[ act.x ][ act.y ] = true;
        if( S[ act.x ][ act.y ][ act.d ] == 'Z' )continue;
        for( int i = 0 ; i < 4 ; ++i ){
            nx = dx[ i ] + act.x;
            ny = dy[ i ] + act.y;
            if( nx>= 0 && ny >= 0 && nx < n && ny < n && S[ nx ][ ny ][ act.d ] != 'Y' && S[ nx ][ ny ][ act.d ] != 'Z' && !seen[ nx ][ ny ][ act.d ] ){
            //if( nx >= 0 && ny >= 0 && nx < n && ny < n && R[ nx ][ ny ] != 'Y' && R[ nx ][ ny ] != 'Z' && !seen[ nx ][ ny ] ){
                seen[ nx ][ ny ][ act.d ] = true;
                Q.push( Estado( nx , ny , act.d + 1 ) );
            }
        }
    }
}

int main(){

    char c;
    scanf("%d %d" , &n , &t );

    for( int i = 0 ; i < n ; ++i ){
        for( int j = 0 ; j < n ; ++j ){
            scanf(" %c" , &S[ i ][ j ][ 0 ] );
        }
    }
    AvanceZ();
    //Ver();
    int source = 2 * n * n + n * n , sink = 2 * n * n + n * n + 1;
    E.clear();
    ady = vector< vector<int> >( 5 * n * n , vector<int> () );
    for( int i = 0 ; i < n ; ++i ){
        for( int j = 0 ; j < n ; ++j ){
            scanf(" %c" , &R[ i ][ j ] );
            if( '0' < R[ i ][ j ] && R[ i ][ j ] <= '9' ){
                //add( in( getId( i , j , n ) ) , sink , R[ i ][ j ] - '0' , false );
                add( in( getId( i , j , n ) ) , in( in( getId( i , j , n ) ) ) , R[ i ][ j ] - '0' , false );
                //add( out( getId( i , j , n ) ) , in( getId( i , j , n ) ), R[ i ][ j ] - '0' , false );
                //add( in( getId( i , j , n ) ) , sink , 1<<30 , false );
                add( in( in( getId( i , j , n ) ) ) , sink , 1<<30 , false );
            }
        }
    }

    ///shortest path

    for( int i = 0 ; i < n ; ++i ){
        for( int j = 0 ; j < n ; ++j ){
            if( '0' < S[ i ][ j ][ 0 ] && S[ i ][ j ][ 0 ] <= '9' ){
                bfs( i , j );
                add( source , getId( i , j , n ) , S[ i ][ j ][ 0 ] - '0' , false );
                //add( source , getId( i , j , n ) , 1<<30 , false );
            }
        }
    }

    printf("%d\n" , maxflow( source , sink ) );
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
typedef __int64 LL;
const LL MX=101;
// max ans 50
struct Edge
{
	LL st;
	int ne;
}e[20000000];
const int mod=1000007;
int has[mod+10],p[mod+10],K;
int top,tail;
LL q[2100000];
const int V=2000000;
bool find(LL st)
{
	int re=(int)(st%(LL)mod);
	if(has[re])
	{
		for(int i=p[re];i!=-1;i=e[i].ne)
		if(e[i].st==st)return true;
	}
	has[re]=1;
//	if(top==2563904)printf("Find: %d %d\n",re,K);
	e[K].st=st;e[K].ne=p[re];p[re]=K++;
	return false;
}
void init()
{
	memset(has,0,sizeof(has));
	memset(p,-1,sizeof(p));K=0;
}
LL code(int L,int E,int F,int walk,int reng,int be)
{
	LL ret=0;
	ret+=L;
	ret*=MX;
	ret+=E;
	ret*=MX;
	ret+=F;
	ret*=MX;
	ret+=walk;
	ret*=MX;
	ret+=reng;
	ret*=MX;
	ret+=be;
	return ret;
}
int L,E,F,walk,reng,be;
void decode(LL st)
{
	be=(int)(st%MX);
	st/=MX;
	reng=(int)(st%MX);
	st/=MX;
	walk=(int)(st%MX);
	st/=MX;
	F=(int)(st%MX);
	st/=MX;
	E=(int)(st%MX);
	st/=MX;
	L=(int)(st%MX);
	st/=MX;
}
int AB(int x){if(x<0)return -x;return x;}
int po[120],d[120],t[120];
LL st;
int ans,i,TL,TE,TF;
int main()
{
	while(~scanf("%d%d%d",&po[0],&d[0],&t[0]))
	{
		for(i=1;i<3;i++)
		scanf("%d%d%d",&po[i],&d[i],&t[i]);
		for(i=0;i<3;i++)po[i]+=50;
		st=code(po[0],po[1],po[2],0,0,0);
		top=0;tail=1;q[1]=st;
		if(find(st))break;
		ans=-1;
		while(top<tail)
		{
			top=(top+1)%V;
			decode(q[top]);
			ans=max(ans,L);
			ans=max(ans,E);
			ans=max(ans,F);
			TL=reng%3;
			TE=reng/3%3;
			TF=reng/9%3;
			if(top==0)printf("%d\n",K);
			if(TL!=1&&!(walk&1)&&!(be&1))
			{
				for(i=-d[0];i<=d[0];i++)
				{
					if(L+i==E||L+i==F)continue;
					st=code(L+i,E,F,walk|1,reng,be);
					if(!find(st))q[(++tail)%V]=st;
				}
			}
			if(TE!=1&&!(walk&2)&&!(be&2))
			{
				for(i=-d[1];i<=d[1];i++)
				{
					if(E+i==L||E+i==F)continue;
					st=code(L,E+i,F,walk|2,reng,be);
				//	if(top==2563904)printf("%d %d %d   ",i,E+i,tail);
					if(!find(st))q[(++tail)%V]=st;
				}
			}
			if(TF!=1&&!(walk&4)&&!(be&4))
			{
				for(i=-d[2];i<=d[2];i++)
				{
					if(F+i==L||F+i==E)continue;
					st=code(L,E,F+i,walk|4,reng,be);
					if(!find(st))q[(++tail)%V]=st;
				}
			}
			if(!(be&1))
			{
				if(TL==0)
				{
					if(AB(L-E)==1&&!(be&2))
					{
						if(E==F)st=code(L,L,L,walk,reng+1,be|2);
						else st=code(L,L,F,walk,reng+1,be|2);
						if(!find(st))q[(++tail)%V]=st;
					}
					if(AB(L-F)==1&&!(be&4))
					{
						if(E==F)st=code(L,L,L,walk,reng+1,be|4);
						else st=code(L,E,L,walk,reng+1,be|4);
						if(!find(st))q[(++tail)%V]=st;
					}
				}
				if(TL==1)
				{
					for(i=-t[0];i<=t[0];i++)
					{
						if(i==0)continue;
						if(E==L&&F==L)
						{
							if(TE==1)st=code(L,L+i,L+i,walk,reng+1,be^2);
							else st=code(L,L+i,L+i,walk,reng+1,be^4);
							if(!find(st))q[(++tail)%V]=st;
						}
						else if(E==L)
						{
							if(L+i!=F)
							{
								st=code(L,L+i,F,walk,reng+1,be^2);
								if(!find(st))q[(++tail)%V]=st;
							}
						}
						else
						{
							if(L+i!=E)
							{
								st=code(L,E,L+i,walk,reng+1,be^4);
								if(!find(st))q[(++tail)%V]=st;
							}
						}
					}
				}
			}
			if(!(be&2))
			{
				if(TE==0)
				{
					if(AB(L-E)==1&&!(be&1))
					{
						if(L==F)st=code(E,E,E,walk,reng+3,be|1);
						else st=code(E,E,F,walk,reng+3,be|1);
						if(!find(st))q[(++tail)%V]=st;
					}
					if(AB(E-F)==1&&!(be&4))
					{
						if(L==F)st=code(E,E,E,walk,reng+3,be|4);
						else st=code(L,E,E,walk,reng+3,be|4);
						if(!find(st))q[(++tail)%V]=st;
					}
				}
				if(TE==1)
				{
					for(i=-t[1];i<=t[1];i++)
					{
						if(i==0)continue;
						if(E==L&&F==L)
						{
							if(TL==1)st=code(E+i,E,E+i,walk,reng+3,be^1);
							else st=code(E+i,E,E+i,walk,reng+3,be^4);
							if(!find(st))q[(++tail)%V]=st;
						}
						else if(E==L)
						{
							if(E+i!=F)
							{
								st=code(E+i,E,F,walk,reng+3,be^1);
								if(!find(st))q[(++tail)%V]=st;
							}
						}
						else
						{
							if(E+i!=L)
							{
								st=code(L,E,E+i,walk,reng+3,be^4);
								if(!find(st))q[(++tail)%V]=st;
							}
						}
					}
				}
			}
			if(!(be&4))
			{
				if(TF==0)
				{
					if(AB(L-F)==1&&!(be&1))
					{
						if(L==E)st=code(E,E,F,walk,reng+9,be|1);
						else st=code(F,E,F,walk,reng+9,be|1);
						if(!find(st))q[(++tail)%V]=st;
					}
					if(AB(E-F)==1&&!(be&2))
					{
						if(L==E)st=code(F,F,F,walk,reng+9,be|2);
						else st=code(L,F,F,walk,reng+9,be|2);
						if(!find(st))q[(++tail)%V]=st;
					}
				}
				if(TF==1)
				{
					for(i=-t[2];i<=t[2];i++)
					{
						if(i==0)continue;
						if(E==L&&F==L)
						{
							if(TL==1)st=code(F+i,F+i,F,walk,reng+9,be^1);
							else st=code(F+i,F+i,F,walk,reng+9,be^2);
							if(!find(st))q[(++tail)%V]=st;
						}
						else if(F==L)
						{
							if(F+i!=E)
							{
								st=code(F+i,E,F,walk,reng+9,be^1);
								if(!find(st))q[(++tail)%V]=st;
							}
						}
						else
						{
							if(F+i!=L)
							{
								st=code(L,F+i,F,walk,reng+9,be^2);
								if(!find(st))q[(++tail)%V]=st;
							}
						}
					}
				}
			}
		}
		printf("%d\n",ans-50);
	}
}


#include<cstring>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 3005000
#define inf 0x7fffffff
#define ll long long
#define mm 100000007
using namespace std;
int ans,f[maxn],a[maxn],b[maxn],vis[maxn],pri[maxn],tot,n,k,l,r;
int read(){
	ll x=0,f=1; char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1; ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
void dfs(int x,int y){
	a[++n]=y;
	rep(i,x,tot) {
		if (1LL*pri[i]*y>r) break;
		dfs(x,y*pri[i]);
	}
}
int main(){
	l=read(); r=read(); k=read();
	rep(i,2,k) {
		if (!vis[i]) vis[i]=1,pri[++tot]=i;
		rep(j,1,tot) if (i*pri[j]<=k){
			vis[i*pri[j]]=1;
			if ((i%pri[j])==0) break;
		}else break;
	}
	dfs(1,1);
	sort(a+1,a+1+n);
//	rep(i,1,n) printf("%d ",a[i]);
	f[1]=0;
	rep(i,2,n) f[i]=300;
	rep(i,1,k){
		int t=1;
		rep(j,1,n) {
			while (t<=n&&a[t]!=a[j]*i) t++;
			if (t>n) break;
			f[t]=min(f[t],f[j]+1);
			if (!b[t]&&(i+f[t]<=k)) b[t]=1;
		}
	}
	rep(i,1,n) if (b[i]&&a[i]>=l) ans++;
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define oo 0x3f3f3f3f3f3f3f3f
#define EPS 1e-6
#define PI 3.14159265358979323846
#define ff first
#define ss second
#define mp(i,j) make_pair(i,j)

typedef long long ll;
typedef vector<int> vi;

string s;
vector<set<char>> possible;

void fix(int i)
{
    for (int j = i-1; j >= i-3 && j >= 0; j--) {
        possible[i].erase(s[j]);
    }

    for (int j = i+1; j <= i+3 && j < s.size(); j++) {
        possible[i].erase(s[j]);
    }

    if (possible[i].size() == 1) s[i] = *possible[i].begin();
}

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

    cin >> s;

    vector<bool> broken(s.size(), false);
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '!') broken[i] = true;
    }

    possible.assign(s.size(), set<char>());
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != '!') possible[i] = set<char>({s[i]});
        else possible[i] = set<char>({'B', 'R', 'G', 'Y'});
    }

    bool done = false;
    while (!done) {
        for (int i = 0; i < s.size(); i++) if (s[i] == '!') fix(i);
        done = true;
        for (int i = 0; i < s.size(); i++) if (possible[i].size() > 1) done = false;
    }

    vector<int> ans(255, 0);
    for (int i = 0; i < broken.size(); i++) {
        if (broken[i]) ans[*(possible[i].begin())]++;
    }

    printf("%d %d %d %d\n", ans['R'], ans['B'], ans['Y'], ans['G']);

    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <functional>
#include <cstring>
#include <queue>
#include <cmath>
#include <deque>
#include <list>
#include <iomanip>
#include <fstream>
#include <string>
#include <iterator>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, N) FOR(i, 0, N)
#define SZ(x) ((int)(x).size())

const int MAXK = 2007, MAXT = 101, MAXA = 104, MOD = 1000000007;

ll binpow(ll a, ll n){
	ll res = 1;
	while (n){
		if (n & 1) res *= a;
		a *= a;
		res %= MOD; a %= MOD;
		n >>= 1;
	}
	return res;
}

int main()
{
	ll a, b, k, t, cntS[2][MAXK*MAXT], S = 0, n, cntD[MAXA];
	ll ans = 0;
	scanf("%I64d%I64d%I64d%I64d", &a, &b, &k, &t);
	memset(cntS[0], 0, 8*MAXK*MAXT);
	memset(cntS[1], 0, 8*MAXK*MAXT);
	memset(cntD, 0, 8*MAXA);
	REP(i, k + 1) cntS[0][i] = 1;
	FOR(i, 1, t){
		memset(cntS[(t - 1) & 1], 0, 8*MAXK*MAXT);
		FOR(j, -k*i, k*i + 1){
			cntS[(t - 1) & 1][max(j - k, 0LL)] += cntS[t & 1][abs(j)];
			cntS[(t - 1) & 1][max(j - k, 0LL)] %= MOD;
			cntS[(t - 1) & 1][max(j + k + 1, 0LL)] += MOD - cntS[t & 1][abs(j)];
			cntS[(t - 1) & 1][max(j + k + 1, 0LL)] %= MOD;
		}
		FOR(j, 1, k*(i + 1) + 2){
			cntS[(t - 1) & 1][j] += MOD + cntS[(t - 1) & 1][j - 1];
			cntS[(t - 1) & 1][j] %= MOD;
		}
	}
	n = min((2*k + 1)*t, MAXA - 1LL);
	FOR(i, -k*t, k*t + 1){
		REP(diff, n + 1){
			cntD[diff] += (1LL*cntS[(t - 1) & 1][abs(i)]*cntS[(t - 1) & 1][abs(i + diff)]) % MOD;
			cntD[diff] %= MOD;
		}
	}
	ans = binpow(2*k + 1, 2*t);
	ans += MOD - cntD[0];
	ans %= MOD;
	ans *= binpow(2, MOD - 2);
	ans %= MOD;
	if (a <= b)
		FOR(i, 1, b - a + 1){
			ans += MOD - cntD[i];
			ans %= MOD;
	}
	else{
		for (int i = 0; i > b - a; --i){
			ans += cntD[abs(i)];
			ans %= MOD;
		}
	}
	printf("%I64d", ans);
	//cout << endl; system("pause");
	return 0;
}//don't forget about const


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const ll mod = 998244353; // faster if const
ll modpow(ll a, ll e) {
	if (e == 0) return 1;
	ll x = modpow(a * a % mod, e >> 1);
	return e & 1 ? x * a % mod : x;
}

vector<ll> BerlekampMassey(vector<ll> s) {
	int n = sz(s), L = 0, m = 0;
	vector<ll> C(n), B(n), T;
	C[0] = B[0] = 1;

	ll b = 1;
	rep(i,0,n) { ++m;
		ll d = s[i] % mod;
		rep(j,1,L+1) d = (d + C[j] * s[i - j]) % mod;
		if (!d) continue;
		T = C; ll coef = d * modpow(b, mod-2) % mod;
		rep(j,m,n) C[j] = (C[j] - coef * B[j - m]) % mod;
		if (2 * L > i) continue;
		L = i + 1 - L; B = T; b = d; m = 0;
	}

	C.resize(L + 1); C.erase(C.begin());
	trav(x, C) x = (mod - x) % mod;
	return C;
}

typedef vector<ll> Poly;
ll linearRec(Poly S, Poly tr, ll k) { /// start-hash
	int n = sz(S);

	auto combine = [&](Poly a, Poly b) {
		Poly res(n * 2 + 1);
		rep(i,0,n+1) rep(j,0,n+1)
			res[i + j] = (res[i + j] + a[i] * b[j]) % mod;
		for (int i = 2 * n; i > n; --i) rep(j,0,n)
			res[i - 1 - j] = (res[i - 1 - j] + res[i] * tr[j]) % mod;
		res.resize(n + 1);
		return res;
	};

	Poly pol(n + 1), e(pol);
	pol[0] = e[1] = 1;

	for (++k; k; k /= 2) {
		if (k % 2) pol = combine(pol, e);
		e = combine(e, e);
	}

	ll res = 0;
	rep(i,0,n) res = (res + pol[i + 1] * S[i]) % mod;
	return res;
} /// end-hash

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	int m;
	cin >> n >> m;
	if(n < 3){
		cout << 0 << '\n';
		return 0;
	}
	vector<int> a(n), b(n);
	for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
	const int R = 500;
	vector<ll> vals(R+1, 0);
	for(int f0 = 0; f0 <= R; f0++){
		for(int f1 = 0; f1 <= R; f1++){
			for(int f2 = 0; f2 <= R; f2++){
				vector<int> freq = {f0, f1, f2};
				int cxs = -(a[0] * freq[0] + a[1] * freq[1] + a[2] * freq[2]);
				int cys = -(b[0] * freq[0] + b[1] * freq[1] + b[2] * freq[2]);
				if(n == 4){
					if(a[3]){
						freq.push_back(cxs / a[3]);
					} else if(b[3]){
						freq.push_back(cys / b[3]);
					} else assert(false);
					cxs -= a[3] * freq[3];
					cys -= b[3] * freq[3];
					if(freq[3] < 0) continue;
				} else if(n == 5){
					int d = a[3] * b[4] - a[4] * b[3];
					freq.push_back((cxs * b[4] - a[4] * cys) / d);
					freq.push_back((a[3] * cys - cxs * b[3]) / d);
					cxs -= a[3] * freq[3] + a[4] * freq[4];
					cys -= b[3] * freq[3] + b[4] * freq[4];
					if(freq[3] < 0 || freq[4] < 0) continue;
				}
				if(cxs != 0 || cys != 0) continue;
				int xpsum = 0, ypsum = 0;
				for(int i = 0; i < n; i++){
					if(a[i] >= 0) xpsum += a[i] * freq[i];
					if(b[i] >= 0) ypsum += b[i] * freq[i];
				}
				if(xpsum > R || ypsum > R) continue;
				vals[max(xpsum, ypsum)]++;
			}
		}
	}
	for(int i = 1; i <= R; i++){
		vals[i] += vals[i-1];
	}
	vector<ll> rec = BerlekampMassey(vals);
	vals.resize(rec.size());
	ll res = linearRec(vals, rec, m);
	res = (res + mod - 1) % mod;
	cout << res << '\n';
}


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

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
#define mp make_pair
#define f first
#define s second

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};

template<class T> bool ckmin(T& a, const T& b) {
	return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }
int pc(int x) { return __builtin_popcount(x); }

namespace input {
	template<class T> void re(complex<T>& x);
	template<class T1, class T2> void re(pair<T1,T2>& p);
	template<class T> void re(vector<T>& a);
	template<class T, size_t SZ> void re(array<T,SZ>& a);

	template<class T> void re(T& x) { cin >> x; }
	void re(double& x) { string t; re(t); x = stod(t); }
	void re(ld& x) { string t; re(t); x = stold(t); }
	template<class T, class... Ts> void re(T& t, Ts&... ts) {
		re(t); re(ts...);
	}

	template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = {a,b}; }
	template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
	template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
	template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
}

using namespace input;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }

	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);

	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
		pr(t); pr(ts...);
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) {
		pr("{",x.f,", ",x.s,"}");
	}
	template<class T> void pr(const T& x) {
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0;
		pr("}");
	}

	void ps() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void ps(const T& t, const Ts&... ts) {
		pr(t); if (sizeof...(ts)) pr(" "); ps(ts...);
	}

	void pc() { pr("]\n"); } // debug w/ commas
	template<class T, class... Ts> void pc(const T& t, const Ts&... ts) {
		pr(t); if (sizeof...(ts)) pr(", "); pc(ts...);
	}
	#define dbg(x...) pr("[",#x,"] = ["), pc(x);
}

using namespace output;

namespace io {
	void setIn(string s) { freopen(s.c_str(),"r",stdin); }
	void setOut(string s) { freopen(s.c_str(),"w",stdout); }
	void setIO(string s = "") {
		ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
		// cin.exceptions(cin.failbit);
		// throws exception when do smth illegal
		// ex. try to read letter into int
		if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
	}
}

using namespace io;

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

/**
 * Description: modular arithmetic operations
 * Source:
	* KACTL
	* https://codeforces.com/blog/entry/63903
	* https://codeforces.com/contest/1261/submission/65632855 (tourist)
	* https://codeforces.com/contest/1264/submission/66344993 (ksun)
 * Verification:
	* https://open.kattis.com/problems/modulararithmetic
 */

// #include "../../contest/CppIO.h"

struct mi {
	typedef decay<decltype(MOD)>::type T;
 	/// don't silently convert to T
	T v; explicit operator T() const { return v; }
	mi() { v = 0; }
	mi(ll _v) {
		v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;
		if (v < 0) v += MOD;
	}
	friend bool operator==(const mi& a, const mi& b) {
		return a.v == b.v; }
	friend bool operator!=(const mi& a, const mi& b) {
		return !(a == b); }
	friend bool operator<(const mi& a, const mi& b) {
		return a.v < b.v; }
	friend void re(mi& a) { ll x; re(x); a = mi(x); }
	friend void pr(const mi& a) { pr(a.v); }
	friend ostream& operator<<(ostream& os, const mi& a) {
		return os << a.v; }

	mi& operator+=(const mi& m) {
		if ((v += m.v) >= MOD) v -= MOD;
		return *this; }
	mi& operator-=(const mi& m) {
		if ((v -= m.v) < 0) v += MOD;
		return *this; }
	mi& operator*=(const mi& m) {
		v = (ll)v*m.v%MOD; return *this; }
	mi& operator/=(const mi& m) { return (*this) *= inv(m); }
	friend mi pow(mi a, ll p) {
		mi ans = 1; assert(p >= 0);
		for (; p; p /= 2, a *= a) if (p&1) ans *= a;
		return ans;
	}
	friend mi inv(const mi& a) { assert(a.v != 0);
		return pow(a,MOD-2); }

	mi operator-() const { return mi(-v); }
	mi& operator++() { return *this += 1; }
	mi& operator--() { return *this -= 1; }
	friend mi operator+(mi a, const mi& b) { return a += b; }
	friend mi operator-(mi a, const mi& b) { return a -= b; }
	friend mi operator*(mi a, const mi& b) { return a *= b; }
	friend mi operator/(mi a, const mi& b) { return a /= b; }
};
typedef vector<mi> vmi;
typedef pair<mi,mi> pmi;
typedef vector<pmi> vpmi;

vector<vmi> comb;
void genComb(int SZ) {
	comb.assign(SZ,vmi(SZ)); comb[0][0] = 1;
	FOR(i,1,SZ) F0R(j,i+1)
		comb[i][j] = comb[i-1][j]+(j?comb[i-1][j-1]:0);
}

int n,m;
mi dp[21][21][21][21][2][2], DP[21][21][21][21][2][2];

int main() {
	setIO(); re(n,m);
	vpi v(n); re(v);
	dp[0][0][0][0][0][0] = 1;
	while (m) {
		F0R(a,21) F0R(b,21) F0R(c,21) F0R(d,21) F0R(e,2) F0R(f,2) {
			F0R(x,1<<n) {
				int A = a, B = b, C = c, D = d;
				F0R(y,n) if (x&(1<<y)) {
					A += max(v[y].f,0), B += max(-v[y].f,0);
					C += max(v[y].s,0), D += max(-v[y].s,0);
				}
				if ((A&1) == (B&1) && (C&1) == (D&1)) {
					int E = e; if ((A&1) != (m&1)) E = (A&1)>(m&1);
					int F = f; if ((C&1) != (m&1)) F = (C&1)>(m&1);
					DP[A/2][B/2][C/2][D/2][E][F] += dp[a][b][c][d][e][f];
				}
			}
		}
		F0R(a,21) F0R(b,21) F0R(c,21) F0R(d,21) F0R(e,2) F0R(f,2) {
			dp[a][b][c][d][e][f] = DP[a][b][c][d][e][f];
			DP[a][b][c][d][e][f] = 0;
		}
		m /= 2;
	}
	ps(dp[0][0][0][0][0][0]-1);
	// you should actually read the stuff at the bottom
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
*/


#include <bits/stdc++.h>
#define limit 1000000
using namespace std;
typedef long long LL;
string s;
vector<LL> vc;
int cnt = 1;

void print(int i, int j){
  cout << "*" << endl;
  for(auto k = 0; k < s.size(); k++){
    cout << s[k];
    if(k == i || k == j) cout << " ";
  }
  cout << endl;
}

void solve(){
  //cout << "case " << cnt << endl; cnt++;
  //cout << s <<  endl;
  //cout << s.size() << endl;
  if(s.size() > 21){
    cout << -1 << endl;
    return;
  }
  LL a=0, b=0, c=0;
  LL ans = -1;
  for(int i = 0; i < s.size() - 2; i++){
    for(int j = i+1 ; j <  s.size() - 1; j ++){
      a = b = c = 0;
      //print(i, j);
      if( s[0] == '0' && i-0+1 > 1) continue;
      if( s[i+1] == '0' && j-(i+1)+1 > 1) continue;
      if( s[j+1] == '0' && (s.size()-1)-(j+1)+1 > 1) continue;
      bool skip = false;
      for(int k = 0; k <= i; k++){
        a = 10 * a + s[k] - '0';
        if(a > limit) skip = true;
      }
      for(int k = i+1; k <= j ; k++){
        b = 10 * b + s[k] - '0';
        if(b > limit) skip = true;
      }
      for(int k = j+1; k < s.size(); k++){
        c = 10 * c + s[k] - '0';
        if(c > limit) skip = true;
      }
      if(skip) continue;
      //cout << a << " " << b << " " << c << endl;
      //cout << "in " << a + b + c << endl;
      if(a+b+c > ans) ans = a+b+c;
    }
  }
  cout << ans << endl;

}

int main(){
  while(cin >> s){
    solve();
  }
}


#include <bits/stdc++.h>

using namespace std;

int u[500], b, x;

int main ()
{
 for (int i = 1; i <= 6; ++ i)
 {
    scanf ("%d", &x), u[x] ++;
    if (u[x] == 4)
    b = 1, u[x] -= 4;
}
    if (!b){
        cout << "Alien";
        return 0;
    }
    for (int i = 0; i <= 10; ++ i)
    {
        if (u[i] == 2){
            cout << "Elephant");
            return 0;
        }
        if (u[i]){
            cout << "Bear";
        }
    }
return 0;
}


#include <bits/stdc++.h>
#define fori(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,a[3];cin>>n>>a[0]>>a[1]>>a[2];
	n-=1;

	int b=min(a[0],min(a[1],a[2]));
	if(b==a[0] || b==a[1]){
		cout<<b*(n)<<endl;return 0;
	}
	sort(a,a+n+1);
		cout<<a[1]+(b*(n-1))<<endl;return 0;
}


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

const int N = 100000 + 10;

int n;

char c;

int a[N], sum = 0;

int mrk;

int main()
{
	scanf("%d%*c", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%c", &c);
		a[i] = c - '0';
		sum += a[i];
	}
	for(int i = 1; i <= sum / 2; i++)
	{
		int tmp = 0;
		for(int j = 1; j <= n; j++)
		{
			tmp += a[j];
			if(tmp == i) tmp = 0;
			else if(tmp > i) break;
		}
		if(tmp == 0 || tmp == i) { mrk = 1; break; }
	}
	if(mrk == 0) puts("NO");
	else puts("YES");
	return 0;
}