#include <iostream>
#include <vector>
using namespace std;
vector<bool> visit(10, false);
bool isOk(int next, int last) {
if (visit[next]) return false;
if((next + last)%2==1) return true;
int mid = (next + last) / 2;
if(visit[mid]==1) return true;
int front[] = {1,4,7,1,2,3,1,3};
int back[] = {3,6,9,7,8,9,9,7};
for(int i=0;i<8;i++){
if((last == front[i] && next ==back[i]) || (last == back[i] && next == front[i]))return false;
}
return true;
}
int numberofPath(int last, int len) {
if (len == 0) return 1;
int sum = 0;
for (int next = 1; next <= 9; ++next) {
if (isOk(next, last)) {
visit[next] = true;
sum += numberofPath(next, len - 1);
visit[next] = false;
}
}
return sum;
}
int main() {
int cnt = 0;
for (int len = 4; len <= 9; ++len) {
visit[1] = true;
cnt += 4 * numberofPath(1, len - 1);
visit[1] = false;
visit[2] = true;
cnt += 4 * numberofPath(2, len - 1);
visit[2] = false;
visit[5] = true;
cnt += numberofPath(5, len - 1);
visit[5] = false;
}
cout << cnt << endl;
}