Connection and Disconnection

AtCoder
IDagc039_a
Time2000ms
Memory256MB
Difficulty
Given is a string $S$. Let $T$ be the concatenation of $K$ copies of $S$. We can repeatedly perform the following operation: choose a character in $T$ and replace it with a different character. Find the minimum number of operations required to satisfy the following condition: any two adjacent characters in $T$ are different. ## Constraints * $1 \leq |S| \leq 100$ * $S$ consists of lowercase English letters. * $1 \leq K \leq 10^9$ * $K$ is an integer. ## Input Input is given from Standard Input in the following format: $S$ $K$ [samples]
Samples
Input #1
issii
2
Output #1
4

$T$ is `issiiissii`. For example, we can rewrite it into `ispiqisyhi`, and now any two adjacent characters are different.
Input #2
qq
81
Output #2
81
Input #3
cooooooooonteeeeeeeeeest
999993333
Output #3
8999939997
API Response (JSON)
{
  "problem": {
    "name": "Connection and Disconnection",
    "description": {
      "content": "Given is a string $S$. Let $T$ be the concatenation of $K$ copies of $S$. We can repeatedly perform the following operation: choose a character in $T$ and replace it with a different character. Find 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": "agc039_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Given is a string $S$. Let $T$ be the concatenation of $K$ copies of $S$. We can repeatedly perform the following operation: choose a character in $T$ and replace it with a different character. Find t...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments