import sys

s = list(input())
k = int(input())

if len(s)==1:
    if k==1:
        print(0)
    else:
        print(k//2)
    sys.exit()  

x = 0
while True:
    if s[x]!=s[x+1]:
        break
    x += 1
    if x == len(s)-1:
        print(len(s)*k//2)
        sys.exit()

if k==1 or s[0]!=s[-1]:
    x = 0
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            x += 1
            s[i+1] = 0
    print(x*k) 
    sys.exit()

if s[0]==s[-1]:
    b = 1
    x = 0
    while True:
        if s[x]==s[x+1]:
            b += 1
            x += 1
        else:
            break
    a = 1
    x = 0
    while True:
        if s[-1-x]==s[-2-x]:
            a += 1
            x += 1
        else:
            break
    x = 0
    for i in range(len(s)-1):
        if s[i]==s[0]:
            continue
        if s[i]==s[i+1]:
            x += 1
            s[i+1] = 0
    print(x*k+((a+b)//2)*(k-1)+a//2+b//2)
 import sys sys s = list(input()) s list(input()) list input() input k = int(input()) k int(input()) int input() input if len(s)==1:
    if k==1:
        print(0)
    else:
        print(k//2)
    sys.exit()   len(s)==1 len(s) len s 1 if k==1:
        print(0)
    else:
        print(k//2)
     k==1 k 1 print(0) print 0 print(k//2) print k//2 k 2 sys.exit() sys.exit sys exit x = 0 x 0 while True:
    if s[x]!=s[x+1]:
        break
    x += 1
    if x == len(s)-1:
        print(len(s)*k//2)
        sys.exit() True if s[x]!=s[x+1]:
        break
     s[x]!=s[x+1] s[x] s x s[x+1] s x+1 x 1 break x += 1 x 1 if x == len(s)-1:
        print(len(s)*k//2)
        sys.exit() x == len(s)-1 x 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 sys.exit() sys.exit sys exit if k==1 or s[0]!=s[-1]:
    x = 0
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            x += 1
            s[i+1] = 0
    print(x*k) 
    sys.exit() k==1 or s[0]!=s[-1] k==1 k 1 s[0]!=s[-1] s[0] s 0 s[-1] s -1 x = 0 x 0 for i in range(len(s)-1):
        if s[i]==s[i+1]:
            x += 1
            s[i+1] = 0
     i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i]==s[i+1]:
            x += 1
            s[i+1] = 0
     s[i]==s[i+1] s[i] s i s[i+1] s i+1 i 1 x += 1 x 1 s[i+1] = 0 s[i+1] s i+1 i 1 0 print(x*k) print x*k x k sys.exit() sys.exit sys exit if s[0]==s[-1]:
    b = 1
    x = 0
    while True:
        if s[x]==s[x+1]:
            b += 1
            x += 1
        else:
            break
    a = 1
    x = 0
    while True:
        if s[-1-x]==s[-2-x]:
            a += 1
            x += 1
        else:
            break
    x = 0
    for i in range(len(s)-1):
        if s[i]==s[0]:
            continue
        if s[i]==s[i+1]:
            x += 1
            s[i+1] = 0
    print(x*k+((a+b)//2)*(k-1)+a//2+b//2) s[0]==s[-1] s[0] s 0 s[-1] s -1 b = 1 b 1 x = 0 x 0 while True:
        if s[x]==s[x+1]:
            b += 1
            x += 1
        else:
            break
     True if s[x]==s[x+1]:
            b += 1
            x += 1
        else:
            break
     s[x]==s[x+1] s[x] s x s[x+1] s x+1 x 1 b += 1 b 1 x += 1 x 1 break a = 1 a 1 x = 0 x 0 while True:
        if s[-1-x]==s[-2-x]:
            a += 1
            x += 1
        else:
            break
     True if s[-1-x]==s[-2-x]:
            a += 1
            x += 1
        else:
            break
     s[-1-x]==s[-2-x] s[-1-x] s -1-x -1 x s[-2-x] s -2-x -2 x a += 1 a 1 x += 1 x 1 break x = 0 x 0 for i in range(len(s)-1):
        if s[i]==s[0]:
            continue
        if s[i]==s[i+1]:
            x += 1
            s[i+1] = 0
     i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i]==s[0]:
            continue
         s[i]==s[0] s[i] s i s[0] s 0 continue if s[i]==s[i+1]:
            x += 1
            s[i+1] = 0
     s[i]==s[i+1] s[i] s i s[i+1] s i+1 i 1 x += 1 x 1 s[i+1] = 0 s[i+1] s i+1 i 1 0 print(x*k+((a+b)//2)*(k-1)+a//2+b//2) print x*k+((a+b)//2)*(k-1)+a//2+b//2 x*k+((a+b)//2)*(k-1)+a//2 x*k+((a+b)//2)*(k-1) x*k x k ((a+b)//2)*(k-1) (a+b)//2 a+b a b 2 k-1 k 1 a//2 a 2 b//2 b 2 x = 0 0 x a += 1 1 a x += 1 1 x b += 1 1 b x += 1 1 x x += 1 1 x a = 1 1 a s = list(input()) list(input()) s x = 0 0 x b = 1 1 b k = int(input()) int(input()) k x = 0 0 x x += 1 1 x x = 0 0 x x = 0 0 x x += 1 1 x
import sys

s = list(input())
k = int(input())

if len(s)==1:
    if k==1:
        print(0)
    else:
        print(k//2)
    sys.exit()  

x = 0
while True:
    if s[x]!=s[x+1]:
        break
    x += 1
    if x == len(s)-1:
        print(len(s)*k//2)
        sys.exit()

if k==1 or s[0]!=s[-1]:
    x = 0
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            x += 1
            s[i+1] = 0
    print(x*k) 
    sys.exit()

if s[0]==s[-1]:
    b = 1
    x = 0
    while True:
        if s[x]==s[x+1]:
            b += 1
            x += 1
        else:
            break
    a = 1
    x = 0
    while True:
        if s[-1-x]==s[-2-x]:
            a += 1
            x += 1
        else:
            break
    x = 0
    for i in range(len(s)-1):
        if s[i]==s[0]:
            continue
        if s[i]==s[i+1]:
            x += 1
            s[i+1] = 0
    print(x*k+((a+b)//2)*(k-1)+a//2+b//2)

