#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
S = input()
k = I()
from itertools import groupby
x = y = 0
g = [len(list(v)) for k,v in groupby(S)]
for c in g:
    x += c//2
if S[-1] == S[0]:
    if g[-1]%2 == 0 or g[0]%2 == 0:
        pass
    elif len(S) == 1:
        y = k//2
    elif len(S) == g[0]:
        y = k//2
    else:
        y = k-1
print(x * k + y) from fractions import gcd from itertools import combinations,permutations,accumulate from collections import deque,defaultdict,Counter import sys sys sys.setrecursionlimit(10000000) sys.setrecursionlimit sys setrecursionlimit 10000000 mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 def readInts():
  return list(map(int,input().split())) readInts return list(map(int,input().split())) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split def I():
  return int(input()) I return int(input()) int(input()) int input() input S = input() S input() input k = I() k I() I from itertools import groupby x = y = 0 x 0 = y = 0 y 0 len(list(v)) for k,v in groupby(S) for k,v in groupby(S) k v groupby(S) groupby S for k,v in groupby(S) len(list(v)) len list(v) list v g = [len(list(v)) for k,v in groupby(S)] g [len(list(v)) for k,v in groupby(S)] for c in g:
    x += c//2 c g x += c//2 x c//2 c 2 if S[-1] == S[0]:
    if g[-1]%2 == 0 or g[0]%2 == 0:
        pass
    elif len(S) == 1:
        y = k//2
    elif len(S) == g[0]:
        y = k//2
    else:
        y = k-1 S[-1] == S[0] S[-1] S -1 S[0] S 0 if g[-1]%2 == 0 or g[0]%2 == 0:
        pass
    elif len(S) == 1:
        y = k//2
    elif len(S) == g[0]:
        y = k//2
    else:
        y = k-1 g[-1]%2 == 0 or g[0]%2 == 0 g[-1]%2 == 0 g[-1]%2 g[-1] g -1 2 0 g[0]%2 == 0 g[0]%2 g[0] g 0 2 0 elif len(S) == 1:
        y = k//2
     len(S) == 1 len(S) len S 1 y = k//2 y k//2 k 2 elif len(S) == g[0]:
        y = k//2
     len(S) == g[0] len(S) len S g[0] g 0 y = k//2 y k//2 k 2 y = k-1 y k-1 k 1 print(x * k + y) print x * k + y x * k x k y g = [len(list(v)) for k,v in groupby(S)] [len(list(v)) for k,v in groupby(S)] g k = I() I() k y = k-1 k-1 y mod = 10**9 + 7 10**9 + 7 mod S = input() input() S y = 0 0 y y = k//2 k//2 y x += c//2 c//2 x x = y = 0 0 x def I():
  return int(input()) def I():
  return int(input()) I y = k//2 k//2 y def readInts():
  return list(map(int,input().split())) def readInts():
  return list(map(int,input().split())) readInts
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
S = input()
k = I()
from itertools import groupby
x = y = 0
g = [len(list(v)) for k,v in groupby(S)]
for c in g:
    x += c//2
if S[-1] == S[0]:
    if g[-1]%2 == 0 or g[0]%2 == 0:
        pass
    elif len(S) == 1:
        y = k//2
    elif len(S) == g[0]:
        y = k//2
    else:
        y = k-1
print(x * k + y)
