#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; void update(char c, pair& pos, int& type, map& ang){ if(type == 0){ map chr; FOR(it,ang) chr[it->second] = it->first; if(ang[c] == 1){//left pos.second--; ang[chr[3]] = 1; ang[chr[2]] = 2; ang[chr[1]] = 3; } else if(ang[c] == 2){//right pos.second++; ang[chr[2]] = 1; ang[chr[1]] = 2; ang[chr[3]] = 3; } else{//down pos.first++; ang[chr[1]] = 1; ang[chr[3]] = 2; ang[chr[2]] = 3; } }else{ map chr; FOR(it,ang) chr[it->second] = it->first; if(ang[c] == 1){//left pos.second--; ang[chr[2]] = 1; ang[chr[1]] = 2; ang[chr[3]] = 3; } else if(ang[c] == 2){//up pos.first--; ang[chr[1]] = 1; ang[chr[3]] = 2; ang[chr[2]] = 3; } else{//right pos.second++; ang[chr[3]] = 1; ang[chr[2]] = 2; ang[chr[1]] = 3; } } type = 1 - type; } int main(){ string S; cin >> S; map,bool> memo; pair pos = make_pair(0,0); memo[pos] = true; int type = 0; map ang; ang['a'] = 1; ang['b'] = 2; ang['c'] = 3; rep(i,S.size()){ update(S[i], pos, type, ang); memo[pos] = true; } cout << memo.size() << endl; return 0; }