//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int encode(VI& vi){
  int res = 0;
  for(int i=0;i<8;++i)
	res = res * 8 + vi[i];
  return res;
}

void g(VI& num){
  int tmp = num[0];
  REP(j,3)
	num[j] = num[j+1];
  num[3] = tmp;
  
  tmp = num[4];
  REP(j,3)
	num[j+4] = num[j+5];
  num[7] = tmp;
}
void func(VI num, set<int>& memo){
  //1234567
  REP(i,4){
	g(num);
	memo.insert(encode(num));
  }
  //14852376
  VI num2 = num;
  num2[0] = num[0];
  num2[1] = num[3];
  num2[2] = num[7];
  num2[3] = num[4];
  num2[4] = num[1];
  num2[5] = num[2];
  num2[6] = num[6];
  num2[7] = num[5];
  REP(i,4){
	g(num2);
	memo.insert(encode(num2));
  }
  //58761432
  num2[0] = num[4];
  num2[1] = num[7];
  num2[2] = num[6];
  num2[3] = num[5];
  num2[4] = num[0];
  num2[5] = num[3];
  num2[6] = num[2];
  num2[7] = num[1];
  REP(i,4){
	g(num2);
	memo.insert(encode(num2));
  }
  //43781265
  num2[0] = num[3];
  num2[1] = num[2];
  num2[2] = num[6];
  num2[3] = num[7];
  num2[4] = num[0];
  num2[5] = num[1];
  num2[6] = num[5];
  num2[7] = num[4];
  REP(i,4){
	g(num2);
	memo.insert(encode(num2));
  }
  // 26731584
  num2[0] = num[1];
  num2[1] = num[5];
  num2[2] = num[6];
  num2[3] = num[2];
  num2[4] = num[0];
  num2[5] = num[4];
  num2[6] = num[7];
  num2[7] = num[3];
  REP(i,4){
	g(num2);
	memo.insert(encode(num2));
  }
  //56218734
  num2[0] = num[4];
  num2[1] = num[5];
  num2[2] = num[1];
  num2[3] = num[0];
  num2[4] = num[7];
  num2[5] = num[6];
  num2[6] = num[2];
  num2[7] = num[3];
  REP(i,4){
	g(num2);
	memo.insert(encode(num2));
  }
  
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string s[8];
  while(cin >> s[0]){
	int cnt = 0;
	VI num(8,0);
	map<string, int> mp;
	mp[s[0]] = cnt++;
	REP(i,7){
	  cin >> s[i+1];
	  if(!mp.count(s[i+1]))
		mp[s[i+1]] = cnt++;
	}
	REP(i,8)
	  num[i] = mp[s[i]];
	SORT(num);

	int ans = 0;
	set<int> memo;
	do{
	  if(memo.count(encode(num))) continue;
	  ++ans;
	  func(num, memo);
	}while(next_permutation(ALL(num)));

	cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3108