from itertools import groupby
import sys
 
input = lambda: sys.stdin.readline().strip()
 
 
def main():
 
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    ans = 0
 
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            ans = a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0] + a[-1]) // 2 * (K - 1)
            ans += sum(n // 2 for n in a[1:-1]) * K
 
    else:
        ans += sum(n // 2 for n in a) * K
 
    print(ans)
 
 
if __name__ == "__main__":
    main() from itertools import groupby import sys sys input = lambda: sys.stdin.readline().strip() input lambda: sys.stdin.readline().strip() sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip def main():
 
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    ans = 0
 
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            ans = a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0] + a[-1]) // 2 * (K - 1)
            ans += sum(n // 2 for n in a[1:-1]) * K
 
    else:
        ans += sum(n // 2 for n in a) * K
 
    print(ans)
 
  main S = input() S input() input K = int(input()) K int(input()) int input() input len(tuple(s)) for _, s in groupby(S) for _, s in groupby(S) _ s groupby(S) groupby S for _, s in groupby(S) len(tuple(s)) len tuple(s) tuple s a = [len(tuple(s)) for _, s in groupby(S)] a [len(tuple(s)) for _, s in groupby(S)] ans = 0 ans 0 if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            ans = a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0] + a[-1]) // 2 * (K - 1)
            ans += sum(n // 2 for n in a[1:-1]) * K
 
    else:
        ans += sum(n // 2 for n in a) * K
 
     S[0] == S[-1] and K > 1 S[0] == S[-1] S[0] S 0 S[-1] S -1 K > 1 K 1 if len(a) == 1:
            ans = a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0] + a[-1]) // 2 * (K - 1)
            ans += sum(n // 2 for n in a[1:-1]) * K
 
     len(a) == 1 len(a) len a 1 ans = a[0] * K // 2 ans a[0] * K // 2 a[0] * K a[0] a 0 K 2 ans = a[0] // 2 + a[-1] // 2 + (a[0] + a[-1]) // 2 * (K - 1) ans a[0] // 2 + a[-1] // 2 + (a[0] + a[-1]) // 2 * (K - 1) a[0] // 2 + a[-1] // 2 a[0] // 2 a[0] a 0 2 a[-1] // 2 a[-1] a -1 2 (a[0] + a[-1]) // 2 * (K - 1) (a[0] + a[-1]) // 2 a[0] + a[-1] a[0] a 0 a[-1] a -1 2 K - 1 K 1 ans += sum(n // 2 for n in a[1:-1]) * K ans sum(n // 2 for n in a[1:-1]) * K sum(n // 2 for n in a[1:-1]) sum n // 2 n 2 K ans += sum(n // 2 for n in a) * K ans sum(n // 2 for n in a) * K sum(n // 2 for n in a) sum n // 2 n 2 K print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main input = lambda: sys.stdin.readline().strip() lambda: sys.stdin.readline().strip() input def main():
 
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    ans = 0
 
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            ans = a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0] + a[-1]) // 2 * (K - 1)
            ans += sum(n // 2 for n in a[1:-1]) * K
 
    else:
        ans += sum(n // 2 for n in a) * K
 
    print(ans)
 
  def main():
 
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    ans = 0
 
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            ans = a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0] + a[-1]) // 2 * (K - 1)
            ans += sum(n // 2 for n in a[1:-1]) * K
 
    else:
        ans += sum(n // 2 for n in a) * K
 
    print(ans)
 
  main
from itertools import groupby
import sys
 
input = lambda: sys.stdin.readline().strip()
 
 
def main():
 
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    ans = 0
 
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            ans = a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0] + a[-1]) // 2 * (K - 1)
            ans += sum(n // 2 for n in a[1:-1]) * K
 
    else:
        ans += sum(n // 2 for n in a) * K
 
    print(ans)
 
 
if __name__ == "__main__":
    main()