class program
{
   define turnRight()
       {
           iterate(3)
              turnleft();
       }
   define pickAll()
       {
           while(nextToABeeper)
               pickbeeper();
       }
    define faceWest()
        {
            while(notFacingWest)
                turnleft();
        }

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


    define cleanLine()
        {
            faceEast();
            while(frontIsClear)
                move();
            faceWest();
            pickAll();
            while(frontIsClear)
                {
                    move();
                    pickAll();
                }
            faceEast();
            while(leftIsBlocked && frontIsClear)
                move();
             turnleft();
         }

    define traceRoute()
        {
            if(frontIsClear)
               {
                  putbeeper();
               }
            else
               {
                    faceWest();
                    while(frontIsClear && rightIsBlocked)
                        {
                           putbeeper();
                           putbeeper();
                           move();
                        }
                    putbeeper();
                    putbeeper();
                    if(rightIsBlocked)
                        {
                            turnleft();
                            turnleft();
                            while(frontIsClear && leftIsBlocked)
                                {
                                   if(nextToABeeper && rightIsBlocked)
                                       pickAll();
                                   else
                                       {
                                           pickAll();
                                           putbeeper();
                                           putbeeper();
                                           putbeeper();
                                       }
                                   move();
                                }
                            if(leftIsClear)
                               {
                                  turnleft();
                                  pickAll();
                                  putbeeper();
                               }
                            else
                               {
                                  turnleft();
                                  turnleft();
                                  while(frontIsClear)
                                     {
                                        pickAll();
                                        move();
                                     }
                                  pickAll();
                                  turnoff();
                               }
                        }
                    else
                        {
                            turnRight();
                            pickAll();
                            putbeeper();
                        }
                }

        }

    program()
        {
            traceRoute();
            while(frontIsClear)
                {
                   move();
                   traceRoute();
                }
            turnoff();
        }

}
