s = input(); k = int(input())
a = 0
def count(t):
    i = 1; x = 0
    while i < len(t):
        if t[i-1] == t[i]:
            x += 1
            i += 1
        i += 1
    return x
for i in range(len(s)-1):
    if s[i] != s[i+1]: break
else: a = 1
if a == 1: print(len(s)*k//2)
else:
    if k == 1: print(count(s))
    else:
        ss = s+s; sss = ss+s
        print(count(ss)+(count(sss)-count(ss))*(k-2)) s = input() s input() input k = int(input()) k int(input()) int input() input a = 0 a 0 def count(t):
    i = 1; x = 0
    while i < len(t):
        if t[i-1] == t[i]:
            x += 1
            i += 1
        i += 1
    return x count i = 1 i 1 x = 0 x 0 while i < len(t):
        if t[i-1] == t[i]:
            x += 1
            i += 1
        i += 1
     i < len(t) i len(t) len t if t[i-1] == t[i]:
            x += 1
            i += 1
         t[i-1] == t[i] t[i-1] t i-1 i 1 t[i] t i x += 1 x 1 i += 1 i 1 i += 1 i 1 return x x t t for i in range(len(s)-1):
    if s[i] != s[i+1]: break
else: a = 1 i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i] != s[i+1]: b s[i] != s[i+1] s[i] s i s[i+1] s i+1 i 1 if a == 1: print(len(s)*k//2)
else:
    if k == 1: print(count(s))
    else:
        ss = s+s; sss = ss+s
        print(count(ss)+(count(sss)-count(ss))*(k-2)) a == 1 a 1 if k == 1: print(count(s))
    else:
        ss = s+s; sss = ss+s
        print(count(ss)+(count(sss)-count(ss))*(k-2)) k == 1 k 1 ss = s+s ss s+s s s sss = ss+s sss ss+s ss s print(count(ss)+(count(sss)-count(ss))*(k-2)) print count(ss)+(count(sss)-count(ss))*(k-2) count(ss) count ss (count(sss)-count(ss))*(k-2) count(sss)-count(ss) count(sss) count sss count(ss) count ss k-2 k 2 s = input() input() s def count(t):
    i = 1; x = 0
    while i < len(t):
        if t[i-1] == t[i]:
            x += 1
            i += 1
        i += 1
    return x def count(t):
    i = 1; x = 0
    while i < len(t):
        if t[i-1] == t[i]:
            x += 1
            i += 1
        i += 1
    return x count k = int(input()) int(input()) k ss = s+s s+s ss sss = ss+s ss+s sss a = 0 0 a
s = input(); k = int(input())
a = 0
def count(t):
    i = 1; x = 0
    while i < len(t):
        if t[i-1] == t[i]:
            x += 1
            i += 1
        i += 1
    return x
for i in range(len(s)-1):
    if s[i] != s[i+1]: break
else: a = 1
if a == 1: print(len(s)*k//2)
else:
    if k == 1: print(count(s))
    else:
        ss = s+s; sss = ss+s
        print(count(ss)+(count(sss)-count(ss))*(k-2))