{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e\u003cspan class\u003d\"tex-font-style-it\"\u003eMoon cake betting\u003c/span\u003e (博饼) is a traditional Mid-autumn festival activity originated in Xiamen and then spread to southern Fujian. It began in the early Qing Dynasty. It was invented by Zheng Chenggong when he stationed in order to resolve the Mid-autumn lovesickness of the soldiers and inspire their morale. As a result, it has become a unique folk custom in Southern Fujian.\u003c/p\u003e\u003ccenter\u003e \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/88b0be52bd48cd26c51810dcd898d741?v\u003d1726229891\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e\u003c/center\u003e\u003cp\u003eHowever, no one around wor knows how to play \u003cspan class\u003d\"tex-font-style-it\"\u003eMoon cake betting\u003c/span\u003e, he have to play it with his brain girlfriend.\u003c/p\u003e\u003cp\u003e\u003cspan class\u003d\"tex-font-style-it\"\u003eMoon cake betting\u003c/span\u003e is a game of dice. Each person rolls 6 dice at a time and gets corresponding prizes according to the result type.\u003c/p\u003e\u003cp\u003eAll result types are as follows:\u003c/p\u003e\u003cul\u003e\u003cp\u003e \u003c/p\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003eZhuangYuan\u003c/span\u003e: There are six sub-situations.\u003cp\u003e \u003c/p\u003e\u003cul\u003e\u003cp\u003e \u003c/p\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003eSiHong\u003c/span\u003e: Four $$$\\texttt{#4}$$$ + two arbitrary non $$$\\texttt{#4}$$$ (non $$$\\texttt{#1#1}$$$), which can not form a \u003cspan class\u003d\"tex-font-style-it\"\u003eMulti-award\u003c/span\u003e special case. \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/8de8ef0bd2664a438114d7d66cffe995?v\u003d1726229891\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003eWuZiDengKe\u003c/span\u003e: Five arbitrary (non $$$\\texttt{#4#4#4#4#4}$$$) + one arbitrary different from the previous ones, which can form a \u003cspan class\u003d\"tex-font-style-it\"\u003eMulti-award\u003c/span\u003e special case. \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/13d53aaadf17a9d930eafb0890b8d78b?v\u003d1726229891\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003eWuHong\u003c/span\u003e: Five $$$\\texttt{#4}$$$ + one arbitrary non $$$\\texttt{#4}$$$, which can not form a \u003cspan class\u003d\"tex-font-style-it\"\u003eMulti-award\u003c/span\u003e special case. \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/413b7218cc2d778f1c21f7d43fd5bb3c?v\u003d1726229891\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003eManDiJin\u003c/span\u003e: Six arbitrary (non $$$\\texttt{#4#4#4#4#4#4}$$$), which can not form a \u003cspan class\u003d\"tex-font-style-it\"\u003eMulti-award\u003c/span\u003e special case. \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/5b4d3ad497e6e6643e3ec497dfaba726?v\u003d1726229891\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003eManTangCai\u003c/span\u003e: Six $$$\\texttt{#4}$$$, which can not form a \u003cspan class\u003d\"tex-font-style-it\"\u003eMulti-award\u003c/span\u003e special case. \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/07d0816a62011785695319d74b0bc516?v\u003d1726229891\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003eZhuangYuanChaJinHua\u003c/span\u003e: Four $$$\\texttt{#4}$$$ + two $$$\\texttt{#1}$$$, which can not form a \u003cspan class\u003d\"tex-font-style-it\"\u003eMulti-award\u003c/span\u003e special case. \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/f2f4f2a0676e73f4ab53a1a5c4d2b3d7?v\u003d1726229891\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/li\u003e\u003c/ul\u003e\u003cp\u003e The rank of \u003cspan class\u003d\"tex-font-style-it\"\u003eZhuangYuan\u003c/span\u003e is compared according to the following rules: \u003c/p\u003e\u003col\u003e\u003cp\u003e \u003c/p\u003e\u003cli\u003e First compare the type. \u003cspan class\u003d\"tex-font-style-it\"\u003eSiHong\u003c/span\u003e \u0026lt; \u003cspan class\u003d\"tex-font-style-it\"\u003eWuZiDengKe\u003c/span\u003e \u0026lt; \u003cspan class\u003d\"tex-font-style-it\"\u003eWuHong\u003c/span\u003e \u0026lt; \u003cspan class\u003d\"tex-font-style-it\"\u003eManDiJin\u003c/span\u003e \u0026lt; \u003cspan class\u003d\"tex-font-style-it\"\u003eManTangCai\u003c/span\u003e \u0026lt; \u003cspan class\u003d\"tex-font-style-it\"\u003eZhuangYuanChaJinHua\u003c/span\u003e \u003c/li\u003e\u003cli\u003e If the types are same, then compare according to the following rules: \u003col\u003e\u003cp\u003e \u003c/p\u003e\u003cli\u003e If they are same \u003cspan class\u003d\"tex-font-style-it\"\u003eSiHong\u003c/span\u003e, then compare the sum of remaining two dices points. \u003c/li\u003e\u003cli\u003e If they are same \u003cspan class\u003d\"tex-font-style-it\"\u003eWuZiDengKe\u003c/span\u003e, then compare the points of dice that form the \u003cspan class\u003d\"tex-font-style-it\"\u003eWuZiDengKe\u003c/span\u003e. If still the same, then compare the remaining one dice points. \u003c/li\u003e\u003cli\u003e If they are same \u003cspan class\u003d\"tex-font-style-it\"\u003eWuHong\u003c/span\u003e, then compare the remaining one dice points. \u003c/li\u003e\u003cli\u003e If they are same \u003cspan class\u003d\"tex-font-style-it\"\u003eManDiJin\u003c/span\u003e, then compare the points of dice that form the \u003cspan class\u003d\"tex-font-style-it\"\u003eManDiJin\u003c/span\u003e. \u003c/li\u003e\u003cli\u003e If still same after compared by above rules, then the first one who rolled will get it. \u003c/li\u003e\u003c/ol\u003e\u003cp\u003e \u003c/p\u003e\u003c/li\u003e\u003c/ol\u003e\u003cp\u003e \u003c/p\u003e\u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003eDuiTang\u003c/span\u003e: $$$\\texttt{#1#2#3#4#5#6}$$$, which can not form a \u003cspan class\u003d\"tex-font-style-it\"\u003eMulti-award\u003c/span\u003e special case.\u003cp\u003e \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/c5d5ec9a878f2c3f5d1ccc0519413e7a?v\u003d1726229891\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/p\u003e\u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003eSanHong\u003c/span\u003e: Three $$$\\texttt{#4}$$$ + three arbitrary non $$$\\texttt{#4}$$$, which can not form a \u003cspan class\u003d\"tex-font-style-it\"\u003eMulti-award\u003c/span\u003e special case. \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/9b492895682a4724ed28a2a48edff0c0?v\u003d1726229891\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003eSiJin\u003c/span\u003e: Four arbitrary non $$$\\texttt{#4}$$$ + two arbitrary different from the previous, which can form a \u003cspan class\u003d\"tex-font-style-it\"\u003eMulti-award\u003c/span\u003e special case. \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/665b26407e4f3b1958bb6a0f80f7b667?v\u003d1726229891\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003eErJu\u003c/span\u003e: Two $$$\\texttt{#4}$$$ + four arbitrary non $$$\\texttt{#4}$$$ and doesn\u0027t constitute any other form, which can not form a \u003cspan class\u003d\"tex-font-style-it\"\u003eMulti-award\u003c/span\u003e special case.\u003cp\u003e \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/a9fe2efa3f2b098e34374c092745bece?v\u003d1726229891\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/p\u003e\u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003eYiXiu\u003c/span\u003e: One $$$\\texttt{#4}$$$ + five arbitrary non $$$\\texttt{#4}$$$ and doesn\u0027t constitute any other form, which can not form a \u003cspan class\u003d\"tex-font-style-it\"\u003eMulti-award\u003c/span\u003e special case. \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/0d72c12c891262583f807f7df965b8cf?v\u003d1726229891\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003eLuoBang\u003c/span\u003e: Doesn\u0027t constitute any other form. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThere are also several special cases:\u003c/p\u003e\u003cul\u003e\u003cp\u003e \u003c/p\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003eTanChu\u003c/span\u003e: If the dice is thrown out of range (concretely, get $$$\\texttt{#0}$$$), the next round will stop, and this roll is invalid. \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003eManTangHei\u003c/span\u003e: Six $$$\\texttt{#6}$$$, a part of \u003cspan class\u003d\"tex-font-style-it\"\u003eManDiJin\u003c/span\u003e, except for the \u003cspan class\u003d\"tex-font-style-it\"\u003eZhuangYuan\u003c/span\u003e prize, the rest of the other prize all will be taken away.\u003cp\u003e \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/6af66e4267b03283e8b1d06c02683f9f?v\u003d1726229891\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003c/p\u003e\u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-it\"\u003eMulti-award\u003c/span\u003e: May appear in the \u003cspan class\u003d\"tex-font-style-it\"\u003eSiJin\u003c/span\u003e and \u003cspan class\u003d\"tex-font-style-it\"\u003eWuZiDengKe\u003c/span\u003e, for example $$$\\texttt{#3#3#3#3#4#2}$$$ is \u003cspan class\u003d\"tex-font-style-it\"\u003eSiJin\u003c/span\u003e with \u003cspan class\u003d\"tex-font-style-it\"\u003eYiXiu\u003c/span\u003e, in this case, player can get the award of \u003cspan class\u003d\"tex-font-style-it\"\u003eSiJin\u003c/span\u003e and \u003cspan class\u003d\"tex-font-style-it\"\u003eYiXiu\u003c/span\u003e at the same time; $$$\\texttt{#5#5#5#5#5#4}$$$ is \u003cspan class\u003d\"tex-font-style-it\"\u003eWuZiDengKe\u003c/span\u003e with \u003cspan class\u003d\"tex-font-style-it\"\u003eYiXiu\u003c/span\u003e, in this case, player can get the award of \u003cspan class\u003d\"tex-font-style-it\"\u003eYiXiu\u003c/span\u003e and record the \u003cspan class\u003d\"tex-font-style-it\"\u003eZhuangYuan\u003c/span\u003e at the same time. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eNow it is known that there are $$$1$$$ \u003cspan class\u003d\"tex-font-style-it\"\u003eZhuangYuan\u003c/span\u003e prize, $$$2$$$ \u003cspan class\u003d\"tex-font-style-it\"\u003eDuiTang\u003c/span\u003e prizes, $$$a$$$ \u003cspan class\u003d\"tex-font-style-it\"\u003eSanHong\u003c/span\u003e prizes, $$$b$$$ \u003cspan class\u003d\"tex-font-style-it\"\u003eSiJin\u003c/span\u003e prizes, $$$c$$$ \u003cspan class\u003d\"tex-font-style-it\"\u003eErJu\u003c/span\u003e prizes, $$$d$$$ \u003cspan class\u003d\"tex-font-style-it\"\u003eYiXiu\u003c/span\u003e prizes.\u003c/p\u003e\u003cp\u003eThe prize rules are as follows:\u003c/p\u003e\u003cul\u003e\u003cp\u003e \u003c/p\u003e\u003cli\u003e For \u003cspan class\u003d\"tex-font-style-it\"\u003eZhuangYuan\u003c/span\u003e prize, at the end of game, the biggest one who rolled will win it, and every one will take the last time that rolled the \u003cspan class\u003d\"tex-font-style-it\"\u003eZhuangYuan\u003c/span\u003e to compared.\u003cp\u003e \u003c/p\u003e\u003c/li\u003e\u003cli\u003e For other prizes, first come, first served. If anyone roll a prize but there is no residue then he get nothing. For example player A roll the \u003cspan class\u003d\"tex-font-style-it\"\u003eYiXiu\u003c/span\u003e and there is only one \u003cspan class\u003d\"tex-font-style-it\"\u003eYiXiu\u003c/span\u003e residue then A can get the last \u003cspan class\u003d\"tex-font-style-it\"\u003eYiXiu\u003c/span\u003e. After that, player B roll the \u003cspan class\u003d\"tex-font-style-it\"\u003eYiXiu\u003c/span\u003e. But now there is no \u003cspan class\u003d\"tex-font-style-it\"\u003eYiXiu\u003c/span\u003e residue so B can not get anything.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eNow we know that $$$n$$$ player sit together in a circle and play $$$m$$$ rounds. Player 1 starts to roll. They roll in turn $$$m$$$ times in the order of $$$(1, 2, 3, \\cdots, n-1, n, 1, 2, \\cdots)$$$.\u003c/p\u003e\u003cp\u003eIf any player throw dice out of the range and get \u003cspan class\u003d\"tex-font-style-it\"\u003eTanChu\u003c/span\u003e, then this roll is invalid, and he will do nothing the next round (Caution, skipped round is counted) and let the next player roll.\u003c/p\u003e\u003cp\u003eGiven the game situation, can you find out the final prize situation of every player?\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains six integers $$$n, m, a, b, c, d ~ (1 \\leq n \\le 10^6; ~ 0 \\le m \\le 10^6; ~ 1 \\le a, b, c, d \\le 10^9)$$$ denoting the number of players, the numbers of rounds to play, $$$a$$$ \u003cspan class\u003d\"tex-font-style-it\"\u003eSanHong\u003c/span\u003e prizes, $$$b$$$ \u003cspan class\u003d\"tex-font-style-it\"\u003eSiJin\u003c/span\u003e prizes, $$$c$$$ \u003cspan class\u003d\"tex-font-style-it\"\u003eErJu\u003c/span\u003e prizes, $$$d$$$ \u003cspan class\u003d\"tex-font-style-it\"\u003eYiXiu\u003c/span\u003e prizes respectively.\u003c/p\u003e\u003cp\u003eFollowing $$$m$$$ lines each contains a string $$$\\texttt{#}g_1\\texttt{#}g_2\\texttt{#}g_3\\texttt{#}g_4\\texttt{#}g_5\\texttt{#}g_6$$$ representing the result of this throw.\u003c/p\u003e\u003cp\u003eIf it is $$$\\texttt{#}0$$$, it means that the dice is thrown out of range.\u003c/p\u003e\u003cp\u003eIf it is between $$$\\texttt{#}1$$$ and $$$\\texttt{#}6$$$, it is the thrown number of dice.\u003c/p\u003e\u003cp\u003eNote that if someone stops for a round, this line will be \u003cspan class\u003d\"tex-font-style-bf\"\u003eblank\u003c/span\u003e.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eOutput $$$n$$$ lines.\u003c/p\u003e\u003cp\u003eEach line contains $$$6$$$ integers representing the final prize situation of every player, in the order of \u003cspan class\u003d\"tex-font-style-it\"\u003eZhuangYuan\u003c/span\u003e, \u003cspan class\u003d\"tex-font-style-it\"\u003eDuiTang\u003c/span\u003e, \u003cspan class\u003d\"tex-font-style-it\"\u003eSanHong\u003c/span\u003e, \u003cspan class\u003d\"tex-font-style-it\"\u003eSiJin\u003c/span\u003e, \u003cspan class\u003d\"tex-font-style-it\"\u003eErJu\u003c/span\u003e, \u003cspan class\u003d\"tex-font-style-it\"\u003eYiXiu\u003c/span\u003e.\u003c/p\u003e"}},{"title":"Examples","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\u003e2 10 10 10 10 10\n#4#4#4#4#1#1\n#1#2#3#4#5#6\n#1#2#3#5#6#6\n#0#4#4#4#4#4\n#4#4#4#4#2#2\n\n#4#1#4#2#4#3\n#5#5#5#5#5#1\n#1#1#1#1#4#4\n#6#6#6#6#6#6\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0 0 1 1 1 0\n1 2 9 9 9 10\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","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\u003e2 20 10 10 10 10\n#2#5#5#6#6#6\n#5#6#3#2#4#3\n#6#3#4#1#1#3\n#4#3#2#5#6#6\n#2#3#3#4#4#3\n#2#6#4#6#1#2\n#4#4#6#4#2#1\n#6#5#6#5#5#6\n#6#3#1#5#2#2\n#4#6#2#3#2#5\n#4#1#3#3#6#6\n#3#1#3#3#2#2\n#6#3#5#6#1#1\n#5#2#6#2#3#3\n#4#1#6#6#2#5\n#5#2#3#5#5#4\n#5#1#1#4#3#4\n#4#2#6#5#4#4\n#5#2#6#3#4#4\n#2#2#6#3#3#5\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0 0 1 0 3 3\n0 0 1 0 0 5\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}