#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
int n,m,k,l,r,t=1,q;
string s[10005][5];

bool c2(int z,int x,int y){
	string t=s[x][y];
	for(int i=z;i<=z+3;i++){
		for(int j=1;j<=4;j++){
			if(s[i][j]==t&&(i!=x||j!=y)){
				return 1;
			}
		}
	}
	return 0;
}
bool check(int x,int y){
	for(int i=x;i<=x+3;i++){
		for(int j=1;j<=4;j++){
			if(c2(y,i,j)) return 0;
		}
	} 
	return 1;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=4;j++){
			cin>>s[i][j];
		}
	}	
	for(int i=1;i<=n-3;i++){
		for(int j=i+1;j<=n-3;j++){
			if(check(i,j)) t++;
		}
	}
	cout<<t<<endl;
}