/* -*- coding: utf-8 -*- * * 1292.cc: No.1292 パタパタ三角形 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 200000; const int dxs[] = { 1, 0, -1, 0 }, dys[] = { 0, 1, 0, -1 }; enum { DRL, RLD, LDR, URL, RLU, LUR }; enum { R, U, L, D }; const int mvs[6][3][2] = { // to_a to_b to_c /* DRL */ { { URL, D }, { RLU, R }, { LUR, L } }, /* RLD */ { { LUR, R }, { URL, L }, { RLU, D } }, /* LDR */ { { RLU, L }, { LUR, D }, { URL, R } }, /* URL */ { { DRL, U }, { RLD, R }, { LDR, L } }, /* RLU */ { { LDR, R }, { DRL, L }, { RLD, U } }, /* LUR */ { { RLD, L }, { LDR, U }, { DRL, R } }, }; /* typedef */ typedef pair pii; typedef set spii; /* global variables */ char s[MAX_N + 4]; spii ps; /* subroutines */ /* main */ int main() { scanf("%s", s); int cur = DRL, x = 0, y = 0; ps.insert(pii(x, y)); for (int i = 0; s[i]; i++) { int si = s[i] - 'a'; int nxt = mvs[cur][si][0]; int di = mvs[cur][si][1]; cur = nxt; x += dxs[di], y += dys[di]; ps.insert(pii(x, y)); } printf("%d\n", (int)ps.size()); return 0; }