import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from collections import deque
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    S = readline().decode('utf-8').strip()
    K = int(readline())
    L = len(S)

    continuous = deque()

    count = 0
    last = ''
    for i in range(L):
        if i == 0:
            last = S[i]
            count += 1
        else:
            if last==S[i]:
                count += 1
            else:
                continuous.append(count)
                count = 1
                last = S[i]
    continuous.append(count)

    ans = 0
    if len(continuous)==1:
        ans = L*K//2
    else:
        if S[0]==S[-1]:
            a = continuous.popleft()
            b = continuous.pop()
            ans += ((a+b)//2)*(K-1) + a//2 + b//2
        while continuous:
            a = continuous.popleft()
            ans += a//2*K
    print(ans)

if __name__ == '__main__':
    main() import sys sys read = sys.stdin.read read sys.stdin.read sys.stdin sys stdin read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline from collections import deque sys.setrecursionlimit(10 ** 8) sys.setrecursionlimit sys setrecursionlimit 10 ** 8 10 8 INF = float('inf') INF float('inf') float 'inf' MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 def main():
    S = readline().decode('utf-8').strip()
    K = int(readline())
    L = len(S)

    continuous = deque()

    count = 0
    last = ''
    for i in range(L):
        if i == 0:
            last = S[i]
            count += 1
        else:
            if last==S[i]:
                count += 1
            else:
                continuous.append(count)
                count = 1
                last = S[i]
    continuous.append(count)

    ans = 0
    if len(continuous)==1:
        ans = L*K//2
    else:
        if S[0]==S[-1]:
            a = continuous.popleft()
            b = continuous.pop()
            ans += ((a+b)//2)*(K-1) + a//2 + b//2
        while continuous:
            a = continuous.popleft()
            ans += a//2*K
    print(ans) main S = readline().decode('utf-8').strip() S readline().decode('utf-8').strip() ().decode('utf-8').strip ().decode('utf-8') ().decode () readline decode 'utf-8' strip K = int(readline()) K int(readline()) int readline() readline L = len(S) L len(S) len S continuous = deque() continuous deque() deque count = 0 count 0 last = '' last '' for i in range(L):
        if i == 0:
            last = S[i]
            count += 1
        else:
            if last==S[i]:
                count += 1
            else:
                continuous.append(count)
                count = 1
                last = S[i]
     i range(L) range L if i == 0:
            last = S[i]
            count += 1
        else:
            if last==S[i]:
                count += 1
            else:
                continuous.append(count)
                count = 1
                last = S[i]
     i == 0 i 0 last = S[i] last S[i] S i count += 1 count 1 if last==S[i]:
                count += 1
            else:
                continuous.append(count)
                count = 1
                last = S[i]
     last==S[i] last S[i] S i count += 1 count 1 continuous.append(count) continuous.append continuous append count count = 1 count 1 last = S[i] last S[i] S i continuous.append(count) continuous.append continuous append count ans = 0 ans 0 if len(continuous)==1:
        ans = L*K//2
    else:
        if S[0]==S[-1]:
            a = continuous.popleft()
            b = continuous.pop()
            ans += ((a+b)//2)*(K-1) + a//2 + b//2
        while continuous:
            a = continuous.popleft()
            ans += a//2*K
     len(continuous)==1 len(continuous) len continuous 1 ans = L*K//2 ans L*K//2 L*K L K 2 if S[0]==S[-1]:
            a = continuous.popleft()
            b = continuous.pop()
            ans += ((a+b)//2)*(K-1) + a//2 + b//2
         S[0]==S[-1] S[0] S 0 S[-1] S -1 a = continuous.popleft() a continuous.popleft() continuous.popleft continuous popleft b = continuous.pop() b continuous.pop() continuous.pop continuous pop ans += ((a+b)//2)*(K-1) + a//2 + b//2 ans ((a+b)//2)*(K-1) + a//2 + b//2 ((a+b)//2)*(K-1) + a//2 ((a+b)//2)*(K-1) (a+b)//2 a+b a b 2 K-1 K 1 a//2 a 2 b//2 b 2 while continuous:
            a = continuous.popleft()
            ans += a//2*K
     continuous a = continuous.popleft() a continuous.popleft() continuous.popleft continuous popleft ans += a//2*K ans a//2*K a//2 a 2 K print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD INF = float('inf') float('inf') INF readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline def main():
    S = readline().decode('utf-8').strip()
    K = int(readline())
    L = len(S)

    continuous = deque()

    count = 0
    last = ''
    for i in range(L):
        if i == 0:
            last = S[i]
            count += 1
        else:
            if last==S[i]:
                count += 1
            else:
                continuous.append(count)
                count = 1
                last = S[i]
    continuous.append(count)

    ans = 0
    if len(continuous)==1:
        ans = L*K//2
    else:
        if S[0]==S[-1]:
            a = continuous.popleft()
            b = continuous.pop()
            ans += ((a+b)//2)*(K-1) + a//2 + b//2
        while continuous:
            a = continuous.popleft()
            ans += a//2*K
    print(ans) def main():
    S = readline().decode('utf-8').strip()
    K = int(readline())
    L = len(S)

    continuous = deque()

    count = 0
    last = ''
    for i in range(L):
        if i == 0:
            last = S[i]
            count += 1
        else:
            if last==S[i]:
                count += 1
            else:
                continuous.append(count)
                count = 1
                last = S[i]
    continuous.append(count)

    ans = 0
    if len(continuous)==1:
        ans = L*K//2
    else:
        if S[0]==S[-1]:
            a = continuous.popleft()
            b = continuous.pop()
            ans += ((a+b)//2)*(K-1) + a//2 + b//2
        while continuous:
            a = continuous.popleft()
            ans += a//2*K
    print(ans) main read = sys.stdin.read sys.stdin.read read
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from collections import deque
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    S = readline().decode('utf-8').strip()
    K = int(readline())
    L = len(S)

    continuous = deque()

    count = 0
    last = ''
    for i in range(L):
        if i == 0:
            last = S[i]
            count += 1
        else:
            if last==S[i]:
                count += 1
            else:
                continuous.append(count)
                count = 1
                last = S[i]
    continuous.append(count)

    ans = 0
    if len(continuous)==1:
        ans = L*K//2
    else:
        if S[0]==S[-1]:
            a = continuous.popleft()
            b = continuous.pop()
            ans += ((a+b)//2)*(K-1) + a//2 + b//2
        while continuous:
            a = continuous.popleft()
            ans += a//2*K
    print(ans)

if __name__ == '__main__':
    main()
