def solver(s, k):
    res = 0
    cnt = [1]
    for i in range(1, len(s)):
        if s[i] == s[i - 1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
    for x in cnt:
        res += (x // 2) * k

    if len(cnt) == 1: #全部同じ場合はここでおわり
        return (len(s) * k) // 2

    if s[0] == s[-1]:
        res -= (cnt[0] // 2) * (k - 1) + (cnt[-1] // 2) * (k - 1)
        res += ((cnt[0] + cnt[-1]) // 2) * (k - 1)
    return res

def solver2(s, k):
    t = []
    for _ in range(k):
        t += s
    res = 0
    cnt = 1
    for i in range(1, len(t)):
        if t[i] == t[i - 1]:
            cnt += 1
        else:
            res += cnt // 2
            cnt = 1
    res += cnt // 2
    return res

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

#ss = s
#kk = k
print(solver(s, k))
#print(solver2(ss, kk))

#　ランダムな英小文字列の生成
import random
import string

# n := 文字列の長さ
def randomCharacter(n):
   alphabet_m = string.ascii_lowercase
   return ''.join([random.choice(alphabet_m) for _ in range(n)])


#for i in range(40):
#    if i == 0:
#        st = 'aaaaaaaaa'
#    elif i == 1:
#        st = 'a'
#    else:
#        l = random.randrange(1, 10)
#        st = randomCharacter(l)
#    sstt = st
#    cnt = 4
#    cnst_st = st[:]
#    res1 = solver(st, cnt)
#    res2 = solver2(sstt, cnt)
#    if res1 == res2:        
#        print("OK!")
#    else:
#        print(''.join(cnst_st), res1, res2)
         def solver(s, k):
    res = 0
    cnt = [1]
    for i in range(1, len(s)):
        if s[i] == s[i - 1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
    for x in cnt:
        res += (x // 2) * k

    if len(cnt) == 1: #全部同じ場合はここでおわり
        return (len(s) * k) // 2

    if s[0] == s[-1]:
        res -= (cnt[0] // 2) * (k - 1) + (cnt[-1] // 2) * (k - 1)
        res += ((cnt[0] + cnt[-1]) // 2) * (k - 1)
    return res solver res = 0 res 0 cnt = [1] cnt [1] 1 for i in range(1, len(s)):
        if s[i] == s[i - 1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
     i range(1, len(s)) range 1 len(s) len s if s[i] == s[i - 1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
     s[i] == s[i - 1] s[i] s i s[i - 1] s i - 1 i 1 cnt[-1] += 1 cnt[-1] cnt -1 1 cnt.append(1) cnt.append cnt append 1 for x in cnt:
        res += (x // 2) * k

     x cnt res += (x // 2) * k res (x // 2) * k x // 2 x 2 k if len(cnt) == 1: #全部同じ場合はここでおわり
        return (len(s) * k) // 2

     len(cnt) == 1 len(cnt) len cnt 1 return (len(s) * k) // 2 (len(s) * k) // 2 len(s) * k len(s) len s k 2 if s[0] == s[-1]:
        res -= (cnt[0] // 2) * (k - 1) + (cnt[-1] // 2) * (k - 1)
        res += ((cnt[0] + cnt[-1]) // 2) * (k - 1)
     s[0] == s[-1] s[0] s 0 s[-1] s -1 res -= (cnt[0] // 2) * (k - 1) + (cnt[-1] // 2) * (k - 1) res (cnt[0] // 2) * (k - 1) + (cnt[-1] // 2) * (k - 1) (cnt[0] // 2) * (k - 1) cnt[0] // 2 cnt[0] cnt 0 2 k - 1 k 1 (cnt[-1] // 2) * (k - 1) cnt[-1] // 2 cnt[-1] cnt -1 2 k - 1 k 1 res += ((cnt[0] + cnt[-1]) // 2) * (k - 1) res ((cnt[0] + cnt[-1]) // 2) * (k - 1) (cnt[0] + cnt[-1]) // 2 cnt[0] + cnt[-1] cnt[0] cnt 0 cnt[-1] cnt -1 2 k - 1 k 1 return res res s s k k def solver2(s, k):
    t = []
    for _ in range(k):
        t += s
    res = 0
    cnt = 1
    for i in range(1, len(t)):
        if t[i] == t[i - 1]:
            cnt += 1
        else:
            res += cnt // 2
            cnt = 1
    res += cnt // 2
    return res solver2 t = [] t [] for _ in range(k):
        t += s
     _ range(k) range k t += s t s res = 0 res 0 cnt = 1 cnt 1 for i in range(1, len(t)):
        if t[i] == t[i - 1]:
            cnt += 1
        else:
            res += cnt // 2
            cnt = 1
     i range(1, len(t)) range 1 len(t) len t if t[i] == t[i - 1]:
            cnt += 1
        else:
            res += cnt // 2
            cnt = 1
     t[i] == t[i - 1] t[i] t i t[i - 1] t i - 1 i 1 cnt += 1 cnt 1 res += cnt // 2 res cnt // 2 cnt 2 cnt = 1 cnt 1 res += cnt // 2 res cnt // 2 cnt 2 return res res s s k k s = input() s input() input k = int(input()) k int(input()) int input() input print(solver(s, k)) print solver(s, k) solver s k import random random import string string def randomCharacter(n):
   alphabet_m = string.ascii_lowercase
   return ''.join([random.choice(alphabet_m) for _ in range(n)])


#for i in range(40):
#    if i == 0:
#        st = 'aaaaaaaaa'
#    elif i == 1:
#        st = 'a'
#    else:
#        l = random.randrange(1, 10)
#        st = randomCharacter(l)
#    sstt = st
#    cnt = 4
#    cnst_st = st[:]
#    res1 = solver(st, cnt)
#    res2 = solver2(sstt, cnt)
#    if res1 == res2:        
#        print("OK!")
#    else:
#        print(''.join(cnst_st), res1, res2)
         randomCharacter alphabet_m = string.ascii_lowercase alphabet_m string.ascii_lowercase string ascii_lowercase random.choice(alphabet_m) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) random.choice(alphabet_m) random.choice random choice alphabet_m return ''.join([random.choice(alphabet_m) for _ in range(n)]) ''.join([random.choice(alphabet_m) for _ in range(n)]) ''.join '' join [random.choice(alphabet_m) for _ in range(n)] n n def solver2(s, k):
    t = []
    for _ in range(k):
        t += s
    res = 0
    cnt = 1
    for i in range(1, len(t)):
        if t[i] == t[i - 1]:
            cnt += 1
        else:
            res += cnt // 2
            cnt = 1
    res += cnt // 2
    return res def solver2(s, k):
    t = []
    for _ in range(k):
        t += s
    res = 0
    cnt = 1
    for i in range(1, len(t)):
        if t[i] == t[i - 1]:
            cnt += 1
        else:
            res += cnt // 2
            cnt = 1
    res += cnt // 2
    return res solver2 def randomCharacter(n):
   alphabet_m = string.ascii_lowercase
   return ''.join([random.choice(alphabet_m) for _ in range(n)])


#for i in range(40):
#    if i == 0:
#        st = 'aaaaaaaaa'
#    elif i == 1:
#        st = 'a'
#    else:
#        l = random.randrange(1, 10)
#        st = randomCharacter(l)
#    sstt = st
#    cnt = 4
#    cnst_st = st[:]
#    res1 = solver(st, cnt)
#    res2 = solver2(sstt, cnt)
#    if res1 == res2:        
#        print("OK!")
#    else:
#        print(''.join(cnst_st), res1, res2)
         def randomCharacter(n):
   alphabet_m = string.ascii_lowercase
   return ''.join([random.choice(alphabet_m) for _ in range(n)])


#for i in range(40):
#    if i == 0:
#        st = 'aaaaaaaaa'
#    elif i == 1:
#        st = 'a'
#    else:
#        l = random.randrange(1, 10)
#        st = randomCharacter(l)
#    sstt = st
#    cnt = 4
#    cnst_st = st[:]
#    res1 = solver(st, cnt)
#    res2 = solver2(sstt, cnt)
#    if res1 == res2:        
#        print("OK!")
#    else:
#        print(''.join(cnst_st), res1, res2)
         randomCharacter k = int(input()) int(input()) k def solver(s, k):
    res = 0
    cnt = [1]
    for i in range(1, len(s)):
        if s[i] == s[i - 1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
    for x in cnt:
        res += (x // 2) * k

    if len(cnt) == 1: #全部同じ場合はここでおわり
        return (len(s) * k) // 2

    if s[0] == s[-1]:
        res -= (cnt[0] // 2) * (k - 1) + (cnt[-1] // 2) * (k - 1)
        res += ((cnt[0] + cnt[-1]) // 2) * (k - 1)
    return res def solver(s, k):
    res = 0
    cnt = [1]
    for i in range(1, len(s)):
        if s[i] == s[i - 1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
    for x in cnt:
        res += (x // 2) * k

    if len(cnt) == 1: #全部同じ場合はここでおわり
        return (len(s) * k) // 2

    if s[0] == s[-1]:
        res -= (cnt[0] // 2) * (k - 1) + (cnt[-1] // 2) * (k - 1)
        res += ((cnt[0] + cnt[-1]) // 2) * (k - 1)
    return res solver s = input() input() s
def solver(s, k):
    res = 0
    cnt = [1]
    for i in range(1, len(s)):
        if s[i] == s[i - 1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
    for x in cnt:
        res += (x // 2) * k

    if len(cnt) == 1: #全部同じ場合はここでおわり
        return (len(s) * k) // 2

    if s[0] == s[-1]:
        res -= (cnt[0] // 2) * (k - 1) + (cnt[-1] // 2) * (k - 1)
        res += ((cnt[0] + cnt[-1]) // 2) * (k - 1)
    return res

def solver2(s, k):
    t = []
    for _ in range(k):
        t += s
    res = 0
    cnt = 1
    for i in range(1, len(t)):
        if t[i] == t[i - 1]:
            cnt += 1
        else:
            res += cnt // 2
            cnt = 1
    res += cnt // 2
    return res

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

#ss = s
#kk = k
print(solver(s, k))
#print(solver2(ss, kk))

#　ランダムな英小文字列の生成
import random
import string

# n := 文字列の長さ
def randomCharacter(n):
   alphabet_m = string.ascii_lowercase
   return ''.join([random.choice(alphabet_m) for _ in range(n)])


#for i in range(40):
#    if i == 0:
#        st = 'aaaaaaaaa'
#    elif i == 1:
#        st = 'a'
#    else:
#        l = random.randrange(1, 10)
#        st = randomCharacter(l)
#    sstt = st
#    cnt = 4
#    cnst_st = st[:]
#    res1 = solver(st, cnt)
#    res2 = solver2(sstt, cnt)
#    if res1 == res2:        
#        print("OK!")
#    else:
#        print(''.join(cnst_st), res1, res2)
        
