#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);
}


Measured memory_bytes: 4032