p02891 AtCoder Grand Contest 039 - Connection and Disconnection
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


Output

Print the minimum number of operations required.

Examples

Input

issii
2


Output

4


Input

qq
81


Output

81


Input

cooooooooonteeeeeeeeeest
999993333


Output

8999939997
```python
s = input()
k = int(input())
m = 0
j = 0
if len(set(list(s))) == 1:
    print((len(s) * k) // 2)
    exit()
for i in range(len(s)):
    if len(s) <= j + 1:
        a = m * k
        if s[0] == s[-1] == s[len(s) // 3]:
            print(a + k - 1)
        else:
            print(a)
        break
    if s[j] == s[j + 1]:
        m += 1
        j += 1
    j += 1
```