import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
s=input()
k=int(input())
m=0
j=0
if len(set(list(s)))==1:print((len(s)*k)//2);exit()
for i in range(len(s)):
    if len(s)<=j+1:
        a=m*k
        if s[0]==s[-1]==s[len(s)//3]:print(a+k-1)
        else:print(a)
        break
    if s[j]==s[j+1]:m+=1;j+=1
    j+=1
 import sys sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush from math import * from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as br, bisect from time import perf_counter from fractions import Fraction mod = int(pow(10, 9) + 7) mod int(pow(10, 9) + 7) int pow(10, 9) + 7 pow(10, 9) pow 10 9 7 mod2 = 998244353 mod2 998244353 def data(): return sys.stdin.readline().strip() data def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end) out end="\n" end "\n" *var def l(): return list(sp()) l def sl(): return list(ssp()) sl def sp(): return map(int, data().split()) sp def ssp(): return map(str, data().split()) ssp val for i in range(n) for i in range(n) i range(n) range n for i in range(n) val def l1d(n, val=0): return [val for i in range(n)] l1d n n val=0 val 0 l1d(n, val) for j in range(m) for j in range(m) j range(m) range m for j in range(m) l1d(n, val) l1d n val def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None) l2d n n m m val=0 val 0 s=input() s input() input k=int(input()) k int(input()) int input() input m=0 m 0 j=0 j 0 if len(set(list(s)))==1:print((len(s)*k)//2);exit() len(set(list(s)))==1 len(set(list(s))) len set(list(s)) set list(s) list s 1 for i in range(len(s)):
    if len(s)<=j+1:
        a=m*k
        if s[0]==s[-1]==s[len(s)//3]:print(a+k-1)
        else:print(a)
        break
    if s[j]==s[j+1]:m+=1;j+=1
    j+=1 i range(len(s)) range len(s) len s if len(s)<=j+1:
        a=m*k
        if s[0]==s[-1]==s[len(s)//3]:print(a+k-1)
        else:print(a)
        break
     len(s)<=j+1 len(s) len s j+1 j 1 a=m*k a m*k m k if s[0]==s[-1]==s[len(s)//3]:print(a+k-1)
        else:print(a)
         s[0]==s[-1]==s[len(s)//3] s[0]==s[-1] s[0] s 0 s[-1] s -1 s[len(s)//3] s len(s)//3 len(s) len s 3 break if s[j]==s[j+1]:m+=1;j+=1
     s[j]==s[j+1] s[j] s j s[j+1] s j+1 j 1 j+=1 j 1 def data(): return sys.stdin.readline().strip() def data(): return sys.stdin.readline().strip() data def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end) def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end) out def sl(): return list(ssp()) def sl(): return list(ssp()) sl def sp(): return map(int, data().split()) def sp(): return map(int, data().split()) sp def ssp(): return map(str, data().split()) def ssp(): return map(str, data().split()) ssp def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None) def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None) l2d m=0 0 m j+=1 1 j mod = int(pow(10, 9) + 7) int(pow(10, 9) + 7) mod mod2 = 998244353 998244353 mod2 a=m*k m*k a def l1d(n, val=0): return [val for i in range(n)] def l1d(n, val=0): return [val for i in range(n)] l1d j=0 0 j s=input() input() s def l(): return list(sp()) def l(): return list(sp()) l k=int(input()) int(input()) k
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
s=input()
k=int(input())
m=0
j=0
if len(set(list(s)))==1:print((len(s)*k)//2);exit()
for i in range(len(s)):
    if len(s)<=j+1:
        a=m*k
        if s[0]==s[-1]==s[len(s)//3]:print(a+k-1)
        else:print(a)
        break
    if s[j]==s[j+1]:m+=1;j+=1
    j+=1

