408362: GYM103107 B Bo Bing

Memory Limit:128 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Bo Bingtime limit per test2 secondsmemory limit per test128 megabytesinputstandard inputoutputstandard output

Moon cake betting (博饼) 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.

However, no one around wor knows how to play Moon cake betting, he have to play it with his brain girlfriend.

Moon cake betting is a game of dice. Each person rolls 6 dice at a time and gets corresponding prizes according to the result type.

All result types are as follows:

  • ZhuangYuan: There are six sub-situations.

    • SiHong: Four $$$\texttt{#4}$$$ + two arbitrary non $$$\texttt{#4}$$$ (non $$$\texttt{#1#1}$$$), which can not form a Multi-award special case.
    • WuZiDengKe: Five arbitrary (non $$$\texttt{#4#4#4#4#4}$$$) + one arbitrary different from the previous ones, which can form a Multi-award special case.
    • WuHong: Five $$$\texttt{#4}$$$ + one arbitrary non $$$\texttt{#4}$$$, which can not form a Multi-award special case.
    • ManDiJin: Six arbitrary (non $$$\texttt{#4#4#4#4#4#4}$$$), which can not form a Multi-award special case.
    • ManTangCai: Six $$$\texttt{#4}$$$, which can not form a Multi-award special case.
    • ZhuangYuanChaJinHua: Four $$$\texttt{#4}$$$ + two $$$\texttt{#1}$$$, which can not form a Multi-award special case.

    The rank of ZhuangYuan is compared according to the following rules:

    1. First compare the type. SiHong < WuZiDengKe < WuHong < ManDiJin < ManTangCai < ZhuangYuanChaJinHua
    2. If the types are same, then compare according to the following rules:

      1. If they are same SiHong, then compare the sum of remaining two dices points.
      2. If they are same WuZiDengKe, then compare the points of dice that form the WuZiDengKe. If still the same, then compare the remaining one dice points.
      3. If they are same WuHong, then compare the remaining one dice points.
      4. If they are same ManDiJin, then compare the points of dice that form the ManDiJin.
      5. If still same after compared by above rules, then the first one who rolled will get it.

  • DuiTang: $$$\texttt{#1#2#3#4#5#6}$$$, which can not form a Multi-award special case.

  • SanHong: Three $$$\texttt{#4}$$$ + three arbitrary non $$$\texttt{#4}$$$, which can not form a Multi-award special case.
  • SiJin: Four arbitrary non $$$\texttt{#4}$$$ + two arbitrary different from the previous, which can form a Multi-award special case.
  • ErJu: Two $$$\texttt{#4}$$$ + four arbitrary non $$$\texttt{#4}$$$ and doesn't constitute any other form, which can not form a Multi-award special case.

  • YiXiu: One $$$\texttt{#4}$$$ + five arbitrary non $$$\texttt{#4}$$$ and doesn't constitute any other form, which can not form a Multi-award special case.
  • LuoBang: Doesn't constitute any other form.

There are also several special cases:

  • TanChu: If the dice is thrown out of range (concretely, get $$$\texttt{#0}$$$), the next round will stop, and this roll is invalid.
  • ManTangHei: Six $$$\texttt{#6}$$$, a part of ManDiJin, except for the ZhuangYuan prize, the rest of the other prize all will be taken away.

  • Multi-award: May appear in the SiJin and WuZiDengKe, for example $$$\texttt{#3#3#3#3#4#2}$$$ is SiJin with YiXiu, in this case, player can get the award of SiJin and YiXiu at the same time; $$$\texttt{#5#5#5#5#5#4}$$$ is WuZiDengKe with YiXiu, in this case, player can get the award of YiXiu and record the ZhuangYuan at the same time.

Now it is known that there are $$$1$$$ ZhuangYuan prize, $$$2$$$ DuiTang prizes, $$$a$$$ SanHong prizes, $$$b$$$ SiJin prizes, $$$c$$$ ErJu prizes, $$$d$$$ YiXiu prizes.

The prize rules are as follows:

  • For ZhuangYuan 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 ZhuangYuan to compared.

  • 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 YiXiu and there is only one YiXiu residue then A can get the last YiXiu. After that, player B roll the YiXiu. But now there is no YiXiu residue so B can not get anything.

Now 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)$$$.

If any player throw dice out of the range and get TanChu, then this roll is invalid, and he will do nothing the next round (Caution, skipped round is counted) and let the next player roll.

Given the game situation, can you find out the final prize situation of every player?

Input

The 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$$$ SanHong prizes, $$$b$$$ SiJin prizes, $$$c$$$ ErJu prizes, $$$d$$$ YiXiu prizes respectively.

Following $$$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.

If it is $$$\texttt{#}0$$$, it means that the dice is thrown out of range.

If it is between $$$\texttt{#}1$$$ and $$$\texttt{#}6$$$, it is the thrown number of dice.

Note that if someone stops for a round, this line will be blank.

Output

Output $$$n$$$ lines.

Each line contains $$$6$$$ integers representing the final prize situation of every player, in the order of ZhuangYuan, DuiTang, SanHong, SiJin, ErJu, YiXiu.

ExamplesInput
2 10 10 10 10 10
#4#4#4#4#1#1
#1#2#3#4#5#6
#1#2#3#5#6#6
#0#4#4#4#4#4
#4#4#4#4#2#2

#4#1#4#2#4#3
#5#5#5#5#5#1
#1#1#1#1#4#4
#6#6#6#6#6#6
Output
0 0 1 1 1 0
1 2 9 9 9 10
Input
2 20 10 10 10 10
#2#5#5#6#6#6
#5#6#3#2#4#3
#6#3#4#1#1#3
#4#3#2#5#6#6
#2#3#3#4#4#3
#2#6#4#6#1#2
#4#4#6#4#2#1
#6#5#6#5#5#6
#6#3#1#5#2#2
#4#6#2#3#2#5
#4#1#3#3#6#6
#3#1#3#3#2#2
#6#3#5#6#1#1
#5#2#6#2#3#3
#4#1#6#6#2#5
#5#2#3#5#5#4
#5#1#1#4#3#4
#4#2#6#5#4#4
#5#2#6#3#4#4
#2#2#6#3#3#5
Output
0 0 1 0 3 3
0 0 1 0 0 5

加入题单

算法标签: