# -*- coding: utf-8 -*-
s = input()
k = int(input())

if len(set(s)) == 1:
    print(len(s) * k // 2)
    exit()

count = []
tmp = 0
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        tmp += 1
    if s[i] != s[i + 1]:
        count.append(tmp + 1)
        tmp = 0
count.append(tmp + 1)
#print(count)

flag = True
ans = 0
if s[0] == s[-1] and (count[-1] > 1 or count[0] > 1) and (count[-1] + count[0]) % 2 == 0:
    flag = False
if s[0] == s[-1]:
    if count[-1] == 1 and count[0] == 1:
        ans += k - 1
        flag = False
    else:
        ans += k - 1
        if count[-1] >= count[0]:
            count[-1] -= 1
        else:
            count[0] -= 1
#print(flag)
#print(ans)
#print(count)
for i in range(len(count)):
    if count[i] > 1:
        ans += (count[i] // 2) * k
if s[0] == s[-1] and count[-1] >= 1 and flag:
    #print("B")
    ans += 1
print(ans) s = input() s input() input k = int(input()) k int(input()) int input() input if len(set(s)) == 1:
    print(len(s) * k // 2)
    exit() len(set(s)) == 1 len(set(s)) len set(s) set s 1 print(len(s) * k // 2) print len(s) * k // 2 len(s) * k len(s) len s k 2 exit() exit count = [] count [] tmp = 0 tmp 0 for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        tmp += 1
    if s[i] != s[i + 1]:
        count.append(tmp + 1)
        tmp = 0 i range(len(s) - 1) range len(s) - 1 len(s) len s 1 if s[i] == s[i + 1]:
        tmp += 1
     s[i] == s[i + 1] s[i] s i s[i + 1] s i + 1 i 1 tmp += 1 tmp 1 if s[i] != s[i + 1]:
        count.append(tmp + 1)
        tmp = 0 s[i] != s[i + 1] s[i] s i s[i + 1] s i + 1 i 1 count.append(tmp + 1) count.append count append tmp + 1 tmp 1 tmp = 0 tmp 0 count.append(tmp + 1) count.append count append tmp + 1 tmp 1 flag = True flag True ans = 0 ans 0 if s[0] == s[-1] and (count[-1] > 1 or count[0] > 1) and (count[-1] + count[0]) % 2 == 0:
    flag = False s[0] == s[-1] and (count[-1] > 1 or count[0] > 1) and (count[-1] + count[0]) % 2 == 0 s[0] == s[-1] and (count[-1] > 1 or count[0] > 1) s[0] == s[-1] s[0] s 0 s[-1] s -1 count[-1] > 1 or count[0] > 1 count[-1] > 1 count[-1] count -1 1 count[0] > 1 count[0] count 0 1 (count[-1] + count[0]) % 2 == 0 (count[-1] + count[0]) % 2 count[-1] + count[0] count[-1] count -1 count[0] count 0 2 0 flag = False flag False if s[0] == s[-1]:
    if count[-1] == 1 and count[0] == 1:
        ans += k - 1
        flag = False
    else:
        ans += k - 1
        if count[-1] >= count[0]:
            count[-1] -= 1
        else:
            count[0] -= 1
#print(flag)
#print(ans)
#print(count) s[0] == s[-1] s[0] s 0 s[-1] s -1 if count[-1] == 1 and count[0] == 1:
        ans += k - 1
        flag = False
    else:
        ans += k - 1
        if count[-1] >= count[0]:
            count[-1] -= 1
        else:
            count[0] -= 1
#print(flag)
#print(ans)
#print(count) count[-1] == 1 and count[0] == 1 count[-1] == 1 count[-1] count -1 1 count[0] == 1 count[0] count 0 1 ans += k - 1 ans k - 1 k 1 flag = False flag False ans += k - 1 ans k - 1 k 1 if count[-1] >= count[0]:
            count[-1] -= 1
        else:
            count[0] -= 1
#print(flag)
#print(ans)
#print(count) count[-1] >= count[0] count[-1] count -1 count[0] count 0 count[-1] -= 1 count[-1] count -1 1 count[0] -= 1 count[0] count 0 1 for i in range(len(count)):
    if count[i] > 1:
        ans += (count[i] // 2) * k i range(len(count)) range len(count) len count if count[i] > 1:
        ans += (count[i] // 2) * k count[i] > 1 count[i] count i 1 ans += (count[i] // 2) * k ans (count[i] // 2) * k count[i] // 2 count[i] count i 2 k if s[0] == s[-1] and count[-1] >= 1 and flag:
    #print("B")
    ans += 1 s[0] == s[-1] and count[-1] >= 1 and flag s[0] == s[-1] and count[-1] >= 1 s[0] == s[-1] s[0] s 0 s[-1] s -1 count[-1] >= 1 count[-1] count -1 1 flag ans += 1 ans 1 print(ans) print ans k = int(input()) int(input()) k tmp += 1 1 tmp ans += 1 1 ans tmp = 0 0 tmp flag = False False flag ans += k - 1 k - 1 ans tmp = 0 0 tmp ans = 0 0 ans ans += k - 1 k - 1 ans flag = True True flag count = [] [] count s = input() input() s flag = False False flag ans += (count[i] // 2) * k (count[i] // 2) * k ans
# -*- coding: utf-8 -*-
s = input()
k = int(input())

if len(set(s)) == 1:
    print(len(s) * k // 2)
    exit()

count = []
tmp = 0
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        tmp += 1
    if s[i] != s[i + 1]:
        count.append(tmp + 1)
        tmp = 0
count.append(tmp + 1)
#print(count)

flag = True
ans = 0
if s[0] == s[-1] and (count[-1] > 1 or count[0] > 1) and (count[-1] + count[0]) % 2 == 0:
    flag = False
if s[0] == s[-1]:
    if count[-1] == 1 and count[0] == 1:
        ans += k - 1
        flag = False
    else:
        ans += k - 1
        if count[-1] >= count[0]:
            count[-1] -= 1
        else:
            count[0] -= 1
#print(flag)
#print(ans)
#print(count)
for i in range(len(count)):
    if count[i] > 1:
        ans += (count[i] // 2) * k
if s[0] == s[-1] and count[-1] >= 1 and flag:
    #print("B")
    ans += 1
print(ans)
