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

void fun(int x, int a, int b, int c, int& count){
 if(a!=x||b!=x||c!=x){
 	 if(c!=x){
 		 if(a+b>x){
 			c=x;
		 }
		 else c=b+a-1;
 		count++;
	 }
	 //printf("%d %d %d\n",a,b,c);
	 fun(x,c,a,b,count);
 }
}

 int main(){
 	int x,y,count=0;
 	scanf("%d%d",&x, &y);
 	fun(x,y,y,y,count);
 	printf("%d\n",count);
 	return 0;
 }


#include <bits/stdc++.h>
using namespace  std;
#define ll __int64
#define ull unsigned long long
const int N = 5e6+10;

int vis[110][110];
int f[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};

struct node {
	int x, y, step;
	friend bool operator < (const node n1, const node n2) {
		return n1.step > n2.step;
	}
}t, e;
priority_queue<node>q;

int bfs(int l, int u, int xi, int yi) {
	e.x=l, e.y=u, e.step=0;
	q.push(e);
	vis[e.x][e.y] = 1;
	while(!q.empty()) {
		e = q.top(); q.pop();
		if(e.x == xi && e.y == yi) return e.step;
		for(int i = 0; i < 4; i++) {
			t.x = e.x + f[i][0];
			t.y = e.y + f[i][1];
			t.step = e.step + 1;
			if(t.x<0 || t.y<0) continue;
			if(vis[t.x][t.y]) continue;
			vis[t.x][t.y] = 1;
			q.push(t);
		}
	}
}

int main() {
	string s;
	cin>>s;
	int len = (int)s.size();
	int x=0, y=0, xx=0, yy=0;
	for(int i = 0; i < len; i++) {
		if(s[i] == 'L') y--;
		if(s[i] == 'R') y++;
		if(s[i] == 'U') x--;
		if(s[i] == 'D') x++;
		xx = min(xx, x);
		yy = min(yy, y);
	}
	xx = -xx, yy = -yy;
	for(int i=0; i<110; i++) {
		for(int j=0; j<110; j++) vis[i][j] = 1;
	}
	x=xx, y=yy;
	for(int i=0; i<len; i++) {

		if(s[i] == 'L') y--;
		if(s[i] == 'R') y++;
		if(s[i] == 'U') x--;
		if(s[i] == 'D') x++;
		vis[x][y] = 0;

	}
	int ans = bfs(xx, yy, x, y);

	if(ans == len) printf("OK\n");
	else printf("BUG\n");
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,m,a=1;
    cin>>n>>m;
    while (m>=a)
    {
        m-=a;
        a++;
        if (a==n+1)
        {
            a=1;
        }
    }
    cout<<m;
    return 0;
}


#include <bits/stdc++.h>

int main() {
	int a, b, y{0};
	std::cin>>a>>b;
	while(a<=b){
		a *= 3;
	    b *= 2;
	    y++;
	}
	std::cout<<y<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
long long int i,j=0,n,c,sum=0,x,a,b,f=0;
int base(int k,int l)
{
    sum=0;
    while(k!=0)
    {
        sum+=k%l;
        k/=l;

    }
    return sum;
}
int gcd(int a,int b)
{
    return(b==0?a:gcd(b,a%b));
}
int main()
{   f=0;
    cin>>n;
    for(i=2;i<n;i++)
        f+=base(n,i);
        j=gcd(f,n-2);
       cout<<(f/j)<<"/"<<(n-2)/j<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int A[81][81];
struct Edge{
	int to, cap, cost, next;
};
Edge E[30000];
int head[7000], ne = 1;
int NV;
inline void addEdge(int from, int to, int cap, int cost) {
	E[++ne] = {to, cap, cost, head[from]}, head[from] = ne;
	E[++ne] = {from, 0, -cost, head[to]}, head[to] = ne;
}
int d[7000], p[7000];
bool inqueue[7000];
pair<int, int> mcmf(int S, int T) {
	int f = 0, c = 0;
	while(1) {
		for(int i = 0; i < NV; ++i) d[i] = 1e9;
		queue<int> Q;
		Q.push(S); d[S] = 0;
		while(!Q.empty()) {
			auto v = Q.front(); Q.pop();
			inqueue[v] = 0;
			for(int x = head[v]; x; x = E[x].next) {
				int &u = E[x].to, &cap = E[x].cap, &cost = E[x].cost;
				if(cap > 0 and d[v] + cost < d[u]) {
					d[u] = d[v] + cost;
					p[u] = x;
					if(!inqueue[u]) Q.push(u), inqueue[u] = 1;
				}
			}
		}
		if(d[T] == 1e9) break;
		int df = 1e9;
		for(int i = T; i != S; i = E[p[i]^1].to)
			df = min(df, E[p[i]].cap);
		for(int i = T; i != S; i = E[p[i]^1].to)
			E[p[i]].cap -= df, E[p[i]^1].cap += df;
		f += df, c += df * d[T];
	}
	return {f, c};
}
int n, m;
inline int group(int i, int j) {
	return (i + j) & 1;
}
inline int id(int i, int j) {
	return (i-1)*m+j;
}
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
			cin >> A[i][j];
	int S = 0, T = 6789;
	NV = 6790;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j) {
			if(group(i, j) == 0)
				addEdge(S, id(i, j), 1, 0);
			else
				addEdge(id(i, j), T, 1, 0);
		}
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			if(group(i, j) == 0) {
				if(i-1 >= 1)
					addEdge(id(i, j), id(i-1, j), 1, A[i][j] != A[i-1][j]);
				if(i+1 <= n)
					addEdge(id(i, j), id(i+1, j), 1, A[i][j] != A[i+1][j]);
				if(j-1 >= 1)
					addEdge(id(i, j), id(i, j-1), 1, A[i][j] != A[i][j-1]);
				if(j+1 <= m)
					addEdge(id(i, j), id(i, j+1), 1, A[i][j] != A[i][j+1]);
			}
		}
	}
	auto ans = mcmf(S, T);
	cout << ans.second << endl;
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<long long> vecll;
typedef stack<int> stki;
typedef stack<long long> stkll;
typedef queue<int> qi;
typedef queue<long long> qll;
typedef deque<int> dqi;
typedef deque<long long> dqll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef priority_queue<int> pqi;
typedef priority_queue<long long> pqll;
typedef string st;

vector <string> ar;
int solved = 0;
void moveStatues(vector <pii> &v) {
    for(int i = 0;i<v.size();i++){
        v[i].first++;
    }
}

int checkOnStatue(int i,int j,vector <pii> v){
    for(int k = 0;k<v.size();k++){
        if(i==v[k].first && j == v[k].second){
            return 1;
        }
    }
    return 0;
}

