#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } // a/\b // /__\ // c // 初期重心 (0, 0) から // a を選択 -> (-1, √3) // b を選択 -> (1, √3) // c を選択 -> (0, -2√3) // と移動するように縮尺を調整して、訪問した重心座標の整数係数を set で管理しておく int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int n = s.length(); // 重心 set> center; center.emplace(0, 0); // 整数係数 ll x = 0, y = 0; // dir : 三角形の向き (0, 1) -> (上, 下) int dir = 0; // move_dir[i] : 文字 ch がどの方向に行くか // 初期の移動方向 (a(0), b(1), c(2)) -> (左(0), 右(1), 上下(2)) vector move_dir(3); for(int i = 0; i < 3; ++i) move_dir[i] = i; for(int i = 0; i < n; ++i){ int j = s[i] - 'a'; if(move_dir[j] == 2){ if(dir == 0) y -= 2; else y += 2; } else{ if(move_dir[j] == 1) x += 1; else x -= 1; if(dir == 0) y += 1; else y -= 1; // move_dir の更新 // まず、(文字 -> 向き) を (向き -> 文字)に変換 vector nxt(3); for(int k = 0; k < 3; ++k){ nxt[move_dir[k]] = k; } // 向きの変更 if(move_dir[j] == 1){ swap(nxt[0], nxt[1]); swap(nxt[1], nxt[2]); } else{ swap(nxt[2], nxt[0]); swap(nxt[1], nxt[2]); } // (文字 -> 向き) の対応関係に戻す for(int k = 0; k < 3; ++k){ move_dir[nxt[k]] = k; } } dir ^= 1; center.emplace(x, y); } cout << center.size() << '\n'; return 0; }