import sys
s = input()
k = int(input())
n = len(s)
if n==1:
    print(k//2)
    sys.exit()
if n==2:
    print(k if s[0]==s[1] else 0)
    sys.exit()
i = 1
change = [0, 0]
same = True
while i<n:
    if s[i-1]==s[i]:
        if i==n-1:
            same = False
        change[0] += 1
        i += 1
    i += 1
if s[0]!=s[-1]:
    same = False
if not same:
    print(change[0]*k)
    sys.exit()
i = 2
change[1] = 1
same = True
while i<n:
    if s[i-1]==s[i]:
        if i==n-1:
            same = False
        change[1] += 1
        i += 1
    i += 1
if same:
    print(change[0]+change[1]*(k-1))
else:
    print(change[0]*((k+1)//2)+change[1]*(k//2)) import sys sys s = input() s input() input k = int(input()) k int(input()) int input() input n = len(s) n len(s) len s if n==1:
    print(k//2)
    sys.exit() n==1 n 1 print(k//2) print k//2 k 2 sys.exit() sys.exit sys exit if n==2:
    print(k if s[0]==s[1] else 0)
    sys.exit() n==2 n 2 print(k if s[0]==s[1] else 0) print k if s[0]==s[1] else 0 s[0]==s[1] s[0] s 0 s[1] s 1 k 0 sys.exit() sys.exit sys exit i = 1 i 1 change = [0, 0] change [0, 0] 0 0 same = True same True while i<n:
    if s[i-1]==s[i]:
        if i==n-1:
            same = False
        change[0] += 1
        i += 1
    i += 1 i<n i n if s[i-1]==s[i]:
        if i==n-1:
            same = False
        change[0] += 1
        i += 1
     s[i-1]==s[i] s[i-1] s i-1 i 1 s[i] s i if i==n-1:
            same = False
         i==n-1 i n-1 n 1 same = False same False change[0] += 1 change[0] change 0 1 i += 1 i 1 i += 1 i 1 if s[0]!=s[-1]:
    same = False s[0]!=s[-1] s[0] s 0 s[-1] s -1 same = False same False if not same:
    print(change[0]*k)
    sys.exit() not same same print(change[0]*k) print change[0]*k change[0] change 0 k sys.exit() sys.exit sys exit i = 2 i 2 change[1] = 1 change[1] change 1 1 same = True same True while i<n:
    if s[i-1]==s[i]:
        if i==n-1:
            same = False
        change[1] += 1
        i += 1
    i += 1 i<n i n if s[i-1]==s[i]:
        if i==n-1:
            same = False
        change[1] += 1
        i += 1
     s[i-1]==s[i] s[i-1] s i-1 i 1 s[i] s i if i==n-1:
            same = False
         i==n-1 i n-1 n 1 same = False same False change[1] += 1 change[1] change 1 1 i += 1 i 1 i += 1 i 1 if same:
    print(change[0]+change[1]*(k-1))
else:
    print(change[0]*((k+1)//2)+change[1]*(k//2)) same print(change[0]+change[1]*(k-1)) print change[0]+change[1]*(k-1) change[0] change 0 change[1]*(k-1) change[1] change 1 k-1 k 1 print(change[0]*((k+1)//2)+change[1]*(k//2)) print change[0]*((k+1)//2)+change[1]*(k//2) change[0]*((k+1)//2) change[0] change 0 (k+1)//2 k+1 k 1 2 change[1]*(k//2) change[1] change 1 k//2 k 2 same = False False same i += 1 1 i i += 1 1 i i += 1 1 i same = True True same same = False False same i = 2 2 i n = len(s) len(s) n s = input() input() s i += 1 1 i k = int(input()) int(input()) k same = True True same change = [0, 0] [0, 0] change same = False False same i = 1 1 i
import sys
s = input()
k = int(input())
n = len(s)
if n==1:
    print(k//2)
    sys.exit()
if n==2:
    print(k if s[0]==s[1] else 0)
    sys.exit()
i = 1
change = [0, 0]
same = True
while i<n:
    if s[i-1]==s[i]:
        if i==n-1:
            same = False
        change[0] += 1
        i += 1
    i += 1
if s[0]!=s[-1]:
    same = False
if not same:
    print(change[0]*k)
    sys.exit()
i = 2
change[1] = 1
same = True
while i<n:
    if s[i-1]==s[i]:
        if i==n-1:
            same = False
        change[1] += 1
        i += 1
    i += 1
if same:
    print(change[0]+change[1]*(k-1))
else:
    print(change[0]*((k+1)//2)+change[1]*(k//2))