Language: C++

#include <cstdio>
#include <vector>
#include <cassert>
using namespace std;

// Dice library
//         ---------
//         | back  |
//         |  (5)  |
// --------+-------+-------+--------+
// | left  |  top  | right | bottom |
// |  (4)  |  (1)  |  (2)  |   (3)  |
// --------+-------+-------+---------
//         | front |
//         |  (0)  |
//         ---------

enum Direction {
    // 北、南、東、西方向 および 右、左回り に 90 度回転
    NORTH = 0, SOUTH = 1, EAST = 2, WEST = 3, ROT_R = 4, ROT_L = 5,
};

enum View {
    // どこから見た時の値か？
    FRONT = 0, TOP = 1, RIGHT = 2, BOTTOM = 3, LEFT = 4, BACK = 5,
};

struct Dice {
    vector<int> value;
    Dice(int front, int top, int right) {
        int sum = 7;
        assert(front + top   != sum);
        assert(top   + right != sum);
        assert(front + right != sum);
        value = {front, top, right, sum-top, sum-right, sum-front};
    }

    void rotate(int dir) {
        vector<int> fnc, swp(6);
        if(dir == NORTH) fnc = {1, 5, 2, 0, 4, 3};
        if(dir == SOUTH) fnc = {3, 0, 2, 5, 4, 1};
        if(dir == EAST ) fnc = {0, 2, 3, 4, 1, 5};
        if(dir == WEST ) fnc = {0, 4, 1, 2, 3, 5};
        if(dir == ROT_R) fnc = {4, 1, 0, 3, 5, 2};
        if(dir == ROT_L) fnc = {2, 1, 5, 3, 0, 4};

        for(int i=0; i<6; i++) swp[ fnc[i] ] = value[i];
        swap(value, swp);
    }

    int get_value(int view) {
        return value[view];
    }
};

const int S = 250;
// front, top
int right_table[7][7];
int board[510][510], height[510][510];

void update(int x, int y, int val) {
    height[x][y]++;
    board[x][y] = val;
}

int main() {
    right_table[3][2] = 1;
    right_table[2][4] = 1;
    right_table[4][5] = 1;
    right_table[5][3] = 1;
    right_table[1][3] = 2;
    right_table[3][6] = 2;
    right_table[6][4] = 2;
    right_table[4][1] = 2;
    right_table[2][1] = 3;
    right_table[1][5] = 3;
    right_table[5][6] = 3;
    right_table[6][2] = 3;
    right_table[5][1] = 4;
    right_table[1][2] = 4;
    right_table[2][6] = 4;
    right_table[6][5] = 4;
    right_table[3][1] = 5;
    right_table[1][4] = 5;
    right_table[4][6] = 5;
    right_table[6][3] = 5;
    right_table[5][4] = 6;
    right_table[4][2] = 6;
    right_table[2][3] = 6;
    right_table[3][5] = 6;

    while(1) {
        memset(board, 0, sizeof(board));
        memset(height, 0, sizeof(height));

        int N; scanf("%d", &N);
        if(N == 0) break;

        for(int i=0; i<N; i++) {
            int top, front; scanf("%d%d", &top, &front);
            Dice dice(front, top, right_table[front][top]);

            int x = S, y = S;
            while(1) {
                if(height[x][y] == 0) {
                    update(x, y, dice.get_value(TOP));
                    break;
                }
                else {
                    int vec[] = {0, 2, 4, 5};
                    int rot[] = {1, 2, 3, 0};
                    int dx[] = {1, 0, 0, -1};
                    int dy[] = {0, 1, -1, 0};
                    int ma = -1, dir = -1;
                    for(int k=0; k<4; k++) {
                        int val = dice.get_value(vec[k]);
                        int nx = x + dx[k], ny = y + dy[k];
                        if(height[x][y] <= height[nx][ny]) continue;
                        if(val > 3 && ma < val) {
                            ma = val;
                            dir = k;
                        }
                    }

                    if(ma == -1) {
                        update(x, y, dice.get_value(TOP));
                        break;
                    }
                    else {
                        x += dx[dir], y += dy[dir];
                        dice.rotate(rot[dir]);
                    }
                }
            }
        }

        int ans[6] = {};
        for(int i=0; i<510; i++) {
            for(int j=0; j<510; j++) {
                int num = board[i][j] - 1;
                if(num < 0) continue;
                else ans[num]++;
            }
        }

        for(int i=0; i<6; i++) {
            if(i != 0) printf(" ");
            printf("%d", ans[i]);
        }
        printf("\n");
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:93:9: error: 'memset' was not declared in this scope
   93 |         memset(board, 0, sizeof(board));
      |         ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <cassert>
  +++ |+#include <cstring>
    4 | using namespace std;