Language: C++

#include<iostream>

using namespace std;
int main()
{
    int h,w,n,i,j;
    cin>>h>>w>>n>>i>>j;
    char s[n],t[n];
    for(int k=0;k<n;k++)
        cin>>s[k];
    for(int k=0;k<n;k++)
        cin>>t[k]; 
    i--;
    j--;
    //cout<<"("<<i<<","<<j<<")"<<endl;
    for(int k=0;k<n;k++)
    {
        if(s[k]=='L')
        {
            if(abs(w-j-j+1)>abs(w-1-j-j))
            {
                j--;
                if(j<0)
                {
                    cout<<"NO";
                    return 0;
                }
            }
        }
        else if(s[k]=='R')
        {
            if(abs(j-(w-1-j))<abs(j+1-(w-j-2)))
            {
                j++;
                if(j>=w)
                {                 
                    cout<<"NO";
                    return 0;
                }
            }
        }
        else if(s[k]=='U')
        {   
            if(abs(i-(h-i-1))<abs(i-1-(h-i)))
            {
                i--;
                if(i<0)
                {
                    cout<<"NO";
                    return 0;
                }
            }
        }
        else
        {
            if(abs(i-(h-i-1))<abs(i+1-(h-(i+1)-1))
            {
                i++;
                if(i>=h)
                {
                    cout<<"NO";
                    return 0;
                }
            }
        }   
        //cout<<"("<<i<<","<<j<<")"<<endl;
        if(t[k]=='L')
        {
            if(abs(w-j-j+1)<abs(w-1-j-j))
            {
                j--;
                if(j<0)
                {
                    cout<<"NO";
                    return 0;
                }
            }
        }
        else if(t[k]=='R')
        {
            if(abs(j-(w-1-j))>abs(j+1-(w-j-2)))
            {
                j++;
                if(j>=w)
                {                 
                    cout<<"NO";
                    return 0;
                }
            }
        }
        else if(t[k]=='U')
        { 
            if(abs(i-(h-i-1))>abs(i-1-(h-i)))
            {
                i--;
                if(i<0)
                {
                    cout<<"NO";
                    return 0;
                }
            
            }
        }
        else
        {
            if(abs(i-(h-i-1))>abs(i+1-(h-(i+1)-1))
            {
                i++;
                if(i>=h)
                {
                    cout<<"NO";
                    return 0;
                }
            }
        } 
            //cout<<"("<<i<<","<<j<<")"<<endl; 
    }
    cout<<"YES"<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:56:51: error: expected ')' before '{' token
   56 |             if(abs(i-(h-i-1))<abs(i+1-(h-(i+1)-1))
      |               ~                                   ^
      |                                                   )
   57 |             {
      |             ~                                      
a.cc:65:9: error: expected primary-expression before '}' token
   65 |         }
      |         ^
a.cc:106:51: error: expected ')' before '{' token
  106 |             if(abs(i-(h-i-1))>abs(i+1-(h-(i+1)-1))
      |               ~                                   ^
      |                                                   )
  107 |             {
      |             ~                                      
a.cc:115:9: error: expected primary-expression before '}' token
  115 |         }
      |         ^