S=input()
k=int(input())
x=1
L=[]
for i in range(len(S)-1):
  if S[i]==S[i+1]:
    x+=1
  else:
    L.append(x)
    x=1
L.append(x)
s=sum([l//2 for l in L])
if S[0]!=S[-1]:
  print(s*k)
else:
  if len(L)>1:
    L[0]+=L[-1]
    print(s+sum([l//2 for l in L[:-1]])*(k-1))
  else:
    print(L[0]*k//2) S=input() S input() input k=int(input()) k int(input()) int input() input x=1 x 1 L=[] L [] for i in range(len(S)-1):
  if S[i]==S[i+1]:
    x+=1
  else:
    L.append(x)
    x=1 i range(len(S)-1) range len(S)-1 len(S) len S 1 if S[i]==S[i+1]:
    x+=1
  else:
    L.append(x)
    x=1 S[i]==S[i+1] S[i] S i S[i+1] S i+1 i 1 x+=1 x 1 L.append(x) L.append L append x x=1 x 1 L.append(x) L.append L append x l//2 for l in L for l in L l L for l in L l//2 l 2 s=sum([l//2 for l in L]) s sum([l//2 for l in L]) sum [l//2 for l in L] if S[0]!=S[-1]:
  print(s*k)
else:
  if len(L)>1:
    L[0]+=L[-1]
    print(s+sum([l//2 for l in L[:-1]])*(k-1))
  else:
    print(L[0]*k//2) S[0]!=S[-1] S[0] S 0 S[-1] S -1 print(s*k) print s*k s k if len(L)>1:
    L[0]+=L[-1]
    print(s+sum([l//2 for l in L[:-1]])*(k-1))
  else:
    print(L[0]*k//2) len(L)>1 len(L) len L 1 L[0]+=L[-1] L[0] L 0 L[-1] L -1 l//2 for l in L[:-1] for l in L[:-1] l L[:-1] L :-1 -1 for l in L[:-1] l//2 l 2 print(s+sum([l//2 for l in L[:-1]])*(k-1)) print s+sum([l//2 for l in L[:-1]])*(k-1) s sum([l//2 for l in L[:-1]])*(k-1) sum([l//2 for l in L[:-1]]) sum [l//2 for l in L[:-1]] k-1 k 1 print(L[0]*k//2) print L[0]*k//2 L[0]*k L[0] L 0 k 2 L=[] [] L k=int(input()) int(input()) k x+=1 1 x x=1 1 x S=input() input() S s=sum([l//2 for l in L]) sum([l//2 for l in L]) s x=1 1 x
S=input()
k=int(input())
x=1
L=[]
for i in range(len(S)-1):
  if S[i]==S[i+1]:
    x+=1
  else:
    L.append(x)
    x=1
L.append(x)
s=sum([l//2 for l in L])
if S[0]!=S[-1]:
  print(s*k)
else:
  if len(L)>1:
    L[0]+=L[-1]
    print(s+sum([l//2 for l in L[:-1]])*(k-1))
  else:
    print(L[0]*k//2)