/**
 *    author:  tourist
 *    created: 03.02.2018 21:31:09       
**/
#include <bits/stdc++.h>

using namespace std;
                     
string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int md = (int) 1e9 + 7;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

inline int mul(int a, int b) {
  return (int) ((long long) a * b % md);
}

inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

int solve1D(int a, int A) {
  return a;
}

int solve2D(int a, int b, int A, int B) {
  int ans = 0;
  add(ans, mul(power(solve1D(a, A), B / b), b));
  add(ans, mul(power(solve1D(b, B), A / a), a));
  sub(ans, mul(a, b));
  return ans;
}

int CC[123][123];
int f[123][123][123];

int solve3D(int a, int b, int c, int A, int B, int C) {
  int ans = 0;
  add(ans, mul(power(solve2D(a, b, A, B), C / c), c));
  add(ans, mul(power(solve2D(a, c, A, C), B / b), b));
  add(ans, mul(power(solve2D(b, c, B, C), A / a), a));
  sub(ans, mul(power(solve1D(a, A), (C / c) * (B / b)), b * c));
  sub(ans, mul(power(solve1D(b, B), (C / c) * (A / a)), a * c));
  sub(ans, mul(power(solve1D(c, C), (B / b) * (A / a)), a * b));
  add(ans, mul(a, mul(b, c)));
  f[0][0][0] = 1;
  for (int layer = 0; layer < C / c; layer++) {
    for (int rows = 0; rows <= A / a; rows++) {
      for (int cols = 0; cols <= B / b; cols++) {
        int ft = f[layer][rows][cols];
        if (ft == 0) {
          continue;
        }
//        debug(layer, rows, cols, ft);
        add(f[layer + 1][rows][cols], ft);
        for (int new_rows = 0; new_rows + rows <= A / a; new_rows++) {
          int ways = power(b, rows);
          if (new_rows == 0) {
            ways--;
          }
          ways = mul(ways, CC[A / a - rows][new_rows]);
          ways = mul(ways, power(b - 1, new_rows));
//          debug(layer, rows, cols, ft, new_rows, ways, a);
          add(f[layer + 1][rows + new_rows][cols], mul(ft, ways));
        }
        for (int new_cols = 0; new_cols + cols <= B / b; new_cols++) {
          int ways = power(a, cols);
          if (new_cols == 0) {
            ways--;
          }
          ways = mul(ways, CC[B / b - cols][new_cols]);
          ways = mul(ways, power(a - 1, new_cols));
          add(f[layer + 1][rows][cols + new_cols], mul(ft, ways));
        }
      }
    }
  }
  for (int rows = 1; rows < A / a; rows++) {
    for (int cols = 1; cols < B / b; cols++) {
      int ft = f[C / c][rows][cols];
      if (ft == 0) {
        continue;
      }
      int cells = (A / a - rows) * (B / b - cols);
      int ways = power(c, cells) - 1;
      add(ans, mul(ft, mul(ways, a * b * c)));
    }
  }
  return ans;
}

int main() {
  for (int i = 0; i < 123; i++) for (int j = 0; j < 123; j++) if (j == 0) CC[i][j] = 1; else if (i == 0) CC[i][j] = 0; else CC[i][j] = (CC[i - 1][j] + CC[i - 1][j - 1]) % md;
  int a, b, c, A, B, C;
  cin >> a >> b >> c >> A >> B >> C;
  if (A % a != 0 || B % b != 0 || C % c != 0) {
    cout << 0 << endl;
    return 0;
  }
  cout << solve3D(a, b, c, A, B, C) << endl;
  return 0;
}


Measured memory_bytes: 6144