import std; void main () { auto A = readln.split.to!(int[]); auto T = readln.split.to!(long[]); auto ord = iota(A.length.to!int).array; ord.sort!((a, b) => T[a] < T[b]); long took = 0; long ans = 0; foreach (i; ord) { long rem = T[$ - 1] - took; long sol = rem / T[i]; sol = min(sol, 1L * A[i]); ans += sol; took += sol * T[i]; } writeln(ans); } void read (T...) (string S, ref T args) { import std.conv : to; import std.array : split; auto buf = S.split; foreach (i, ref arg; args) { arg = buf[i].to!(typeof(arg)); } }