#include using namespace std; #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define All(v) (v).begin(), (v).end() #define pb push_back #define MP(a, b) make_pair((a), (b)) template vector make_vec(size_t a, T val) { return vector(a, val); } template auto make_vec(size_t a, Ts... ts) { return vector(a, make_vec(ts...)); } using ll = long long; using pii = pair; using pll = pair; using Graph = vector>; template struct edge { int to; T cost; edge(int t, T c) : to(t), cost(c) {} }; template using WGraph = vector>>; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1e9 + 7; struct Triangle { int x, y; map ope; const pii yp = {0, 1}, ym = {0, -1}, xp = {1, 0}, xm = {-1, 0}; Triangle() { x = 0, y = 0; ope['a'] = {0, -1}; ope['b'] = {0, 1}; ope['c'] = {1, 0}; }; void operation(char c) { const pii order = ope[c]; auto [dx, dy] = order; for(auto &[_c, op] : ope) { if((x + y) % 2 == 0) { if(order == yp) { if(c == _c) { op.first *= -1; op.second *= -1; } else { swap(op.first, op.second); } } else if(order == ym) { if(c == _c) { op.first *= -1; op.second *= -1; } else { swap(op.first, op.second); op.first *= -1; op.second *= -1; } } else { if(c == _c) { op.first *= -1; op.second *= -1; } else { } } } else { if(order == yp) { if(c == _c) { op.first *= -1; op.second *= -1; } else { swap(op.first, op.second); op.first *= -1; op.second *= -1; } } else if(order == ym) { if(c == _c) { op.first *= -1; op.second *= -1; } else { swap(op.first, op.second); } } else { if(c == _c) { op.first *= -1; op.second *= -1; } else { } } } } x += dx, y += dy; } }; int main() { string S; cin >> S; int N = S.size(); set se; pii state = {0, 0}; se.insert(state); Triangle tri = Triangle(); for(int i = 0; i < N; i++) { tri.operation(S[i]); se.insert({tri.x, tri.y}); } cout << se.size() << endl; }