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

if list(S).count(S[0])==len(S):
    print(len(S)*K//2)

else:
    S_count=0
    i=0
    while i<len(S)-1:
        if S[i]==S[i+1]:
            S_count+=1
            i+=1
        i+=1

    if S[0]==S[-1]:
        a=1
        i=0
        while i<len(S)-1:
            if S[i]==S[i+1]:
                a+=1
                i+=1
            else:
                break
        b=1
        i=len(S)-1
        while i>0:
            if S[i]==S[i-1]:
                b+=1
                i+=-1
            else:
                break

        S_count*=K
        S_count-=(K-1)*(a//2 + b//2 - (a+b)//2)

    else:
        S_count*=K
    print(S_count) S=input() S input() input K=int(input()) K int(input()) int input() input if list(S).count(S[0])==len(S):
    print(len(S)*K//2)

else:
    S_count=0
    i=0
    while i<len(S)-1:
        if S[i]==S[i+1]:
            S_count+=1
            i+=1
        i+=1

    if S[0]==S[-1]:
        a=1
        i=0
        while i<len(S)-1:
            if S[i]==S[i+1]:
                a+=1
                i+=1
            else:
                break
        b=1
        i=len(S)-1
        while i>0:
            if S[i]==S[i-1]:
                b+=1
                i+=-1
            else:
                break

        S_count*=K
        S_count-=(K-1)*(a//2 + b//2 - (a+b)//2)

    else:
        S_count*=K
    print(S_count) list(S).count(S[0])==len(S) list(S).count(S[0]) (S).count (S) list S count S[0] S 0 len(S) len S print(len(S)*K//2) print len(S)*K//2 len(S)*K len(S) len S K 2 S_count=0 S_count 0 i=0 i 0 while i<len(S)-1:
        if S[i]==S[i+1]:
            S_count+=1
            i+=1
        i+=1

     i<len(S)-1 i len(S)-1 len(S) len S 1 if S[i]==S[i+1]:
            S_count+=1
            i+=1
         S[i]==S[i+1] S[i] S i S[i+1] S i+1 i 1 S_count+=1 S_count 1 i+=1 i 1 i+=1 i 1 if S[0]==S[-1]:
        a=1
        i=0
        while i<len(S)-1:
            if S[i]==S[i+1]:
                a+=1
                i+=1
            else:
                break
        b=1
        i=len(S)-1
        while i>0:
            if S[i]==S[i-1]:
                b+=1
                i+=-1
            else:
                break

        S_count*=K
        S_count-=(K-1)*(a//2 + b//2 - (a+b)//2)

    else:
        S_count*=K
     S[0]==S[-1] S[0] S 0 S[-1] S -1 a=1 a 1 i=0 i 0 while i<len(S)-1:
            if S[i]==S[i+1]:
                a+=1
                i+=1
            else:
                break
         i<len(S)-1 i len(S)-1 len(S) len S 1 if S[i]==S[i+1]:
                a+=1
                i+=1
            else:
                break
         S[i]==S[i+1] S[i] S i S[i+1] S i+1 i 1 a+=1 a 1 i+=1 i 1 break b=1 b 1 i=len(S)-1 i len(S)-1 len(S) len S 1 while i>0:
            if S[i]==S[i-1]:
                b+=1
                i+=-1
            else:
                break

         i>0 i 0 if S[i]==S[i-1]:
                b+=1
                i+=-1
            else:
                break

         S[i]==S[i-1] S[i] S i S[i-1] S i-1 i 1 b+=1 b 1 i+=-1 i -1 break S_count*=K S_count K S_count-=(K-1)*(a//2 + b//2 - (a+b)//2) S_count (K-1)*(a//2 + b//2 - (a+b)//2) K-1 K 1 a//2 + b//2 - (a+b)//2 a//2 + b//2 a//2 a 2 b//2 b 2 (a+b)//2 a+b a b 2 S_count*=K S_count K print(S_count) print S_count S_count*=K K S_count S_count=0 0 S_count i+=1 1 i S_count-=(K-1)*(a//2 + b//2 - (a+b)//2) (K-1)*(a//2 + b//2 - (a+b)//2) S_count b+=1 1 b i=0 0 i S_count+=1 1 S_count i+=-1 -1 i S_count*=K K S_count S=input() input() S i+=1 1 i i=0 0 i i+=1 1 i i=len(S)-1 len(S)-1 i a=1 1 a b=1 1 b K=int(input()) int(input()) K a+=1 1 a
S=input()
K=int(input())

if list(S).count(S[0])==len(S):
    print(len(S)*K//2)

else:
    S_count=0
    i=0
    while i<len(S)-1:
        if S[i]==S[i+1]:
            S_count+=1
            i+=1
        i+=1

    if S[0]==S[-1]:
        a=1
        i=0
        while i<len(S)-1:
            if S[i]==S[i+1]:
                a+=1
                i+=1
            else:
                break
        b=1
        i=len(S)-1
        while i>0:
            if S[i]==S[i-1]:
                b+=1
                i+=-1
            else:
                break

        S_count*=K
        S_count-=(K-1)*(a//2 + b//2 - (a+b)//2)

    else:
        S_count*=K
    print(S_count)
