#include #include using namespace std; using ull = unsigned long long; using ll = long long; using xy = pair; using coord = pair; using bs8 = bitset<8>; using bs16 = bitset<16>; using bs32 = bitset<32>; using bs64 = bitset<64>; using vl = vector; using vvl = vector; using vvvl = vector; using vd = vector; using vvd = vector; using vs = vector; using vvs = vector; using vxy = vector; using vvxy = vector; using vcoord = vector; using vvcoord = vector; #define rep(var, n) for (ll var = 0; var < (ll)(n); var++) #define cnt(var, n, m) for (ll var = (n); var <= (ll)(m); var++) #define rcnt(var, n, m) for (ll var = (n); var >= (ll)(m); var--) #define each(ite, C) for (auto ite = (C).begin(); ite != (C).end(); ite++) #define reach(ite, C) for (auto ite = (C).rbegin(); ite != (C).rend(); ite++) #define yn(b) cout << (((b) > 0) ? "Yes" : "No") << endl; #define ZINIT 1 #if __has_include("zout.h") #include "zout.h" #else namespace zz_print { class dbg { public: static bool unprint; static string margin; static string separated; static string indentS; static int hierarchical; static int topHier; static int precision; static bool exponential; static void setFloat(const int& prec, const bool& expo) { precision = prec; exponential = expo; }; template static void zout(Args&&... args) {}; }; bool dbg::unprint = false; string dbg::margin = ""; string dbg::separated = ""; string dbg::indentS = ""; int dbg::hierarchical = 0; int dbg::topHier = 0; int dbg::precision = 6; bool dbg::exponential = false; }; // namespace zz_print using namespace zz_print; #endif xy gcdex(ll a, ll b) { xy ans; if (abs(a) < abs(b)) { ans = gcdex(b, a); swap(ans.first, ans.second); return ans; } else if (b == 0) { return xy{1, 0}; } // a > b // da x + db y = d // a x + b y = 1 // (b(a/b) + a%b) x + b y = 1 // b ((a/b)x + y) + a%b x = 1 // b x' + a%b y' = 1 // // |x| | 0 1 | |x'| // | | = | |*| | // |y| | 1 -a/b | |y'| // ans = gcdex(b, a % b); return xy{ans.second, ans.first - (a / b) * ans.second}; }; xy gcdex(xy ab) { return gcdex(ab.first, ab.second); } ll gcd(ll a, ll b) { xy ans = gcdex(a, b); return abs(a * ans.first + b * ans.second); } ll gcd(xy ab) { return gcd(ab.first, ab.second); } vl gcd(const vl& vec) { ll n = vec.size(); vl subvec; rep(i, n / 2) subvec.push_back(gcd(vec[2 * i], vec[2 * i + 1])); if (n % 2) subvec.push_back(vec[n - 1]); return gcd(subvec); } ll ganner(const vxy& pm) { ll p = 1, mod; if (pm.empty()) return p; ll n = pm.size(); p = pm[0].first; mod = pm[0].second; cnt(i, 1, n - 1) { xy ans = gcdex(mod, pm[i].second); ll d = mod * ans.first + pm[i].second * ans.second; if ((p % d) != (pm[i].first % d)) return -1; ll s = (pm[i].first - p) / d; dbg::zout("ganner: ", p, mod, pm[i], ans, d, s); p = (s * mod * ans.first + p); mod /= d; mod *= pm[i].second; // p %= mod; // if (p < 0) p += mod; } return p; }; namespace zz_mod { template class pp { public: ll val; void flush() { val %= mod; if (val < 0) val += mod; }; void weak_flush() { if (val < 0) { val += mod; } else if (val >= mod) { val -= mod; } }; pp(ll x = 0) { val = x % mod; weak_flush(); }; friend std::ostream& operator<<(std::ostream& os, const pp& x) { return os << '{' << x.val << '|' << mod << '}'; }; pp& operator+=(const pp& p) { val += p.val; weak_flush(); return *this; }; pp& operator+=(ll x) { val += x % mod; weak_flush(); return *this; }; friend pp operator+(pp a, const pp& b) { return a += b; }; friend pp operator+(pp a, ll x) { return a += x; }; friend pp operator+(ll x, pp a) { return a += x; }; pp& operator-=(const pp& p) { val -= p.val; weak_flush(); return *this; }; pp& operator-=(ll x) { val -= x % mod; weak_flush(); return *this; }; friend pp operator-(pp a, const pp& b) { return a -= b; }; friend pp operator-(pp a, ll x) { return a -= x; }; friend pp operator-(ll x, const pp& a) { return pp(x) -= a; }; pp& operator*=(const pp& p) { val = (__int128)val * p.val; flush(); return *this; }; pp& operator*=(ll x) { val = (__int128)val * x; flush(); return *this; }; friend pp operator*(pp a, const pp& b) { return a *= b; }; friend pp operator*(pp a, ll x) { return a *= x; }; friend pp operator*(ll x, const pp& a) { return pp(x) *= a; }; pp inv() { xy ans = gcdex(mod, val); assert((mod * ans.first + val * ans.second) == 1); pp p(ans.second); return p; }; pp& operator/=(const pp& p) { return *this *= p.inv(); } pp& operator/=(ll x) { return *this *= gcdex(mod, x).second; } friend pp operator/(pp a, const pp& b) { return a /= b; }; friend pp operator/(pp a, ll x) { return a /= x; }; friend pp operator/(ll x, const pp& a) { a = a.inv(); return a /= x; }; pp exp(ll n) { if (n < 0) return inv().exp(-n); pp p = *this, ans(1); while (n > 1) { if (n & 1) ans *= p; p *= p; n >>= 1; } if (n > 0) ans *= p; return ans; }; }; } // namespace zz_mod using namespace zz_mod; ///////////////////////////////////////////////// ///////////////////////////////////////////////// int main() { // dbg::unprint = true; vl X(3), Y(3); rep(i, 3) cin >> X[i] >> Y[i]; vxy VEC; rep(i, 3) VEC.emplace_back(X[i], Y[i]); cout << ganner(VEC) << endl; return 0; }