#include #define MOD (long long)(1e9 + 7) using namespace std; // as + bt = GCD(a,b) a,b:const s,t:var(any) // return GCD(a,b) long long extGCD(long long a, long long b, long long& s, long long& t) { s = 1, t = 0; while(b) { long long tmp = a / b; a -= b * tmp; s -= t * tmp; swap(a, b); swap(s, t); } return a; } // (mod)x+ay=1, calculate y -> a^-1 (mod m) (a,m : coprime) long long calcinv(long long a, long long m) { long long s, t; extGCD(a, m, s, t); return (s + m) % m; } // x≡b_i(mod m_i) calc min x,lcm(m_i). // if not exist, return (-1,-1) pair ChineseRem( const vector& b, const vector& m) { long long r = 0, lcm = 1; assert(b.size() == m.size()); long long bsize = b.size(); for(int i = 0; i < bsize; ++i) { long long p, q, d, now; d = extGCD(lcm, m[i], p, q); if((b[i] - r) % d != 0) return make_pair(-1, -1); now = (b[i] - r) / d * p % (m[i] / d); r += lcm * now; lcm *= m[i] / d; } return make_pair((r + lcm) % lcm, lcm); } // x≡b_i(mod m_i) calc min x(mod nowMOD). // if not exist, return -1 long long Garner(vector& b, vector& m, long long nowMOD = 9223372036854775807LL) { assert(b.size() == m.size()); // prepair, O(N^2) // if m_i are coprime, don't have to do it long long bsize = b.size(), msize = m.size() + 1, dummy1, dummy2; for(int i = 0; i < bsize; ++i) for(int j = 0; j < i; ++j) { long long g = extGCD(m[i], m[j], dummy1, dummy2); if((b[i] - b[j]) % g != 0) return -1; m[i] /= g; m[j] /= g; long long gi = extGCD(m[i], g, dummy1, dummy2), gj; gj = g / gi; do { g = extGCD(gi, gj, dummy1, dummy2); gi *= g, gj /= g; } while(g != 1); m[i] *= gi, m[j] *= gj; b[i] %= m[i], b[j] %= m[j]; } // calc m.push_back(nowMOD); vector coeffs(msize, 1); vector constants(msize, 0); for(int k = 0; k < bsize; ++k) { long long tmp = (b[k] - constants[k]) % m[k]; long long t = (tmp + m[k]) % m[k] * calcinv(coeffs[k], m[k]) % m[k]; for(int i = k + 1; i < msize; ++i) { (constants[i] += t * coeffs[i] % m[i]) %= m[i]; (coeffs[i] *= m[k]) %= m[i]; } } return constants.back(); } long long n; vector x, y; bool ch = 0; int main() { n = 3; x.resize(n); y.resize(n); for(int i = 0; i < n; ++i) { cin >> x[i] >> y[i]; if(x[i]) ch = 1; } if(!ch) { long long ans = 1; Garner(x, y, MOD); for(int i = 0; i < n; ++i) (ans *= y[i]) %= MOD; cout << ans << endl; } else cout << Garner(x, y, MOD) << endl; return 0; }