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

n = len(s)

s_ = list(s)
if len(set(s_)) == 1:
    print((n*k)//2)
    exit()

cur = s[0]
X = []
cnt = 0
for i in range(n):
    if s[i] != cur:
        X.append(cnt)
        cur = s[i]
        cnt = 1
    else:
        cnt += 1
else:
    X.append(cnt)

#print(X)
ans = 0
if s[0] != s[-1]:
    for x in X:
        ans += k*(x//2)
else:
    for i, x in enumerate(X):
        if i == 0 or i == len(X)-1:
            continue
        else:
            ans += k*(x//2)
    ans += X[0]//2
    ans += X[-1]//2
    ans += (k-1)*((X[0]+X[-1])//2)
print(ans) 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 s_ = list(s) s_ list(s) list s if len(set(s_)) == 1:
    print((n*k)//2)
    exit() len(set(s_)) == 1 len(set(s_)) len set(s_) set s_ 1 print((n*k)//2) print (n*k)//2 n*k n k 2 exit() exit cur = s[0] cur s[0] s 0 X = [] X [] cnt = 0 cnt 0 for i in range(n):
    if s[i] != cur:
        X.append(cnt)
        cur = s[i]
        cnt = 1
    else:
        cnt += 1
else:
    X.append(cnt)

#print(X) i range(n) range n if s[i] != cur:
        X.append(cnt)
        cur = s[i]
        cnt = 1
    else:
        cnt += 1 s[i] != cur s[i] s i cur X.append(cnt) X.append X append cnt cur = s[i] cur s[i] s i cnt = 1 cnt 1 cnt += 1 cnt 1 X.append(cnt) X.append X append cnt ans = 0 ans 0 if s[0] != s[-1]:
    for x in X:
        ans += k*(x//2)
else:
    for i, x in enumerate(X):
        if i == 0 or i == len(X)-1:
            continue
        else:
            ans += k*(x//2)
    ans += X[0]//2
    ans += X[-1]//2
    ans += (k-1)*((X[0]+X[-1])//2) s[0] != s[-1] s[0] s 0 s[-1] s -1 for x in X:
        ans += k*(x//2) x X ans += k*(x//2) ans k*(x//2) k x//2 x 2 for i, x in enumerate(X):
        if i == 0 or i == len(X)-1:
            continue
        else:
            ans += k*(x//2)
     i x enumerate(X) enumerate X if i == 0 or i == len(X)-1:
            continue
        else:
            ans += k*(x//2)
     i == 0 or i == len(X)-1 i == 0 i 0 i == len(X)-1 i len(X)-1 len(X) len X 1 continue ans += k*(x//2) ans k*(x//2) k x//2 x 2 ans += X[0]//2 ans X[0]//2 X[0] X 0 2 ans += X[-1]//2 ans X[-1]//2 X[-1] X -1 2 ans += (k-1)*((X[0]+X[-1])//2) ans (k-1)*((X[0]+X[-1])//2) k-1 k 1 (X[0]+X[-1])//2 X[0]+X[-1] X[0] X 0 X[-1] X -1 2 print(ans) print ans cnt += 1 1 cnt s = str(input()) str(input()) s ans += k*(x//2) k*(x//2) ans n = len(s) len(s) n cnt = 0 0 cnt X = [] [] X cur = s[i] s[i] cur k = int(input()) int(input()) k ans += X[0]//2 X[0]//2 ans cnt = 1 1 cnt ans = 0 0 ans ans += (k-1)*((X[0]+X[-1])//2) (k-1)*((X[0]+X[-1])//2) ans s_ = list(s) list(s) s_ cur = s[0] s[0] cur ans += X[-1]//2 X[-1]//2 ans ans += k*(x//2) k*(x//2) ans
s = str(input())
k = int(input())

n = len(s)

s_ = list(s)
if len(set(s_)) == 1:
    print((n*k)//2)
    exit()

cur = s[0]
X = []
cnt = 0
for i in range(n):
    if s[i] != cur:
        X.append(cnt)
        cur = s[i]
        cnt = 1
    else:
        cnt += 1
else:
    X.append(cnt)

#print(X)
ans = 0
if s[0] != s[-1]:
    for x in X:
        ans += k*(x//2)
else:
    for i, x in enumerate(X):
        if i == 0 or i == len(X)-1:
            continue
        else:
            ans += k*(x//2)
    ans += X[0]//2
    ans += X[-1]//2
    ans += (k-1)*((X[0]+X[-1])//2)
print(ans)
