S = input()
K = int(input())

def count(s):
    """何文字変更が必要か
    """
    a = []
    b = ''
    c = 1
    for si in s:
        if b == si:
            c += 1
        else:
            a.append(c)
            c = 1
        b = si
    a.append(c)

    r = 0
    for ai in a:
        r += ai // 2
    # print(s, a, r)
    return r

if K == 1:
    ans = count(S)
elif len(S) == 1:
    ans = K // 2
elif len(set(S)) == 1:
    c = count(S*2)
    if K % 2 == 0:
        ans = c * (K//2)
    else:
        diff = count(S*3) - count(S*2)
        ans = c * (K//2) + diff
else:
    a1 = count(S*2)
    a2 = count(S*3)
    ans = a1 + (a2-a1) * (K-2)

print(ans)

# for i in range(1, 10):
#     print(i, S*i, count(S*i)) S = input() S input() input K = int(input()) K int(input()) int input() input def count(s):
    """何文字変更が必要か
    """
    a = []
    b = ''
    c = 1
    for si in s:
        if b == si:
            c += 1
        else:
            a.append(c)
            c = 1
        b = si
    a.append(c)

    r = 0
    for ai in a:
        r += ai // 2
    # print(s, a, r)
    return r count """何文字変更が必要か
    """ a = [] a [] b = '' b '' c = 1 c 1 for si in s:
        if b == si:
            c += 1
        else:
            a.append(c)
            c = 1
        b = si
     si s if b == si:
            c += 1
        else:
            a.append(c)
            c = 1
         b == si b si c += 1 c 1 a.append(c) a.append a append c c = 1 c 1 b = si b si a.append(c) a.append a append c r = 0 r 0 for ai in a:
        r += ai // 2
    # print(s, a, r)
     ai a r += ai // 2 r ai // 2 ai 2 return r r s s if K == 1:
    ans = count(S)
elif len(S) == 1:
    ans = K // 2
elif len(set(S)) == 1:
    c = count(S*2)
    if K % 2 == 0:
        ans = c * (K//2)
    else:
        diff = count(S*3) - count(S*2)
        ans = c * (K//2) + diff
else:
    a1 = count(S*2)
    a2 = count(S*3)
    ans = a1 + (a2-a1) * (K-2) K == 1 K 1 ans = count(S) ans count(S) count S elif len(S) == 1:
    ans = K // 2 len(S) == 1 len(S) len S 1 ans = K // 2 ans K // 2 K 2 elif len(set(S)) == 1:
    c = count(S*2)
    if K % 2 == 0:
        ans = c * (K//2)
    else:
        diff = count(S*3) - count(S*2)
        ans = c * (K//2) + diff len(set(S)) == 1 len(set(S)) len set(S) set S 1 c = count(S*2) c count(S*2) count S*2 S 2 if K % 2 == 0:
        ans = c * (K//2)
    else:
        diff = count(S*3) - count(S*2)
        ans = c * (K//2) + diff K % 2 == 0 K % 2 K 2 0 ans = c * (K//2) ans c * (K//2) c K//2 K 2 diff = count(S*3) - count(S*2) diff count(S*3) - count(S*2) count(S*3) count S*3 S 3 count(S*2) count S*2 S 2 ans = c * (K//2) + diff ans c * (K//2) + diff c * (K//2) c K//2 K 2 diff a1 = count(S*2) a1 count(S*2) count S*2 S 2 a2 = count(S*3) a2 count(S*3) count S*3 S 3 ans = a1 + (a2-a1) * (K-2) ans a1 + (a2-a1) * (K-2) a1 (a2-a1) * (K-2) a2-a1 a2 a1 K-2 K 2 print(ans) print ans c = count(S*2) count(S*2) c def count(s):
    """何文字変更が必要か
    """
    a = []
    b = ''
    c = 1
    for si in s:
        if b == si:
            c += 1
        else:
            a.append(c)
            c = 1
        b = si
    a.append(c)

    r = 0
    for ai in a:
        r += ai // 2
    # print(s, a, r)
    return r def count(s):
    """何文字変更が必要か
    """
    a = []
    b = ''
    c = 1
    for si in s:
        if b == si:
            c += 1
        else:
            a.append(c)
            c = 1
        b = si
    a.append(c)

    r = 0
    for ai in a:
        r += ai // 2
    # print(s, a, r)
    return r count ans = c * (K//2) + diff c * (K//2) + diff ans ans = count(S) count(S) ans ans = K // 2 K // 2 ans diff = count(S*3) - count(S*2) count(S*3) - count(S*2) diff ans = a1 + (a2-a1) * (K-2) a1 + (a2-a1) * (K-2) ans a1 = count(S*2) count(S*2) a1 ans = c * (K//2) c * (K//2) ans K = int(input()) int(input()) K a2 = count(S*3) count(S*3) a2 S = input() input() S
S = input()
K = int(input())

def count(s):
    """何文字変更が必要か
    """
    a = []
    b = ''
    c = 1
    for si in s:
        if b == si:
            c += 1
        else:
            a.append(c)
            c = 1
        b = si
    a.append(c)

    r = 0
    for ai in a:
        r += ai // 2
    # print(s, a, r)
    return r

if K == 1:
    ans = count(S)
elif len(S) == 1:
    ans = K // 2
elif len(set(S)) == 1:
    c = count(S*2)
    if K % 2 == 0:
        ans = c * (K//2)
    else:
        diff = count(S*3) - count(S*2)
        ans = c * (K//2) + diff
else:
    a1 = count(S*2)
    a2 = count(S*3)
    ans = a1 + (a2-a1) * (K-2)

print(ans)

# for i in range(1, 10):
#     print(i, S*i, count(S*i))
