S = input()
K = int(input())
oans = 0
head = 0
tail = 0
N = len(S)
count = 1

if S.count(S[0]) == N:
  print(N*K//2)
  exit()
for i in range(N-1):
  if S[i+1] == S[i]:
    count += 1
  else:
    oans += count // 2
    if head == 0:
      head = count
    count = 1
  if i == N-2:
    oans += count // 2
    tail = count
    if head == 0:
      print(N*K//2)
      exit()
plus = 0

if S[0] != S[-1]:
  print(oans * K)
  exit()

d = head//2 + tail //2 -(head + tail)//2

print(oans*K -(K-1)*d) S = input() S input() input K = int(input()) K int(input()) int input() input oans = 0 oans 0 head = 0 head 0 tail = 0 tail 0 N = len(S) N len(S) len S count = 1 count 1 if S.count(S[0]) == N:
  print(N*K//2)
  exit() S.count(S[0]) == N S.count(S[0]) S.count S count S[0] S 0 N print(N*K//2) print N*K//2 N*K N K 2 exit() exit for i in range(N-1):
  if S[i+1] == S[i]:
    count += 1
  else:
    oans += count // 2
    if head == 0:
      head = count
    count = 1
  if i == N-2:
    oans += count // 2
    tail = count
    if head == 0:
      print(N*K//2)
      exit() i range(N-1) range N-1 N 1 if S[i+1] == S[i]:
    count += 1
  else:
    oans += count // 2
    if head == 0:
      head = count
    count = 1
   S[i+1] == S[i] S[i+1] S i+1 i 1 S[i] S i count += 1 count 1 oans += count // 2 oans count // 2 count 2 if head == 0:
      head = count
     head == 0 head 0 head = count head count count = 1 count 1 if i == N-2:
    oans += count // 2
    tail = count
    if head == 0:
      print(N*K//2)
      exit() i == N-2 i N-2 N 2 oans += count // 2 oans count // 2 count 2 tail = count tail count if head == 0:
      print(N*K//2)
      exit() head == 0 head 0 print(N*K//2) print N*K//2 N*K N K 2 exit() exit plus = 0 plus 0 if S[0] != S[-1]:
  print(oans * K)
  exit() S[0] != S[-1] S[0] S 0 S[-1] S -1 print(oans * K) print oans * K oans K exit() exit d = head//2 + tail //2 -(head + tail)//2 d head//2 + tail //2 -(head + tail)//2 head//2 + tail //2 head//2 head 2 tail //2 tail 2 (head + tail)//2 head + tail head tail 2 print(oans*K -(K-1)*d) print oans*K -(K-1)*d oans*K oans K (K-1)*d K-1 K 1 d head = count count head K = int(input()) int(input()) K S = input() input() S head = 0 0 head N = len(S) len(S) N tail = count count tail oans += count // 2 count // 2 oans count = 1 1 count plus = 0 0 plus d = head//2 + tail //2 -(head + tail)//2 head//2 + tail //2 -(head + tail)//2 d count += 1 1 count tail = 0 0 tail oans = 0 0 oans count = 1 1 count oans += count // 2 count // 2 oans
S = input()
K = int(input())
oans = 0
head = 0
tail = 0
N = len(S)
count = 1

if S.count(S[0]) == N:
  print(N*K//2)
  exit()
for i in range(N-1):
  if S[i+1] == S[i]:
    count += 1
  else:
    oans += count // 2
    if head == 0:
      head = count
    count = 1
  if i == N-2:
    oans += count // 2
    tail = count
    if head == 0:
      print(N*K//2)
      exit()
plus = 0

if S[0] != S[-1]:
  print(oans * K)
  exit()

d = head//2 + tail //2 -(head + tail)//2

print(oans*K -(K-1)*d)