{"problem":{"name":"A. Fly","description":{"content":"Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Ea","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF1010A"},"statements":[{"statement_type":"Markdown","content":"Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \\to 2 \\to \\ldots n \\to 1$.\n\nFlight from $x$ to $y$ consists of two phases: take-off from planet $x$ and landing to planet $y$. This way, the overall itinerary of the trip will be: the $1$\\-st planet $\\to$ take-off from the $1$\\-st planet $\\to$ landing to the $2$\\-nd planet $\\to$ $2$\\-nd planet $\\to$ take-off from the $2$\\-nd planet $\\to$ $\\ldots$ $\\to$ landing to the $n$\\-th planet $\\to$ the $n$\\-th planet $\\to$ take-off from the $n$\\-th planet $\\to$ landing to the $1$\\-st planet $\\to$ the $1$\\-st planet.\n\nThe mass of the rocket together with all the useful cargo (but without fuel) is $m$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $1$ ton of fuel can lift off $a_i$ tons of rocket from the $i$\\-th planet or to land $b_i$ tons of rocket onto the $i$\\-th planet.\n\nFor example, if the weight of rocket is $9$ tons, weight of fuel is $3$ tons and take-off coefficient is $8$ ($a_i = 8$), then $1.5$ tons of fuel will be burnt (since $1.5 \\cdot 8 = 9 + 3$). The new weight of fuel after take-off will be $1.5$ tons.\n\nPlease note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.\n\nHelp Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.\n\n## Input\n\nThe first line contains a single integer $n$ ($2 \\le n \\le 1000$) — number of planets.\n\nThe second line contains the only integer $m$ ($1 \\le m \\le 1000$) — weight of the payload.\n\nThe third line contains $n$ integers $a_1, a_2, \\ldots, a_n$ ($1 \\le a_i \\le 1000$), where $a_i$ is the number of tons, which can be lifted off by one ton of fuel.\n\nThe fourth line contains $n$ integers $b_1, b_2, \\ldots, b_n$ ($1 \\le b_i \\le 1000$), where $b_i$ is the number of tons, which can be landed by one ton of fuel.\n\nIt is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel.\n\n## Output\n\nIf Natasha can fly to Mars through $(n - 2)$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $-1$.\n\nIt is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel.\n\nThe answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$. Formally, let your answer be $p$, and the jury's answer be $q$. Your answer is considered correct if $\\frac{|p - q|}{\\max{(1, |q|)}} \\le 10^{-6}$.\n\n[samples]\n\n## Note\n\nLet's consider the first example.\n\nInitially, the mass of a rocket with fuel is $22$ tons.\n\n*   At take-off from Earth one ton of fuel can lift off $11$ tons of cargo, so to lift off $22$ tons you need to burn $2$ tons of fuel. Remaining weight of the rocket with fuel is $20$ tons.\n*   During landing on Mars, one ton of fuel can land $5$ tons of cargo, so for landing $20$ tons you will need to burn $4$ tons of fuel. There will be $16$ tons of the rocket with fuel remaining.\n*   While taking off from Mars, one ton of fuel can raise $8$ tons of cargo, so to lift off $16$ tons you will need to burn $2$ tons of fuel. There will be $14$ tons of rocket with fuel after that.\n*   During landing on Earth, one ton of fuel can land $7$ tons of cargo, so for landing $14$ tons you will need to burn $2$ tons of fuel. Remaining weight is $12$ tons, that is, a rocket without any fuel.\n\nIn the second case, the rocket will not be able even to take off from Earth.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"Natasha 将乘坐火箭飞往火星并返回地球。在前往火星的途中，她将降落于 $n - 2$ 个中间行星。形式上：我们将所有行星编号为 $1$ 到 $n$，其中 $1$ 是地球，$n$ 是火星。Natasha 将进行恰好 $n$ 次飞行：$1 \\to 2 \\to \\dots \\to n \\to 1$。\n\n从 $x$ 飞往 $y$ 的飞行包含两个阶段：从行星 $x$ 起飞和在行星 $y$ 着陆。因此，整个行程的顺序为：第 $1$ 个行星 $\\to$ 从第 $1$ 个行星起飞 $\\to$ 在第 $2$ 个行星着陆 $\\to$ 第 $2$ 个行星 $\\to$ 从第 $2$ 个行星起飞 $\\to$ $\\dots \\to$ 在第 $n$ 个行星着陆 $\\to$ 第 $n$ 个行星 $\\to$ 从第 $n$ 个行星起飞 $\\to$ 在第 $1$ 个行星着陆 $\\to$ 第 $1$ 个行星。\n\n火箭（包括所有有效载荷，但不包括燃料）的质量为 $m$ 吨。然而，Natasha 不知道应装载多少燃料。不幸的是，燃料只能在地球上装载，因此如果火箭在其他行星上耗尽燃料，Natasha 将无法返回家园。燃料用于从每个行星起飞和在每个行星着陆。已知 $1$ 吨燃料可以从第 $i$ 个行星起飞 $a_i$ 吨的火箭，或在第 $i$ 个行星着陆 $b_i$ 吨的火箭。\n\n例如，如果火箭重量为 $9$ 吨，燃料重量为 $3$ 吨，起飞系数为 $8$（即 $a_i = 8$），则将消耗 $1.5$ 吨燃料（因为 $1.5 \\times 8 = 9 + 3$）。起飞后，燃料的新重量为 $1.5$ 吨。\n\n请注意，起飞或着陆过程中允许消耗非整数的燃料，初始燃料量也可以是非整数。\n\n请帮助 Natasha 计算需要装载到火箭中的最小燃料质量。注意，火箭必须携带有效载荷和燃料本身，但不需要携带已经燃烧掉的燃料。假设火箭起飞和着陆是瞬时完成的。\n\n第一行包含一个整数 $n$（$2 \\leq n \\leq 1000$）——行星数量。\n\n第二行包含一个整数 $m$（$1 \\leq m \\leq 1000$）——有效载荷重量。\n\n第三行包含 $n$ 个整数 $a_1, a_2, \\dots, a_n$（$1 \\leq a_i \\leq 1000$），其中 $a_i$ 表示一吨燃料能从第 $i$ 个行星起飞的吨数。\n\n第四行包含 $n$ 个整数 $b_1, b_2, \\dots, b_n$（$1 \\leq b_i \\leq 1000$），其中 $b_i$ 表示一吨燃料能在第 $i$ 个行星着陆的吨数。\n\n保证如果 Natasha 能完成飞行，则所需燃料不超过 $10^9$ 吨。\n\n如果 Natasha 能通过 $(n - 2)$ 个行星飞往火星并返回地球，请输出她应装载的最小燃料质量（单位：吨）。否则，输出单个数字 $-1$。\n\n保证如果 Natasha 能完成飞行，则所需燃料不超过 $10^9$ 吨。\n\n如果你的答案 $p$ 与标准答案 $q$ 的绝对误差或相对误差不超过 $10^{-6}$，则视为正确。形式化地，若 $\\frac{|p - q|}{\\max(1, |q|)} \\leq 10^{-6}$，则你的答案正确。\n\n考虑第一个示例：\n\n初始时，火箭与燃料的总质量为 $22$ 吨。\n\n在第二种情况下，火箭甚至无法从地球起飞。\n\n## Input\n\n第一行包含一个整数 $n$（$2 \\leq n \\leq 1000$）——行星数量。\n\n第二行包含一个整数 $m$（$1 \\leq m \\leq 1000$）——有效载荷重量。\n\n第三行包含 $n$ 个整数 $a_1, a_2, \\dots, a_n$（$1 \\leq a_i \\leq 1000$），其中 $a_i$ 表示一吨燃料能从第 $i$ 个行星起飞的吨数。\n\n第四行包含 $n$ 个整数 $b_1, b_2, \\dots, b_n$（$1 \\leq b_i \\leq 1000$），其中 $b_i$ 表示一吨燃料能在第 $i$ 个行星着陆的吨数。\n\n保证如果 Natasha 能完成飞行，则所需燃料不超过 $10^9$ 吨。\n\n## Output\n\n如果 Natasha 能通过 $(n - 2)$ 个行星飞往火星并返回地球，请输出她应装载的最小燃料质量（单位：吨）。否则，输出单个数字 $-1$。\n\n保证如果 Natasha 能完成飞行，则所需燃料不超过 $10^9$ 吨。\n\n如果你的答案 $p$ 与标准答案 $q$ 的绝对误差或相对误差不超过 $10^{-6}$，则视为正确。形式化地，若 $\\frac{|p - q|}{\\max(1, |q|)} \\leq 10^{-6}$，则你的答案正确。\n\n[samples]\n\n## Note\n\n考虑第一个示例：\n\n初始时，火箭与燃料的总质量为 $22$ 吨。\n\n从地球起飞时，一吨燃料可提升 $11$ 吨载荷，因此要提升 $22$ 吨，需燃烧 $2$ 吨燃料。剩余火箭与燃料总质量为 $20$ 吨。\n\n在火星着陆时，一吨燃料可降落 $5$ 吨载荷，因此降落 $20$ 吨需燃烧 $4$ 吨燃料。剩余火箭与燃料总质量为 $16$ 吨。\n\n从火星起飞时，一吨燃料可提升 $8$ 吨载荷，因此提升 $16$ 吨需燃烧 $2$ 吨燃料。剩余火箭与燃料总质量为 $14$ 吨。\n\n在地球着陆时，一吨燃料可降落 $7$ 吨载荷，因此降落 $14$ 吨需燃烧 $2$ 吨燃料。最终剩余质量为 $12$ 吨，即无燃料的火箭。\n\n在第二种情况下，火箭甚至无法从地球起飞。","is_translate":true,"language":"Chinese"}],"meta":{"iden":"CF1010A","tags":["binary search","math"],"sample_group":[["2\n12\n11 8\n7 5","10.0000000000"],["3\n1\n1 4 1\n2 5 3","\\-1"],["6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3","85.4800000000"]],"created_at":"2026-03-03 11:00:39"}}