from math import floor, ceil
s = input()
k = int(input())

def f(s):
    b = ''
    ret = 0
    for i in s:
        if i==b:
            b = ''
            ret += 1
            continue
        b = i
    return ret

b = f(s*2) - f(s*1)
c = f(s*3) - f(s*2)
print(f(s) + b*floor(k/2) + c*ceil(k/2-1)) from math import floor, ceil s = input() s input() input k = int(input()) k int(input()) int input() input def f(s):
    b = ''
    ret = 0
    for i in s:
        if i==b:
            b = ''
            ret += 1
            continue
        b = i
    return ret f b = '' b '' ret = 0 ret 0 for i in s:
        if i==b:
            b = ''
            ret += 1
            continue
        b = i
     i s if i==b:
            b = ''
            ret += 1
            continue
         i==b i b b = '' b '' ret += 1 ret 1 continue b = i b i return ret ret s s b = f(s*2) - f(s*1) b f(s*2) - f(s*1) f(s*2) f s*2 s 2 f(s*1) f s*1 s 1 c = f(s*3) - f(s*2) c f(s*3) - f(s*2) f(s*3) f s*3 s 3 f(s*2) f s*2 s 2 print(f(s) + b*floor(k/2) + c*ceil(k/2-1)) print f(s) + b*floor(k/2) + c*ceil(k/2-1) f(s) + b*floor(k/2) f(s) f s b*floor(k/2) b floor(k/2) floor k/2 k 2 c*ceil(k/2-1) c ceil(k/2-1) ceil k/2-1 k/2 k 2 1 def f(s):
    b = ''
    ret = 0
    for i in s:
        if i==b:
            b = ''
            ret += 1
            continue
        b = i
    return ret def f(s):
    b = ''
    ret = 0
    for i in s:
        if i==b:
            b = ''
            ret += 1
            continue
        b = i
    return ret f s = input() input() s c = f(s*3) - f(s*2) f(s*3) - f(s*2) c k = int(input()) int(input()) k b = f(s*2) - f(s*1) f(s*2) - f(s*1) b
from math import floor, ceil
s = input()
k = int(input())

def f(s):
    b = ''
    ret = 0
    for i in s:
        if i==b:
            b = ''
            ret += 1
            continue
        b = i
    return ret

b = f(s*2) - f(s*1)
c = f(s*3) - f(s*2)
print(f(s) + b*floor(k/2) + c*ceil(k/2-1))