import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

S = list(input())
K = iin()
s = copy.deepcopy(S)
last_update = False
count1 = 0
for si in range(1, len(s)):
    if s[si-1] == s[si]:
        s[si] = '?'
        count1 += 1
        if si == len(s)-1:
            last_update = True
count2 = 0
last_update2 = False
if not last_update and S[0] == S[-1]:
    count2 = 1
    S2 = list('?')
    S2.extend(S[1:])
    for i in range(2, len(S2)):
        if S2[i-1] == S2[i]:
            S2[i] = '?'
            count2 += 1
            if i == len(S2)-1:
                last_update2 = True
if len(S) ==1:
    print(len(S)*K//2)
elif K == 1:
    print(count1)
elif count2 == 0:
    print(K*count1)
else:
    if last_update2:
        count12 = count1+count2
        ans = count12*(K//2)
        if K % 2 == 1: 
            ans+= count1
        print(ans)
    else:
        print(count1 + count2*(K-1)) import math math import fractions fractions import bisect bisect import collections collections import itertools itertools import heapq heapq import string string import sys sys import copy copy from decimal import * from collections import deque sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 MOD = 10**9+7 MOD 10**9+7 10**9 10 9 7 INF = float('inf') INF float('inf') float 'inf' def gcd(a,b):return fractions.gcd(a,b) #最大公約数 gcd a a b b def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数 lcm a a b b def iin(): return int(sys.stdin.readline()) #整数読み込み iin def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み ifn def isn(): return sys.stdin.readline().split() #文字列読み込み isn def imn(): return map(int, sys.stdin.readline().split()) #整数map取得 imn def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得 imnn def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得 fmn def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得 iln def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 iln_s def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 iln_r def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得 fln def join(l, s=''): return s.join(l) #リストを文字列に変換 join l l s='' s '' def perm(l, n): return itertools.permutations(l, n) # 順列取得 perm l l n n def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数 perm_count n n r r def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 comb l l n n def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数 comb_count n n r r def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離 two_distance a a b b c c d d def m_add(a,b): return (a+b) % MOD m_add a a b b def print_list(l): print(*l, sep='\n') print_list l l def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime sieves_of_e is_prime = [True] * (n+1) is_prime [True] * (n+1) [True] True n+1 n 1 is_prime[0] = False is_prime[0] is_prime 0 False is_prime[1] = False is_prime[1] is_prime 1 False for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
     i range(2, int(n**0.5)+1) range 2 int(n**0.5)+1 int(n**0.5) int n**0.5 n 0.5 1 if not is_prime[i]: continue
         not is_prime[i] is_prime[i] is_prime i for j in range(i * 2, n+1, i): is_prime[j] = False
     j range(i * 2, n+1, i) range i * 2 i 2 n+1 n 1 i return is_prime is_prime n n S = list(input()) S list(input()) list input() input K = iin() K iin() iin s = copy.deepcopy(S) s copy.deepcopy(S) copy.deepcopy copy deepcopy S last_update = False last_update False count1 = 0 count1 0 for si in range(1, len(s)):
    if s[si-1] == s[si]:
        s[si] = '?'
        count1 += 1
        if si == len(s)-1:
            last_update = True si range(1, len(s)) range 1 len(s) len s if s[si-1] == s[si]:
        s[si] = '?'
        count1 += 1
        if si == len(s)-1:
            last_update = True s[si-1] == s[si] s[si-1] s si-1 si 1 s[si] s si s[si] = '?' s[si] s si '?' count1 += 1 count1 1 if si == len(s)-1:
            last_update = True si == len(s)-1 si len(s)-1 len(s) len s 1 last_update = True last_update True count2 = 0 count2 0 last_update2 = False last_update2 False if not last_update and S[0] == S[-1]:
    count2 = 1
    S2 = list('?')
    S2.extend(S[1:])
    for i in range(2, len(S2)):
        if S2[i-1] == S2[i]:
            S2[i] = '?'
            count2 += 1
            if i == len(S2)-1:
                last_update2 = True not last_update and S[0] == S[-1] not last_update last_update S[0] == S[-1] S[0] S 0 S[-1] S -1 count2 = 1 count2 1 S2 = list('?') S2 list('?') list '?' S2.extend(S[1:]) S2.extend S2 extend S[1:] S 1: 1 for i in range(2, len(S2)):
        if S2[i-1] == S2[i]:
            S2[i] = '?'
            count2 += 1
            if i == len(S2)-1:
                last_update2 = True i range(2, len(S2)) range 2 len(S2) len S2 if S2[i-1] == S2[i]:
            S2[i] = '?'
            count2 += 1
            if i == len(S2)-1:
                last_update2 = True S2[i-1] == S2[i] S2[i-1] S2 i-1 i 1 S2[i] S2 i S2[i] = '?' S2[i] S2 i '?' count2 += 1 count2 1 if i == len(S2)-1:
                last_update2 = True i == len(S2)-1 i len(S2)-1 len(S2) len S2 1 last_update2 = True last_update2 True if len(S) ==1:
    print(len(S)*K//2)
elif K == 1:
    print(count1)
elif count2 == 0:
    print(K*count1)
else:
    if last_update2:
        count12 = count1+count2
        ans = count12*(K//2)
        if K % 2 == 1: 
            ans+= count1
        print(ans)
    else:
        print(count1 + count2*(K-1)) len(S) ==1 len(S) len S 1 print(len(S)*K//2) print len(S)*K//2 len(S)*K len(S) len S K 2 elif K == 1:
    print(count1) K == 1 K 1 print(count1) print count1 elif count2 == 0:
    print(K*count1) count2 == 0 count2 0 print(K*count1) print K*count1 K count1 if last_update2:
        count12 = count1+count2
        ans = count12*(K//2)
        if K % 2 == 1: 
            ans+= count1
        print(ans)
    else:
        print(count1 + count2*(K-1)) last_update2 count12 = count1+count2 count12 count1+count2 count1 count2 ans = count12*(K//2) ans count12*(K//2) count12 K//2 K 2 if K % 2 == 1: 
            ans+= count1
         K % 2 == 1 K % 2 K 2 1 ans+= count1 ans count1 print(ans) print ans print(count1 + count2*(K-1)) print count1 + count2*(K-1) count1 count2*(K-1) count2 K-1 K 1 def gcd(a,b):return fractions.gcd(a,b) #最大公約数 def gcd(a,b):return fractions.gcd(a,b) #最大公約数 gcd def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離 def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離 two_distance def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得 def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得 iln def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime sieves_of_e last_update = False False last_update def imn(): return map(int, sys.stdin.readline().split()) #整数map取得 def imn(): return map(int, sys.stdin.readline().split()) #整数map取得 imn def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 comb def isn(): return sys.stdin.readline().split() #文字列読み込み def isn(): return sys.stdin.readline().split() #文字列読み込み isn def iin(): return int(sys.stdin.readline()) #整数読み込み def iin(): return int(sys.stdin.readline()) #整数読み込み iin count2 = 1 1 count2 MOD = 10**9+7 10**9+7 MOD count1 = 0 0 count1 def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 iln_r def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得 def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得 fln K = iin() iin() K last_update = True True last_update def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得 def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得 fmn def print_list(l): print(*l, sep='\n') def print_list(l): print(*l, sep='\n') print_list last_update2 = False False last_update2 INF = float('inf') float('inf') INF count1 += 1 1 count1 def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数 def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数 comb_count S2 = list('?') list('?') S2 count2 += 1 1 count2 s = copy.deepcopy(S) copy.deepcopy(S) s count2 = 0 0 count2 def m_add(a,b): return (a+b) % MOD def m_add(a,b): return (a+b) % MOD m_add def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み ifn S = list(input()) list(input()) S ans = count12*(K//2) count12*(K//2) ans def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 iln_s def join(l, s=''): return s.join(l) #リストを文字列に変換 def join(l, s=''): return s.join(l) #リストを文字列に変換 join def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得 def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得 imnn def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数 def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数 perm_count count12 = count1+count2 count1+count2 count12 ans+= count1 count1 ans def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数 def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数 lcm last_update2 = True True last_update2 def perm(l, n): return itertools.permutations(l, n) # 順列取得 def perm(l, n): return itertools.permutations(l, n) # 順列取得 perm
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

S = list(input())
K = iin()
s = copy.deepcopy(S)
last_update = False
count1 = 0
for si in range(1, len(s)):
    if s[si-1] == s[si]:
        s[si] = '?'
        count1 += 1
        if si == len(s)-1:
            last_update = True
count2 = 0
last_update2 = False
if not last_update and S[0] == S[-1]:
    count2 = 1
    S2 = list('?')
    S2.extend(S[1:])
    for i in range(2, len(S2)):
        if S2[i-1] == S2[i]:
            S2[i] = '?'
            count2 += 1
            if i == len(S2)-1:
                last_update2 = True
if len(S) ==1:
    print(len(S)*K//2)
elif K == 1:
    print(count1)
elif count2 == 0:
    print(K*count1)
else:
    if last_update2:
        count12 = count1+count2
        ans = count12*(K//2)
        if K % 2 == 1: 
            ans+= count1
        print(ans)
    else:
        print(count1 + count2*(K-1))