Language: C++

ll r,c;
void go(int i,int j)
{
    q.push(make_pair(i,j));  // put them in queue
    vis[i][j]=1; // this is visited
    dis[i][j]=0; // initially no magic is needed
    while(!q.empty())
    {
        ll u=q.top().first;  // nearest point
        ll v=q.top().second;
        q.pop();
        for(int x=-2; x<=2; x++)  // try 5x5 grid
        {
            for(int y=-2; y<=2; y++)
            {
                if(u+x>r||u+x<1||v+y>c||v+y<1||(x==0&&y==0)) // out of bound
                    continue;
                if(vis[u+x][v+y]==0&&A[u+x][v+y]=='.') // possible to go
                {
                    vis[u+x][v+y]=1;
                    if(abs(x)+abs(y)>1) // if its a magic, OPeration B
                        dis[u+x][v+y]=dis[u][v]+1;
                    else  // operation A
                        dis[u+x][v+y]=dis[u][v];
                    q.push(make_pair(u+x,v+y));
                }
                else if(A[u+x][v+y]=='.') // to find minimum dis
                {
                    if((abs(x)+abs(y)>1)&&dis[u+x][v+y]>dis[u][v]+1) // can be improved
                    {                      // +1 because we are using magic
                        dis[u+x][v+y]=dis[u][v]+1;
                        q.push(make_pair(u+x,v+y));
                    }
                    else if(dis[u][v]<dis[u+x][v+y]&&(abs(x)+abs(y)<=1)) // can be improved
                    {
                        dis[u+x][v+y]=dis[u][v];
                        q.push(make_pair(u+x,v+y));
                    }
                }
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll sx,sy,dx,dy;
    string s;
    cin>>r>>c;
    cin>>sx>>sy;
    cin>>dx>>dy;
    for(int i=1; i<=r; i++)
    {
        cin>>s;
        for(int j=1; j<=c; j++)
        {
            A[i][j]=s[j-1];
            dis[i][j]=99999999999999; // fill dis with inf
        }
    }
    go(sx,sy); // start from source
    if(vis[dx][dy]==0) // not possible
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<dis[dx][dy]<<endl;   // minimum distance
    }
    return 0;
}

Compiler output:
a.cc:1:1: error: 'll' does not name a type
    1 | ll r,c;
      | ^~
a.cc: In function 'void go(int, int)':
a.cc:4:5: error: 'q' was not declared in this scope
    4 |     q.push(make_pair(i,j));  // put them in queue
      |     ^
a.cc:4:12: error: 'make_pair' was not declared in this scope
    4 |     q.push(make_pair(i,j));  // put them in queue
      |            ^~~~~~~~~
a.cc:5:5: error: 'vis' was not declared in this scope
    5 |     vis[i][j]=1; // this is visited
      |     ^~~
a.cc:6:5: error: 'dis' was not declared in this scope
    6 |     dis[i][j]=0; // initially no magic is needed
      |     ^~~
a.cc:9:9: error: 'll' was not declared in this scope
    9 |         ll u=q.top().first;  // nearest point
      |         ^~
a.cc:10:11: error: expected ';' before 'v'
   10 |         ll v=q.top().second;
      |           ^~
      |           ;
a.cc:16:20: error: 'u' was not declared in this scope
   16 |                 if(u+x>r||u+x<1||v+y>c||v+y<1||(x==0&&y==0)) // out of bound
      |                    ^
a.cc:16:24: error: 'r' was not declared in this scope
   16 |                 if(u+x>r||u+x<1||v+y>c||v+y<1||(x==0&&y==0)) // out of bound
      |                        ^
a.cc:16:34: error: 'v' was not declared in this scope
   16 |                 if(u+x>r||u+x<1||v+y>c||v+y<1||(x==0&&y==0)) // out of bound
      |                                  ^
a.cc:16:38: error: 'c' was not declared in this scope
   16 |                 if(u+x>r||u+x<1||v+y>c||v+y<1||(x==0&&y==0)) // out of bound
      |                                      ^
a.cc:18:24: error: 'u' was not declared in this scope
   18 |                 if(vis[u+x][v+y]==0&&A[u+x][v+y]=='.') // possible to go
      |                        ^
a.cc:18:29: error: 'v' was not declared in this scope
   18 |                 if(vis[u+x][v+y]==0&&A[u+x][v+y]=='.') // possible to go
      |                             ^
a.cc:18:38: error: 'A' was not declared in this scope
   18 |                 if(vis[u+x][v+y]==0&&A[u+x][v+y]=='.') // possible to go
      |                                      ^
a.cc:21:24: error: 'abs' was not declared in this scope
   21 |                     if(abs(x)+abs(y)>1) // if its a magic, OPeration B
      |                        ^~~
a.cc:29:25: error: 'abs' was not declared in this scope
   29 |                     if((abs(x)+abs(y)>1)&&dis[u+x][v+y]>dis[u][v]+1) // can be improved
      |                         ^~~
a.cc: In function 'int main()':
a.cc:46:5: error: 'ios' has not been declared
   46 |     ios::sync_with_stdio(false);
      |     ^~~
a.cc:47:5: error: 'cin' was not declared in this scope
   47 |     cin.tie(nullptr);
      |     ^~~
a.cc:49:5: error: 'll' was not declared in this scope
   49 |     ll sx,sy,dx,dy;
      |     ^~
a.cc:50:5: error: 'string' was not declared in this scope
   50 |     string s;
      |     ^~~~~~
a.cc:51:10: error: 'r' was not declared in this scope
   51 |     cin>>r>>c;
      |          ^
a.cc:51:13: error: 'c' was not declared in this scope
   51 |     cin>>r>>c;
      |             ^
a.cc:52:10: error: 'sx' was not declared in this scope
   52 |     cin>>sx>>sy;
      |          ^~
a.cc:52:14: error: 'sy' was not declared in this scope
   52 |     cin>>sx>>sy;
      |              ^~
a.cc:53:10: error: 'dx' was not declared in this scope
   53 |     cin>>dx>>dy;
      |          ^~
a.cc:53:14: error: 'dy' was not declared in this scope
   53 |     cin>>dx>>dy;
      |              ^~
a.cc:56:14: error: 's' was not declared in this scope
   56 |         cin>>s;
      |              ^
a.cc:59:13: error: 'A' was not declared in this scope
   59 |             A[i][j]=s[j-1];
      |             ^
a.cc:60:13: error: 'dis' was not declared in this scope
   60 |             dis[i][j]=99999999999999; // fill dis with inf
      |             ^~~
a.cc:64:8: error: 'vis' was not declared in this scope
   64 |     if(vis[dx][dy]==0) // not possible
      |        ^~~
a.cc:66:9: error: 'cout' was not declared in this scope
   66 |         cout<<-1<<endl;
      |         ^~~~
a.cc:66:19: error: 'endl' was not declared in this scope
   66 |         cout<<-1<<endl;
      |                   ^~~~
a.cc:70:9: error: 'cout' was not declared in this scope
   70 |         cout<<dis[dx][dy]<<endl;   // minimum distance
      |         ^~~~
a.cc:70:15: error: 'dis' was not declared in this scope
   70 |         cout<<dis[dx][dy]<<endl;   // minimum distance
      |               ^~~
a.cc:70:28: error: 'endl' was not declared in this scope
   70 |         cout<<dis[dx][dy]<<endl;   // minimum distance
      |                            ^~~~