import sys
from collections import Counter
input = sys.stdin.readline

def main():
    a = input().strip()
    n = int(input())
    l = len(a)
    b = Counter(a)
    if len(b) == 1:
        c = (n * l) // 2
        print(c)
        exit()
    su = 0
    ans = []
    for i in range(1, l):
        if a[i] == a[i - 1]:
            su += 1
        else:
            ans.append(su + 1)
            su = 0
    ans.append(su + 1)
    rev = 0
    for j in ans:
        rev += j // 2
    if a[0] == a[-1]:
        dif = ans[0]//2 + ans[-1]//2 - (ans[0]+ans[-1])//2
        print(rev*n - dif*(n - 1))
    else:
        print(rev*n)

if __name__ == '__main__':
    main() import sys sys from collections import Counter input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
    a = input().strip()
    n = int(input())
    l = len(a)
    b = Counter(a)
    if len(b) == 1:
        c = (n * l) // 2
        print(c)
        exit()
    su = 0
    ans = []
    for i in range(1, l):
        if a[i] == a[i - 1]:
            su += 1
        else:
            ans.append(su + 1)
            su = 0
    ans.append(su + 1)
    rev = 0
    for j in ans:
        rev += j // 2
    if a[0] == a[-1]:
        dif = ans[0]//2 + ans[-1]//2 - (ans[0]+ans[-1])//2
        print(rev*n - dif*(n - 1))
    else:
        print(rev*n) main a = input().strip() a input().strip() ().strip () input strip n = int(input()) n int(input()) int input() input l = len(a) l len(a) len a b = Counter(a) b Counter(a) Counter a if len(b) == 1:
        c = (n * l) // 2
        print(c)
        exit()
     len(b) == 1 len(b) len b 1 c = (n * l) // 2 c (n * l) // 2 n * l n l 2 print(c) print c exit() exit su = 0 su 0 ans = [] ans [] for i in range(1, l):
        if a[i] == a[i - 1]:
            su += 1
        else:
            ans.append(su + 1)
            su = 0
     i range(1, l) range 1 l if a[i] == a[i - 1]:
            su += 1
        else:
            ans.append(su + 1)
            su = 0
     a[i] == a[i - 1] a[i] a i a[i - 1] a i - 1 i 1 su += 1 su 1 ans.append(su + 1) ans.append ans append su + 1 su 1 su = 0 su 0 ans.append(su + 1) ans.append ans append su + 1 su 1 rev = 0 rev 0 for j in ans:
        rev += j // 2
     j ans rev += j // 2 rev j // 2 j 2 if a[0] == a[-1]:
        dif = ans[0]//2 + ans[-1]//2 - (ans[0]+ans[-1])//2
        print(rev*n - dif*(n - 1))
    else:
        print(rev*n) a[0] == a[-1] a[0] a 0 a[-1] a -1 dif = ans[0]//2 + ans[-1]//2 - (ans[0]+ans[-1])//2 dif ans[0]//2 + ans[-1]//2 - (ans[0]+ans[-1])//2 ans[0]//2 + ans[-1]//2 ans[0]//2 ans[0] ans 0 2 ans[-1]//2 ans[-1] ans -1 2 (ans[0]+ans[-1])//2 ans[0]+ans[-1] ans[0] ans 0 ans[-1] ans -1 2 print(rev*n - dif*(n - 1)) print rev*n - dif*(n - 1) rev*n rev n dif*(n - 1) dif n - 1 n 1 print(rev*n) print rev*n rev n if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    a = input().strip()
    n = int(input())
    l = len(a)
    b = Counter(a)
    if len(b) == 1:
        c = (n * l) // 2
        print(c)
        exit()
    su = 0
    ans = []
    for i in range(1, l):
        if a[i] == a[i - 1]:
            su += 1
        else:
            ans.append(su + 1)
            su = 0
    ans.append(su + 1)
    rev = 0
    for j in ans:
        rev += j // 2
    if a[0] == a[-1]:
        dif = ans[0]//2 + ans[-1]//2 - (ans[0]+ans[-1])//2
        print(rev*n - dif*(n - 1))
    else:
        print(rev*n) def main():
    a = input().strip()
    n = int(input())
    l = len(a)
    b = Counter(a)
    if len(b) == 1:
        c = (n * l) // 2
        print(c)
        exit()
    su = 0
    ans = []
    for i in range(1, l):
        if a[i] == a[i - 1]:
            su += 1
        else:
            ans.append(su + 1)
            su = 0
    ans.append(su + 1)
    rev = 0
    for j in ans:
        rev += j // 2
    if a[0] == a[-1]:
        dif = ans[0]//2 + ans[-1]//2 - (ans[0]+ans[-1])//2
        print(rev*n - dif*(n - 1))
    else:
        print(rev*n) main input = sys.stdin.readline sys.stdin.readline input
import sys
from collections import Counter
input = sys.stdin.readline

def main():
    a = input().strip()
    n = int(input())
    l = len(a)
    b = Counter(a)
    if len(b) == 1:
        c = (n * l) // 2
        print(c)
        exit()
    su = 0
    ans = []
    for i in range(1, l):
        if a[i] == a[i - 1]:
            su += 1
        else:
            ans.append(su + 1)
            su = 0
    ans.append(su + 1)
    rev = 0
    for j in ans:
        rev += j // 2
    if a[0] == a[-1]:
        dif = ans[0]//2 + ans[-1]//2 - (ans[0]+ans[-1])//2
        print(rev*n - dif*(n - 1))
    else:
        print(rev*n)

if __name__ == '__main__':
    main()
