Language: C++

g#include <iostream>
#include <cstring>

using namespace std;

//倒れる向き
#define FRONT 0
#define RIGHT 1
#define BACK 2
#define LEFT 3

//地面の中心
#define CENTER 100

int input[100][2], answer[6], height = 0, n, k = 0, w = 0; //入力される数字、答え、高さ、処理する番号、どっちの回転が適用されたか
int x, y; //現在の座標
int tmp[2];// top and front
int field[201][201][102] = {}; //サイコロの転がり落ちるフィールド
int field_d[200][200] = {};
int graph[6][6][3] = {
    {{-1, -1, -1}, {BACK, LEFT, 4}, {BACK, RIGHT, 2}, {BACK, LEFT, 5}, {BACK, RIGHT, 3}, {-1, -1, -1}},
    {{BACK, RIGHT, 3}, {-1, -1, -1}, {LEFT, BACK, 6}, {RIGHT, BACK, 1}, {-1, -1, -1}, {BACK, LEFT, 4}},
    {{LEFT, BACK, 5}, {RIGHT, BACK, 1}, {-1, -1, -1}, {-1, -1, -1}, {LEFT, BACK, 6}, {RIGHT, BACK, 2}},
    {{RIGHT, FRONT, 2}, {LEFT, RIGHT, 6}, {-1, -1, -1}, {-1, -1, -1}, {RIGHT, FRONT, 1}, {LEFT, FRONT, 5}},
    {{FRONT, LEFT, 4}, {-1, -1, -1}, {RIGHT, FRONT, 1}, {LEFT, FRONT, 6}, {-1, -1, -1}, {FRONT, RIGHT, 3}},
    {{-1, -1, -1}, {FRONT, RIGHT, 3}, {FRONT, LEFT, 5}, {FRONT, RIGHT, 2}, {FRONT, LEFT, 4}, {-1, -1, -1}}
}; //0:front 1:right 2:dack 3:left

//落下
bool Drop()
{
    for(int i = 0; i < 102; i++)
    {
        if(!field[CENTER][CENTER][i])
        {
            field[CENTER][CENTER][i]++;
            height = i;
            return true;
        }
    }
    return false;
}

//回転できるか
bool CanMove(int k)
{
    if(height == 0)
        return false;
    else
    {
        switch(graph[tmp[1] - 1][tmp[0] - 1][0])
        {
            case FRONT:
                if(field[y + 1][x][height - 1])
                {
                    switch(graph[tmp[1] - 1][tmp[0] - 1][1])
                    {
                        case FRONT:
                            if(field[y + 1][x][height - 1])
                                return false;
                            else
                                w = 1;
                            break;
                        case RIGHT:
                            if(field[y][x - 1][height - 1])
                                return false;
                            else
                                w = 1;
                            break;
                        case BACK:
                            if(field[y - 1][x][height - 1])
                                return false;
                            else
                                w = 1;
                            break;
                        case LEFT:
                            if(field[y][x + 1][height - 1])
                                return false;
                            else
                                w = 1;
                            break;
                    }
                }
                else
                    w = 0;
                break;
            case RIGHT:
                if(field[y][x - 1][height - 1])
                {
                    switch(graph[tmp[1] - 1][tmp[0] - 1][1])
                    {
                        case FRONT:
                            if(field[y + 1][x][height - 1])
                                return false;
                            else
                                w = 1;
                            break;
                        case RIGHT:
                            if(field[y][x - 1][height - 1])
                                return false;
                            else
                                w = 1;
                            break;
                        case BACK:
                            if(field[y - 1][x][height - 1])
                                return false;
                            else
                                w = 1;
                            break;
                        case LEFT:
                            if(field[y][x + 1][height - 1])
                                return false;
                            else
                                w = 1;
                            break;
                    }

                }
                else
                    w = 0;
                break;
            case BACK:
                if(field[y - 1][x][height - 1])
                {
                    switch(graph[tmp[1] - 1][tmp[0] - 1][1])
                    {
                        case FRONT:
                            if(field[y + 1][x][height - 1])
                                return false;
                            else
                                w = 1;
                            break;
                        case RIGHT:
                            if(field[y][x - 1][height - 1])
                                return false;
                            else
                                w = 1;
                            break;
                        case BACK:
                            if(field[y - 1][x][height - 1])
                                return false;
                            else
                                w = 1;
                            break;
                        case LEFT:
                            if(field[y][x + 1][height - 1])
                                return false;
                            else
                                w = 1;
                            break;
                    }

                }
                else
                    w = 0;
                break;
            case LEFT:
                if(field[y][x + 1][height - 1])
                {
                    switch(graph[tmp[1] - 1][tmp[0] - 1][1])
                    {
                        case FRONT:
                            if(field[y + 1][x][height - 1])
                                return false;
                            else
                                w = 1;
                            break;
                        case RIGHT:
                            if(field[y][x - 1][height - 1])
                                return false;
                            else
                                w = 1;
                            break;
                        case BACK:
                            if(field[y - 1][x][height - 1])
                                return false;
                            else
                                w = 1;
                            break;
                        case LEFT:
                            if(field[y][x + 1][height - 1])
                                return false;
                            else
                                w = 1;
                            break;
                    }

                }
                else
                    w = 0;
                break;
        }
        return true;
    }
}

