# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

s = input()
K = ir()
ind = len(s)-1
while ind > 0 and s[ind] == s[ind-1]:
    ind-=1
if ind == 0:
    print(len(s)*K//2)
else:
    tmp = ''.join([s[ind:], s[:ind]])
    k = 0
    ans_div = 0
    pre = ''
    for c in tmp:
        if c != pre:
            ans_div+=((k+1)//2)
            k=0
        else:
            k+=1
        pre = c
    ans_div +=((k+1)//2)
    fir = s[:ind]
    firc = 0
    las = s[ind:]
    lasc = 0
    k = 0
    pre = ''
    for c in fir:
        if c != pre:
            firc+=((k+1)//2)
            k=0
        else:
            k+=1
        pre = c
    firc += ((k+1)//2)
    k = 0
    pre = ''
    for c in las:
        if c != pre:
            lasc+=((k+1)//2)
            k=0
        else:
            k+=1
        pre = c
    lasc += ((k+1)//2)
    print(firc+lasc+ans_div*(K-1)) import math math import fractions fractions import sys sys import bisect bisect import heapq heapq import collections collections from collections import Counter from collections import deque import pprint pprint import itertools itertools sr = lambda: input() sr lambda: input() input() input ir = lambda: int(sr()) ir lambda: int(sr()) int(sr()) int sr() sr lr = lambda: list(map(int, sr().split())) lr lambda: list(map(int, sr().split())) list(map(int, sr().split())) list map(int, sr().split()) map int sr().split() ().split () sr split """nを素因数分解""" """2以上の整数n => [[素因数, 指数], ...]の2次元リスト""" def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n factorization arr = [] arr [] temp = n temp n if n == 1:
        return arr

     n == 1 n 1 return arr arr for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

     i range(2, int(-(-n ** 0.5 // 1)) + 1) range 2 int(-(-n ** 0.5 // 1)) + 1 int(-(-n ** 0.5 // 1)) int -(-n ** 0.5 // 1) -n ** 0.5 // 1 -n ** 0.5 n ** 0.5 n 0.5 1 1 if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

     temp % i == 0 temp % i temp i 0 cnt = 0 cnt 0 while temp % i == 0:
                cnt += 1
                temp //= i
             temp % i == 0 temp % i temp i 0 cnt += 1 cnt 1 temp //= i temp i arr.append([i, cnt]) arr.append arr append [i, cnt] i cnt if temp != 1:
        arr.append([temp, 1])

     temp != 1 temp 1 arr.append([temp, 1]) arr.append arr append [temp, 1] temp 1 if arr == []:
        arr.append([n, 1])

     arr == [] arr [] arr.append([n, 1]) arr.append arr append [n, 1] n 1 return arr arr n n def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l power x = 1 x 1 while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
     n if n & 1:
            x *= a % mod
         n & 1 n 1 x *= a % mod x a % mod a mod n >>= 1 n 1 a *= a % mod a a % mod a mod return x % mod x % mod x mod a a n n mod mod def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a kaijo if n == 0:
        return 1
     n == 0 n 0 return 1 1 a = n a n tmp = n - 1 tmp n - 1 n 1 while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
     tmp >= l tmp l a = a * tmp % mod a a * tmp % mod a * tmp a tmp mod tmp -= 1 tmp 1 return a a n n l l mod mod inf = 10 ** 18 inf 10 ** 18 10 18 mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 s = input() s input() input K = ir() K ir() ir ind = len(s)-1 ind len(s)-1 len(s) len s 1 while ind > 0 and s[ind] == s[ind-1]:
    ind-=1 ind > 0 and s[ind] == s[ind-1] ind > 0 ind 0 s[ind] == s[ind-1] s[ind] s ind s[ind-1] s ind-1 ind 1 ind-=1 ind 1 if ind == 0:
    print(len(s)*K//2)
else:
    tmp = ''.join([s[ind:], s[:ind]])
    k = 0
    ans_div = 0
    pre = ''
    for c in tmp:
        if c != pre:
            ans_div+=((k+1)//2)
            k=0
        else:
            k+=1
        pre = c
    ans_div +=((k+1)//2)
    fir = s[:ind]
    firc = 0
    las = s[ind:]
    lasc = 0
    k = 0
    pre = ''
    for c in fir:
        if c != pre:
            firc+=((k+1)//2)
            k=0
        else:
            k+=1
        pre = c
    firc += ((k+1)//2)
    k = 0
    pre = ''
    for c in las:
        if c != pre:
            lasc+=((k+1)//2)
            k=0
        else:
            k+=1
        pre = c
    lasc += ((k+1)//2)
    print(firc+lasc+ans_div*(K-1)) ind == 0 ind 0 print(len(s)*K//2) print len(s)*K//2 len(s)*K len(s) len s K 2 tmp = ''.join([s[ind:], s[:ind]]) tmp ''.join([s[ind:], s[:ind]]) ''.join '' join [s[ind:], s[:ind]] s[ind:] s ind: ind s[:ind] s :ind ind k = 0 k 0 ans_div = 0 ans_div 0 pre = '' pre '' for c in tmp:
        if c != pre:
            ans_div+=((k+1)//2)
            k=0
        else:
            k+=1
        pre = c
     c tmp if c != pre:
            ans_div+=((k+1)//2)
            k=0
        else:
            k+=1
         c != pre c pre ans_div+=((k+1)//2) ans_div (k+1)//2 k+1 k 1 2 k=0 k 0 k+=1 k 1 pre = c pre c ans_div +=((k+1)//2) ans_div (k+1)//2 k+1 k 1 2 fir = s[:ind] fir s[:ind] s :ind ind firc = 0 firc 0 las = s[ind:] las s[ind:] s ind: ind lasc = 0 lasc 0 k = 0 k 0 pre = '' pre '' for c in fir:
        if c != pre:
            firc+=((k+1)//2)
            k=0
        else:
            k+=1
        pre = c
     c fir if c != pre:
            firc+=((k+1)//2)
            k=0
        else:
            k+=1
         c != pre c pre firc+=((k+1)//2) firc (k+1)//2 k+1 k 1 2 k=0 k 0 k+=1 k 1 pre = c pre c firc += ((k+1)//2) firc (k+1)//2 k+1 k 1 2 k = 0 k 0 pre = '' pre '' for c in las:
        if c != pre:
            lasc+=((k+1)//2)
            k=0
        else:
            k+=1
        pre = c
     c las if c != pre:
            lasc+=((k+1)//2)
            k=0
        else:
            k+=1
         c != pre c pre lasc+=((k+1)//2) lasc (k+1)//2 k+1 k 1 2 k=0 k 0 k+=1 k 1 pre = c pre c lasc += ((k+1)//2) lasc (k+1)//2 k+1 k 1 2 print(firc+lasc+ans_div*(K-1)) print firc+lasc+ans_div*(K-1) firc+lasc firc lasc ans_div*(K-1) ans_div K-1 K 1 k=0 0 k firc += ((k+1)//2) (k+1)//2 firc pre = c c pre fir = s[:ind] s[:ind] fir inf = 10 ** 18 10 ** 18 inf tmp = ''.join([s[ind:], s[:ind]]) ''.join([s[ind:], s[:ind]]) tmp firc = 0 0 firc pre = '' '' pre pre = c c pre mod = 10 ** 9 + 7 10 ** 9 + 7 mod def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n factorization k+=1 1 k k+=1 1 k pre = c c pre firc+=((k+1)//2) (k+1)//2 firc lasc+=((k+1)//2) (k+1)//2 lasc pre = '' '' pre lasc = 0 0 lasc def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a kaijo ind-=1 1 ind def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l power pre = '' '' pre ind = len(s)-1 len(s)-1 ind ans_div +=((k+1)//2) (k+1)//2 ans_div ans_div+=((k+1)//2) (k+1)//2 ans_div las = s[ind:] s[ind:] las sr = lambda: input() lambda: input() sr k = 0 0 k ans_div = 0 0 ans_div ir = lambda: int(sr()) lambda: int(sr()) ir k = 0 0 k s = input() input() s k=0 0 k K = ir() ir() K lr = lambda: list(map(int, sr().split())) lambda: list(map(int, sr().split())) lr k = 0 0 k lasc += ((k+1)//2) (k+1)//2 lasc k=0 0 k k+=1 1 k
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

s = input()
K = ir()
ind = len(s)-1
while ind > 0 and s[ind] == s[ind-1]:
    ind-=1
if ind == 0:
    print(len(s)*K//2)
else:
    tmp = ''.join([s[ind:], s[:ind]])
    k = 0
    ans_div = 0
    pre = ''
    for c in tmp:
        if c != pre:
            ans_div+=((k+1)//2)
            k=0
        else:
            k+=1
        pre = c
    ans_div +=((k+1)//2)
    fir = s[:ind]
    firc = 0
    las = s[ind:]
    lasc = 0
    k = 0
    pre = ''
    for c in fir:
        if c != pre:
            firc+=((k+1)//2)
            k=0
        else:
            k+=1
        pre = c
    firc += ((k+1)//2)
    k = 0
    pre = ''
    for c in las:
        if c != pre:
            lasc+=((k+1)//2)
            k=0
        else:
            k+=1
        pre = c
    lasc += ((k+1)//2)
    print(firc+lasc+ans_div*(K-1))