S = input()
K = int(input())
before = ''
count = 0
change_cnt = 0
for c in S:
  if c == before:
    count += 1
  else:
    if count >= 0:
      change_cnt += (count+1)//2
      count = 0
    before = c
if count > 0:
    change_cnt += (count+1)//2
c_cnt = 0
if S[0] == S[-1]:
  for c in S:
    if c == before:
      c_cnt += 1
    else:
      break
all_same = False
plus = False
if count%2 == 0 and c_cnt%2 != 0:
  plus = True
if count+c_cnt >= len(S):
  all_same = True
# print(all_same, plus, count, change_cnt, c_cnt)  
if all_same:
  print((K//2)*len(S) + (K%2)*(len(S)//2))
elif plus:
  print(K*change_cnt + K-1)
else:
  print(K*change_cnt)
  
   S = input() S input() input K = int(input()) K int(input()) int input() input before = '' before '' count = 0 count 0 change_cnt = 0 change_cnt 0 for c in S:
  if c == before:
    count += 1
  else:
    if count >= 0:
      change_cnt += (count+1)//2
      count = 0
    before = c c S if c == before:
    count += 1
  else:
    if count >= 0:
      change_cnt += (count+1)//2
      count = 0
    before = c c == before c before count += 1 count 1 if count >= 0:
      change_cnt += (count+1)//2
      count = 0
     count >= 0 count 0 change_cnt += (count+1)//2 change_cnt (count+1)//2 count+1 count 1 2 count = 0 count 0 before = c before c if count > 0:
    change_cnt += (count+1)//2 count > 0 count 0 change_cnt += (count+1)//2 change_cnt (count+1)//2 count+1 count 1 2 c_cnt = 0 c_cnt 0 if S[0] == S[-1]:
  for c in S:
    if c == before:
      c_cnt += 1
    else:
      break S[0] == S[-1] S[0] S 0 S[-1] S -1 for c in S:
    if c == before:
      c_cnt += 1
    else:
      break c S if c == before:
      c_cnt += 1
    else:
      break c == before c before c_cnt += 1 c_cnt 1 break all_same = False all_same False plus = False plus False if count%2 == 0 and c_cnt%2 != 0:
  plus = True count%2 == 0 and c_cnt%2 != 0 count%2 == 0 count%2 count 2 0 c_cnt%2 != 0 c_cnt%2 c_cnt 2 0 plus = True plus True if count+c_cnt >= len(S):
  all_same = True
# print(all_same, plus, count, change_cnt, c_cnt)   count+c_cnt >= len(S) count+c_cnt count c_cnt len(S) len S all_same = True all_same True if all_same:
  print((K//2)*len(S) + (K%2)*(len(S)//2))
elif plus:
  print(K*change_cnt + K-1)
else:
  print(K*change_cnt)
  
   all_same print((K//2)*len(S) + (K%2)*(len(S)//2)) print (K//2)*len(S) + (K%2)*(len(S)//2) (K//2)*len(S) K//2 K 2 len(S) len S (K%2)*(len(S)//2) K%2 K 2 len(S)//2 len(S) len S 2 elif plus:
  print(K*change_cnt + K-1) plus print(K*change_cnt + K-1) print K*change_cnt + K-1 K*change_cnt + K K*change_cnt K change_cnt K 1 print(K*change_cnt) print K*change_cnt K change_cnt K = int(input()) int(input()) K c_cnt = 0 0 c_cnt c_cnt += 1 1 c_cnt count = 0 0 count S = input() input() S count = 0 0 count before = c c before plus = False False plus all_same = False False all_same count += 1 1 count change_cnt += (count+1)//2 (count+1)//2 change_cnt before = '' '' before change_cnt += (count+1)//2 (count+1)//2 change_cnt change_cnt = 0 0 change_cnt plus = True True plus all_same = True True all_same
S = input()
K = int(input())
before = ''
count = 0
change_cnt = 0
for c in S:
  if c == before:
    count += 1
  else:
    if count >= 0:
      change_cnt += (count+1)//2
      count = 0
    before = c
if count > 0:
    change_cnt += (count+1)//2
c_cnt = 0
if S[0] == S[-1]:
  for c in S:
    if c == before:
      c_cnt += 1
    else:
      break
all_same = False
plus = False
if count%2 == 0 and c_cnt%2 != 0:
  plus = True
if count+c_cnt >= len(S):
  all_same = True
# print(all_same, plus, count, change_cnt, c_cnt)  
if all_same:
  print((K//2)*len(S) + (K%2)*(len(S)//2))
elif plus:
  print(K*change_cnt + K-1)
else:
  print(K*change_cnt)
  
  
