s = input()
k = int(input())
li = list(s)
lee = len(s)

if len(list(set(li))) == 1:
    print((lee)*k//2)
    exit()


def motome(n,list):
    count = 0
    kaihi_flag = False
    li = list*n
    for i,l in enumerate(li):
        if i == 0:
            continue
        if l == li[i-1] and not kaihi_flag:
            count += 1
            kaihi_flag = True
        else:
            kaihi_flag = False
    #print(count)
    #print(count*k)
    return count

if k >= 5 and k%2 == 1:
    a = motome(3,li)
    b = motome(5,li)
    diff = b - a
    ans = b + (k-5)//2*diff
    print(ans)
elif k >=5 and k%2 == 0:
    a = motome(2,li)
    b = motome(4,li)
    diff = b - a
    ans = b + (k-4)//2*diff
    print(ans)
else:
    count = 0
    kaihi_flag = False
    li = li*k
    for i,l in enumerate(li):
        if i == 0:
            continue
        if l == li[i-1] and not kaihi_flag:
            count += 1
            kaihi_flag = True
        else:
            kaihi_flag = False
    #print(count)
    #print(count*k)
    print(count) s = input() s input() input k = int(input()) k int(input()) int input() input li = list(s) li list(s) list s lee = len(s) lee len(s) len s if len(list(set(li))) == 1:
    print((lee)*k//2)
    exit() len(list(set(li))) == 1 len(list(set(li))) len list(set(li)) list set(li) set li 1 print((lee)*k//2) print (lee)*k//2 (lee)*k lee k 2 exit() exit def motome(n,list):
    count = 0
    kaihi_flag = False
    li = list*n
    for i,l in enumerate(li):
        if i == 0:
            continue
        if l == li[i-1] and not kaihi_flag:
            count += 1
            kaihi_flag = True
        else:
            kaihi_flag = False
    #print(count)
    #print(count*k)
    return count motome count = 0 count 0 kaihi_flag = False kaihi_flag False li = list*n li list*n list n for i,l in enumerate(li):
        if i == 0:
            continue
        if l == li[i-1] and not kaihi_flag:
            count += 1
            kaihi_flag = True
        else:
            kaihi_flag = False
    #print(count)
    #print(count*k)
     i l enumerate(li) enumerate li if i == 0:
            continue
         i == 0 i 0 continue if l == li[i-1] and not kaihi_flag:
            count += 1
            kaihi_flag = True
        else:
            kaihi_flag = False
    #print(count)
    #print(count*k)
     l == li[i-1] and not kaihi_flag l == li[i-1] l li[i-1] li i-1 i 1 not kaihi_flag kaihi_flag count += 1 count 1 kaihi_flag = True kaihi_flag True kaihi_flag = False kaihi_flag False return count count n n list list if k >= 5 and k%2 == 1:
    a = motome(3,li)
    b = motome(5,li)
    diff = b - a
    ans = b + (k-5)//2*diff
    print(ans)
elif k >=5 and k%2 == 0:
    a = motome(2,li)
    b = motome(4,li)
    diff = b - a
    ans = b + (k-4)//2*diff
    print(ans)
else:
    count = 0
    kaihi_flag = False
    li = li*k
    for i,l in enumerate(li):
        if i == 0:
            continue
        if l == li[i-1] and not kaihi_flag:
            count += 1
            kaihi_flag = True
        else:
            kaihi_flag = False
    #print(count)
    #print(count*k)
    print(count) k >= 5 and k%2 == 1 k >= 5 k 5 k%2 == 1 k%2 k 2 1 a = motome(3,li) a motome(3,li) motome 3 li b = motome(5,li) b motome(5,li) motome 5 li diff = b - a diff b - a b a ans = b + (k-5)//2*diff ans b + (k-5)//2*diff b (k-5)//2*diff (k-5)//2 k-5 k 5 2 diff print(ans) print ans elif k >=5 and k%2 == 0:
    a = motome(2,li)
    b = motome(4,li)
    diff = b - a
    ans = b + (k-4)//2*diff
    print(ans) k >=5 and k%2 == 0 k >=5 k 5 k%2 == 0 k%2 k 2 0 a = motome(2,li) a motome(2,li) motome 2 li b = motome(4,li) b motome(4,li) motome 4 li diff = b - a diff b - a b a ans = b + (k-4)//2*diff ans b + (k-4)//2*diff b (k-4)//2*diff (k-4)//2 k-4 k 4 2 diff print(ans) print ans count = 0 count 0 kaihi_flag = False kaihi_flag False li = li*k li li*k li k for i,l in enumerate(li):
        if i == 0:
            continue
        if l == li[i-1] and not kaihi_flag:
            count += 1
            kaihi_flag = True
        else:
            kaihi_flag = False
    #print(count)
    #print(count*k)
     i l enumerate(li) enumerate li if i == 0:
            continue
         i == 0 i 0 continue if l == li[i-1] and not kaihi_flag:
            count += 1
            kaihi_flag = True
        else:
            kaihi_flag = False
    #print(count)
    #print(count*k)
     l == li[i-1] and not kaihi_flag l == li[i-1] l li[i-1] li i-1 i 1 not kaihi_flag kaihi_flag count += 1 count 1 kaihi_flag = True kaihi_flag True kaihi_flag = False kaihi_flag False print(count) print count li = list(s) list(s) li b = motome(5,li) motome(5,li) b count += 1 1 count b = motome(4,li) motome(4,li) b ans = b + (k-5)//2*diff b + (k-5)//2*diff ans count = 0 0 count a = motome(2,li) motome(2,li) a kaihi_flag = False False kaihi_flag s = input() input() s lee = len(s) len(s) lee ans = b + (k-4)//2*diff b + (k-4)//2*diff ans a = motome(3,li) motome(3,li) a k = int(input()) int(input()) k diff = b - a b - a diff li = li*k li*k li kaihi_flag = False False kaihi_flag kaihi_flag = True True kaihi_flag def motome(n,list):
    count = 0
    kaihi_flag = False
    li = list*n
    for i,l in enumerate(li):
        if i == 0:
            continue
        if l == li[i-1] and not kaihi_flag:
            count += 1
            kaihi_flag = True
        else:
            kaihi_flag = False
    #print(count)
    #print(count*k)
    return count def motome(n,list):
    count = 0
    kaihi_flag = False
    li = list*n
    for i,l in enumerate(li):
        if i == 0:
            continue
        if l == li[i-1] and not kaihi_flag:
            count += 1
            kaihi_flag = True
        else:
            kaihi_flag = False
    #print(count)
    #print(count*k)
    return count motome diff = b - a b - a diff
s = input()
k = int(input())
li = list(s)
lee = len(s)

if len(list(set(li))) == 1:
    print((lee)*k//2)
    exit()


def motome(n,list):
    count = 0
    kaihi_flag = False
    li = list*n
    for i,l in enumerate(li):
        if i == 0:
            continue
        if l == li[i-1] and not kaihi_flag:
            count += 1
            kaihi_flag = True
        else:
            kaihi_flag = False
    #print(count)
    #print(count*k)
    return count

if k >= 5 and k%2 == 1:
    a = motome(3,li)
    b = motome(5,li)
    diff = b - a
    ans = b + (k-5)//2*diff
    print(ans)
elif k >=5 and k%2 == 0:
    a = motome(2,li)
    b = motome(4,li)
    diff = b - a
    ans = b + (k-4)//2*diff
    print(ans)
else:
    count = 0
    kaihi_flag = False
    li = li*k
    for i,l in enumerate(li):
        if i == 0:
            continue
        if l == li[i-1] and not kaihi_flag:
            count += 1
            kaihi_flag = True
        else:
            kaihi_flag = False
    #print(count)
    #print(count*k)
    print(count)
