#AGC039-A Connection and Disconnection
"""
sをk回繰り返して得られる文字列tを、全て隣り合う文字が異なるようにする
為に必要な操作回数を求めよ
解法：
最初と最後だけ愚直にカウント
あとは中間部分を連結してそれをk-1回繰り返す
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
s = readline().rstrip().decode('utf-8')
k = int(readline())
first = 0
last = 0
l = 0
r = len(s)

#全部同じ文字だとまずい
if len(set(s)) == 1:
    print(len(s)*k//2)
    exit()

if s[0] == s[-1]:
    res = s[0]
    for idx,i in enumerate(s):
        if i == res:
            first += 1
        else:
            l = idx
            break
    res = s[-1]
    for idx,i in enumerate(s[::-1]):
        if i == res:
            last += 1
        else:
            r = len(s)-idx
            break

count = 0
res = ""
for i in s[l:r]:
    if res == "":
        res = i
    elif res == i:
        count += 1
        res = ""
    else:
        res = i

print(first//2+last//2+(first+last)//2*(k-1)+count*k) """
sをk回繰り返して得られる文字列tを、全て隣り合う文字が異なるようにする
為に必要な操作回数を求めよ
解法：
最初と最後だけ愚直にカウント
あとは中間部分を連結してそれをk-1回繰り返す
""" import sys sys readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline def even(n): return 1 if n%2==0 else 0 even n n s = readline().rstrip().decode('utf-8') s readline().rstrip().decode('utf-8') ().rstrip().decode ().rstrip() ().rstrip () readline rstrip decode 'utf-8' k = int(readline()) k int(readline()) int readline() readline first = 0 first 0 last = 0 last 0 l = 0 l 0 r = len(s) r len(s) len s if len(set(s)) == 1:
    print(len(s)*k//2)
    exit() len(set(s)) == 1 len(set(s)) len set(s) set s 1 print(len(s)*k//2) print len(s)*k//2 len(s)*k len(s) len s k 2 exit() exit if s[0] == s[-1]:
    res = s[0]
    for idx,i in enumerate(s):
        if i == res:
            first += 1
        else:
            l = idx
            break
    res = s[-1]
    for idx,i in enumerate(s[::-1]):
        if i == res:
            last += 1
        else:
            r = len(s)-idx
            break s[0] == s[-1] s[0] s 0 s[-1] s -1 res = s[0] res s[0] s 0 for idx,i in enumerate(s):
        if i == res:
            first += 1
        else:
            l = idx
            break
     idx i enumerate(s) enumerate s if i == res:
            first += 1
        else:
            l = idx
            break
     i == res i res first += 1 first 1 l = idx l idx break res = s[-1] res s[-1] s -1 for idx,i in enumerate(s[::-1]):
        if i == res:
            last += 1
        else:
            r = len(s)-idx
            break idx i enumerate(s[::-1]) enumerate s[::-1] s ::-1 -1 if i == res:
            last += 1
        else:
            r = len(s)-idx
            break i == res i res last += 1 last 1 r = len(s)-idx r len(s)-idx len(s) len s idx break count = 0 count 0 res = "" res "" for i in s[l:r]:
    if res == "":
        res = i
    elif res == i:
        count += 1
        res = ""
    else:
        res = i i s[l:r] s l:r l r if res == "":
        res = i
    elif res == i:
        count += 1
        res = ""
    else:
        res = i res == "" res "" res = i res i elif res == i:
        count += 1
        res = ""
     res == i res i count += 1 count 1 res = "" res "" res = i res i print(first//2+last//2+(first+last)//2*(k-1)+count*k) print first//2+last//2+(first+last)//2*(k-1)+count*k first//2+last//2+(first+last)//2*(k-1) first//2+last//2 first//2 first 2 last//2 last 2 (first+last)//2*(k-1) (first+last)//2 first+last first last 2 k-1 k 1 count*k count k first = 0 0 first res = "" "" res r = len(s) len(s) r last += 1 1 last def even(n): return 1 if n%2==0 else 0 def even(n): return 1 if n%2==0 else 0 even count += 1 1 count last = 0 0 last res = s[0] s[0] res count = 0 0 count res = i i res l = 0 0 l k = int(readline()) int(readline()) k l = idx idx l res = i i res s = readline().rstrip().decode('utf-8') readline().rstrip().decode('utf-8') s res = s[-1] s[-1] res res = "" "" res r = len(s)-idx len(s)-idx r first += 1 1 first readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline
#AGC039-A Connection and Disconnection
"""
sをk回繰り返して得られる文字列tを、全て隣り合う文字が異なるようにする
為に必要な操作回数を求めよ
解法：
最初と最後だけ愚直にカウント
あとは中間部分を連結してそれをk-1回繰り返す
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
s = readline().rstrip().decode('utf-8')
k = int(readline())
first = 0
last = 0
l = 0
r = len(s)

#全部同じ文字だとまずい
if len(set(s)) == 1:
    print(len(s)*k//2)
    exit()

if s[0] == s[-1]:
    res = s[0]
    for idx,i in enumerate(s):
        if i == res:
            first += 1
        else:
            l = idx
            break
    res = s[-1]
    for idx,i in enumerate(s[::-1]):
        if i == res:
            last += 1
        else:
            r = len(s)-idx
            break

count = 0
res = ""
for i in s[l:r]:
    if res == "":
        res = i
    elif res == i:
        count += 1
        res = ""
    else:
        res = i

print(first//2+last//2+(first+last)//2*(k-1)+count*k)