#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<int,int> P;

string str[8];
map<string,int> m;
int num[8];
vector<int> f;

void solve(){
	int cnt = 0;
	m.clear(); f.clear();
	rep(i,8) num[i] = 0;
	rep(i,8){
		if(m.count(str[i]) == 0){
			m[str[i]] = cnt;
			num[cnt]++;
			cnt++;
		} else num[m[str[i]]]++;
	}
	rep(i,8) if(num[i] > 0) f.push_back(num[i]);
	sort(f.begin(),f.end());
	if(f.size() == 1){
		cout << 1 << endl;
		return;
	}
	if(f.size() == 2 && f[0] == 1){
		cout << 1 << endl;
		return;
	}
	if(f.size() == 2 && f[0] == 2){
		cout << 3 << endl;
		return;
	}
	if(f.size() == 2 && f[0] == 3){
		cout << 3 << endl;
		return;
	} else if(f.size() == 2 && f[0] == 4){
		cout << 7 << endl;
		return;
	}
	long long ans = 0;
	int x[8];
	if(f[0] == 1){
		for(int i = 1; i < f.size(); i++){
			f[i]--;
			for(int j = 0; j < (1<<(f.size()-1)*2); j++){
				int J = j, checker = 0;
				vector<int> y, z;
				for(int k = 1; k < f.size(); k++){
					x[k] = J%4;
					if(x[k] > 0) y.push_back(x[k]);
					checker += x[k];
					J /= 4;
				}
				if(checker != 3) continue;
				for(int k = 1; k < f.size(); k++) if(f[k] < x[k]) checker = -1;
				if(checker == -1) continue;
				for(int k = 1; k < f.size(); k++) if(f[k] > x[k]) z.push_back(f[k]-x[k]);
				if(y.size() == 1){
					if(z.size() == 1) ans += 1;
					if(z.size() == 2) ans += 1;
					if(z.size() == 3) ans += 2;
				} else if(y.size() == 2){
					if(z.size() == 1) ans += 1;
					if(z.size() == 2) ans += 3;
					if(z.size() == 3) ans += 6;
				} else{
					if(z.size() == 1) ans += 2;
					if(z.size() == 2) ans += 6;
					if(z.size() == 3) ans += 12;
				}
			}
			f[i]++;
		}
	} else if(f[0] == 2){
		/*
		for(int j = 0; j < (1<<(f.size()-1)*2); j++){
			int J = j, checker = 0;
			bool val = true;
			vector<int> y, z;
			for(int k = 1; k < f.size(); k++){
				x[k] = J%4;
				if(x[k] > 0) y.push_back(x[k]);
				checker += x[k];
				J /= 4;
			}
			if(checker != 3) continue;
			for(int k = 1; k < f.size(); k++) if(f[k] < x[k]) checker = -1;
			if(checker == -1) continue;
			for(int k = 1; k < f.size(); k++) if(f[k] > x[k]) z.push_back(f[k]-x[k]);
			for(int k = 1; k < f.size(); k++) if(f[k] != x[k]*2 && x[k] > 0) val = false;
			if(!val){
				if(y.size() == 1){
					if(z.size() == 1) ans += 1;
					if(z.size() == 2) ans += 1;
					if(z.size() == 3) ans += 2;
				} else if(y.size() == 2){
					if(z.size() == 1) ans += 1;
					if(z.size() == 2) ans += 3;
					if(z.size() == 3) ans += 6;
				} else{
					if(z.size() == 1) ans += 2;
					if(z.size() == 2) ans += 6;
					if(z.size() == 3) ans += 12;
				}
			} else{
				if(y.size() == 1){
					if(z.size() == 1) ans += 1*2;
					if(z.size() == 2) ans += 1;
					if(z.size() == 3) ans += 2;
				} else if(y.size() == 2){
					if(z.size() == 1) ans += 1;
					if(z.size() == 2) ans += 2*2;
					if(z.size() == 3) ans += 6;
				} else{
					if(z.size() == 1) ans += 2;
					if(z.size() == 2) ans += 6;
					if(z.size() == 3) ans += 9*2;
				}
			}
		}
		ans /= 2;
		long long tmpans = 0;
		for(int i = 1; i < f.size(); i++){
			f[i]--;
			for(int i2 = i; i2 < f.size(); i2++){
				if(f[i2] <= 0) continue;
				f[i2]--;
				int tmp = 4*3*2*1;
				for(int j = 1; j < f.size(); j++){
					if(f[j] <= 0) continue;
					for(int k = f[j]; k >= 1; k--) tmp /= k;
				}
				if(i != i2){
					tmpans += tmp;
				} else{
					vector<int> y;
					for(int j = 1; j < f.size(); j++) if(f[j] > 0) y.push_back(f[j]);
					if(y.size() == 1) tmpans += 1;
					else if(y.size() == 2 && y[0] == 2) tmpans += 4;
					else{
						tmpans += tmp;
					}
				}
				f[i2]++;
			}
			f[i]++;
		}
		ans += tmpans*2;
		*/
		if(f[1] == 3){
			ans = 24;
		} else{
			if(f[2] == 2) ans = 114;
			else ans = 22;
		}
	}
	
	cout << ans << endl;
}

int main(){
	while(cin >> str[0]){
		for(int i = 1; i < 8; i++) cin >> str[i];
		solve();
	}
}

Measured memory_bytes: 1224