let l = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"); let n = BigInt(l[0]); let [a0, b0] = l[1].split(" ").map(s => BigInt(s)); let [a1, b1] = l[2].split(" ").map(s => BigInt(s)); let [a2, b2] = l[3].split(" ").map(s => BigInt(s)); if (a1*b2= 0n; i += bq, di -= aq) { for (let j = 0n, dj = di; j < jmax && dj >= 0n; j += br, dj -= ar) { let t = dj / ap * bp + i + j; r = (r < t) ? t : r; } } return r; } let r = solve(n, a2, b2, a0, b0, a1, b1); console.log(r.toString());