#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; set

se; se.insert(P(0,0)); int x, y; x = y = 0; vector node(3); node[0] = 'a', node[1] = 'b', node[2] = 'c'; int k = 0; rep(i,s.size()){ vector e(3); int id; rep(j,3) if(s[i] == node[j]) id = j; if(k == 0){ k = 1; if(id == 0){ y--; e[0] = node[0]; e[1] = node[1]; e[2] = node[2]; } if(id == 1){ x--, y++; e[0] = node[2]; e[1] = node[0]; e[2] = node[1]; } if(id == 2){ x++; e[0] = node[1]; e[1] = node[2]; e[2] = node[0]; } } else{ k = 0; if(id == 0){ y++; e[0] = node[0]; e[1] = node[1]; e[2] = node[2]; } if(id == 1){ y--; e[0] = node[2]; e[1] = node[0]; e[2] = node[1]; } if(id == 2){ x++, y--; e[0] = node[1]; e[1] = node[2]; e[2] = node[0]; } } se.insert(P(x,y)); node = e; } cout << se.size() << endl; }