//#pragma GCC optimize("Ofast") //#pragma GCC target("avx") //#undef LOCAL #include #include #include #include #include #include #include #include namespace yosupo { namespace internal { int ceil_pow2(int n) { int x = 0; while ((1U << x) < (unsigned int)(n)) x++; return x; } } // namespace internal int bsf(unsigned int n) { return __builtin_ctz(n); } int bsf(unsigned long n) { return __builtin_ctzl(n); } int bsf(unsigned long long n) { return __builtin_ctzll(n); } int bsr(unsigned int n) { return 8 * (int)sizeof(unsigned int) - 1 - __builtin_clz(n); } int bsr(unsigned long n) { return 8 * (int)sizeof(unsigned long) - 1 - __builtin_clzl(n); } int bsr(unsigned long long n) { return 8 * (int)sizeof(unsigned long long) - 1 - __builtin_clzll(n); } } // namespace yosupo #include #include #include namespace yosupo { namespace internal { template using is_signed_int128 = typename std::conditional::value || std::is_same::value, std::true_type, std::false_type>::type; template using is_unsigned_int128 = typename std::conditional::value || std::is_same::value, std::true_type, std::false_type>::type; template using make_unsigned_int128 = typename std::conditional::value, __uint128_t, unsigned __int128>; template using is_integral = typename std::conditional::value || internal::is_signed_int128::value || internal::is_unsigned_int128::value, std::true_type, std::false_type>::type; template using is_signed_int = typename std::conditional<(is_integral::value && std::is_signed::value) || is_signed_int128::value, std::true_type, std::false_type>::type; template using is_unsigned_int = typename std::conditional<(is_integral::value && std::is_unsigned::value) || is_unsigned_int128::value, std::true_type, std::false_type>::type; template using to_unsigned = typename std::conditional< is_signed_int128::value, make_unsigned_int128, typename std::conditional::value, std::make_unsigned, std::common_type>::type>::type; template using is_integral_t = std::enable_if_t::value>; template using is_signed_int_t = std::enable_if_t::value>; template using is_unsigned_int_t = std::enable_if_t::value>; template using to_unsigned_t = typename to_unsigned::type; } // namespace internal } // namespace yosupo namespace yosupo { struct Scanner { public: Scanner(FILE* fp) : fd(fileno(fp)) {} void read() {} template void read(H& h, T&... t) { bool f = read_single(h); assert(f); read(t...); } int read_unsafe() { return 0; } template int read_unsafe(H& h, T&... t) { bool f = read_single(h); if (!f) return 0; return 1 + read_unsafe(t...); } private: static constexpr size_t SIZE = 1 << 15; bool read_single(std::string& ref) { if (!skip_space()) return false; ref = ""; while (true) { char c = top(); if (c <= ' ') break; ref += c; st++; } return true; } bool read_single(double& ref) { std::string s; if (!read_single(s)) return false; ref = std::stod(s); return true; } template * = nullptr> bool read_single(T& sref) { using U = internal::to_unsigned_t; if (!skip_space(50)) return false; bool neg = false; if (line[st] == '-') { neg = true; st++; } U ref = 0; do { ref = 10 * ref + (line[st++] & 0x0f); } while (line[st] >= '0'); sref = neg ? -ref : ref; return true; } template * = nullptr> bool read_single(U& ref) { if (!skip_space(50)) return false; ref = 0; do { ref = 10 * ref + (line[st++] & 0x0f); } while (line[st] >= '0'); return true; } int fd = -1; char line[SIZE]; size_t st = 0, ed = 0; bool eof = false; bool reread() { if (ed - st >= 50) return true; if (st > SIZE / 2) { std::memmove(line, line + st, ed - st); ed -= st; st = 0; } if (eof) return false; auto u = ::read(fd, line + ed, SIZE - ed); if (u == 0) { eof = true; line[ed] = '\0'; u = 1; } ed += u; return true; } char top() { if (st == ed) { bool f = reread(); assert(f); } return line[st]; } bool skip_space(unsigned int token_len = 0) { while (true) { while (st != ed && line[st] <= ' ') st++; if (ed - st > token_len) return true; for (auto i = st; i < ed; i++) { if (line[i] <= ' ') return true; } if (!reread()) return false; } } }; struct Printer { public: template void write() {} template void write(const H& h, const T&... t) { if (F) write_single(' '); write_single(h); write(t...); } template void writeln(const T&... t) { write(t...); write_single('\n'); } Printer(FILE* _fp) : fd(fileno(_fp)) {} ~Printer() { flush(); } void flush() { ::write(fd, line, pos); pos = 0; } private: static std::array, 100> small; static std::array tens; static int calc_len(unsigned long long x) { int i = (bsr(x) * 3 + 3) / 10; if (x < tens[i]) return i; else return i + 1; } static constexpr size_t SIZE = 1 << 15; int fd; char line[SIZE]; size_t pos = 0; void write_single(const char& val) { if (pos == SIZE) flush(); line[pos++] = val; } template * = nullptr> void write_single(const T& val) { using U = internal::to_unsigned_t; if (val == 0) { write_single('0'); return; } if (pos > SIZE - 50) flush(); U uval = val; if (val < 0) { write_single('-'); uval = -uval; } write_unsigned(uval); } template * = nullptr> void write_single(U uval) { if (uval == 0) { write_single('0'); return; } if (pos > SIZE - 50) flush(); write_unsigned(uval); } template * = nullptr, std::enable_if_t* = nullptr> void write_unsigned(U uval) { write_unsigned(uint64_t(uval)); } template * = nullptr, std::enable_if_t* = nullptr> void write_unsigned(U uval) { size_t len = calc_len(uval); pos += len; char* ptr = line + pos; while (uval >= 100) { ptr -= 2; memcpy(ptr, small[uval % 100].data(), 2); uval /= 100; } if (uval >= 10) { memcpy(ptr - 2, small[uval].data(), 2); } else { *(ptr - 1) = char('0' + uval); } } void write_single(const std::string& s) { for (char c : s) write_single(c); } void write_single(const char* s) { size_t len = strlen(s); for (size_t i = 0; i < len; i++) write_single(s[i]); } template void write_single(const std::vector& val) { auto n = val.size(); for (size_t i = 0; i < n; i++) { if (i) write_single(' '); write_single(val[i]); } } }; std::array, 100> Printer::small = [] { std::array, 100> table; for (int i = 0; i <= 99; i++) { table[i][1] = char('0' + (i % 10)); table[i][0] = char('0' + (i / 10 % 10)); } return table; }(); std::array Printer::tens = [] { std::array table; for (int i = 0; i < 20; i++) { table[i] = 1; for (int j = 0; j < i; j++) { table[i] *= 10; } } return table; }(); } // namespace yosupo using namespace yosupo; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template using V = vector; template using VV = V>; #ifdef LOCAL ostream& operator<<(ostream& os, __int128_t x) { if (x < 0) { os << "-"; x *= -1; } if (x == 0) { return os << "0"; } string s; while (x) { s += char(x % 10 + '0'); x /= 10; } reverse(s.begin(), s.end()); return os << s; } ostream& operator<<(ostream& os, __uint128_t x) { if (x == 0) { return os << "0"; } string s; while (x) { s += char(x % 10 + '0'); x /= 10; } reverse(s.begin(), s.end()); return os << s; } template ostream& operator<<(ostream& os, const pair& p); template ostream& operator<<(ostream& os, const V& v); template ostream& operator<<(ostream& os, const deque& v); template ostream& operator<<(ostream& os, const array& a); template ostream& operator<<(ostream& os, const set& s); template ostream& operator<<(ostream& os, const map& m); template ostream& operator<<(ostream& os, const pair& p) { return os << "P(" << p.first << ", " << p.second << ")"; } template ostream& operator<<(ostream& os, const V& v) { os << "["; bool f = false; for (auto d : v) { if (f) os << ", "; f = true; os << d; } return os << "]"; } template ostream& operator<<(ostream& os, const deque& v) { os << "["; bool f = false; for (auto d : v) { if (f) os << ", "; f = true; os << d; } return os << "]"; } template ostream& operator<<(ostream& os, const array& a) { os << "["; bool f = false; for (auto d : a) { if (f) os << ", "; f = true; os << d; } return os << "]"; } template ostream& operator<<(ostream& os, const set& s) { os << "{"; bool f = false; for (auto d : s) { if (f) os << ", "; f = true; os << d; } return os << "}"; } template ostream& operator<<(ostream& os, const map& s) { os << "{"; bool f = false; for (auto p : s) { if (f) os << ", "; f = true; os << p.first << ": " << p.second; } return os << "}"; } struct PrettyOS { ostream& os; bool first; template auto operator<<(T&& x) { if (!first) os << ", "; first = false; os << x; return *this; } }; template void dbg0(T&&... t) { (PrettyOS{cerr, true} << ... << t); } #define dbg(...) \ do { \ cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \ dbg0(__VA_ARGS__); \ cerr << endl; \ } while (false); #else #define dbg(...) #endif Scanner sc = Scanner(stdin); Printer pr = Printer(stdout); using P = pair; const int di[6][2] = { {1, 0}, {0, 1}, {-1, 1}, {-1, 0}, {0, -1}, {1, -1}, }; int main() { array ar = {0, 120, 240}; string s; sc.read(s); P pos = P(0, 0); set

st; st.insert(pos); for (char c : s) { int id = -1; if (c == 'a') id = 0; else if (c == 'b') id = 1; else id = 2; // move ar[id] int a = ar[id]; pos.first += di[a / 60][0]; pos.second += di[a / 60][1]; st.insert(pos); for (int i = 0; i < 3; i++) { // ar[i] + x = 2 * a + 180 ar[i] = (2 * a + 180 - ar[i]); ar[i] = (ar[i] % 360 + 360) % 360; } } pr.writeln(st.size()); return 0; }