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

tmp = 1
count = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        tmp += 1
    else:
        count += tmp // 2
        tmp = 1
count += tmp//2

if len(set(s))==1:
    print(len(s)*k//2)
else:
    if s[0] != s[-1]:
        print(count*k)
    else:
        h = 0
        for i in s:
            if i != s[0]:
                break
            else:
                h += 1
        t = 0
        for i in s[::-1]:
            if i != s[-1]:
                break
            else:
                t += 1
        print(count*k-(h//2+t//2-(h+t)//2)*(k-1)) s = input() s input() input k = int(input()) k int(input()) int input() input tmp = 1 tmp 1 count = 0 count 0 for i in range(len(s)-1):
    if s[i] == s[i+1]:
        tmp += 1
    else:
        count += tmp // 2
        tmp = 1 i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i] == s[i+1]:
        tmp += 1
    else:
        count += tmp // 2
        tmp = 1 s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 tmp += 1 tmp 1 count += tmp // 2 count tmp // 2 tmp 2 tmp = 1 tmp 1 count += tmp//2 count tmp//2 tmp 2 if len(set(s))==1:
    print(len(s)*k//2)
else:
    if s[0] != s[-1]:
        print(count*k)
    else:
        h = 0
        for i in s:
            if i != s[0]:
                break
            else:
                h += 1
        t = 0
        for i in s[::-1]:
            if i != s[-1]:
                break
            else:
                t += 1
        print(count*k-(h//2+t//2-(h+t)//2)*(k-1)) len(set(s))==1 len(set(s)) len set(s) set s 1 print(len(s)*k//2) print len(s)*k//2 len(s)*k len(s) len s k 2 if s[0] != s[-1]:
        print(count*k)
    else:
        h = 0
        for i in s:
            if i != s[0]:
                break
            else:
                h += 1
        t = 0
        for i in s[::-1]:
            if i != s[-1]:
                break
            else:
                t += 1
        print(count*k-(h//2+t//2-(h+t)//2)*(k-1)) s[0] != s[-1] s[0] s 0 s[-1] s -1 print(count*k) print count*k count k h = 0 h 0 for i in s:
            if i != s[0]:
                break
            else:
                h += 1
         i s if i != s[0]:
                break
            else:
                h += 1
         i != s[0] i s[0] s 0 break h += 1 h 1 t = 0 t 0 for i in s[::-1]:
            if i != s[-1]:
                break
            else:
                t += 1
         i s[::-1] s ::-1 -1 if i != s[-1]:
                break
            else:
                t += 1
         i != s[-1] i s[-1] s -1 break t += 1 t 1 print(count*k-(h//2+t//2-(h+t)//2)*(k-1)) print count*k-(h//2+t//2-(h+t)//2)*(k-1) count*k count k (h//2+t//2-(h+t)//2)*(k-1) h//2+t//2-(h+t)//2 h//2+t//2 h//2 h 2 t//2 t 2 (h+t)//2 h+t h t 2 k-1 k 1 t = 0 0 t tmp = 1 1 tmp h = 0 0 h count += tmp // 2 tmp // 2 count count += tmp//2 tmp//2 count h += 1 1 h t += 1 1 t tmp = 1 1 tmp tmp += 1 1 tmp count = 0 0 count k = int(input()) int(input()) k s = input() input() s
s = input()
k = int(input())

tmp = 1
count = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        tmp += 1
    else:
        count += tmp // 2
        tmp = 1
count += tmp//2

if len(set(s))==1:
    print(len(s)*k//2)
else:
    if s[0] != s[-1]:
        print(count*k)
    else:
        h = 0
        for i in s:
            if i != s[0]:
                break
            else:
                h += 1
        t = 0
        for i in s[::-1]:
            if i != s[-1]:
                break
            else:
                t += 1
        print(count*k-(h//2+t//2-(h+t)//2)*(k-1))
