#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int n, a[N][N], b[N];
map<string, int> h;
int dist(int a, int b, int c, int d) {
if (b < a) b += 10;
if (d < c) d += 10;
return b - a == d - c;
}
bool check(int b[]) {
string s;
for (int i = 1; i <= 5; i ++)
s += b[i] - '0';
if (h[s]) return false;
bool c[N];
memset(c, false, sizeof c);
int res = 0;
for (int i = 1; i <= 5; i ++)
for (int j = 1; j <= n; j ++)
if (a[j][i] != b[i])
if (!c[i])
c[i] = true, res ++;
if (res == 1) return true;
if (res > 2) return false;
for (int i = 1; i < 5; i ++) {
if (i == 1 && c[i] && !c[i + 1]) return false;
if (i != 1 && c[i] && !c[i - 1] && !c[i + 1]) return false;
if (c[i] && c[i + 1]) {
for (int j = 1; j <= n; j ++)
if (!dist(b[i], a[j][i], b[i + 1], a[j][i + 1]) && b[i] != a[j][i] && b[i + 1] != a[j][i + 1])
return false;
}
}
return true;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i ++) {
string s;
for (int j = 1; j <= 5; j ++) {
cin >> a[i][j];
s += a[i][j] - '0';
}
h[s] = true;
}
int res = 0;
for (int A = 0; A <= 9; A ++)
for (int k = 0; k <= 9; k ++)
for (int c = 0; c <= 9; c ++)
for (int s = 0; s <= 9; s ++)
for (int p = 0; p <= 9; p ++) {
b[1] = A, b[2] = k, b[3] = c, b[4] = s, b[5] = p;
if (check(b))
res ++;
}
cout << res << endl;
return 0;
}