s = str(input())
k = int(input())
 
n = len(s)
l = [0] * n

for i in range(n-1):
    if s[i] == s[i+1] and l[i] == 0:
        l[i+1] = 1

if s.count(s[0]) == n:
    print(n*k//2)
elif s[0] != s[-1]:
    print(sum(l) * k)
else:
    a = 0
    b = 0
    ac = True
    bc = True
    for i in range(n-1):
        if s[i] == s[0] and ac == True:
            a += 1
        elif s[i] != s[0]:
            ac = False
        if s[n-1-i] == s[n-1] and bc == True:
            b += 1
        else: bc = False  
    sub = a//2 + b//2 - (a+b)//2
    print(sum(l)*k - sub*(k-1)) s = str(input()) s str(input()) str input() input k = int(input()) k int(input()) int input() input n = len(s) n len(s) len s l = [0] * n l [0] * n [0] 0 n for i in range(n-1):
    if s[i] == s[i+1] and l[i] == 0:
        l[i+1] = 1 i range(n-1) range n-1 n 1 if s[i] == s[i+1] and l[i] == 0:
        l[i+1] = 1 s[i] == s[i+1] and l[i] == 0 s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 l[i] == 0 l[i] l i 0 l[i+1] = 1 l[i+1] l i+1 i 1 1 if s.count(s[0]) == n:
    print(n*k//2)
elif s[0] != s[-1]:
    print(sum(l) * k)
else:
    a = 0
    b = 0
    ac = True
    bc = True
    for i in range(n-1):
        if s[i] == s[0] and ac == True:
            a += 1
        elif s[i] != s[0]:
            ac = False
        if s[n-1-i] == s[n-1] and bc == True:
            b += 1
        else: bc = False  
    sub = a//2 + b//2 - (a+b)//2
    print(sum(l)*k - sub*(k-1)) s.count(s[0]) == n s.count(s[0]) s.count s count s[0] s 0 n print(n*k//2) print n*k//2 n*k n k 2 elif s[0] != s[-1]:
    print(sum(l) * k) s[0] != s[-1] s[0] s 0 s[-1] s -1 print(sum(l) * k) print sum(l) * k sum(l) sum l k a = 0 a 0 b = 0 b 0 ac = True ac True bc = True bc True for i in range(n-1):
        if s[i] == s[0] and ac == True:
            a += 1
        elif s[i] != s[0]:
            ac = False
        if s[n-1-i] == s[n-1] and bc == True:
            b += 1
        else: bc = False  
     i range(n-1) range n-1 n 1 if s[i] == s[0] and ac == True:
            a += 1
        elif s[i] != s[0]:
            ac = False
         s[i] == s[0] and ac == True s[i] == s[0] s[i] s i s[0] s 0 ac == True ac True a += 1 a 1 elif s[i] != s[0]:
            ac = False
         s[i] != s[0] s[i] s i s[0] s 0 ac = False ac False if s[n-1-i] == s[n-1] and bc == True:
            b += 1
        else: bc = False  
     s[n-1-i] == s[n-1] and bc == True s[n-1-i] == s[n-1] s[n-1-i] s n-1-i n-1 n 1 i s[n-1] s n-1 n 1 bc == True bc True b += 1 b 1 sub = a//2 + b//2 - (a+b)//2 sub a//2 + b//2 - (a+b)//2 a//2 + b//2 a//2 a 2 b//2 b 2 (a+b)//2 a+b a b 2 print(sum(l)*k - sub*(k-1)) print sum(l)*k - sub*(k-1) sum(l)*k sum(l) sum l k sub*(k-1) sub k-1 k 1 a += 1 1 a b = 0 0 b a = 0 0 a ac = True True ac n = len(s) len(s) n b += 1 1 b k = int(input()) int(input()) k sub = a//2 + b//2 - (a+b)//2 a//2 + b//2 - (a+b)//2 sub l = [0] * n [0] * n l s = str(input()) str(input()) s ac = False False ac bc = True True bc
s = str(input())
k = int(input())
 
n = len(s)
l = [0] * n

for i in range(n-1):
    if s[i] == s[i+1] and l[i] == 0:
        l[i+1] = 1

if s.count(s[0]) == n:
    print(n*k//2)
elif s[0] != s[-1]:
    print(sum(l) * k)
else:
    a = 0
    b = 0
    ac = True
    bc = True
    for i in range(n-1):
        if s[i] == s[0] and ac == True:
            a += 1
        elif s[i] != s[0]:
            ac = False
        if s[n-1-i] == s[n-1] and bc == True:
            b += 1
        else: bc = False  
    sub = a//2 + b//2 - (a+b)//2
    print(sum(l)*k - sub*(k-1))