s = input()
k = int(input())
di = []
cnt = 1
ans = 0
if len(s) > 1:
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            di.append(cnt)
            cnt = 1
    di.append(cnt)
    if di[0] != len(s):
        for j in di:
            ans += j//2
        ans *= k
        if s[0] == s[-1] and di[-1] % 2 == 1 and di[0] % 2 == 1:
            ans += k - 1
    else:
        ans = k*len(s)//2
else:
    ans = k//2
print(ans) s = input() s input() input k = int(input()) k int(input()) int input() input di = [] di [] cnt = 1 cnt 1 ans = 0 ans 0 if len(s) > 1:
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            di.append(cnt)
            cnt = 1
    di.append(cnt)
    if di[0] != len(s):
        for j in di:
            ans += j//2
        ans *= k
        if s[0] == s[-1] and di[-1] % 2 == 1 and di[0] % 2 == 1:
            ans += k - 1
    else:
        ans = k*len(s)//2
else:
    ans = k//2 len(s) > 1 len(s) len s 1 for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            di.append(cnt)
            cnt = 1
     i range(1,len(s)) range 1 len(s) len s if s[i] == s[i-1]:
            cnt += 1
        else:
            di.append(cnt)
            cnt = 1
     s[i] == s[i-1] s[i] s i s[i-1] s i-1 i 1 cnt += 1 cnt 1 di.append(cnt) di.append di append cnt cnt = 1 cnt 1 di.append(cnt) di.append di append cnt if di[0] != len(s):
        for j in di:
            ans += j//2
        ans *= k
        if s[0] == s[-1] and di[-1] % 2 == 1 and di[0] % 2 == 1:
            ans += k - 1
    else:
        ans = k*len(s)//2 di[0] != len(s) di[0] di 0 len(s) len s for j in di:
            ans += j//2
         j di ans += j//2 ans j//2 j 2 ans *= k ans k if s[0] == s[-1] and di[-1] % 2 == 1 and di[0] % 2 == 1:
            ans += k - 1
     s[0] == s[-1] and di[-1] % 2 == 1 and di[0] % 2 == 1 s[0] == s[-1] and di[-1] % 2 == 1 s[0] == s[-1] s[0] s 0 s[-1] s -1 di[-1] % 2 == 1 di[-1] % 2 di[-1] di -1 2 1 di[0] % 2 == 1 di[0] % 2 di[0] di 0 2 1 ans += k - 1 ans k - 1 k 1 ans = k*len(s)//2 ans k*len(s)//2 k*len(s) k len(s) len s 2 ans = k//2 ans k//2 k 2 print(ans) print ans ans = k//2 k//2 ans cnt = 1 1 cnt cnt = 1 1 cnt di = [] [] di ans = 0 0 ans ans *= k k ans ans += k - 1 k - 1 ans s = input() input() s k = int(input()) int(input()) k cnt += 1 1 cnt ans += j//2 j//2 ans ans = k*len(s)//2 k*len(s)//2 ans
s = input()
k = int(input())
di = []
cnt = 1
ans = 0
if len(s) > 1:
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            di.append(cnt)
            cnt = 1
    di.append(cnt)
    if di[0] != len(s):
        for j in di:
            ans += j//2
        ans *= k
        if s[0] == s[-1] and di[-1] % 2 == 1 and di[0] % 2 == 1:
            ans += k - 1
    else:
        ans = k*len(s)//2
else:
    ans = k//2
print(ans)