{"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 \u003cdiv style\u003d\"width:36.00%\" class\u003d\"illustration\"\u003e\n \u003cimg src\u003d\"CDN_BASE_URL/3a1f062daa6a1bbd7c52f0ea99ec1183?v\u003d1715311698\" alt\u003d\"/problems/redistribution/file/statement/en/img-0001.jpg\" class\u003d\"illustration\"\u003e\n\n \n \u003c/div\u003e\n\n \u003cp\u003eLinda is giving an exam. When the exam is over, Linda will\n redistribute the exams among the students for a peer review, so\n they may grade each other’s answers and assign preliminary\n scores.\u003c/p\u003e\n\n \u003cp\u003eThe students are split up in several rooms of varying sizes.\n Linda has devised the following scheme for redistributing the\n exams:\u003c/p\u003e\n\n \u003col class\u003d\"enumerate\"\u003e\n \u003cli\u003e\n \u003cp\u003eLinda visits the first room, picks up all exams written\n there, and places them in a pile.\u003c/p\u003e\n \u003c/li\u003e\n\n \u003cli\u003e\n \u003cp\u003eIn each subsequent room Linda takes exams from the top\n of her pile and randomly distributes them to the students\n in the room. She then picks up all exams written in that\n room and adds them to the bottom of her pile.\u003c/p\u003e\n \u003c/li\u003e\n\n \u003cli\u003e\n \u003cp\u003eAfter having visited each room exactly once, Linda\n returns to the first room, and distributes the remaining\n exams from her pile there.\u003c/p\u003e\n \u003c/li\u003e\n \u003c/ol\u003e\n\n \u003cp\u003eNaturally, it is imperative that no student receives their\n own exam to review, and that Linda does not run out of exams in\n her pile while doing the redistribution (i.e., that when\n entering a room after the first one, Linda’s pile contains at\n least as many exams as there are students in the room). Whether\n or not this is the case depends on the order in which the rooms\n are visited. We say that an ordering of the rooms is\n \u003cem\u003esafe\u003c/em\u003e if Linda will not run out of exams in her pile\n when visiting rooms in that order, and that there is no chance\n that any student receives their own exam to review.\u003c/p\u003e\n\n \u003cp\u003eCan you find a safe order in which to visit the rooms (or\n determine that no safe order exists)?\u003c/p\u003e\n\n \u003ch2\u003eInput\u003c/h2\u003e\n\n \u003cp\u003eThe input consists of:\u003c/p\u003e\n\n \u003cul class\u003d\"itemize\"\u003e\n \u003cli\u003e\n \u003cp\u003eone line containing an integer \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$2 \\le n \\le 30$\u003c/span\u003e), the number of\n rooms.\u003c/p\u003e\n \u003c/li\u003e\n\n \u003cli\u003e\n \u003cp\u003eone line containing \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e integers \u003cspan class\u003d\"tex2jax_process\"\u003e$s_1, \\ldots , s_ n$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$1 \\le s_ i \\le 100$\u003c/span\u003e for each\n \u003cspan class\u003d\"tex2jax_process\"\u003e$i$\u003c/span\u003e), where\n \u003cspan class\u003d\"tex2jax_process\"\u003e$s_ i$\u003c/span\u003e is the number\n of students in room \u003cspan class\u003d\"tex2jax_process\"\u003e$i$\u003c/span\u003e.\u003c/p\u003e\n \u003c/li\u003e\n \u003c/ul\u003e\n\n \u003ch2\u003eOutput\u003c/h2\u003e\n\n \u003cp\u003eIf it is impossible to redistribute the exams safely, output\n “\u003ctt class\u003d\"ttfamily\"\u003eimpossible\u003c/tt\u003e”. Otherwise, output a\n safe order in which to visit the rooms. If there are multiple\n safe orders, you may give any of them.\u003c/p\u003e\n\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\u003e4\n2 3 3 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2 3 4 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n\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\n10 20\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eimpossible\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n "}}]}