Language: C++

#include<algorithm>
#include<cstring>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
using namespace std;

int main(){
  int mv[4][3]=
    {{0,1,1}, //forward
     {-1,0,0},//left
     {0,-1,0},//backward
     {1,0,0}};//right
  int n,m,num,x,y;
  string op;

  while(true){
    cin >> n >> m;
    if(n == 0 && m == 0)break;
    x=1;y=1;

    while(true){
      cin >> op;
      
      if(op == "STOP")break;
      else if(op == "LEFT")
	{
	  for(int i=0;i<4;i++)
	    {
	      if(mv[i][2] == 1)
		{
		  if(i != 3){
		    mv[i][2]=0;
		    mv[i+1][2]=1;
		  }
		  else if(i == 3)
		    {
		      mv[0][2]=1;
		      mv[3][2]=0;
		    }
		  else cout << "********arienai********" << endl;
		  break;
		}
	    }
	}
      else if(op == "RIGHT")
	{//
	  for(int i=0;i<4;i++)
	    {
	      if(mv[i][2] == 1)
		{
		  if(i == 0)
		    {
		      mv[0][2]=0;
		      mv[3][2]=1;
		    }
		  else
		    {
		      mv[i][2]=0;
		      mv[i-1][2]=1;
		    }
		  break;
		}
	    }
	}//
      else if(op == "FORWARD")
	{
	  cin >> num;
	  for(int i=0;i<4;i++)
	    {
	      if(mv[i][2] == 1)
		{
		  if(i == 0)
		    {
		      if(y+num > m)
			{
			  // y=m;
			}
		      else
			{
			  y+=num;
			}
		      //break;
		    }
		  else if(i == 1)
		    {
		      if(x-num < 0)
			{
			  // x=1;
			}
		      else
			{
			  x-=num;
			}
		      //break;
		    }
		  else if(i == 2)
		    {
		      if(y-num < 0)
			{
			  //y=1;
			}
		      else
			{
			  y-=num;
			}
		      //break;
		    }
		  else if(i == 3)
		    {
		      //cout << "x = " << x << ", num = " << num << endl;
		      if(x+num > n)
			{
			  //x=n;
			}
		      else
			{
			  x+=num;
			}
		      //break;
		    }

		  break;
		}

	    }


	}
 else if(op == "BACKWARD")
	{
	  cin >> num;
	  for(int i=0;i<4;i++)
	    {
	      if(mv[i][2] == 1)
		{
		  if(i == 0)
		    {
		      if(y-num < 0)
			{
			  //y=1;
			}
		      else
			{
			  y-=num;
			}
		      //break;
		    }
		  else if(i == 1)
		    {
		      if(x+num > n)
			{
			  //x=n;
			}
		      else
			{
			  x+=num;
			}
		      //break;
		    }
		  else if(i == 2)
		    {
		      if(y+num > m)
			{
			  //y=m;
			}
		      else
			{
			  y+=num;
			}
		      //break;
		    }
		  else if(i == 3)
		    {
		      if(x-num < 0)
			{
			  //x=1;
			}
		      else
			{
			  x-=num;
			}
		      //break;
		    }
		  break;

		}

	    }


	}
      //for(int i=0;i<4;i++)if(mv[i][2] == 1)cout << "i= " << i << endl;
// cout << "op = " << op << ",num =  " << num << ", "  << x << " " << y << endl; 

    }
    cout << x << " " << y << endl; 
    
  }

}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:3: error: 'string' was not declared in this scope
   16 |   string op;
      |   ^~~~~~
a.cc:5:1: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
    4 | #include<set>
  +++ |+#include <string>
    5 | #define rep(i,n) for(int i=0;i<n;i++)
a.cc:19:5: error: 'cin' was not declared in this scope
   19 |     cin >> n >> m;
      |     ^~~
a.cc:5:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    4 | #include<set>
  +++ |+#include <iostream>
    5 | #define rep(i,n) for(int i=0;i<n;i++)
a.cc:24:14: error: 'op' was not declared in this scope
   24 |       cin >> op;
      |              ^~
a.cc:42:24: error: 'cout' was not declared in this scope
   42 |                   else cout << "********arienai********" << endl;
      |                        ^~~~
a.cc:42:24: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:42:61: error: 'endl' was not declared in this scope
   42 |                   else cout << "********arienai********" << endl;
      |                                                             ^~~~
a.cc:5:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    4 | #include<set>
  +++ |+#include <ostream>
    5 | #define rep(i,n) for(int i=0;i<n;i++)
a.cc:198:5: error: 'cout' was not declared in this scope
  198 |     cout << x << " " << y << endl;
      |     ^~~~
a.cc:198:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:198:30: error: 'endl' was not declared in this scope
  198 |     cout << x << " " << y << endl;
      |                              ^~~~
a.cc:198:30: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'