//NAME      : Hung Huynh
//SCHOOL    : Kalamazoo AMSC
//DIVISION  : Senior-5
//PROGRAM   : ACSL Veitch
//CONTEST   : Round 4
//DATE      : March 2020

#include 
#include 
#include 
#include 
#include 

using namespace std;

//Open input file
ifstream fin ("4sr_testdata.txt");

//Declare global variables
bool isPrime[53];
bool willMoveVert[53];
bool willMoveHorz[53];
bool occupied[53];
//Declare global variables
int numRolls=0, currentDiceVal=0, currentLoc=0, newLoc=0, tempIndex=0, oppSum=0, mySum=0;
bool hasHorz=false, hasVert=false;
vector oppMarkers(3);
vector myMarkers(3);
vector diceVal;

void makeMove()
{
  if (!occupied[newLoc])
  {
    if (isPrime[newLoc]) //rule 7 (if prime move forward until reach 6 or occupied)
    {
      //cout << "RULE 7" << endl;
      for (int a=1; a<=6; ++a)
      {
        if (newLoc+1 <= 52 && !occupied[newLoc+1])
          ++newLoc;
        else if (newLoc+1 > 52)
        {
          newLoc = currentLoc;
          break;
        }
        else
          break;
      }
    }
    else if (sqrt(newLoc) == int(sqrt(newLoc)) && newLoc > 4) //rule 8 (if perfect root >4 move back until reach 6 or occupied)
    {
      //cout << "RULE 8" << endl;
      for (int a=1; a<=6 && !occupied[newLoc-1]; ++a)
      {
        --newLoc;
      }
    }
    else //rule 9
    {
      //cout << "RULE 9" << endl;
      tempIndex=0;
      hasHorz = false;
      hasVert = false;

      for (; !hasHorz && tempIndex> oppMarkers[0] >> oppMarkers[1] >> oppMarkers[2];
    fin >> myMarkers[0] >> myMarkers[1] >> myMarkers[2];
    occupied[oppMarkers[0]] = true;
    occupied[oppMarkers[1]] = true;
    occupied[oppMarkers[2]] = true;
    occupied[myMarkers[0]] = true;
    occupied[myMarkers[1]] = true;
    occupied[myMarkers[2]] = true;
    sort(oppMarkers.begin(), oppMarkers.end());
    sort(myMarkers.begin(), myMarkers.end());
    occupied[52] = false;

    //cout << oppMarkers[0] << oppMarkers[1] << oppMarkers[2] << endl;
    //cout << myMarkers[0] << myMarkers[1] << myMarkers[2] << endl;

    fin >> numRolls;
    for (int currRoll = 0; currRoll < numRolls; ++currRoll)
    {
      fin >> currentDiceVal;
      diceVal.push_back(currentDiceVal);
    }

    //Make moves
    for (int currentDice=0; currentDice