#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

template <typename T> inline bool CheckMax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

template <typename T> inline bool CheckMin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}

const int N = 105;
const int mod = 1e9 + 7;

inline int Qow(int x, int y) {
  int r = 1;
  for (; y; y >>= 1, x = 1LL * x * x % mod) {
    if (y & 1) {
      r = 1LL * r * x % mod;
    }
  }
  return r;
}


inline int Solve(int a, int A) {
  return a;
}

inline int Solve(int a, int A, int b, int B) {
  int ans = 0;
  ans = (1LL * b * Qow(Solve(a, A), B / b) + ans) % mod;
  ans = (1LL * a * Qow(Solve(b, B), A / a) + ans) % mod;
  ans = (ans - a * b + mod) % mod;
  return ans;
}

inline int Solve(int a, int A, int b, int B, int c, int C) {
  static int f[N][N], bin[N][N];
  int ans = 0;
  ans = (1LL * c * Qow(Solve(a, A, b, B), C / c) + ans) % mod;
  ans = (1LL * b * Qow(Solve(a, A, c, C), B / b) + ans) % mod;
  ans = (1LL * a * Qow(Solve(b, B, c, C), A / a) + ans) % mod;
  ans = (ans - 1LL * b * c * Qow(Solve(a, A), B / b * C / c) % mod + mod) % mod;
  ans = (ans - 1LL * a * c * Qow(Solve(b, B), A / a * C / c) % mod + mod) % mod;
  ans = (ans - 1LL * a * b * Qow(Solve(c, C), A / a * B / b) % mod + mod) % mod;
  ans = (ans + a * b * c) % mod;
  for (int i = 0; i <= max(A / a, B / b); ++i) {
    bin[i][0] = 1;
    for (int j = 1; j <= i; ++j) {
      bin[i][j] = (bin[i - 1][j] + bin[i - 1][j - 1]) % mod;
    }
  }
  for (int i = A / a; i; --i) {
    for (int j = B / b; j; --j) {
      f[i][j] = 1LL * bin[A / a][i] * bin[B / b][j] % mod * Qow(c, (A / a - i) * (B / b - j)) % mod;
      for (int k = i; k <= A / a; ++k) {
        for (int l = j; l <= B / b; ++l) {
          if (k != i || l != j) {
            f[i][j] = (f[i][j] - 1LL * f[k][l] * bin[k][i] % mod * bin[l][j] % mod + mod) % mod;
          }
        }
      }
      if (i == A / a && j == B / b) {
        continue;
      }
      int tmp = 0;
      tmp = (tmp + Qow(Qow(b, i) + Qow(a, j) - 1, C / c)) % mod;
      tmp = (tmp - Qow(Qow(b, i), C / c) + mod) % mod;
      tmp = (tmp - Qow(Qow(a, j), C / c) + mod) % mod;
      tmp = (tmp + 1) % mod;
      tmp = 1LL * tmp * a * b * c % mod;
      ans = (1LL * f[i][j] * tmp + ans) % mod;
    }
  }
  return ans;
}

int main() {
#ifdef wxh010910
  freopen("d.in", "r", stdin);
#endif
  int a, b, c, A, B, C;
  Read(a), Read(b), Read(c), Read(A), Read(B), Read(C);
  if (A % a || B % b || C % c) {
    puts("0");
  } else {
    printf("%d\n", Solve(a, A, b, B, c, C));
  }
#ifdef wxh010910
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}


Measured memory_bytes: 384