#P2139. 小Z的掷骰游戏

小Z的掷骰游戏

Description

Xiao Z obtained a peculiar die (as shown below) and wants to play a dice game with it.

The game is simple: each time, Xiao Z drops one die vertically from the same position. The die stops when it lands on the plane or on top of another die. However, because this is a special die, it will continue to roll and fall. This die has the following properties:

  • A normal die might roll in four directions, but this die can only roll toward the faces numbered 4,5,64, 5, 6. In the situation shown below, this die can only roll in two directions.

  • This die rolls only if rolling will cause it to descend (as shown below). When there are multiple directions available, it rolls toward the direction with the largest face number.

  • After rolling exactly 9090^\circ, the die falls vertically. When it lands on the plane or on another die (as BB and CC in the figure below), it stops, and then continues the process of rolling and falling.

The figure above shows the process of dropping 44 dice in sequence, each initially with top face 66 and front face 44.

Now Xiao Z has dropped nn dice. He wants to know, after the game ends, how many times each number appears on the top when viewed from above (as shown below). Please help him.

Input Format

There are multiple test cases. Each test case is formatted as follows:

  • Line 11: an integer nn, the number of dice dropped.
  • Lines 22 to n+1n+1: each line contains two integers t,ft, f, meaning one die is dropped with top face tt and front face ff.

Output Format

For each test case, output one line containing six integers, representing how many times each number appears on the top after the game ends, when viewed from above.

4
6 4
6 4
6 4
6 4
1
2 1

0 1 1 0 0 1
0 1 0 0 0 0

Hint

This problem has 44 test points, each worth 2525 points.

For 25%25\% of the testdata, n=1n = 1.

For another 25%25\% of the testdata, n=2n = 2.

For 100%100\% of the testdata, 1n1001 \leq n \leq 100, and there are at most 3030 test cases.

Translated by ChatGPT 5