Language: C++

#include <queue>
#include <cstdio>
#include <algorithm>
using namespace std;
int n, a[100], b[100], d[100][2];
int main() {
	while(scanf("%d", &n), n) {
		for(int i = 0; i < n; i++) scanf("%d", &a[i]);
		for(int i = 0; i < n; i++) scanf("%d", &b[i]);
		for(int i = 1; i < n; i++) d[i][0] = -1, d[i][1] = -1;
		d[0][0] = 0, d[0][1] = 0;
		queue<int> que; que.push(0); que.push(1);
		while(!que.empty()) {
			int x = que.front() / 2, y = que.front() % 2; que.pop();
			for(int i = 0; i <= 2 && x + i < n; i++) {
				if(y == 1) {
					int tx = x + i;
					if(a[tx] == 1) {
						for(; tx + 1 < n; tx++) {
							if(a[tx + 1] != 1) break;
						}
					}
					else if(a[tx] == 2) {
						for(; tx - 1 > 0; tx--) {
							if(a[tx - 1] != 2) break;
						}
					}
					if(d[tx][0] > d[x][y] + 1) {
						d[tx][0] = d[x][y] + 1;
						que.push_back(make_pair(tx * 2));
					}
				}
				else {
					int tx = x + i;
					if(b[tx] == 1) {
						for(; tx + 1 < n; tx++) {
							if(b[tx + 1] != 1) break;
						}
					}
					else if(b[tx] == 2) {
						for(; tx - 1 > 0; tx--) {
							if(b[tx - 1] != 2) break;
						}
					}
					if(d[tx][1] == -1) {
						d[tx][1] = d[x][y] + 1;
						que.push_back(make_pair(tx * 2 + 1));
					}
				}
			}
		}
		int r = min(d[n - 1][0], d[n - 1][1]);
		if(r == -1) printf("NA\n");
		else printf("%d\n", r);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:53: error: 'class std::queue<int>' has no member named 'push_back'
   30 |                                                 que.push_back(make_pair(tx * 2));
      |                                                     ^~~~~~~~~
a.cc:30:72: error: no matching function for call to 'make_pair(int)'
   30 |                                                 que.push_back(make_pair(tx * 2));
      |                                                               ~~~~~~~~~^~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/deque:62,
                 from /usr/include/c++/14/queue:62,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:1132:5: note: candidate: 'template<class _T1, class _T2> constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&)'
 1132 |     make_pair(_T1&& __x, _T2&& __y)
      |     ^~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1132:5: note:   candidate expects 2 arguments, 1 provided
a.cc:47:53: error: 'class std::queue<int>' has no member named 'push_back'
   47 |                                                 que.push_back(make_pair(tx * 2 + 1));
      |                                                     ^~~~~~~~~
a.cc:47:72: error: no matching function for call to 'make_pair(int)'
   47 |                                                 que.push_back(make_pair(tx * 2 + 1));
      |                                                               ~~~~~~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1132:5: note: candidate: 'template<class _T1, class _T2> constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&)'
 1132 |     make_pair(_T1&& __x, _T2&& __y)
      |     ^~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1132:5: note:   candidate expects 2 arguments, 1 provided