We have a rectangular parallelepiped of dimensions A×B×C, divided into 1×1×1 small cubes. The small cubes have coordinates from (0, 0, 0) through (A-1, B-1, C-1).

Let p, q and r be integers. Consider the following set of abc small cubes:

\\{(\ (p + i) mod A, (q + j) mod B, (r + k) mod C\ ) | i, j and k are integers satisfying 0 ≤ i < a, 0 ≤ j < b, 0 ≤ k < c \\}

A set of small cubes that can be expressed in the above format using some integers p, q and r, is called a torus cuboid of size a×b×c.

Find the number of the sets of torus cuboids of size a×b×c that satisfy the following condition, modulo 10^9+7:

* No two torus cuboids in the set have intersection.
* The union of all torus cuboids in the set is the whole rectangular parallelepiped of dimensions A×B×C.

Constraints

* 1 ≤ a < A ≤ 100
* 1 ≤ b < B ≤ 100
* 1 ≤ c < C ≤ 100
* All input values are integers.

Input

Input is given from Standard Input in the following format:


a b c A B C


Output

Print the number of the sets of torus cuboids of size a×b×c that satisfy the condition, modulo 10^9+7.

Examples

Input

1 1 1 2 2 2


Output

1


Input

2 2 2 4 4 4


Output

744


Input

2 3 4 6 7 8


Output

0


Input

2 3 4 98 99 100


Output

471975164
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
 
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
 
const int mod=1000000007;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}
const int FACT_SIZE=1111111;
int fact[FACT_SIZE];
int inv[FACT_SIZE];
struct fact_exec{
    fact_exec(){
        fact[0]=1;
        for(int i=1;i<FACT_SIZE;i++)fact[i]=fact[i-1]*i%mod;
        inv[FACT_SIZE-1]=mpow(fact[FACT_SIZE-1],mod-2);
        for(int i=FACT_SIZE-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
    }
}factexec;
int nCk(int n,int k){
    if(n<0|k<0||k>n)return 0;
    return fact[n]*inv[k]%mod*inv[n-k]%mod;
}
int nPk(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*inv[n-k]%mod;
}
 
 
inline int f(int a,int b){
    return (mpow(a,b)-a+mod)%mod;
}
 
int dp[111][111];
int dp2[111][111];
int dp3[111][111];
signed main(){
    int a,b,c,A,B,C;
    cin>>a>>b>>c>>A>>B>>C;
 
    if(A%a||B%b||C%c){
        cout<<0<<endl;
        return 0;
    }
 
    int x=A/a;
    int y=B/b;
    int z=C/c;
 
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            dp2[i][j]=mpow(mpow(c,i)-1+mod,j);
            for(int k=1;k<=i;k++){
                int tmp=0;
                add(tmp,(mpow(c,k)-1+mod)*mpow(c,(i-k)*j)%mod);
                add(tmp,mpow(mpow(c,i-k)-1+mod,j));
                tmp=tmp*nCk(i,k)%mod;
                if(k&1)add(dp2[i][j],mod-tmp);
                else add(dp2[i][j],tmp);
            }
        }
    }
 
 
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            dp[i][j]=mpow(mpow(c,i)-1+mod,j);
            for(int k=1;k<=i;k++){
                int tmp=mpow(mpow(c,i-k)-1+mod,j);
                tmp=tmp*nCk(i,k)%mod;
                if(k&1)add(dp[i][j],mod-tmp);
                else add(dp[i][j],tmp);
            }
        }
    }
 
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            dp3[i][j]=mpow(f(c,i),j);
            for(int k=1;k<=i;k++){
                int tmp=0;
                add(tmp,f(c,k)*mpow(c,(i-k)*j)%mod);
                add(tmp,c*mpow(mpow(c,i-k)-1,j)%mod);
                tmp=tmp*nCk(i,k)%mod;
                if(k&1)add(dp3[i][j],mod-tmp);
                else add(dp3[i][j],tmp);
            }
        }
    }
 
 
 
 
    int ans=0;
    rep(uku,2){
        int sum=f(b,x)*mpow(f(c,y),x)%mod;
        for(int i=1;i<=x;i++){
            int tmp=0;
            add(tmp,f(b,x)*f(c,i)%mod*mpow(f(c,y),x-i)%mod*mpow(b,i*(z-1))%mod);
            if(i!=x){
                add(tmp,c*mpow(b,i)%mod*f(b,x-i)%mod*mpow(f(c,y),x-i)%mod*mpow(b,i*(z-1))%mod);
                int ei=b*(mpow(b,i)-1+mod)%mod*c%mod;
                add(tmp,ei*dp2[x-i][y]%mod*mpow(b,i*(z-1))%mod);
                for(int j=1;j<y;j++){
                    add(tmp,ei*nCk(y,j)%mod*dp[x-i][y-j]%mod*mpow((mpow(b,i)+mpow(a,j)-1+mod)%mod,z-1)%mod);
                }
            }
            tmp=tmp*nCk(x,i)%mod;
            add(sum,tmp);
        }
        add(sum,c*f(b,x)%mod*mpow((f(b,x)*a+f(a,y)*b+a*b)%mod,z-1)%mod);
        sum=sum*a%mod;
        add(ans,sum);
 
        swap(a,b);
        swap(x,y);
    }
 
    int sum=0;
    for(int i=0;i<=x;i++){
        for(int j=0;j<=y;j++){
            if(i==0&&j==0){
                add(sum,dp3[x][y]);
            }
            else if(i==0){
                add(sum,nCk(y,j)*f(c,j)%mod*mpow(f(c,x),y-j)%mod*mpow(a,j*(z-1))%mod);
                add(sum,nCk(y,j)*c%mod*dp2[y-j][x]%mod*mpow(a,j*(z-1))%mod);
            }
            else if(j==0){
                add(sum,nCk(x,i)*f(c,i)%mod*mpow(f(c,y),x-i)%mod*mpow(b,i*(z-1))%mod);
                add(sum,nCk(x,i)*c%mod*dp2[x-i][y]%mod*mpow(b,i*(z-1))%mod);
            }
            else if(i<x&&j<y){
                add(sum,c*nCk(x,i)%mod*nCk(y,j)%mod*dp[x-i][y-j]%mod*mpow((mpow(b,i)+mpow(a,j)-1+mod)%mod,z-1)%mod);
            }
        }
    }
    add(sum,c*mpow((f(b,x)*a+f(a,y)*b+a*b)%mod,z-1)%mod);
    add(ans,sum*a%mod*b%mod);
    cout<<ans<<endl;
    return 0;
}