#include #include #include #include using namespace std; #include using Rational = boost::multiprecision::cpp_rational; vector> to_slope(const vector> &AB) { Rational x(0), y(0); vector> ret; for (auto [_, a, b, i] : AB) { x += a; y += b; ret.emplace_back(x, y); } return ret; } bool solve() { int N; cin >> N; vector A(N), B(N), C(N), D(N); for (auto &x : A) cin >> x; for (auto &x : B) cin >> x; for (auto &x : C) cin >> x; for (auto &x : D) cin >> x; vector> AB, CD; for (int i = 0; i < N; ++i) { AB.emplace_back(B.at(i) / A.at(i), A.at(i), B.at(i), i); CD.emplace_back(D.at(i) / C.at(i), C.at(i), D.at(i), i); } sort(AB.begin(), AB.end()); sort(CD.begin(), CD.end()); const auto lb_xys = to_slope(AB); const auto ub_xys = to_slope(CD); { Rational x0(0), y0(0); for (int i = 0; i < (int)lb_xys.size(); ++i) { auto [x1, y1] = lb_xys.at(i); for (auto [x, y] : ub_xys) { if ((x1 - x0) * (y - y0) - (y1 - y0) * (x - x0) < 0) return false; } x0 = x1, y0 = y1; } } { bool same = true; for (int i = 0; i < N; ++i) same &= get<3>(AB.at(i)) == get<3>(CD.at(i)); if (same) return true; } Rational vx(0), vy(0); for (int i = 0; i + 1 < N; ++i) { // cerr << i << " " << vx << " " << vy << endl; const auto &[px, py] = ub_xys.at(i); if (px <= vx) return true; // y = a1 x + b1 const Rational a1 = (py - vy) / (px - vx); const Rational b1 = vy - a1 * vx; // y = a2 x + b2 const auto &[ax, ay] = lb_xys.at(i); const auto &[bx, by] = lb_xys.at(i + 1); const Rational a2 = (by - ay) / (bx - ax); const Rational b2 = ay - a2 * ax; if (a1 >= a2) return true; vx = (b2 - b1) / (a1 - a2); vy = a1 * vx + b1; if (vx >= bx) return true; } return false; } int main() { cin.tie(nullptr); cin.sync_with_stdio(false); cout << (solve() ? "Yes" : "No") << '\n'; }