int dfs (int i ,int j,vector <pii> v,vector<veci> used) {
    if(i<0 || j < 0 || j >= 8 || i >= 8 || used[i][j]) {
        return 0;
    }
    if (checkOnStatue(i,j,v)) {
        return 0;
    }
    if(i == 0 && j == 7){
        solved = 1;
        return 1;
    }
    moveStatues(v);
    if (checkOnStatue(i,j,v)) {
        return 0;
    }
    int x = 0;
    used[i][j] = 1;

    x = max(dfs(i-1,j,v,used),x);if(solved) return 1;
     x = max(dfs(i,j+1,v,used),x);if(solved) return 1;
    x = max(dfs(i,j-1,v,used),x);if(solved) return 1;
   x = max(dfs(i+1,j,v,used),x); if(solved) return 1;
    x = max(dfs(i+1,j+1,v,used),x);if(solved) return 1;
    x = max(dfs(i+1,j-1,v,used),x);if(solved) return 1;
    x = max(dfs(i-1,j+1,v,used),x);if(solved) return 1;
    x = max(dfs(i-1,j-1,v,used),x);if(solved) return 1;
    x = max(dfs(i,j,v,used),x);if(solved) return 1;
    return x;
}
int main()
{
   ios_base::sync_with_stdio(0),cin.tie(0);
   int n,m,k,r,i,j,temp,temp1,temp2,temp3,x,x1,x2,x3;
   st str;
   vector <veci> used;
   veci asd(8);
   for(i = 0;i<8;i++){
        used.push_back(asd);
   }
    vector <pii> v;
   for ( i = 0;i<8;i++) {
    cin>>str;
    ar.push_back(str);
    for(j = 0;j<8;j++) {
            if(str[j] == 'S') {
                v.push_back(make_pair(i,j));

            }
        }
   }

x = 0;
  x = dfs(7,0,v,used);
    if (x == 1) {cout<<"WIN"<<endl; return 0;}
  x =  dfs(6,0,v,used);
     if (x == 1) {cout<<"WIN"<<endl; return 0;}
  x = dfs(6,1,v,used);
      if (x == 1) {cout<<"WIN"<<endl; return 0;}
  x = dfs(7,1,v,used);
      if (x == 1) {cout<<"WIN"<<endl; return 0;}
      else {
        cout<<"LOSE"<<endl;
      }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <sstream>
#include <cmath>
#include <stdio.h>
#include <iomanip>
#include <queue>
#include <map>

#define pb push_back
#define mp make_pair
#define f1 first
#define f2 second
#define X first
#define Y second

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef vector <int> VINT;

const int maxn = 1000 * 100 + 5;
const int mod = 1000 * 1000 * 1000 + 7;

VINT adj[maxn], adjr[maxn];
int mark[maxn], ans[maxn];
int st[maxn];

void dfs1(int x)
{
	mark[x] = 1;
	ans[x]++;
//	if (st[x] == 2)
//		return;
	for (int i = 0; i < (int)adj[x].size(); i++)
	{
		int u = adj[x][i];
		if (!mark[u])
			dfs1(u);
	}
}
void dfs2(int x)
{
	mark[x] = 1;
	ans[x]++;
	if (st[x] == 1)
		return;
	for (int i = 0; i < (int)adjr[x].size(); i++)
	{
		int u = adjr[x][i];
		if (!mark[u])
			dfs2(u);
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> st[i];
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;
		adj[u].pb(v);
		adjr[v].pb(u);
	}
	for (int i = 0; i < n; i++)
		if (!mark[i] && st[i] == 1)
			dfs1(i);
	for (int i = 0; i < n; i++)
		mark[i] = 0;
	for (int i = 0; i < n; i++)
		if (!mark[i] && st[i] == 2)
			dfs2(i);
	for (int i = 0; i < n; i++)
		if (ans[i] == 2)
			cout << 1 << endl;
		else
			cout << 0 << endl;
	return 0;
}


#include<iostream>
#define ll long long
#define MOD ((ll)1e9+7)
using namespace std;
ll dp[2020][2020];
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=0;i<max(n,m);i++)
        for(int j=0;j<=i;j++)
            dp[j][i]=j?(dp[j][i-1]+dp[j-1][i-1])%MOD:1;
    cout<<(dp[2*k][n-1]*dp[2*k][m-1])%MOD<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std ;
int main()
{
    long long  a  , b , m  , c = 0;
    cin >> a >> b >> m ;
    if (a > b )
        swap(a,b);
    if (a <= 0 && b <= 0 && b < m )
    {
            cout << -1 ; return 0 ;
    }
    else if (b < m)
    {
        if (a < 0 )
        {
            c += (-a) / b ;
            if ((-a) % b != 0 ) c++;
            a = b - ( (-a) % b );
            if (a == b) a = 0 ;
        }
        // cout << a << " " << c << endl;
        while( b < m)
        {
            long long d = b;
            a += b ; // a1 = 2
            b = a; // a2 = 2
            a = d;
            c++;
        }
    }

    cout << c;
}


#include <bits/stdc++.h>

using namespace std;

