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;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll a,b,c,A,B,C;
ll mo=1000000007;
const int CN=401;
ll C_[CN][CN];
ll pat[101][101];

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

ll hoge1d(int a,int A) {
	return a;
}
ll hoge2d(int a,int A,int b,int B) {
	ll ret=0;
	// 2planes
	ret-=a*b;
	// 1planes
	ret+=a*modpow(hoge1d(b,B),A/a);
	ret+=b*modpow(hoge1d(a,A),B/b);
	return (ret+mo)%mo;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	FOR(i,CN) for(j=0;j<=i;j++) C_[i][j]=(j==0||j==i)?1:(C_[i-1][j-1]+C_[i-1][j])%mo;

	cin>>a>>b>>c>>A>>B>>C;
	if(A%a || B%b || C%c) return _P("0\n");
	
	ll ret=0;
	// 3planes
	ret=a*b*c;
	// 2planes
	ret-=a*b*modpow(hoge1d(c,C),A/a*B/b);
	ret-=b*c*modpow(hoge1d(a,A),B/b*C/c);
	ret-=c*a*modpow(hoge1d(b,B),C/c*A/a);
	// 1planes
	ret+=a*modpow(hoge2d(b,B,c,C),A/a);
	ret+=b*modpow(hoge2d(c,C,a,A),B/b);
	ret+=c*modpow(hoge2d(a,A,b,B),C/c);
	ret=(ret%mo+mo)%mo;
	
	// nontribial
	int p,q,p2,q2;
	for(p=A/a;p>=1;p--) for(q=B/b;q>=1;q--) {
		pat[p][q]=C_[A/a][p]*C_[B/b][q]%mo*modpow(c,(A/a-p)*(B/b-q))%mo;
		for(p2=p;p2<=A/a;p2++) for(q2=q;q2<=B/b;q2++) {
			if(p==p2 && q==q2) continue;
			pat[p][q] -= pat[p2][q2]*C_[p2][p]%mo*C_[q2][q]%mo;
		}
		pat[p][q]=(pat[p][q]%mo+mo)%mo;
		ll way=modpow(modpow(b,p)+modpow(a,q)+mo-1,C/c)-modpow(modpow(b,p),C/c)-modpow(modpow(a,q),C/c)+1;
		if(p<A/a && q<B/b) (ret+=a*b*c*(way%mo+mo)%mo*pat[p][q])%=mo;
	}
	
	
	
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
