class program
{

   define faceEast()
   {
      while(notFacingEast)
         turnleft();
   }

   define faceWest()
   {
      while(notFacingWest)
         turnleft();
   }

   define faceSouth()
   {
      while(notFacingSouth)
         turnleft();
   }

   define turnBack()
   {
      turnleft();
      turnleft();
   }

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

   define goSouth()
   {
      faceSouth();
      while(nextToABeeper && frontIsClear)
         move();
      if(notNextToABeeper)
         {
            turnBack();
            move();
         }
   }

   define goWest()
   {
      faceWest();
      while(nextToABeeper && frontIsClear)
         move();
      faceEast();
      if(notNextToABeeper)
         {
            move();
         }
   }

   define climb()
   {
      if(frontIsClear)
         {
            move();
            turnleft();
            if(frontIsClear)
               {
                  move();
                  if(nextToABeeper)
                     {
                        turnRight();
                        climb();
                        putbeeper();
                     }
                  else
                     {
                        turnBack();
                        move();
                        turnRight();
                        move();
                        turnRight();
                        move();
                        putbeeper();
                     }
               }
            else
               {
                  turnleft();
                  move();
                  turnRight();
                  move();
                  putbeeper();
               }
         }
      else
         {
            turnleft();
            move();
            putbeeper();
         }
   }

   program()
      {
         goSouth();
         goWest();
         climb();
         turnoff();
      }

}
