Language: C++

#include <iostream>
#include <cstdlib>

using namespace std;

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

//地面の中心
#define CENTER 15

int input[100][2], answer[6], height = 0, n, k = 0, w = 0; //入力される数字、答え、高さ、処理する番号、どっちの回転が適用されたか
int x, y; //現在の座標
int tmp[2];// top and front
int field[30][30][10] = {}; //サイコロの転がり落ちるフィールド
int field_d[30][30] = {};
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 < 10; 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));
	k = height = 0;
}

int main(void)
{
	while(true)
	{
		cin >> n;
		if(n == 0) break;

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

		x = y = CENTER;
		tmp[0] = input[k][0];
		tmp[1] = input[k][1];
		while(true)
		{
			Init();
			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;
		}

		cout << answer[0] << " "
			<< answer[1] << " "
			<< answer[2] << " "
			<< answer[3] << " "
			<< answer[4] << " "
			<< answer[5] << endl;

	}
	return 0;
}

Compiler output:
a.cc: In function 'void Init()':
a.cc:234:9: error: 'memset' was not declared in this scope
  234 |         memset(answer, 0, sizeof(answer));
      |         ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include <cstdlib>
  +++ |+#include <cstring>
    3 |