ABBreviate

AtCoder
IDagc027_e
Time2000ms
Memory256MB
Difficulty
There is a string $s$ consisting of `a` and `b`. Snuke can perform the following two kinds of operation any number of times in any order: * Choose an occurrence of `aa` as a substring, and replace it with `b`. * Choose an occurrence of `bb` as a substring, and replace it with `a`. How many strings $s$ can be obtained by this sequence of operations? Find the count modulo $10^9 + 7$. ## Constraints * $1 \leq |s| \leq 10^5$ * $s$ consists of `a` and `b`. ## Input Input is given from Standard Input in the following format: $s$ [samples]
Samples
Input #1
aaaa
Output #1
6

Six strings can be obtained:

*   `aaaa`
*   `aab`
*   `aba`
*   `baa`
*   `bb`
*   `a`
Input #2
aabb
Output #2
5

Five strings can be obtained:

*   `aabb`
*   `aaa`
*   `bbb`
*   `ab`
*   `ba`
Input #3
ababababa
Output #3
1

Snuke cannot perform any operation.
Input #4
babbabaaba
Output #4
35
API Response (JSON)
{
  "problem": {
    "name": "ABBreviate",
    "description": {
      "content": "There is a string $s$ consisting of `a` and `b`. Snuke can perform the following two kinds of operation any number of times in any order: *   Choose an occurrence of `aa` as a substring, and replace ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "agc027_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There is a string $s$ consisting of `a` and `b`. Snuke can perform the following two kinds of operation any number of times in any order:\n\n*   Choose an occurrence of `aa` as a substring, and replace ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments