Problem p02386 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>

#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

class dice {

public:
  int m[6];
  int Set();
  int R(char c);
};

int main() {

  int i, j, n, a = 1;
  dice dice[2];
  string s1 = "SSSSWSSSSWSSSS";
  string s2 = "ssss";

  cin >> n;
  dice[0].Set();
  for (i = 1; i < n; i++) {
    dice[1].Set();

    for (j = 0; j < s1.size(); j++) {
      if (dice[0].m[0] == dice[1].m[0] && dice[0].m[5] == dice[1].m[5])
        break;
      else {
        dice[1].R(s1[j]);
      }
    }

    for (j = 0; j < s2.size(); j++) {
      if (dice[0].m[1] == dice[1].m[1] && dice[0].m[2] == dice[1].m[2] &&
          dice[0].m[3] == dice[1].m[3] && dice[0].m[4] == dice[1].m[4])
        break;
      else {
        dice[1].R(s2[j]);
      }
    }

    if (dice[0].m[0] == dice[1].m[0] && dice[0].m[1] == dice[1].m[1] &&
        dice[0].m[2] == dice[1].m[2] && dice[0].m[3] == dice[1].m[3] &&
        dice[0].m[4] == dice[1].m[4] && dice[0].m[5] == dice[1].m[5])
      a = 0;
  }

  if (a == 1)
    cout << "Yes" << endl;
  else {
    cout << "No" << endl;
  }

  return 0;
}

int dice::Set() {

  int i;

  for (i = 0; i < 6; i++) {
    cin >> m[i];
  }

  return 0;
}

int dice::R(char c) {

  int t = 0;

  if (c == 'N') {
    t = m[0];
    m[0] = m[1];
    m[1] = m[5];
    m[5] = m[4];
    m[4] = t;
  } else if (c == 'S') {
    t = m[0];
    m[0] = m[4];
    m[4] = m[5];
    m[5] = m[1];
    m[1] = t;
  } else if (c == 'W') {
    t = m[0];
    m[0] = m[2];
    m[2] = m[5];
    m[5] = m[3];
    m[3] = t;
  } else if (c == 'E') {
    t = m[0];
    m[0] = m[3];
    m[3] = m[5];
    m[5] = m[2];
    m[2] = t;
  } else {
    t = m[1];
    m[1] = m[2];
    m[2] = m[4];
    m[4] = m[3];
    m[3] = t;
  }

  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>

#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int num[6] = {0};

void POINT(char point) {

  if (point == 'E') {
    swap(num[0], num[3]);
    swap(num[3], num[5]);
    swap(num[5], num[2]);
  }
  if (point == 'W') {
    swap(num[0], num[2]);
    swap(num[2], num[5]);
    swap(num[5], num[3]);
  }
  if (point == 'S') {
    swap(num[0], num[4]);
    swap(num[4], num[5]);
    swap(num[5], num[1]);
  }
  if (point == 'N') {
    swap(num[0], num[1]);
    swap(num[1], num[5]);
    swap(num[5], num[4]);
  }
}

int main() {

  int i = 0, j = 0, n = 0, t = 0;
  int a[][6] = {0};
  int d[6] = {0};
  string s1 = "NNNNENNNN";
  string s2 = "EEEENNNN";
  string s3 = "EEEENEEEE";

  //??\\???
  cin >> n;
  for (j = 0; j < n; j++) {
    for (i = 0; i < 6; i++) {
      cin >> a[j][i];
    }
  }

  for (i = 0; i < 6; i++) {
    d[i] = a[0][i];
  }

  for (j = 1; j < n; j++) {

    for (i = 0; i < 6; i++) {
      num[i] = a[j][i];
    }

    for (i = 0; i < s1.size(); i++) {
      if (num[0] == d[0] && num[5] == d[5])
        break;
      POINT(s1[i]);
    }
    for (i = 0; i < s2.size(); i++) {
      if (num[1] == d[1] && num[4] == d[4])
        break;
      POINT(s2[i]);
    }
    for (i = 0; i < s3.size(); i++) {
      if (num[3] == d[3] && num[2] == d[2])
        break;
      POINT(s3[i]);
    }

    if (num[0] == d[0] && num[1] == d[1] && num[2] == d[2] && num[3] == d[3] &&
        num[4] == d[4] && num[5] == d[5]) {
      t = 1;
      break;
    }
  }

  if (t == 1)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;

  return 0;
}