import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
k = INT()
ans = 0
a = 0
b = 0
if s[0] == s[-1]:
    if len(set(s)) == 1:
        ans = len(s) * k // 2
        print(ans)
        exit()
    for j in range(len(s)):
        if s[0] == s[j]:
            a += 1
        else:
            break
    for j in reversed(range(len(s))):
        if s[-1] == s[j]:
            b += 1
        else:
            break
    ans = a // 2 + b // 2 + (a + b) // 2 * (k - 1)
i = a
ans2 = 0
while i < len(s) - b:
    tmp = 1
    for j in range(i + 1, len(s)):
        if s[i] == s[j]:
            tmp += 1
        else:
            break
    i += tmp
    tmp //= 2
    ans2 += tmp
print(ans + ans2 * k) import sys, re, os sys re os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() input def STR(): return input() STR def INT(): return int(input()) INT def MAP(): return map(int, input().split()) MAP def S_MAP(): return map(str, input().split()) S_MAP def LIST(): return list(map(int, input().split())) LIST def S_LIST(): return list(map(str, input().split())) S_LIST sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 inf = sys.maxsize inf sys.maxsize sys maxsize mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 s = STR() s STR() STR k = INT() k INT() INT ans = 0 ans 0 a = 0 a 0 b = 0 b 0 if s[0] == s[-1]:
    if len(set(s)) == 1:
        ans = len(s) * k // 2
        print(ans)
        exit()
    for j in range(len(s)):
        if s[0] == s[j]:
            a += 1
        else:
            break
    for j in reversed(range(len(s))):
        if s[-1] == s[j]:
            b += 1
        else:
            break
    ans = a // 2 + b // 2 + (a + b) // 2 * (k - 1) s[0] == s[-1] s[0] s 0 s[-1] s -1 if len(set(s)) == 1:
        ans = len(s) * k // 2
        print(ans)
        exit()
     len(set(s)) == 1 len(set(s)) len set(s) set s 1 ans = len(s) * k // 2 ans len(s) * k // 2 len(s) * k len(s) len s k 2 print(ans) print ans exit() exit for j in range(len(s)):
        if s[0] == s[j]:
            a += 1
        else:
            break
     j range(len(s)) range len(s) len s if s[0] == s[j]:
            a += 1
        else:
            break
     s[0] == s[j] s[0] s 0 s[j] s j a += 1 a 1 break for j in reversed(range(len(s))):
        if s[-1] == s[j]:
            b += 1
        else:
            break
     j reversed(range(len(s))) reversed range(len(s)) range len(s) len s if s[-1] == s[j]:
            b += 1
        else:
            break
     s[-1] == s[j] s[-1] s -1 s[j] s j b += 1 b 1 break ans = a // 2 + b // 2 + (a + b) // 2 * (k - 1) ans a // 2 + b // 2 + (a + b) // 2 * (k - 1) a // 2 + b // 2 a // 2 a 2 b // 2 b 2 (a + b) // 2 * (k - 1) (a + b) // 2 a + b a b 2 k - 1 k 1 i = a i a ans2 = 0 ans2 0 while i < len(s) - b:
    tmp = 1
    for j in range(i + 1, len(s)):
        if s[i] == s[j]:
            tmp += 1
        else:
            break
    i += tmp
    tmp //= 2
    ans2 += tmp i < len(s) - b i len(s) - b len(s) len s b tmp = 1 tmp 1 for j in range(i + 1, len(s)):
        if s[i] == s[j]:
            tmp += 1
        else:
            break
     j range(i + 1, len(s)) range i + 1 i 1 len(s) len s if s[i] == s[j]:
            tmp += 1
        else:
            break
     s[i] == s[j] s[i] s i s[j] s j tmp += 1 tmp 1 break i += tmp i tmp tmp //= 2 tmp 2 ans2 += tmp ans2 tmp print(ans + ans2 * k) print ans + ans2 * k ans ans2 * k ans2 k def MAP(): return map(int, input().split()) def MAP(): return map(int, input().split()) MAP def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input def INT(): return int(input()) def INT(): return int(input()) INT s = STR() STR() s b += 1 1 b def S_MAP(): return map(str, input().split()) def S_MAP(): return map(str, input().split()) S_MAP i = a a i b = 0 0 b def S_LIST(): return list(map(str, input().split())) def S_LIST(): return list(map(str, input().split())) S_LIST a += 1 1 a ans = len(s) * k // 2 len(s) * k // 2 ans ans2 += tmp tmp ans2 def LIST(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) LIST mod = 10 ** 9 + 7 10 ** 9 + 7 mod ans = 0 0 ans ans = a // 2 + b // 2 + (a + b) // 2 * (k - 1) a // 2 + b // 2 + (a + b) // 2 * (k - 1) ans tmp += 1 1 tmp tmp = 1 1 tmp ans2 = 0 0 ans2 tmp //= 2 2 tmp def STR(): return input() def STR(): return input() STR i += tmp tmp i k = INT() INT() k a = 0 0 a inf = sys.maxsize sys.maxsize inf
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
k = INT()
ans = 0
a = 0
b = 0
if s[0] == s[-1]:
    if len(set(s)) == 1:
        ans = len(s) * k // 2
        print(ans)
        exit()
    for j in range(len(s)):
        if s[0] == s[j]:
            a += 1
        else:
            break
    for j in reversed(range(len(s))):
        if s[-1] == s[j]:
            b += 1
        else:
            break
    ans = a // 2 + b // 2 + (a + b) // 2 * (k - 1)
i = a
ans2 = 0
while i < len(s) - b:
    tmp = 1
    for j in range(i + 1, len(s)):
        if s[i] == s[j]:
            tmp += 1
        else:
            break
    i += tmp
    tmp //= 2
    ans2 += tmp
print(ans + ans2 * k)