import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 1
ans = 0
inf = float("inf")

s = s()
k = k()

if s[0]*len(s) == s:
    print(len(s)*k // 2)
    sys.exit()

res = [1]

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        res[-1] += 1
    else:
        res.append(1)

for i in res:
    ans += (i//2)*k
if s[0] == s[-1]:
    diff = (res[0]+res[-1])//2 - (res[0]//2 + res[-1]//2)
    ans += diff*(k-1)
print(ans) import sys sys import math math import itertools itertools import bisect bisect from copy import copy from collections import deque,Counter from decimal import Decimal import functools functools def s(): return input() s def k(): return int(input()) k def S(): return input().split() S def I(): return map(int,input().split()) I def X(): return list(input()) X def L(): return list(input().split()) L def l(): return list(map(int,input().split())) l def lcm(a,b): return a*b//math.gcd(a,b) lcm a a b b sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 cnt = 1 cnt 1 ans = 0 ans 0 inf = float("inf") inf float("inf") float "inf" s = s() s s() s k = k() k k() k if s[0]*len(s) == s:
    print(len(s)*k // 2)
    sys.exit() s[0]*len(s) == s s[0]*len(s) s[0] s 0 len(s) len s s 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 res = [1] res [1] 1 for i in range(len(s)-1):
    if s[i] == s[i+1]:
        res[-1] += 1
    else:
        res.append(1) i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i] == s[i+1]:
        res[-1] += 1
    else:
        res.append(1) s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 res[-1] += 1 res[-1] res -1 1 res.append(1) res.append res append 1 for i in res:
    ans += (i//2)*k i res ans += (i//2)*k ans (i//2)*k i//2 i 2 k if s[0] == s[-1]:
    diff = (res[0]+res[-1])//2 - (res[0]//2 + res[-1]//2)
    ans += diff*(k-1) s[0] == s[-1] s[0] s 0 s[-1] s -1 diff = (res[0]+res[-1])//2 - (res[0]//2 + res[-1]//2) diff (res[0]+res[-1])//2 - (res[0]//2 + res[-1]//2) (res[0]+res[-1])//2 res[0]+res[-1] res[0] res 0 res[-1] res -1 2 res[0]//2 + res[-1]//2 res[0]//2 res[0] res 0 2 res[-1]//2 res[-1] res -1 2 ans += diff*(k-1) ans diff*(k-1) diff k-1 k 1 print(ans) print ans ans += diff*(k-1) diff*(k-1) ans def l(): return list(map(int,input().split())) def l(): return list(map(int,input().split())) l def X(): return list(input()) def X(): return list(input()) X mod = 10**9+7 10**9+7 mod ans = 0 0 ans def S(): return input().split() def S(): return input().split() S def k(): return int(input()) def k(): return int(input()) k s = s() s() s res = [1] [1] res ans += (i//2)*k (i//2)*k ans def s(): return input() def s(): return input() s k = k() k() k def L(): return list(input().split()) def L(): return list(input().split()) L def lcm(a,b): return a*b//math.gcd(a,b) def lcm(a,b): return a*b//math.gcd(a,b) lcm cnt = 1 1 cnt inf = float("inf") float("inf") inf diff = (res[0]+res[-1])//2 - (res[0]//2 + res[-1]//2) (res[0]+res[-1])//2 - (res[0]//2 + res[-1]//2) diff def I(): return map(int,input().split()) def I(): return map(int,input().split()) I
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 1
ans = 0
inf = float("inf")

s = s()
k = k()

if s[0]*len(s) == s:
    print(len(s)*k // 2)
    sys.exit()

res = [1]

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        res[-1] += 1
    else:
        res.append(1)

for i in res:
    ans += (i//2)*k
if s[0] == s[-1]:
    diff = (res[0]+res[-1])//2 - (res[0]//2 + res[-1]//2)
    ans += diff*(k-1)
print(ans)
