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 <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <vector>

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		std::vector<int> num;
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (; x; x /= 10) {
			num.push_back(x % 10);
		}
		while (!num.empty()) {
			putchar(num.back() ^ '0');
			num.pop_back();
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 505, P = 1000000007;

int a, b, c, A, B, C, Cm[N][N], f[N];

int qpow(int a, int b) {
	int s = 1;
	for (; b; b >>= 1) {
		if (b & 1) {
			s = 1ll * s * a % P;
		}
		a = 1ll * a * a % P;
	}
	return s;
}

int calc(int a, int b, int A, int B) {
	return ((1ll * a * qpow(b, A) + 1ll * b * qpow(a, B) - 1ll * a * b) % P + P) % P;
}

int main() {
	read(a), read(b), read(c), read(A), read(B), read(C);
	if (A % a || B % b || C % c) {
		print(0);
		return 0;
	}
	for (int i = 0; i < N; ++i) {
		Cm[i][0] = Cm[i][i] = 1;
		for (int j = 1; j < i; ++j) {
			Cm[i][j] = (Cm[i - 1][j - 1] + Cm[i - 1][j]) % P;
		}
	}
	A /= a, B /= b, C /= c;
	int ans = 0;
	ans = (ans + 1ll * a * qpow(calc(b, c, B, C), A)) % P;
	ans = (ans + 1ll * b * qpow(calc(a, c, A, C), B)) % P;
	ans = (ans + 1ll * c * qpow(calc(a, b, A, B), C)) % P;
	ans = (ans + 1ll * a * b % P * (P - qpow(qpow(c, A), B))) % P;
	ans = (ans + 1ll * a * c % P * (P - qpow(qpow(b, A), C))) % P;
	ans = (ans + 1ll * b * c % P * (P - qpow(qpow(a, B), C))) % P;
	ans = (ans + 1ll * a * b % P * c) % P;
	for (int p = 1; p < A; ++p) {
		for (int q = B - 1; q > 0; --q) {
			f[q] = 1ll * Cm[A][p] * Cm[B][q] % P * qpow(qpow(c, B - q) - 1, A - p) % P;
			for (int k = q + 1; k < B; ++k) {
				f[q] = (f[q] + 1ll * (P - Cm[k][q]) * f[k]) % P;
			}
			ans = (ans + (1ll * qpow((qpow(b, p) + qpow(a, q) - 1) % P, C) + P - qpow(qpow(b, p), C) + P - qpow(qpow(a, q), C) + 1) * f[q] % P * a % P * b % P * c) % P;
		}
	}
	print(ans);
}
