Language: C++

#include <cstdio>
#include <utility>
#include <queue>
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;
	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(tx==kx&&ty==ky) {
				count=p.second;
				break;
			}
			bool b=false;
			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]][ty+dy[i]]) {
					ntx+=dx[i],nty+=dy[i];
					b=true;
				}
				if(C(nkx-dx[i],X)&&C(nky-dy[i],Y)&&!d[kx-dx[i]][ky-dy[i]]) {
					nkx-=dx[i],nky-=dy[i];
					b=true;
				}
				que.push(P(_P(__P(ntx,nty),__P(nkx,nky)),p.second+1));
			}
			if(!b) break;
			que.pop();
		}
		if(count!=-1) {
			printf("%d\n",count);
		}else {
			printf("NA\n");
		}
	}
}

Compiler output:
a.cc:31:40: error: macro "__P" passed 2 arguments, but takes just 1
   31 |                 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:31:51: error: macro "__P" passed 2 arguments, but takes just 1
   31 |                 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:57:58: error: macro "__P" passed 2 arguments, but takes just 1
   57 |                                 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:57:71: error: macro "__P" passed 2 arguments, but takes just 1
   57 |                                 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:31:27: error: expected primary-expression before '(' token
   31 |                 que.push(P(_P(__P(tx,ty),__P(kx,ky)),0));
      |                           ^
a.cc:31:30: error: expected primary-expression before '(' token
   31 |                 que.push(P(_P(__P(tx,ty),__P(kx,ky)),0));
      |                              ^
a.cc:31:41: error: expected primary-expression before ',' token
   31 |                 que.push(P(_P(__P(tx,ty),__P(kx,ky)),0));
      |                                         ^
a.cc:31:52: error: expected primary-expression before ')' token
   31 |                 que.push(P(_P(__P(tx,ty),__P(kx,ky)),0));
      |                                                    ^
a.cc:57:43: error: expected primary-expression before '(' token
   57 |                                 que.push(P(_P(__P(ntx,nty),__P(nkx,nky)),p.second+1));
      |                                           ^
a.cc:57:46: error: expected primary-expression before '(' token
   57 |                                 que.push(P(_P(__P(ntx,nty),__P(nkx,nky)),p.second+1));
      |                                              ^
a.cc:57:59: error: expected primary-expression before ',' token
   57 |                                 que.push(P(_P(__P(ntx,nty),__P(nkx,nky)),p.second+1));
      |                                                           ^
a.cc:57:72: error: expected primary-expression before ')' token
   57 |                                 que.push(P(_P(__P(ntx,nty),__P(nkx,nky)),p.second+1));
      |                                                                        ^