Many 110

AtCoder
IDarc110_b
Time2000ms
Memory256MB
Difficulty
Let $S$ be the concatenation of $10^{10}$ copies of the string `110`. (For reference, the concatenation of $3$ copies of `110` is `110110110`.) We have a string $T$ of length $N$. Find the number of times $T$ occurs in $S$ as a contiguous substring. ## Constraints * $1 \leq N \leq 2 \times 10^5$ * $T$ is a string of length $N$ consisting of `0` and `1`. ## Input Input is given from Standard Input in the following format: $N$ $T$ [samples]
Samples
Input #1
4
1011
Output #1
9999999999

$S$ is so long, so let us instead count the number of times `1011` occurs in the concatenation of $3$ copies of `110`, that is, `110110110`. We can see it occurs twice:

*   $1$ `1011` $0110$
    
*   $1101$ `1011` $0$
Input #2
22
1011011011011011011011
Output #2
9999999993
API Response (JSON)
{
  "problem": {
    "name": "Many 110",
    "description": {
      "content": "Let $S$ be the concatenation of $10^{10}$ copies of the string `110`. (For reference, the concatenation of $3$ copies of `110` is `110110110`.) We have a string $T$ of length $N$. Find the number of t",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc110_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Let $S$ be the concatenation of $10^{10}$ copies of the string `110`. (For reference, the concatenation of $3$ copies of `110` is `110110110`.)\nWe have a string $T$ of length $N$.\nFind the number of t...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments