Language: C++

#include <cstdio>
#include <utility>
#include <queue>
#include <map>
using namespace std;

typedef pair<int,int> __P;
typedef pair<__P,__P> _P;
typedef pair<_P,int> P;

#define C(A,B) (0<=(A)&&(A)<(B))

int main() {
	queue<P> que;
	map<P,bool> mp;
	int X,Y;
	int tx,ty;
	int kx,ky;
	int count;
	int d[50][50];
	int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
	while(true) {
		scanf("%d %d",&X,&Y);
		if(X==0&&Y==0) break;
		scanf("%d %d",&tx,&ty);
		scanf("%d %d",&kx,&ky);
		tx--;ty--;kx--;ky--;
		for(int i=0;i<Y;i++) {
			for(int j=0;j<X;j++) {
				scanf("%d",&d[j][i]);
			}
		}
		que.push(P(_P(__P(tx,ty),__P(kx,ky)),0));
		count=-1;
		while(que.size()) {
			P& p=que.front();
			tx=p.first.first.first;
			ty=p.first.first.second;
			kx=p.first.second.first;
			ky=p.first.second.second;
			if(p.second>=100) {
				break;
			}
			if(mp[p]==true) {
				break;
			}
			if(tx==kx&&ty==ky) {
				count=p.second;
				break;
			}
			mp[p]=true;
			for(int i=0;i<4;i++) {
				int ntx=tx,nty=ty,nkx=kx,nky=ky;
				if(C(ntx+dx[i],X)&&C(nty+dy[i],Y)&&!d[ntx+dx[i]][nty+dy[i]]) {
					ntx+=dx[i],nty+=dy[i];
				}
				if(C(nkx-dx[i],X)&&C(nky-dy[i],Y)&&!d[nkx-dx[i]][nky-dy[i]]) {
					nkx-=dx[i],nky-=dy[i];
				}
				que.push(P(_P(__P(ntx,nty),__P(nkx,nky)),p.second+1));
			}
			
			que.pop();
		}
		if(count!=-1) {
			printf("%d\n",count);
		}else {
			printf("NA\n");
		}
	}
}

Compiler output:
a.cc:33:40: error: macro "__P" passed 2 arguments, but takes just 1
   33 |                 que.push(P(_P(__P(tx,ty),__P(kx,ky)),0));
      |                                        ^
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
                 from /usr/include/c++/14/cstdio:41,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/sys/cdefs.h:125:9: note: macro "__P" defined here
  125 | #define __P(args)       args
      |         ^~~
a.cc:33:51: error: macro "__P" passed 2 arguments, but takes just 1
   33 |                 que.push(P(_P(__P(tx,ty),__P(kx,ky)),0));
      |                                                   ^
/usr/include/x86_64-linux-gnu/sys/cdefs.h:125:9: note: macro "__P" defined here
  125 | #define __P(args)       args
      |         ^~~
a.cc:60:58: error: macro "__P" passed 2 arguments, but takes just 1
   60 |                                 que.push(P(_P(__P(ntx,nty),__P(nkx,nky)),p.second+1));
      |                                                          ^
/usr/include/x86_64-linux-gnu/sys/cdefs.h:125:9: note: macro "__P" defined here
  125 | #define __P(args)       args
      |         ^~~
a.cc:60:71: error: macro "__P" passed 2 arguments, but takes just 1
   60 |                                 que.push(P(_P(__P(ntx,nty),__P(nkx,nky)),p.second+1));
      |                                                                       ^
/usr/include/x86_64-linux-gnu/sys/cdefs.h:125:9: note: macro "__P" defined here
  125 | #define __P(args)       args
      |         ^~~
a.cc: In function 'int main()':
a.cc:33:27: error: expected primary-expression before '(' token
   33 |                 que.push(P(_P(__P(tx,ty),__P(kx,ky)),0));
      |                           ^
a.cc:33:30: error: expected primary-expression before '(' token
   33 |                 que.push(P(_P(__P(tx,ty),__P(kx,ky)),0));
      |                              ^
a.cc:33:41: error: expected primary-expression before ',' token
   33 |                 que.push(P(_P(__P(tx,ty),__P(kx,ky)),0));
      |                                         ^
a.cc:33:52: error: expected primary-expression before ')' token
   33 |                 que.push(P(_P(__P(tx,ty),__P(kx,ky)),0));
      |                                                    ^
a.cc:60:43: error: expected primary-expression before '(' token
   60 |                                 que.push(P(_P(__P(ntx,nty),__P(nkx,nky)),p.second+1));
      |                                           ^
a.cc:60:46: error: expected primary-expression before '(' token
   60 |                                 que.push(P(_P(__P(ntx,nty),__P(nkx,nky)),p.second+1));
      |                                              ^
a.cc:60:59: error: expected primary-expression before ',' token
   60 |                                 que.push(P(_P(__P(ntx,nty),__P(nkx,nky)),p.second+1));
      |                                                           ^
a.cc:60:72: error: expected primary-expression before ')' token
   60 |                                 que.push(P(_P(__P(ntx,nty),__P(nkx,nky)),p.second+1));
      |                                                                        ^