Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n


import string

from bisect import bisect_left

def solve():
    # n, m = [int(x) for x in input().split()]
    s = [x for x in input()]
    a = s[:]
    k = int(input())
    if len(s) == 1:
        print(k // 2)
        return
    if len(set(s)) == 1:
        print((s * k)//2)
        return
    cnt = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s[i] = '.'
            cnt += 1

    cnt *= k
    
    if s[0] == s[-1] and s[0] != '.':
        cnt += (k - 1)

    print(min(cnt,ans))


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""


# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n


import string

from bisect import bisect_left

def solve():
    # n, m = [int(x) for x in input().split()]
    s = [x for x in input()]
    a = s[:]
    k = int(input())
    if len(s) == 1:
        print(k // 2)
        return
    if len(set(s)) == 1:
        print((len(s) * k)//2)
        return
    cnt = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s[i] = '.'
            cnt += 1

    cnt *= k
    
    if s[0] == s[-1] and s[0] != '.':
        cnt += (k - 1)

    print(min(cnt,ans))


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""


# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n


import string

from bisect import bisect_left

def solve():
    # n, m = [int(x) for x in input().split()]
    s = [x for x in input()]
    k = int(input())
    n = len(s)
    if s == s[0] * n:
        print(n*k//2)
        return
    b = [1]
    for i in range(1, n):
        if s[i] == s[i-1]:
            b[-1] += 1
        else:
            b.append(1)
    ans = 0
    for e in b:
        ans += e // 2 * k

    if s[0] == s[-1]:
        ans -= b[0]  // 2 * k
        ans -= b[-1] // 2 * k
        ans += (b[0] + b[-1]) // 2 * (k-1)
    
    print(ans)


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""


# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n


import string

from bisect import bisect_left

def solve():
    # n, m = [int(x) for x in input().split()]
    s = [x for x in input()]
    k = int(input())
    n = len(s)
    if len(set(s)) == 1:
        print(n*k//2)
        return
    b = [1]
    for i in range(1, n):
        if s[i] == s[i-1]:
            b[-1] += 1
        else:
            b.append(1)
    ans = 0
    for e in b:
        ans += e // 2 * k

    if s[0] == s[-1] and b[0] % 2 and b[-1] % 2:
        ans += k-1
    
    print(ans)


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted