시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 128 MB72115359423974.947%

문제

5×5 크기의 숫자판이 있다. 각각의 칸에는 숫자(digit, 0부터 9까지)가 적혀 있다. 이 숫자판의 임의의 위치에서 시작해서, 인접해 있는 네 방향으로 다섯 번 이동하면서, 각 칸에 적혀있는 숫자를 차례로 붙이면 6자리의 수가 된다. 이동을 할 때에는 한 번 거쳤던 칸을 다시 거쳐도 되며, 0으로 시작하는 000123과 같은 수로 만들 수 있다.

숫자판이 주어졌을 때, 만들 수 있는 서로 다른 여섯 자리의 수들의 개수를 구하는 프로그램을 작성하시오.

입력

다섯 개의 줄에 다섯 개의 정수로 숫자판이 주어진다.

출력

첫째 줄에 만들 수 있는 수들의 개수를 출력한다.

예제 입력 1

1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 2 1
1 1 1 1 1

예제 출력 1

15

힌트

111111, 111112, 111121, 111211, 111212, 112111, 112121, 121111, 121112, 121211, 121212, 211111, 211121, 212111, 212121 이 가능한 경우들이다.

W3sicHJvYmxlbV9pZCI6IjIyMTAiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWMyMmJcdWM3OTBcdWQzMTAgXHVjODEwXHVkNTA0IiwiZGVzY3JpcHRpb24iOiI8cD41JnRpbWVzOzUgXHVkMDZjXHVhZTMwXHVjNzU4IFx1YzIyYlx1Yzc5MFx1ZDMxMFx1Yzc3NCBcdWM3ODhcdWIyZTQuIFx1YWMwMVx1YWMwMVx1Yzc1OCBcdWNlNzhcdWM1ZDBcdWIyOTQgXHVjMjJiXHVjNzkwKGRpZ2l0LCAwXHViZDgwXHVkMTMwIDlcdWFlNGNcdWM5YzApXHVhYzAwIFx1YzgwMVx1ZDYwMCBcdWM3ODhcdWIyZTQuIFx1Yzc3NCBcdWMyMmJcdWM3OTBcdWQzMTBcdWM3NTggXHVjNzg0XHVjNzU4XHVjNzU4IFx1YzcwNFx1Y2U1OFx1YzVkMFx1YzExYyBcdWMyZGN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