vector<long long> divisors(long long num)
{
    vector<long long>ret;
    long long i;
    for(i=2;i*i<num;i++)
        if(num%i==0)
        {
            ret.push_back(i);
            ret.push_back(num/i);
        }
    if(i*i==num)
        ret.push_back(i);
    return ret;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    long long n,m,k;
    while(scanf("%lld%lld%lld",&n,&m,&k)!=EOF)
    {
    	if(n%2==0)
    	{
    		printf("Marsel\n");
    		continue;
    	}
    	vector<long long>div=divisors(m);
    	bool flag=false;
    	if(m>1)
    		div.push_back(1);
    	for(int i=0;i<div.size()&&!flag;i++)
    		if(div[i]>=k)
    			flag=true;
    	if(flag)
    		printf("Timur\n");
    	else
    		printf("Marsel\n");
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pi 3.14159265358979323846
const ll INF=1<<28;
#define MOD 1000000007
using namespace std;

ll POWER(ll base,ll expo)
{
    ll num=1;
    ll i=expo;
    while(i)
    {
        num=num*base;
        i--;
    }
    return num;
}
int main()
{
    ll t=1; //cin>>t;
    while(t--)
    {
       ll n,m,k; cin>>n>>m>>k;
       ll a[n];
       for(ll i=0;i<n;i++)
        cin>>a[i];
       sort(a,a+n);
       if(m<=k)cout<<0;
       else
       {
           ll sum=0,i=n,devices=m,soc=k;
           while(sum<m && devices>soc &&i>=1)
           {
               i--;
               sum+=a[i];
               devices-=a[i];
               soc--;
           }
           if(devices<=soc)cout<<n-i;
           else
           {
               ll i=n,used=0,ss=0,j=0;
               while(i>=1 && ss<m)
               {
                 i--;
                 if(used>=k*j && j>=1)
                    ss--;
                 ss+=a[i];
                 used++;
                 if(used%k==0 && used!=0)
                    j++;
               }
               if(ss>=m)cout<<used;
               else cout<<-1;
           }
       }
    }
    return 0;
}


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

const int UP = 0 , DOWN = 1 , LEFT = 2 , RIGHT = 3;
const int UPLEFT = 4 , UPRIGHT = 5, DOWNLEFT = 6 , DOWNRIGHT = 7;

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

const int MAX = 5 * 30 + 5;
bool marked[2 * MAX][2 * MAX][8][32][6];

map<pair<int, int>, bool > mp;
int t[100];

pair<int, int> rot(int dir)
{
  if(dir == UP)
    return make_pair(UPLEFT , UPRIGHT);
  if(dir == DOWN)
    return make_pair(DOWNLEFT , DOWNRIGHT);
  if(dir == LEFT)
    return make_pair(UPLEFT, DOWNLEFT);
  if(dir == RIGHT)
    return make_pair(UPRIGHT , DOWNRIGHT);
  if(dir == UPLEFT)
    return make_pair(UP , LEFT);
  if(dir == UPRIGHT)
    return make_pair(UP , RIGHT);
  if(dir == DOWNLEFT)
    return make_pair(DOWN , LEFT);
  if(dir == DOWNRIGHT)
    return make_pair(DOWN, RIGHT);
}
struct node
{
  int x , y, dir;
  int lev , far;
  node(int _x, int _y , int _dir , int _lev , int _far)
  {
    x = _x , y = _y , dir = _dir , lev = _lev , far = _far;
  }
};
queue<node> Q;

int main()
{
  int n;
  cin >> n;
  for(int i = 1;i <= n;i ++)
    cin >> t[i];

  int ans = 0;
  Q.push(node(MAX , MAX , UP , 1 , 1));

  marked[MAX][MAX][UP][1][1] = true;
  mp[pair<int, int>(MAX , MAX)] = true;
  ans ++;
  while(!Q.empty())
  {
      node v = Q.front();
      Q.pop();

      if(!mp[pair<int, int>(v.x , v.y)])
      {
        mp[pair<int, int>(v.x , v.y)] = true;
        ans ++;
      }

      int lev = v.lev;
      int far = v.far;

      int x2 = v.x , y2 = v.y;

      if(lev == n + 1)
        continue;

      if(far != t[lev])
      {
        x2 += dx[v.dir] , y2 += dy[v.dir];
        if(marked[x2][y2][v.dir][lev][far + 1]) continue;
        marked[x2][y2][v.dir][lev][far + 1] = true;
        Q.push(node(x2 , y2 , v.dir , lev , far + 1));
      }
      else
      {
        pair<int, int> dirs = rot(v.dir);
        if(!marked[v.x][v.y][dirs.first][lev + 1][0])
        {
            marked[v.x][v.y][dirs.first][lev + 1][0] = true;
            Q.push(node(v.x, v.y , dirs.first, lev + 1, 0));
        }
        if(!marked[v.x][v.y][dirs.second][lev + 1][0])
        {
            marked[v.x][v.y][dirs.second][lev + 1][0] = true;
            Q.push(node(v.x, v.y , dirs.second, lev + 1, 0));
        }
      }
  }
  cout << ans << endl;

  return 0;
}


#include <iostream>
using namespace std;

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

int main()
{
    int a, b, x, y;
    cin >> a >> b >> x >> y;

    int d = gcd(x, y);
    x /= d; y /= d;
    int k1 = a / x;
    int k2 = b / y;
    int k = min(k1, k2);

    cout << x * k << " " << y * k << endl;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>

#define F first
#define S second
#define eps 1e-8
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define INF 2000000000

typedef long long ll;

using namespace std;
ll l, r, ans;
int q, Q, p;
bool w[99], W[99];
int main()
{
	ios::sync_with_stdio(0);
	cin >> l >> r;
	while(l){
		w[q++] = l % 2;
		l >>= 1;
	}
	while(r){
		W[Q++] = r % 2;
		r >>= 1;
	}
	for(int i = Q; i >= 0; i--)
		if(w[i] != W[i]){
			p = i + 1;
			break;
		}
	ans = (1ll << p) - 1ll;
	cout << ans;

	return 0;
}


//hey Stalker
#include<bits/stdc++.h>
#define ll long long
#define vect vector<ll>
#define pb push_back
#define f(n) for(i=0;i<n;i++)
#define F(n) for(i=1;i<=n;i++)
#define s second
#define mod 1000000007
#define Map map<ll , ll >
using namespace std;
main()
{ll t;
cin>>t;
while(t--)
{
	ll n,k,d;
	cin>>n>>k>>d;
	ll i;
	Map m;
	ll a[n];
	f(n)
		cin>>a[i];
	f(d)
			m[a[i]]+=1;
	ll ans=m.size();
//	cout<<ans<<endl;
	for(i=d;i<n;i++)
	{
//		if(m.find(a[i])==m.end())
			m[a[i]]+=1;
		m[a[i-d]]--;
		if(m[a[i-d]]==0)
			m.erase(a[i-d]);
		ans=min(ans,(ll)m.size());

	}
	cout<<ans<<endl;
}
}


#include <iostream>
#include <cstdio>
#include <cctype>
#define il inline
#define vd void
#define rep(i,x,y) for(register int i=x;i<=y;++i)
#define drp(i,x,y) for(register int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il int rd(); il vd pc(char c); il vd rt(int x); il vd flush();
int n,s;
int main(){//sjn AK IOI
	cin>>n>>s;
	int ans=s/n;
	if(s%n) ++ans;
	cout<<ans;
	return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il int rd(){char c;
	while(!isdigit(c=gc())&&c!='-');
	int f=c=='-'?c=gc(),1:0,x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(int x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}


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

int main(){
	char a, b;
	int h1, h2, m1, m2;
	cin >> h1 >> a >> m1 >> h2 >> b >> m2;
	int t1 = h1*60 + m1;
	int t2 = h2*60 + m2;
	int mid = (t1+t2)/2;
	int hAns = mid/60;
	int mAns = mid%60;
	if(hAns < 10) cout << "0" << hAns << ":";
	else cout << hAns << ":";
	if(mAns < 10) cout << "0" << mAns << endl;
	else cout << mAns << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	char str[510];
	scanf("%s",str);
	int t=0,i;
	for(i=0;i<strlen(str);i++)
	{
		if(str[i]-'a'>t)
		{
		  printf("NO\n");
		  break;
	    }
		if(str[i]-'a'==t)
		t++;
	}
	if(i==strlen(str))
	printf("YES\n");
	return 0;
}


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

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

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

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

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

}


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

using namespace std;

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

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

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

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

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

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

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

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


#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int INF = 0x3f3f3f3f;

void solve() {
        int n;
        cin >> n;
        int a[3], b[3];
        for (int i = 0; i < 3; ++i)
                cin >> a[i];
        for (int i = 0; i < 3; ++i)
                cin >> b[i];

        cout << max({0, a[0] - b[0] - b[2], a[1] - b[0] - b[1], a[2] - b[2] - b[1]}) << ' ' <<
                min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0]) << endl;
}

int main() {
        solve();
        return 0;
}


#include<iostream>
#include<iomanip>
#include<fstream>
#include<algorithm>
using namespace std;
int a,b,c;
int sum;
int main()
{
	string s,st,stt;
	cin>>s;
	cin>>stt;
	int len=s.size();
	for(int i=len-1;i>-1;i--)
	{
		st+=s[i];
	}
	for(int i=0;i<len;i++)
	{
		if(stt[i]==st[i])
		{
			sum++;
		}
	}
	if(sum==len)
	cout<<"YES";
	else
	cout<<"NO";
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
mat mul(mat a,mat b,ll mod)
{
    mat c(a.size(),vec(b[0].size()));
    for(int i=0;i<a.size();i++)
    {
        for(int k=0;k<a[0].size();k++)
        {
            for(int j=0;j<b[0].size();j++)
            {
                c[i][j]=(c[i][j]+a[i][k]*b[k][j]%mod)%mod;
            }
        }
    }
    return c;
}
mat q_pow(mat base,ll n,ll mod)
{
    mat ans(base.size(),vec(base.size()));
    for(int i=0;i<ans.size();i++)ans[i][i]=1;
    while(n)
    {
        if(n&1)ans=mul(ans,base,mod);
        base=mul(base,base,mod);
        n>>=1;
    }
    return ans;
}
int main()
{
    ll n,sx,sy,dx,dy,t;
    while(~scanf("%lld%lld%lld%lld%lld%lld",&n,&sx,&sy,&dx,&dy,&t))
    {
        sx--;
        sy--;
        mat a(6,vec(6));
        a={
            {2,1,1,0,1,2},
            {1,2,0,1,1,2},
            {1,1,1,0,1,2},
            {1,1,0,1,1,2},
            {0,0,0,0,1,1},
            {0,0,0,0,0,1}
          };
          a=q_pow(a,t,n);
          mat b(6,vec(1));
          b[0][0]=sx;
          b[1][0]=sy;
          b[2][0]=(dx%n+n)%n;
          b[3][0]=(dy%n+n)%n;
          b[4][0]=0;
          b[5][0]=1;
          a=mul(a,b,n);
          printf("%lld %lld\n",a[0][0]+1,a[1][0]+1);
    }
    return 0;
}


#include <iostream>
using namespace std;
long long n;
int main()
{
    cin>>n;
    if(n%2==1)
    {
        cout<<"black";
        return 0;
    }
    cout<<"white"<<endl;
    cout<<1<<" "<<2;
    return 0;
}


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

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

using namespace std;

#ifdef ONLINE_JUDGE
	#define WAIT
#else
	#define WAIT cout<<flush, system("PAUSE")
#endif

#define FOR(IN,N) for(int I = IN;I < N;++I)
#define FORR(END,N) for(int I = N-1;I >= END;--I)
#define foreach(arr) for(auto item : arr)
#define REP(I,A,B) for(int I = A;I < B;++I)

#define CONTAINS(m,x) m.find(x) != m.end()
#define clr(x) memset((x),0,sizeof(x))
#define PB push_back
#define remove erase
#define ALL(v) v.begin(),v.end()
#define sz(a) a.size();
#define endl '\n'
#define MAX 10010

typedef long long i64;
typedef pair<int,int> pii;

//const int MOD = ;

string solve,s; int N;

void Check(){

	if(solve[0] == '.'){
		solve.remove(0,1);
		solve = "dot" + solve;
	}
	else if(solve[0] == '@'){
		solve.remove(0,1);
		solve = "at" + solve;
	}

	if(solve[solve.size() - 1] == '.'){
		solve.remove(solve.size() - 1,1);
		solve += "dot";
	}
	else if(solve[solve.size() - 1] == '@'){
		solve.remove(solve.size() - 1,1);
		solve += "at";
	}

}

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

	cin >> s;

	N = sz(s);

	solve = "";

	for(int I = 0;I < N;++I){

		if(I + 3 <= N){
			if(s.substr(I,3) == "dot"){
				solve += ".";
				I+=2;
			}
			else{
				if(I + 2 <= N){
					if(s.substr(I,2) == "at"){
						solve += "@";
						I+=1;
					}
					else solve += s[I];
				}
				else solve += s[I];
			}
		}
		else if(I + 2 <= N){
			if(s.substr(I,2) == "at"){
				solve += "@";
				I+=1;
			}
			else solve += s[I];
		}
		else solve += s[I];
	}

	Check();

	int cont = 0;

	for(int I = 0;I < solve.size();++I){

		if(solve[I] == '@') ++cont;

	}

	if(cont == 1) cout << solve << endl;

	else{

		bool ok = 1;

		for(int I = 0;I < solve.size();++I){

			if(solve[I] == '@'){
				if(ok){
					cout << '@';
					ok = false;
				}
				else{
					cout << "at";
				}
				continue;
			}
			cout << solve[I];
		}
		cout << endl;
	}
}


#include <bits/stdc++.h>
#include <vector>
using namespace std;
int freq[26];
int main()
{
	int n;string s;
	cin>>n>>s;
	long long int maxi=0;
	set<char>c;
	for(int i=0;i<n;i++)
	{
		if(isupper(s[i]))
		{
			long long int size=c.size();
			maxi=max(maxi,size);
			c.clear();
		}
		else
		{
			c.insert(s[i]);
			// freq[s[i]-'a']++;
		}
	}
	long long int size=c.size();
	//cout<<size<<endl;
			maxi=max(maxi,size);
			c.clear();
	cout<<maxi;

	return 0;
}


#include <iostream>
using namespace std;
//Karswrmepl
int main ()
{
long long n;
cin>>n;
if (n%2){
	cout<<1;
}
else {
	cout<<2;
}
}


// In the name of GOD!
// 1396 / 03 / 23

#include <iostream>
#include <map>

using namespace std;

map<string, int> d;

void pre();
string chrd(string x, string y, string z);

int main() {
	string x, y, z;
	cin >> x >> y >> z;
	pre();
	if (chrd(x, y, z) != "0") cout << chrd(x, y, z) << '\n';
	else if (chrd(x, z, y) != "0") cout << chrd(x, z, y) << '\n';
	else if (chrd(y, x, z) != "0") cout << chrd(y, x, z) << '\n';
	else if (chrd(y, z, x) != "0") cout << chrd(y, z, x) << '\n';
	else if (chrd(z, x, y) != "0") cout << chrd(z, x, y) << '\n';
	else if (chrd(z, y, x) != "0") cout << chrd(z, y, x) << '\n';
	else cout << "strange\n";
}

void pre() {
	d["C"] = 0;
	d["C#"] = 1;
	d["D"] = 2;
	d["D#"] = 3;
	d["E"] = 4;
	d["F"] = 5;
	d["F#"] = 6;
	d["G"] = 7;
	d["G#"] = 8;
	d["A"] = 9;
	d["B"] = 10;
	d["H"] = 11;
}

string chrd(string x, string y, string z) {
	int a, b;
	a = (d[y] - d[x] + 12) % 12;
	b = (d[z] - d[y] + 12) % 12;
	if (a == 4 && b == 3) return "major";
	if (a == 3 && b == 4) return "minor";
	return "0";
}


#include <bits/stdc++.h>

using namespace std;

const int MaxN = 2e3 + 23;

const int MOD = 998244353;

int pless, pgreater;
int CP[MaxN][MaxN];
int STRONG[MaxN];
int ans[MaxN];

int bpow(int a, int b)
{
    if(!b)
        return 1;
    int res = bpow(a, b >> 1);
    res = (res * 1ll * res) % MOD;
    if(b & 1)
        res = (res * 1ll * a) % MOD;
    return res;
}

void calcCP(int n, int s)
{
    if(!s)
        CP[n][s] = 1;
    else
    {
        CP[n][s] = (CP[n - 1][s - 1] * 1ll * bpow(pgreater, n - s)) % MOD + (CP[n - 1][s] * 1ll * bpow(pless, s)) % MOD;
        if(CP[n][s] >= MOD)
            CP[n][s] -= MOD;
    }
}

void calcStrong(int n)
{
    STRONG[n] = 1;
    if(n > 1)
    {
        for(int i = 1; i < n; ++i)
        {
            STRONG[n] -= (STRONG[i] * 1ll * CP[n][i]) % MOD;
            if(STRONG[n] < 0)
                STRONG[n] += MOD;
        }
    }
}

void calcAns(int n)
{
    if(n < 2)
        ans[n] = 0;
    else
    {
        for(int i = 1; i <= n; ++i)
        {
            ans[n] += STRONG[i] * 1ll * CP[n][i] % MOD * 1ll * (i * (n - i) + (i * (i - 1)) / 2 + (long long) (i < n ? ans[i] : 0) + ans[n - i]) % MOD;
            if(ans[n] >= MOD)
                ans[n] -= MOD;
        }
        int coef = 1 - (STRONG[n] * 1ll * CP[n][n]) % MOD;

        if(coef < 0)
            coef += MOD;

        ans[n] = (ans[n] * 1ll * bpow(coef, MOD - 2)) % MOD;
    }
}

main()
{
//    freopen("input.txt", "r", stdin);
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    int n, a, b;
    cin >> n >> a >> b;

    pless = (a * 1ll * bpow(b, MOD - 2)) % MOD;
    pgreater = ((b - a) * 1ll * bpow(b, MOD - 2)) % MOD;

    for(int i = 0; i <= n; ++i)
        for(int j = 0; j <= i; ++j)
            calcCP(i, j);

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

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

    cout << ans[n] << '\n';

    return 0;
}


#include <bits/stdc++.h>
#define len(x) ((int)(x).size())
#define x first
#define y second
using namespace std;

const int K = 1010, MOD = 1e9 + 7;

int powmod(int a, int x){
	if(x == 0) return 1;
	if(x%2 == 0) return powmod(a*1LL*a%MOD, x/2);
	return a*1LL*powmod(a, x - 1)%MOD;
}

int dp[K][K];

int main(){
	int k, va, vb;
	scanf("%d %d %d", &k, &va, &vb);

	int den = powmod(va + vb, MOD - 2);
	int pa = va*1LL*den%MOD;
	int pb = vb*1LL*den%MOD;
	int one_b = pa*1LL*powmod(pb, MOD - 2)%MOD;

	for(int i = k - 1; i >= 0; i--){
		for(int j = k; j >= 1; j--){
			if(i + j >= k){
				dp[i][j] = (i + j + one_b)%MOD;
			}else{
				dp[i][j] = (pa*1LL*dp[i][j + 1] + pb*1LL*dp[i + j][j])%MOD;
			}
		}
	}
	printf("%d\n", dp[0][1]);
	return 0;
}


// Author : Mohamed Sameh
#include<bits/stdc++.h>
using namespace std ;

typedef long long ll ;
////////////////////////////////////////////////////////////////////
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
///#Read And Write  From File
/*

  freopen("in.txt","r",stdin);
  freopen("out.txt","w",stdout);

*/
int ReadInt ()
{
    int t ;
    cin >> t ;
    return t ;
}
ll ReadLong ()
{
    ll t ;
    cin >> t ;
    return t ;
}
bool Check (string t )
{
    int l = 0 ;
    int r = t.size() -1 ;
    while (l <= r )
    {
        if ( t[l] != t[r]) return false ;
        l++;
        r--;
    }
    return true ;
}
bool check_User (string t )
{
    int c = 0, C = 0;
    bool Next = 0 ;
    int sc = 0 ;
    for (int i = 0 ; i < t.size() ; i ++ )
    {
        if ( t[i] == '@' )
        {
            if (i+1 == t.size() ) return false ;
            Next =  (c > 0 && c < 17 );
            sc = i+1 ;
            break ;
        }
        if (   !( ( t[i] >= 'a' && t[i] <= 'z' ) || ( t[i] >= 'A' && t[i] <= 'Z' ) ||  ( t[i] >= '0' && t[i] <= '9' )|| t[i] == '_'    ) )
            return false ;
        c++;
    }

    if ( Next )
    {
        Next = 0;
        bool SNext = 0 ;
        c = 0 ;
        C = 0 ;
        bool Turn = 0 ;
        bool Slash = 0;
        for (int i = sc ; i < t.size() ; i++)
        {
            if ( i+1 == t.size() && t[i] == '.')return false ;
            if ( t[i] == '/')
            {
                if ( i-1 > 0 && t[ i-1 ] == '.') return false ;
                Slash = 1;
                if ( Turn == 0 )
                    SNext = 1 ;
                sc = i+1 ;
                break ;
            }

            if (t[i] == '.'  )
            {
                Turn = 1 ;
                if (c >0 && c < 17 )
                {
                    c=0;
                    continue ;
                }else
                return false ;

            }

            if (!( ( t[i] >= 'a' && t[i] <= 'z' ) || ( t[i] >= 'A' && t[i] <= 'Z' ) ||  ( t[i] >= '0' && t[i] <= '9' )|| (t[i] == '_')    ) )
                return false ;
            c++;

        }

        ///
        if (!SNext && Slash )
        {

            c = 0 ;
            for (int i =sc ; i < t.size() ; i++)
            {

                if (!( ( t[i] >= 'a' && t[i] <= 'z' ) || ( t[i] >= 'A' && t[i] <= 'Z' ) ||  ( t[i] >= '0' && t[i] <= '9' )|| (t[i] == '_')    ) )
                    return false ;
                c++;
            }
            if ( c>0 && c < 17  ) return true ;
            return false ;

        }
        else
        {
            if (Slash)
            {
                c = 0 ;
                for (int i =sc ; i < t.size() ; i++)
                {

                    if (!( ( t[i] >= 'a' && t[i] <= 'z' ) || ( t[i] >= 'A' && t[i] <= 'Z' ) ||  ( t[i] >= '0' && t[i] <= '9' )|| (t[i] == '_')    ) )
                        return false ;
                    c++;
                }

                if ( c>0 && c < 17  ) return true ;
                return false ;
            }
            return true ;
        }

    }
    else
    {

        return false  ;
    }

}
int main ()
{

    string Id ;
    cin >> Id ;
    if ( check_User(Id))
        cout <<"YES\n";
    else
        cout <<"NO\n";

    return 0 ;
}


#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(a),_ed=(b);i<=_ed;++i)
#define DREP(i,a,b) for(int i=(a),_ed=(b);i>=_ed;--i)
#define mp(x,y) make_pair((x),(y))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
inline int read(){
    register int x=0,f=1;register char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
    while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}
    return f?x:-x;
}

const int N=2e5+5,M=2e6+5,mod=1e9+7;
int n,p[N],num[M],cnt[M],a[N];
inline int power(int b,int n){int ans=1;for(;n;n>>=1,b=1ll*b*b%mod)if(n&1)ans=1ll*ans*b%mod;return ans;}

int insert(int p){
	if(!num[p])return num[p]=cnt[p]=1,0;
	--p;
	for(int i=2;i<=sqrt(p);++i){
		if(p%i)continue;
		int c=0;
		while(p%i==0)p/=i,++c;
		if(num[i]<c)num[i]=c,cnt[i]=1;
		else if(num[i]==c)++cnt[i];
	}
	if(p^1){
		int c=1;
		if(num[p]<c)num[p]=c,cnt[p]=1;
		else if(num[p]==c)++cnt[p];
	}
	return 1;
}

bool check(int x){
	for(int i=2;i<=sqrt(x);++i){
		if(x%i)continue;
		int c=0;
		while(x%i==0)x/=i,++c;
		if(c==num[i]&&cnt[i]==1)return 0;
	}
	if(x^1&&num[x]==1&&cnt[x]==1)return 0;
	return 1;
}

int main(){
	//fruitea
	n=read();
	REP(i,1,n)p[i]=read();
	sort(p+1,p+n+1,[&](int a,int b){return a>b;});
	REP(i,1,n)a[i]=p[i]-insert(p[i]);
	int ans=1;
	REP(i,2,M-1)ans=1ll*ans*power(i,num[i])%mod;
	REP(i,1,n)if(check(a[i])){ans=(ans+1)%mod;break;}
	printf("%d\n",ans);
	return 0;
}


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

const int N=510,mod=1e9+7;
int n,m,a[N],b[N],c[N],z[N],A[N],B[N];
ll K;

void inc(int &x,int y){ x=x+y>=mod ? x+y-mod : x+y;}
void dec(int &x,int y){ x=x-y<0 ? x-y+mod : x-y;}

void mult(int u[],int v[]){
	memset(z,0,sizeof(z));
	rep(i,0,249) rep(j,0,249) z[i+j]=(z[i+j]+1LL*u[i]*v[j])%mod;
	for(int i=498; i>=250; i--)
		rep(j,1,m) inc(z[i-b[j]],z[i]);
	rep(i,0,249) u[i]=z[i];
}

void ksm(int c[],ll n){
	memset(A,0,sizeof(A));
	A[0]=1;
	while(n){
		if(n&1) mult(A,c);
		n>>=1,mult(c,c);
	}
}

int main(){
	cin>>n>>m>>K;
	rep(i,1,n) scanf("%d",&a[i]);
	rep(i,1,m) scanf("%d",&b[i]);
	rep(i,1,n){
		memset(c,0,sizeof(c));
		c[1]=1; ksm(c,a[i]);
		rep(j,0,249) inc(B[j],A[j]);
	}
	ksm(B,K);
	rep(i,0,249) B[i]=A[i];
	for(int i=249; i>0; i--) rep(j,1,m) if(i>=b[j]) inc(B[i-b[j]],B[i]);
	cout<<B[0]<<endl;
	return 0;
}


//CLOCKS_PER_SEC
using namespace std;
#include<bits/stdc++.h>
#define sqr(x) (x)*(x)
//#define sort stable_sort
#define ll long long
#define mk make_pair
#define pb push_back
#define in insert
#define mtr(x,y,z) mk(mk(x,y),z)
#define fi first
#define se second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)|1)
#define all(x) (x).begin(),(x).end()
#define titose CLOCKS_PER_SEC
#define fpi(x) freopen(x,"r",stdin);
#define fpo(x) freopen(x,"w",stdout);
#define fprio fpi("in.txt");fpo("out.txt");
#define fast ios_base::sync_with_stdio(false);
inline void read(int &x){int v=0,f=1;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}
inline void read(ll &x){ll v=0ll,f=1ll;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=(c&15);while (isdigit(c=getchar())) v=(v<<1)+(v<<3)+(c&15);x=v*f;}
inline void readc(char &x){char c;while (((c=getchar())==' ')||c=='\n');x=c;}
inline void writes(string s){puts(s.c_str());}
inline void writeln(){writes("");}
inline void writei(int x){if (x<0){putchar('-');x=abs(x);}if (!x) putchar('0');char a[25];int top=0;while (x){a[++top]=(x%10)+'0';x/=10;}while (top){putchar(a[top]);top--;}}
inline void writell(ll x){if (x<0){putchar('-');x=abs(x);}if (!x) putchar('0');char a[25];int top=0;while (x){a[++top]=(x%10)+'0';x/=10;}while (top){putchar(a[top]);top--;}}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define si set<int>
#define sl set<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define msi map<string,int>
#define msl map<string,ll>
#define piii pair<int,pii >
#define piipi pair<pii,int>
#define plll pair<ll,pll >
#define pllpl pair<pll,ll>
#define pqi priority_queue<int>
#define pql priority_queue<ll>
#define npqi priority_queue<int,vector<int>,greater<int> >
#define npql priority_queue<ll,vector<ll>,greater<ll> >
#define forup(i,a,b) for ((i)=(a);(i)<=(b);(i)++)
#define fordo(i,a,b) for ((i)=(a);(i)>=(b);(i)--)
#define rep(i,x) forup ((i),1,(x))
#define repd(i,x) fordo ((i),(x),1)
#define itr iterator
#define fe(itcalc,c) for(__typeof((c).begin()) itcalc=(c).begin();itcalc!=(c).end();itcalc++)
#define NO {cout<<"NO";return 0;}
#define YES {cout<<"YES";return 0;}
#define y0 y000000000000000000000000000
#define y1 y111111111111111111111111111
#define j0 j000000000000000000000000000
#define j1 j111111111111111111111111111
#define cl0(a) memset((a),(0),(sizeof((a))))
#define clz(a) memset((a),(0x16),(sizeof((a))))
#define clf(a) memset((a),(-(0x16)),(sizeof((a))))
#define inf 0x3bbbbbbb
#define lnf 0x1bbbbbbbbbbbbbbbll
#define sqrt divi
#define p2(i) (1ll<<(i))
#define readi read
#define readll read
/*************************************************/
int mod=998244353;
void add(int &x,int y)
{
	x+=y;
	if(x>=mod) x-=mod;
}
int n,m,i,j,msk,cpx,cnx,cpy,cny,bx,by,dp[31][21][21][21][21][2][2],x[15],y[15],px[1<<5],py[1<<5],nx[1<<5],ny[1<<5];
int main()
{
	read(n);read(m);
	rep(i,n){
		read(x[i]);
		read(y[i]);
	}
	forup(i,0,(1<<n)-1){
		rep(j,n){
			if((i>>(j-1))&1){
				(x[j]>0?px[i]:nx[i])+=abs(x[j]);
				(y[j]>0?py[i]:ny[i])+=abs(y[j]);
			}
		}
	}
	dp[0][0][0][0][0][0][0]=1;
	forup(i,0,29){
		forup(cpx,0,19)forup(cnx,0,19)forup(cpy,0,19)forup(cny,0,19){
			forup(bx,0,1)forup(by,0,1)if(dp[i][cpx][cnx][cpy][cny][bx][by]){
				forup(msk,0,(1<<n)-1){
					int npx=cpx+px[msk];
					int npy=cpy+py[msk];
					int nnx=cnx+nx[msk];
					int nny=cny+ny[msk];
					if((npx&1)!=(nnx&1)) continue;
					if((npy&1)!=(nny&1)) continue;
					int cx=(npx&1),cy=(npy&1);
					int mx=((m>>i)&1),my=mx;
					add(dp[i+1][npx>>1][nnx>>1][npy>>1][nny>>1][(cx==mx)?bx:(cx>mx)][(cy==my)?by:(cy>my)],dp[i][cpx][cnx][cpy][cny][bx][by]);
				}
			}
		}
	}
	cout<<(dp[30][0][0][0][0][0][0]+mod-1)%mod;
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <string>
#include <vector>
#include <ctime>
#include <queue>
#include <cmath>
#include <set>
#define CLR(a,v)        memset(a,v,sizeof(a))
#define ReadFile(file)  freopen(file,"r",stdin)
#define WriteFile(file) freopen(file,"w",stdout)
using namespace std;
typedef long long       ll;
typedef pair<int,int>   pii;
typedef unsigned int    uint;
typedef unsigned long long    ull;

const double eps = 1e-6;
const double PI  = acos(-1.0);
const double EPS = eps;
const double pi  = PI;
const int N = 1e2+10;

struct Point{
	double x,y;
	Point(){}
	Point(const Point& Val){x=Val.x;y=Val.y;}
	Point(double x,double y):x(x),y(y){}
	void set(double x,double y){
		this->x = x;this->y = y;
	}
	void read(){
		scanf("%lf%lf",&x,&y);
	}
	void print(char end[]){
		if(end==NULL) end[0]='\0';
		printf("%.6f %.6f%s",x,y,end);
	}
	Point rot90(){
		return Point(-y,x);
	}
	Point operator + (const Point& Val)const{
		return Point(x+Val.x, y+Val.y);
	}
	Point operator - (const Point& Val)const{
		return Point(x-Val.x, y-Val.y);
	}
	Point operator * (double Val)const{
		return Point(x*Val, y*Val);
	}
	Point operator / (double Val)const{
		return (*this) * (1.0/Val);
	}
};
typedef Point Vec;
istream& operator >> (istream &io, Point& p){
	io >> p.x >> p.y;
	return io;
}
ostream& operator << (ostream &io, Point& p){
	io << "(" << (fabs(p.x-0)<eps?0:p.x) << "," << (fabs(p.y-0)<eps?0:p.y) << ")" ;
	return io;
}

//--------向量运算---------
Vec PtoV(Point a,Point b){
	// 两点 所示 向量
	return Vec(b.x - a.x , b.y - a.y );
}
double dMult(Vec a,Vec b){
	// 点乘
	return (a.x*b.x) + (a.y*b.y) ;
}
double xMult(Vec a,Vec b){
	// 叉积，有向面积|a||b|形成的平行四边形
	return a.x*b.y-a.y*b.x;
}
double VecMod(Vec a){
	// 模
	return sqrt(dMult(a,a));
}
double VecMod2(Vec a){
	// 模平方
	return dMult(a,a);
}
double Corner2V(Vec a,Vec b){
	//两向量夹角 返回弧度 debuged
	return fabs( acos( dMult(a,b)/VecMod(a)/VecMod(b) ) );
}
Vec VecUnit(Vec a){
	// a的单位向量
	return a / VecMod(a);
}
Vec VRotate(Vec v,double alph){
	// 获得v向量的逆时针旋转alph角度的向量
	double sa = sin(alph),ca = cos(alph);
	return Vec(v.x*ca - v.y*sa , v.x*sa + v.y*ca);
}
   Point PRotate(Point p,Point o,double alph){
	// wait for debug...
	return Point(o+VRotate(PtoV(o,p),alph));
}
Vec GetVV(Vec v){
	// 获得v向量的垂直向量 wait for test ...
	return VRotate(v,pi/2);
}
Point ShadowPOnLine(Point p,Point a,Point b){
	// p在直线|ab|上的垂足
	Vec ab = PtoV(a,b) , ap = PtoV(a,p);
	Vec alph = VecUnit(ab) * dMult(ab,ap) / VecMod(ab);
	return a + alph;
}
vector<Point> LineCrossCircle(Point a,Point b,Point o,double r){
	// 直线与圆的交点
	vector<Point> ret;
	Point t = ShadowPOnLine(o,a,b); // o到直线|ab|的垂足
	Vec ot = PtoV(o,t);
	if(VecMod(ot)-r>eps)return ret; // 没有交点
	if(fabs(VecMod(ot)-r)<eps){ // 如果相切
		ret.push_back(t);
		return ret;
	}
	double lr = sqrt(r*r-VecMod2(ot));
	Vec ta = t + VecUnit(PtoV(t,a))*lr , tb = t + VecUnit(PtoV(t,b))*lr;
	ret.push_back(ta);
	ret.push_back(tb);
	return ret;
}

vector<Point> PointTangentCircle(Point p,Point o,double r){
	// 圆外一点作两个切线 返回切点
	double x2 = VecMod2(p-o);
	double d2 = x2 - r*r;
	vector<Point> ret;
	if(d2 < -eps)return ret; // 点在圆内
	if(r <= eps){ // 圆退化为点
		ret.push_back(o);
		ret.push_back(o);
		return ret;
	}
	d2 = max(d2,0.);
	Point q1 = o + (p-o) * (r*r/x2);
	Point q2 = (p-o).rot90() * (-r*sqrt(d2) / x2);
	ret.push_back(q1 - q2);
	ret.push_back(q1 + q2);
	return ret;
	//double x2 = (p - c).abs2(); // x * x + y * y
	//double d2 = x2 - r * r;
	//vector<Point> ret;
	//if (d2 < -EPS)
	//	return ret;
	//if (r <= EPS) {
	//	ret.push_back(c);
	//	ret.push_back(c);
	//	return ret;
	//}
	//d2 = max(d2, 0.);
	//Point q1 = c + (p - c) * (r * r / x2);
	//Point q2 = (p - c).rot90() * (-r * sqrt(d2) / x2);
	//ret.push_back(q1 - q2);
	//ret.push_back(q1 + q2);
	//return ret;

	//vector<Point> ret;
	//Vec po = PtoV(p,o);
	//if(VecMod(po)-r < eps) return ret;
	//if(fabs(VecMod(po)-r) < eps){
	//	ret.push_back(p);
	//	return ret;
	//}
	//double alph = asin(r/VecMod(po));
	//cout << "alpha===>" << alph*180/pi << "  r=>" << r << "  |po|=>" << VecMod(po) << endl;
	//cout << "circle o==>" << o << " p===>" << p << endl;
	//cout << "|p,T2|==>" << VRotate(VecUnit(po),alph) * sqrt(VecMod2(po)+r*r) << endl;
	//cout << "单位向量|p.T2|" << VRotate(VecUnit(po),alph) << "  长度|pT2|" << sqrt(VecMod2(po)+r*r) << endl;
	//
	//ret.push_back(p + VRotate(VecUnit(po),alph) * sqrt(VecMod2(po)+r*r));
	//ret.push_back(p + VRotate(VecUnit(po),2*pi-alph) * sqrt(VecMod2(po)+r*r));
	//return ret;

	//Vec pt = VecUnit(VRotate(po,asin(r/VecMod(po))))*sqrt(VecMod2(po)+r*r);
	//ret.push_back(p+pt);
	//Point tot = ShadowPOnLine(p+pt,p,o);
	//ret.push_back(tot + PtoV(tot,o));
	//return ret;
}
bool POnSeg(Point p, Point a, Point b){
	// 点在线段上
	if(fabs(xMult(PtoV(a,b), PtoV(a,p))) > eps)return false;
	if(min(a.x,b.x) > p.x || p.x > max(a.x,b.x))return false;
	if(min(a.y,b.y) > p.y || p.y > max(a.y,b.y))return false;
	return true;
}

double PDisLine(Point p,Point a, Point b){
	// p点到直线|ab| 的距离
	return VecMod(ShadowPOnLine(p,a,b) - p);
}
//--------向量运算---------End

void debug_function(){
	Point h(25,45),j(30,30),i(15,35),k(5,45);
	//cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(9);
	Point aaa(0,0), bbb(0,5), ppp(0,-1);
	cout << "p in |ab| ? => " << POnSeg(ppp,aaa,bbb) << endl;

	cout << "π:" << pi << "\t\tπ checked" << endl;
	cout << i << h << j << "\tio checked" << endl;
	cout << Corner2V(PtoV(i,h),PtoV(i,j))*(180/pi) << "\t\t\tCorner2V() checked" << endl;
	i.set(0,0);k.set(-10,4);
	cout << VRotate(PtoV(i,k),pi/2) << " " << PtoV(i,k) << PtoV(i,Point(-4,-10)) << "VRotate() checked" << endl;
	Point p(10,2) , a(-6,6) , b(10,-10);
	cout << ShadowPOnLine(p,a,b) << "\t\t\tShadowPOnLine() checked" << endl;

	double r = 6.64;
	vector<Point> CP = LineCrossCircle(a,b,Point(0,0),r);
	cout << "cross point:" << CP.size() << " ";
	for(int i = 0 ; i < CP.size() ; i++) cout << CP[i] << " " ;
	cout << "\tchecked" << endl;

	p.set(10,2); r = 6.64;
	vector<Point> CT = PointTangentCircle(p,Point(0,0),r);
	cout << "tangent point:" << CT.size() << " ";
	for(int i = 0 ; i < CT.size() ; i++) cout << CT[i] << " " ;
	cout << endl;

	exit(0);
}

Point p,s;
double vp,vs,r , sita;
bool check(double t){
	double len_or = VecMod(p);
	Point e(len_or * cos(sita+t*vp/len_or) , len_or * sin(sita+t*vp/len_or)); // 终点
	//printf("t:%lf (%lf,%lf) \t\t",t,e.x,e.y);
	vector<Point> ccp;
	ccp = LineCrossCircle(s,e, Point(0,0), r);
	if(ccp.size() != 2 || (!POnSeg(ccp[0], s, e) && !POnSeg(ccp[1], s, e)) ){
		//cout << "| |len = " << VecMod(e-s) << endl;
		return vs*t > VecMod(e-s); // 如果没有交点路径就是直线
	}
	vector<Point> ttp1 = PointTangentCircle(s,Point(0,0),r);
	if( PDisLine(ttp1[0],s,e) > PDisLine(ttp1[1],s,e) )
		swap(ttp1[0],ttp1[1]);
	double l1 = VecMod(PtoV(s,ttp1[0]));

	vector<Point> ttp2 = PointTangentCircle(e,Point(0,0),r);
	if( PDisLine(ttp2[0],s,e) > PDisLine(ttp2[1],s,e) )
		swap(ttp2[0],ttp2[1]);
	double l2 = VecMod(PtoV(e,ttp2[0]));

	double alph = Corner2V(PtoV(Point(0,0),ttp1[0]) , PtoV(Point(0,0),ttp2[0]));
	//cout << "tangent:" <<  ttp1[0] << " " << ttp2[0] << endl;
	//cout << "|-|alph = " << alph << ", " << VecMod( PtoV(s,ttp1[0]) )   << "," << VecMod( PtoV(e,ttp2[0]) ) << endl;
	return VecMod( PtoV(s,ttp1[0]) )
		+  VecMod( PtoV(e,ttp2[0]) )
		+ alph * r < vs*t;
}
int main(){
	ios::sync_with_stdio(false);
	//debug_function();
	//freopen("d:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\por\\20130820\\20130820\\in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	//cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2);
	//cout << fixed << setprecision(2) << (*it).first << endl;
	while(cin >> p >> vp >> s >> vs >> r){
		//cout << p << vp << s << vs << " " << r << endl;
		//check(9.584544103);exit(0);
		sita = acos(p.x/VecMod(p));
		if(p.y<0)sita = -sita; // 跨过了180度

		double  left = 0, right = 1e+10;
		while( fabs(left-right) > 1e-12 ){
			double mid = (left+right)*0.5;
 			if(check(mid))
				right = mid;
			else
				left = mid;
		}
		cout << fixed << setprecision(9) << left << endl;
	}
	return 0;
}