#include typedef long long ll; typedef unsigned long long ull; #define FOR(i,a,b) for(int (i)=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define RANGE(vec) (vec).begin(),(vec).end() using namespace std; template T gcd(T a, T b) { if ( std::abs(a) < std::abs(b) ) std::swap(a,b); if ( b == 0 ) return a; return gcd(b, a%b); } template T extgcd(T a, T b, T &x, T &y) { T d = a; if (b != 0) { d = extgcd(b, a%b, y, x); y -= (a/b)*x; } else { x=1; y=0; } return d; } // mod M の逆元を求める template T mod_inverse(T a, T M) { T x, y; T d = extgcd(a, M, x, y); assert(d == 1); return (M + x%M) % M; } template std::pair linear_congruence( const std::vector &A, const std::vector &B, const std::vector &M) { T x = 0, m = 1; for (int i = 0; i < A.size(); ++i) { T a = A[i] * m; T b = B[i] - A[i] * x; T d = gcd(M[i], a); if (b % d) // solution does not exist. return std::make_pair(0, -1); T md = M[i]/d; T t = b / d * mod_inverse(a / d, M[i] / d) % (M[i] / d); x = x + m * t; m *= M[i] / d; } return std::make_pair(x % m, m); } class ChiniseStyleEasy { public: void solve(void) { vector x(3); vector y(3); REP(i, 3) cin>>x[i]>>y[i]; vector a(3,1); ll z,m; tie(z,m) = linear_congruence(a,x,y); if (m < 0) { cout<<-1<solve(); delete obj; return 0; } #endif