{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n div.illustration {\n float: right;\n padding-left: 20px;\n }\n div.illustration .illustration {\n width: 100%;\n border-radius: 4px;\n }\n pre {\n display: block;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n color: #333;\n word-break: break-all;\n word-wrap: break-word;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\n \u003cp\u003eThere are two different species of \u003ca href\u003d\"https://en.wikipedia.org/wiki/Periodical_cicadas\"\u003eperiodical\n cicadas\u003c/a\u003e that only appear from hibernation every\n \u003cspan class\u003d\"tex2jax_process\"\u003e$13$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$17$\u003c/span\u003e years, respectively. Your old\n grandpa tells you that he saw them simultaneously back in ’92.\n You start pondering how many years you have to wait until you\n see them again. You collect information about other pairs of\n periodical cicadas and when they were last observed to find out\n when the next simultaneous appearance is.\u003c/p\u003e\n \u003cp\u003eGiven several different pairs of cicadas and their last\n simultaneous appearance, find the next year that one of the\n pairs reappears.\u003c/p\u003e\n \u003ch2\u003eInput\u003c/h2\u003e\n \u003cp\u003eThe first line of input contains a single integer\n \u003cspan class\u003d\"tex2jax_process\"\u003e$k$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$1 \\le k \\le 99$\u003c/span\u003e), the number of pairs\n of periodical cicadas. Then follow \u003cspan class\u003d\"tex2jax_process\"\u003e$k$\u003c/span\u003e lines, each containing three\n integers \u003cspan class\u003d\"tex2jax_process\"\u003e$y$\u003c/span\u003e, \u003cspan class\u003d\"tex2jax_process\"\u003e$c_1$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$c_2$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$1800 \\le y \\le 2021$\u003c/span\u003e, \u003cspan class\u003d\"tex2jax_process\"\u003e$1 \\le c_1, c_2 \\le 99$\u003c/span\u003e), the year\n this pair was last observed and cycle lengths for the first and\n second species, respectively. You may assume that none of the\n \u003cspan class\u003d\"tex2jax_process\"\u003e$k$\u003c/span\u003e pairs reappears\n earlier than \u003cspan class\u003d\"tex2jax_process\"\u003e$2022$\u003c/span\u003e.\u003c/p\u003e\n \u003ch2\u003eOutput\u003c/h2\u003e\n \u003cp\u003eOutput the first year a pair reappears.\u003c/p\u003e\n \u003ch2\u003eSample 1\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3\n1992 13 17\n1992 14 18\n2001 5 7\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2036\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n \u003ch2\u003eSample 2\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\n2020 2 3\n2019 3 4\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2026\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n "}}]}