링크 : https://www.acmicpc.net/problem/2210
/*
문제 : 숫자만 점프
링크 : https://www.acmicpc.net/problem/2210
*/
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int arr[5][5], ans = 0;
bool visited[1000000];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
void dfs(int y, int x, int sum, int cnt){
if(cnt == 5){
if(!visited[sum]){
visited[sum] = true;
ans ++;
}
return;
}
for(int i = 0; i < 4; i++){
int nx = x + dx[i];
int ny = y + dy[i];
if(nx >=0 && ny >= 0 && nx < 5 && ny < 5){
dfs(ny, nx, sum * 10 + arr[ny][nx], cnt + 1);
}
}
}
int main(){
for(int i = 0; i < 5; i++){
for(int j = 0; j < 5; j++){
cin >> arr[i][j];
}
}
for(int i = 0; i < 5; i++){
for(int j = 0; j < 5; j++){
dfs(i, j, arr[i][j], 0);
}
}
cout << ans << '\n';
return 0;
}