class program {

define turnRight()
   {
      iterate(3)
         turnleft();
   }

define halfTurn()
   {
      turnleft();
      turnleft();
   }

define step()
   {
      if(frontIsClear && leftIsBlocked)
         move();
      else if(leftIsClear)
         {
            turnleft();
            move();
         }
      else
         {
            while(frontIsBlocked && leftIsBlocked)
               turnRight();
            move();
         }
   }

define backStep()
   {
      if(frontIsClear && rightIsBlocked)
         move();
      else if(rightIsClear)
         {
            turnRight();
            move();
         }
      else
         {
            while(frontIsBlocked && rightIsBlocked)
               turnleft();
            move();
         }

   }

define searchTwo()
   {
      while(notNextToABeeper)
         step();
      pickbeeper();
      if(nextToABeeper)
         putbeeper();
      else
         {
            putbeeper();
            step();
            searchTwo();
         }
   }

define swap()
   {
      if(nextToABeeper)
         {
            putbeeper();
            halfTurn();
            move();
         }
      else
         {
            step();
            swap();
            backStep();
         }
   }



program()
{
    while(frontIsClear)
       move();
    turnRight();
    searchTwo();
    pickbeeper();
    pickbeeper();
    swap();
    halfTurn();
    move();
    putbeeper();
    turnoff();
}

}
