# 等差数列 or 例外
import sys
from collections import Counter

s = sys.stdin.readline().rstrip()
k = int(sys.stdin.readline())

ans = 0

def f(s):
    num = 0
    prev = s[0]
    counter = 1
    for letter in s[1:]:
        if prev != letter:
            num += counter // 2
            counter = 1
            prev = letter
        else:
            counter += 1
    num += counter // 2
    return num


if len(Counter(s)) == 1:
    ans = len(s) * k // 2
else:
    s1 = f(s)
    s2 = f(s+s) - s1
    ans = s1 + s2 * (k-1)

print(ans) import sys sys from collections import Counter s = sys.stdin.readline().rstrip() s sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip k = int(sys.stdin.readline()) k int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline ans = 0 ans 0 def f(s):
    num = 0
    prev = s[0]
    counter = 1
    for letter in s[1:]:
        if prev != letter:
            num += counter // 2
            counter = 1
            prev = letter
        else:
            counter += 1
    num += counter // 2
    return num f num = 0 num 0 prev = s[0] prev s[0] s 0 counter = 1 counter 1 for letter in s[1:]:
        if prev != letter:
            num += counter // 2
            counter = 1
            prev = letter
        else:
            counter += 1
     letter s[1:] s 1: 1 if prev != letter:
            num += counter // 2
            counter = 1
            prev = letter
        else:
            counter += 1
     prev != letter prev letter num += counter // 2 num counter // 2 counter 2 counter = 1 counter 1 prev = letter prev letter counter += 1 counter 1 num += counter // 2 num counter // 2 counter 2 return num num s s if len(Counter(s)) == 1:
    ans = len(s) * k // 2
else:
    s1 = f(s)
    s2 = f(s+s) - s1
    ans = s1 + s2 * (k-1) len(Counter(s)) == 1 len(Counter(s)) len Counter(s) Counter s 1 ans = len(s) * k // 2 ans len(s) * k // 2 len(s) * k len(s) len s k 2 s1 = f(s) s1 f(s) f s s2 = f(s+s) - s1 s2 f(s+s) - s1 f(s+s) f s+s s s s1 ans = s1 + s2 * (k-1) ans s1 + s2 * (k-1) s1 s2 * (k-1) s2 k-1 k 1 print(ans) print ans k = int(sys.stdin.readline()) int(sys.stdin.readline()) k ans = len(s) * k // 2 len(s) * k // 2 ans def f(s):
    num = 0
    prev = s[0]
    counter = 1
    for letter in s[1:]:
        if prev != letter:
            num += counter // 2
            counter = 1
            prev = letter
        else:
            counter += 1
    num += counter // 2
    return num def f(s):
    num = 0
    prev = s[0]
    counter = 1
    for letter in s[1:]:
        if prev != letter:
            num += counter // 2
            counter = 1
            prev = letter
        else:
            counter += 1
    num += counter // 2
    return num f ans = s1 + s2 * (k-1) s1 + s2 * (k-1) ans s1 = f(s) f(s) s1 s2 = f(s+s) - s1 f(s+s) - s1 s2 ans = 0 0 ans s = sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() s
# 等差数列 or 例外
import sys
from collections import Counter

s = sys.stdin.readline().rstrip()
k = int(sys.stdin.readline())

ans = 0

def f(s):
    num = 0
    prev = s[0]
    counter = 1
    for letter in s[1:]:
        if prev != letter:
            num += counter // 2
            counter = 1
            prev = letter
        else:
            counter += 1
    num += counter // 2
    return num


if len(Counter(s)) == 1:
    ans = len(s) * k // 2
else:
    s1 = f(s)
    s2 = f(s+s) - s1
    ans = s1 + s2 * (k-1)

print(ans)
