Go: package main

import (
	"fmt"
	"math"
)

type Position struct {
	X int64
	Y int64
}

func (one Position) Distance(another Position) int64 {
	return int64(math.Abs(float64(one.X-another.X)) + math.Abs(float64(one.Y-another.Y)))
}

type PersonPosition struct {
	Takayuki Position
	Kazuyuki Position
}

func (one PersonPosition) Distance() int64 {
	return one.Takayuki.Distance(one.Kazuyuki)
}

type Status struct {
	Person PersonPosition
	Turn   int64
}

type PQStatus []*Status

func solve(h, w int64) {
	var tx, ty, kx, ky int64
	fmt.Scan(&tx, &ty, &kx, &ky)
	tx--
	ty--
	kx--
	ky--
	m := make([][]int64, h)
	for i := range m {
		m[i] = make([]int64, w)
		for j := int64(0); j < w; j++ {
			fmt.Scan(&m[i][j])
		}
	}
	start := &Status{Person: PersonPosition{Takayuki: Position{X: tx, Y: ty}, Kazuyuki: Position{X: kx, Y: ky}}, Turn: 0}
	pq := make(PQStatus, 0)
	pq = append(pq, start)
	dx := []int64{0, 1, 0, -1}
	dy := []int64{1, 0, -1, 0}
	memo := make(map[PersonPosition]int64, 0)
	ans := int64(102)
	for len(pq) > 0 {
		now := &Status{}
		now = pq[0]
		pq = pq[1:]
		if ans <= now.Turn {
			continue
		}
		if _, ok := memo[now.Person]; ok {
			continue
		}
		memo[now.Person] = now.Turn

		if now.Person.Distance() == 0 && ans > now.Turn {
			ans = now.Turn
		}

		for i := 0; i < 4; i++ {
			next := &Status{}
			next = now
			next.Person.Kazuyuki.X += dx[i]
			next.Person.Kazuyuki.Y += dy[i]
			if next.Person.Kazuyuki.X < 0 || next.Person.Kazuyuki.X >= w ||
				next.Person.Kazuyuki.Y < 0 || next.Person.Kazuyuki.Y >= h ||
				m[next.Person.Kazuyuki.Y][next.Person.Kazuyuki.X] == 1 {
				next.Person.Kazuyuki.X -= dx[i]
				next.Person.Kazuyuki.Y -= dy[i]
			}
			next.Person.Takayuki.X -= dx[i]
			next.Person.Takayuki.Y -= dy[i]
			if next.Person.Takayuki.X < 0 || next.Person.Takayuki.X >= w ||
				next.Person.Takayuki.Y < 0 || next.Person.Takayuki.Y >= h ||
				m[next.Person.Takayuki.Y][next.Person.Takayuki.X] == 1 {
				next.Person.Takayuki.X += dx[i]
				next.Person.Takayuki.Y += dy[i]
			}
			next.Turn++
			if next.Turn <= 100 {
				pq = append(pq, next)
			}
		}
	}
	if ans == 102 {
		fmt.Println("NA")
	} else {
		fmt.Println(ans)
	}
}

func main() {
	var h, w int64
	for {
		fmt.Scan(&h, &w)
		if h == 0 && w == 0 {
			break
		}
		solve(h, w)
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

class Position {
public:
	int tx, ty, kx, ky;
	int cnt;

	Position() {
		tx = ty = kx = ky = cnt = 0;
	}

	Position(int x1, int y1, int x2, int y2) : tx(x1), ty(y1), kx(x2), ky(y2) {
		cnt = 0;
	}
};

int W, H, Ans;
int MapData[50][50];
int Dx[4] = { 1,0,-1,0 };
int Dy[4] = { 0,1,0,-1 };
bool Visited[50][50][50][50];

bool solve(int x1, int y1, int x2, int y2) {
	int curTx, curTy, curKx, curKy, nextTx, nextTy, nextKx, nextKy;
	queue<Position> positionList;
	Position curPos, next;

	memset(Visited, false, sizeof(Visited));
	positionList.push(Position(x1, y1, x2, y2));
	while (!positionList.empty()) {
		curPos = positionList.front();
		positionList.pop();

		if (curPos.cnt == 100) {
			return false;
		}
		curTx = curPos.tx;
		curTy = curPos.ty;
		curKx = curPos.kx;
		curKy = curPos.ky;
		if (curTx == curKx && curTy == curKy) {
			Ans = curPos.cnt;
			return true;
		}
		if (Visited[curTx][curTy][curKx][curKy]) {
			continue;
		}
		Visited[curTx][curTy][curKx][curKy] = true;
		next.cnt = curPos.cnt + 1;

		for (int i = 0; i < 4; ++i) {
			nextTx = curTx + Dx[i];
			nextTy = curTy + Dy[i];
			nextKx = curKx - Dx[i];
			nextKy = curKy - Dy[i];
			if (nextTx < 0 || nextTx > W - 1 || nextTy < 0 || nextTy > H - 1 || MapData[nextTy][nextTx] == 1) {
				next.tx = curTx;
				next.ty = curTy;
			}
			else {
				next.tx = nextTx;
				next.ty = nextTy;
			}

			if (nextKx < 0 || nextKx > W - 1 || nextKy < 0 || nextKy > H - 1 || MapData[nextKy][nextKx] == 1) {
				next.kx = curKx;
				next.ky = curKy;
			}
			else {
				next.kx = nextKx;
				next.ky = nextKy;
			}
			positionList.push(next);
		}
	}

	return false;
}

int main() {
	int x1, y1, x2, y2;

	while (cin >> W >> H, W) {
		cin >> x1 >> y1 >> x2 >> y2;
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				cin >> MapData[i][j];
			}
		}
		if (solve(--x1, --y1, --x2, --y2)) {
			cout << Ans << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  long long int in;
  while(cin>>in,in){
    string ans="";
    long long int t=1;
    int i=0;
    while(in!=0){
      i++;
      t*=10;
      if(i%2){
	int co=0;
	while((double)in/t!=in/t){co++;in-=t/10;}
	ans=(char)(co+'0')+ans;
      }else{
	int co=0;
	while((double)in/t!=in/t){co++;in+=t/10;}
	ans=(char)(co+'0')+ans;
      }
      //cout<<in<<endl;
    }
    cout<<ans<<endl;
  }


}

C++: #include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int m[50][50];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int bfs[50][50][50][50];
struct wolf{
	int a,b,c,d;
	wolf(int A,int B,int C,int D){
		a=A;
		b=B;
		c=C;
		d=D;
	}
};
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a+b){
		int r1,r2,c1,c2;
		scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
		for(int i=0;i<b;i++)
			for(int j=0;j<a;j++)
				scanf("%d",&m[i][j]);
		int inf=999999999;
		for(int i=0;i<b;i++)
			for(int j=0;j<a;j++)
				for(int k=0;k<b;k++)
					for(int l=0;l<a;l++)
						bfs[i][j][k][l]=inf;
		r1--;c1--;r2--;c2--;
		bfs[r1][c1][r2][c2]=0;
		queue<wolf> Q;
		Q.push(wolf(r1,c1,r2,c2));
		while(Q.size()){
			wolf at=Q.front();
			Q.pop();
			if(bfs[at.a][at.b][at.c][at.d]==100)continue;
			for(int i=0;i<4;i++){
				int s1=at.a+dx[i];
				int t1=at.b+dy[i];
				int s2=at.c-dx[i];
				int t2=at.d-dy[i];
				if(s1<0||s1>=b||m[s1][t1])s1-=dx[i];
				if(t1<0||t1>=a||m[s1][t1])t1-=dy[i];
				if(s2<0||s2>=b||m[s2][t2])s2+=dx[i];
				if(t2<0||t2>=a||m[s2][t2])t2+=dy[i];
				if(bfs[s1][t1][s2][t2]==inf){
					bfs[s1][t1][s2][t2]=bfs[at.a][at.b][at.c][at.d]+1;
					Q.push(wolf(s1,t1,s2,t2));
				}
			}
		}
		int ret=inf;
		for(int i=0;i<b;i++)for(int j=0;j<a;j++)ret=min(ret,bfs[i][j][i][j]);if(ret==inf)printf("NA\n");else printf("%d\n",ret);
	}
}