//回転
void Move()
{
    int t = 0;
    switch(graph[tmp[1] - 1][tmp[0] - 1][w])
    {
        case FRONT:
            field[y][x][height]--;
            y++;
            t = tmp[0];
            tmp[0] = 7 - tmp[1];
            tmp[1] = t;
            break;
        case RIGHT:
            field[y][x][height]--;
            x--;
            tmp[0] = graph[tmp[1] - 1][tmp[0] - 1][2];
            break;
        case BACK:
            field[y][x][height]--;
            y--;
            t = tmp[0];
            tmp[0] = tmp[1];
            tmp[1] = 7 - t;
            break;
        case LEFT:
            field[y][x][height]--;
            x++;
            tmp[0] = 7 - graph[tmp[1] - 1][tmp[0] - 1][2];
            break;
    }
    height--;
    field[y][x][height]++;
}

void Init()
{
    memset(answer, 0, sizeof(answer));
    memset(tmp, 0, sizeof(tmp));
    memset(field, 0, sizeof(field));
    memset(field_d, 0, sizeof(field_d));
    memset(input, 0 ,sizeof(input));
    k = height = 0;
}

int main(void)
{
    while(true)
    {
        int t, f;
        cin >> n;
        if(n == 0 || cin.eof()) break;

        for(int i = 0; i < n; i++)
        {
            cin >> t >> f;
            input[i][0] = t;
            input[i][1] = f;
        }

        x = y = CENTER;
        tmp[0] = input[k][0];
        tmp[1] = input[k][1];
        while(true)
        {
            if(k >= n) break;
            if(!Drop()) break;
            while(true)
            {
                if(!CanMove(k))
                {
                    if(field[y][x][height - 1] && height != 0)
                    {
                        answer[field_d[y][x]]--;
                    }
                    break;
                }
                Move();
            }
            answer[tmp[0] - 1]++;
            field_d[y][x] = tmp[0] - 1;
            k++;
            tmp[0] = input[k][0];
            tmp[1] = input[k][1];
            y = x = CENTER;
        }

        for(int i = 0; i < 6; i++)
            cout << answer[i] << ((i < 5) ? " " : "");

        cout << endl;

        Init();
    }
    return 0;
}

Compiler output:
a.cc:1:2: error: stray '#' in program
    1 | g#include <iostream>
      |  ^
a.cc:1:1: error: 'g' does not name a type
    1 | g#include <iostream>
      | ^
a.cc: In function 'int main()':
a.cc:247:9: error: 'cin' was not declared in this scope
  247 |         cin >> n;
      |         ^~~
a.cc:3:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    2 | #include <cstring>
  +++ |+#include <iostream>
    3 | 
a.cc:285:13: error: 'cout' was not declared in this scope
  285 |             cout << answer[i] << ((i < 5) ? " " : "");
      |             ^~~~
a.cc:285:13: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:287:9: error: 'cout' was not declared in this scope
  287 |         cout << endl;
      |         ^~~~
a.cc:287:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:287:17: error: 'endl' was not declared in this scope
  287 |         cout << endl;
      |                 ^~~~
a.cc:3:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    2 | #include <cstring>
  +++ |+#include <ostream>
    3 |