Language: C++

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

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
typedef pair<int, int> pii;
class dice{
public:
  int surf[6];
  int t;
  int f;
  dice(){};
  
  vector<int> roll(){
    int direct[3] = {0};
    vector<int> res;
      
    for (int i = 1; i <= 4; i++) {
      //std::cout << "surf:" << surf[i] << std::endl;
      if(surf[i] == 4 || surf[i] || 5 || surf[i] == 6){
        direct[surf[i] - 4] = i;
      }
    }
    for (int i = 2; i >= 0; i--) {
      if(direct[i] != 0)res.push_back(direct[i] - 1);
    }
    return res;
  }
  void init(int top, int front){
    t = top;
    f = front;
    surf[0] = top;
    surf[1] = front;
    surf[3] = 7 - front;
    surf[5] = 7 - top;
    if(surf[0] == 1){
      switch(surf[1]){
      case 2:
        surf[2] = 3;
        surf[4] = 4;
        break;
      case 3:
        surf[2] = 5;
        surf[4] = 2;
        break;
      case 5:
        surf[2] = 4;
        surf[4] = 3;
        break;
      case 4:        
        surf[2] = 2;
        surf[4] = 5;
        break;
      }
    }else if(surf[0] == 2){
      switch(surf[1]){
      case 1:
        surf[2] = 4;
        surf[4] = 3;
        break;
      case 3:
        surf[2] = 1;
        surf[4] = 6;
        break;
      case 6:
        surf[2] = 3;
        surf[4] = 4;
        break;
      case 4:        
        surf[2] = 6;
        surf[4] = 1;
        break;
      }
    }else if(surf[0] == 3){
      switch(surf[1]){
      case 1:
        surf[2] = 2;
        surf[4] = 5;
        break;
      case 2:
        surf[2] = 6;
        surf[4] = 1;
        break;
      case 6:
        surf[2] = 5;
        surf[4] = 2;
        break;
      case 5:        
        surf[2] = 1;
        surf[4] = 6;
        break;
      }
    }else if(surf[0] == 4){
      switch(surf[1]){
      case 1:
        surf[2] = 5;
        surf[4] = 2;
        break;
      case 5:
        surf[2] = 6;
        surf[4] = 1;
        break;
      case 6:
        surf[2] = 2;
        surf[4] = 5;
        break;
      case 2:        
        surf[2] = 1;
        surf[4] = 6;
        break;
      }
    }else if(surf[0] == 5){
      switch(surf[1]){
      case 1:
        surf[2] = 3;
        surf[4] = 4;
        break;
      case 3:
        surf[2] = 6;
        surf[4] = 1;
        break;
      case 6:
        surf[2] = 4;
        surf[4] = 3;
        break;
      case 4:        
        surf[2] = 1;
        surf[4] = 6;
        break;
      }
    }else if(surf[0] == 6){
      switch(surf[1]){
      case 2:
        surf[2] = 4;
        surf[4] = 3;
        break;
      case 4:
        surf[2] = 5;
        surf[4] = 2;
        break;
      case 5:
        surf[2] = 3;
        surf[4] = 4;
        break;
      case 3:        
        surf[2] = 2;
        surf[4] = 5;
        break;
      }
    }
  }
};
typedef pair <int, vector<dice> > pid;
pid grid[500][500];

void drop(int top, int front, int x, int y){
  //std::cout << x << " " << y << std::endl;
  dice d;
  d.init(top, front);
  grid[y][x].first++;
  grid[y][x].second.push_back(d);
  vector<int> direct = d.roll();
  bool flag = false;
  // for (int i = 0; i < direct.size(); i++) {
  //   std::cout << direct[i] << " ";
  // }
  //  std::cout << std::endl;
  for (int i = 0; i < direct.size() && flag == false; i++) {
    int nx = x + dx[direct[i]], ny = y + dy[direct[i]];
    if(grid[ny][nx].first + 1 < grid[y][x].first) {
      flag = true;
      grid[y][x].first--;
      grid[y][x].second.pop_back();
      switch(direct[i]){
      case 0:
        drop(d.surf[3], top, nx, ny);
        break;
      case 1:
        drop(d.surf[4], front, nx, ny);
        break;
      case 2:
        drop(d.surf[1], d.surf[5], nx, ny);
        break;
      case 3:
        drop(d.surf[2], front, nx, ny);
        break;
      }
    }
    if(flag)break;
  }
}

int main(int argc, char *argv[]){
  int n, top, front;
  while(cin >> n, n){
    memset(grid, 0, sizeof(grid));
    for (int i = 0; i < n; i++) {
      cin >> top >> front;
      drop(top, front, 100, 100);
    }
    int ans[6] = {0};
    for (int i = 70; i < 410; i++) {
      for (int j = 70; j < 410; j++) {
        if(grid[i][j].second.empty()){
          //std::cout << -1 << " ";
         continue;
        }
        //std::cout << grid[i][j].second.back().surf[0] << " ";
        ans[grid[i][j].second.back().surf[0] - 1]++;
      }
    }
     for (int i = 0; i < 5; i++) {
       std::cout << ans[i] << " ";
     }
     std::cout << ans[5] << std::endl;
  }

  return 0;
}

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