import sys
from collections import defaultdict

s = list(map(str, input().rstrip()))
k = int(input())
connection = False

if all([x == s[0] for x in s]):
    print(len(s) * k // 2)
    sys.exit()

cnt = 0
if s[0] == s[-1] and k != 1:
    connection = True
    cnt = 2
    start = 1
    goal = 1
    x = s[0]

    for i in s[1:]:
        if i == x:
            cnt += 1
            start += 1
        else:
            break

    for i in s[:-1][::-1]:
        if i == x:
            cnt += 1
            goal += 1
        else:
            break

d = defaultdict(int)

if connection:
    ss = s[:start]
    sg = s[-goal:]
    s = s[start:-goal]
    
prev = s[0]
tmp = 1
for i, x in enumerate(s[1:]):
    if prev == x and i == (len(s) - 2):
        tmp += 1
        d[tmp] += 1
    elif prev == x:
        tmp += 1
    else:
        d[tmp] += 1
        prev = x
        tmp = 1

if connection:
    d[cnt] += 1

ans = 0
for key, val in d.items():
    if key == 1:
        continue
    else:
        ans += key // 2 * val * k

if connection:
    ans -= cnt // 2
    ans += len(ss) // 2 + len(sg) // 2

print(ans) import sys sys from collections import defaultdict s = list(map(str, input().rstrip())) s list(map(str, input().rstrip())) list map(str, input().rstrip()) map str input().rstrip() ().rstrip () input rstrip k = int(input()) k int(input()) int input() input connection = False connection False if all([x == s[0] for x in s]):
    print(len(s) * k // 2)
    sys.exit() all([x == s[0] for x in s]) all [x == s[0] for x in s] print(len(s) * k // 2) print len(s) * k // 2 len(s) * k len(s) len s k 2 sys.exit() sys.exit sys exit cnt = 0 cnt 0 if s[0] == s[-1] and k != 1:
    connection = True
    cnt = 2
    start = 1
    goal = 1
    x = s[0]

    for i in s[1:]:
        if i == x:
            cnt += 1
            start += 1
        else:
            break

    for i in s[:-1][::-1]:
        if i == x:
            cnt += 1
            goal += 1
        else:
            break s[0] == s[-1] and k != 1 s[0] == s[-1] s[0] s 0 s[-1] s -1 k != 1 k 1 connection = True connection True cnt = 2 cnt 2 start = 1 start 1 goal = 1 goal 1 x = s[0] x s[0] s 0 for i in s[1:]:
        if i == x:
            cnt += 1
            start += 1
        else:
            break

     i s[1:] s 1: 1 if i == x:
            cnt += 1
            start += 1
        else:
            break

     i == x i x cnt += 1 cnt 1 start += 1 start 1 break for i in s[:-1][::-1]:
        if i == x:
            cnt += 1
            goal += 1
        else:
            break i s[:-1][::-1] [:-1] s :-1 -1 ::-1 -1 if i == x:
            cnt += 1
            goal += 1
        else:
            break i == x i x cnt += 1 cnt 1 goal += 1 goal 1 break d = defaultdict(int) d defaultdict(int) defaultdict int if connection:
    ss = s[:start]
    sg = s[-goal:]
    s = s[start:-goal]
     connection ss = s[:start] ss s[:start] s :start start sg = s[-goal:] sg s[-goal:] s -goal: -goal goal s = s[start:-goal] s s[start:-goal] s start:-goal start -goal goal prev = s[0] prev s[0] s 0 tmp = 1 tmp 1 for i, x in enumerate(s[1:]):
    if prev == x and i == (len(s) - 2):
        tmp += 1
        d[tmp] += 1
    elif prev == x:
        tmp += 1
    else:
        d[tmp] += 1
        prev = x
        tmp = 1 i x enumerate(s[1:]) enumerate s[1:] s 1: 1 if prev == x and i == (len(s) - 2):
        tmp += 1
        d[tmp] += 1
    elif prev == x:
        tmp += 1
    else:
        d[tmp] += 1
        prev = x
        tmp = 1 prev == x and i == (len(s) - 2) prev == x prev x i == (len(s) - 2) i len(s) - 2 len(s) len s 2 tmp += 1 tmp 1 d[tmp] += 1 d[tmp] d tmp 1 elif prev == x:
        tmp += 1
     prev == x prev x tmp += 1 tmp 1 d[tmp] += 1 d[tmp] d tmp 1 prev = x prev x tmp = 1 tmp 1 if connection:
    d[cnt] += 1 connection d[cnt] += 1 d[cnt] d cnt 1 ans = 0 ans 0 for key, val in d.items():
    if key == 1:
        continue
    else:
        ans += key // 2 * val * k key val d.items() d.items d items if key == 1:
        continue
    else:
        ans += key // 2 * val * k key == 1 key 1 continue ans += key // 2 * val * k ans key // 2 * val * k key // 2 * val key // 2 key 2 val k if connection:
    ans -= cnt // 2
    ans += len(ss) // 2 + len(sg) // 2 connection ans -= cnt // 2 ans cnt // 2 cnt 2 ans += len(ss) // 2 + len(sg) // 2 ans len(ss) // 2 + len(sg) // 2 len(ss) // 2 len(ss) len ss 2 len(sg) // 2 len(sg) len sg 2 print(ans) print ans x = s[0] s[0] x ss = s[:start] s[:start] ss ans = 0 0 ans cnt = 0 0 cnt start = 1 1 start start += 1 1 start cnt += 1 1 cnt tmp += 1 1 tmp connection = False False connection tmp = 1 1 tmp tmp = 1 1 tmp s = s[start:-goal] s[start:-goal] s ans += len(ss) // 2 + len(sg) // 2 len(ss) // 2 + len(sg) // 2 ans cnt += 1 1 cnt connection = True True connection tmp += 1 1 tmp sg = s[-goal:] s[-goal:] sg cnt = 2 2 cnt goal = 1 1 goal s = list(map(str, input().rstrip())) list(map(str, input().rstrip())) s goal += 1 1 goal prev = s[0] s[0] prev d = defaultdict(int) defaultdict(int) d k = int(input()) int(input()) k ans -= cnt // 2 cnt // 2 ans ans += key // 2 * val * k key // 2 * val * k ans prev = x x prev
import sys
from collections import defaultdict

s = list(map(str, input().rstrip()))
k = int(input())
connection = False

if all([x == s[0] for x in s]):
    print(len(s) * k // 2)
    sys.exit()

cnt = 0
if s[0] == s[-1] and k != 1:
    connection = True
    cnt = 2
    start = 1
    goal = 1
    x = s[0]

    for i in s[1:]:
        if i == x:
            cnt += 1
            start += 1
        else:
            break

    for i in s[:-1][::-1]:
        if i == x:
            cnt += 1
            goal += 1
        else:
            break

d = defaultdict(int)

if connection:
    ss = s[:start]
    sg = s[-goal:]
    s = s[start:-goal]
    
prev = s[0]
tmp = 1
for i, x in enumerate(s[1:]):
    if prev == x and i == (len(s) - 2):
        tmp += 1
        d[tmp] += 1
    elif prev == x:
        tmp += 1
    else:
        d[tmp] += 1
        prev = x
        tmp = 1

if connection:
    d[cnt] += 1

ans = 0
for key, val in d.items():
    if key == 1:
        continue
    else:
        ans += key // 2 * val * k

if connection:
    ans -= cnt // 2
    ans += len(ss) // 2 + len(sg) // 2

print(ans)