#pragma GCC optimize("O3") #include #define ll long long using namespace std; template struct CRT { vector rem, mod; void add(T r, T m) { rem.emplace_back(r); mod.emplace_back(m); } pair calc() { T r = 0, m = 1; for (int i=0; i<(int)rem.size(); i++) { auto ext_gcd = [](T a, T b) -> tuple { T x = 1, y = 0, u = 0, v = 1; while (b) { T p = a/b, q = a%b, r = x-u*p; x = u, u = r; r = y-v*p; y = v, v = r; a = b, b = q; } return {x,y,a}; }; auto [p, q, d] = ext_gcd(m, mod[i]); if ((rem[i]-r)%d != 0) return {0, 0}; T t = (rem[i]-r)/d*p%(mod[i]/d); r += m*t; m *= mod[i]/d; } return {r<0?r+m:r, m}; } }; void solve() { CRT crt; for (int i=0; i<3; i++) { int x, y; cin >> x >> y; crt.add(x, y); } cout << crt.calc().first << '\n'; } signed main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); solve(); return 0; }