{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003e WANGPENG is a freshman. He is requested to have a physical examination when entering the university.\u003cbr\u003e Now WANGPENG arrives at the hospital. Er….. There are so many students, and the number is increasing!\u003cbr\u003e There are many examination subjects to do, and there is a queue for every subject. The queues are getting longer as time goes by. Choosing the queue to stand is always a problem. Please help WANGPENG to determine an exam sequence, so that he can finish all the physical examination subjects as early as possible.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":" There are several test cases. Each test case starts with a positive integer n in a line, meaning the number of subjects(queues).\u003cbr\u003e Then n lines follow. The i-th line has a pair of integers (ai, bi) to describe the i-th queue:\u003cbr\u003e 1. If WANGPENG follows this queue at time 0, WANGPENG has to wait for ai seconds to finish this subject.\u003cbr\u003e 2. As the queue is getting longer, the waiting time will increase bi seconds every second while WANGPENG is not in the queue.\u003cbr\u003e The input ends with n \u003d 0.\u003cbr\u003e For all test cases, 0\u0026lt;n≤100000, 0≤a\u003csub\u003ei\u003c/sub\u003e,b\u003csub\u003ei\u003c/sub\u003e\u0026lt;2\u003csup\u003e31\u003c/sup\u003e. "}},{"title":"Output","value":{"format":"HTML","content":" For each test case, output one line with an integer: the earliest time (counted by seconds) that WANGPENG can finish all exam subjects. Since WANGPENG is always confused by years, just print the seconds mod 365×24×60×60."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\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\u003e5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n0\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1419\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"\u003cbr\u003eIn the Sample Input, WANGPENG just follow the given order. He spends 1 second in the first queue, 5 seconds in the 2th queue, 27 seconds in the 3th queue, \u003cbr\u003e169 seconds in the 4th queue, and 1217 seconds in the 5th queue. So the total time is 1419s. WANGPENG has computed all possible orders in his \u003cbr\u003e120-core-parallel head, and decided that this is the optimal choice.\u003cbr\u003e"}}]}