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

if(S.count(S[0]) == len(S)):
    print(len(S)*K//2)
else:
    cnt = 0
    lst = []
    tmp = S[0]
    for i in range(len(S)):
        if(tmp == S[i]):
            cnt += 1
        else:
            tmp = S[i]
            if(cnt > 1):
                lst.append(cnt)
            cnt = 1   
    if(cnt > 1):
        lst.append(cnt)
        
    ans = 0
    for i in lst:
        ans += K*(i//2)
    if(S[0] != S[-1]):
        print(ans)
    else:
        a = 0
        b = 0
        for i in range(len(S)):
            if(tmp != S[i]):
                break
            a += 1
        for i in S[::-1]:
            if(tmp != i):
                break
            b += 1
        print(ans+((a+b)//2-(a//2+b//2))*(K-1)) S = input() S input() input K = int(input()) K int(input()) int input() input if(S.count(S[0]) == len(S)):
    print(len(S)*K//2)
else:
    cnt = 0
    lst = []
    tmp = S[0]
    for i in range(len(S)):
        if(tmp == S[i]):
            cnt += 1
        else:
            tmp = S[i]
            if(cnt > 1):
                lst.append(cnt)
            cnt = 1   
    if(cnt > 1):
        lst.append(cnt)
        
    ans = 0
    for i in lst:
        ans += K*(i//2)
    if(S[0] != S[-1]):
        print(ans)
    else:
        a = 0
        b = 0
        for i in range(len(S)):
            if(tmp != S[i]):
                break
            a += 1
        for i in S[::-1]:
            if(tmp != i):
                break
            b += 1
        print(ans+((a+b)//2-(a//2+b//2))*(K-1)) S.count(S[0]) == len(S) S.count(S[0]) S.count 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 cnt = 0 cnt 0 lst = [] lst [] tmp = S[0] tmp S[0] S 0 for i in range(len(S)):
        if(tmp == S[i]):
            cnt += 1
        else:
            tmp = S[i]
            if(cnt > 1):
                lst.append(cnt)
            cnt = 1   
     i range(len(S)) range len(S) len S if(tmp == S[i]):
            cnt += 1
        else:
            tmp = S[i]
            if(cnt > 1):
                lst.append(cnt)
            cnt = 1   
     tmp == S[i] tmp S[i] S i cnt += 1 cnt 1 tmp = S[i] tmp S[i] S i if(cnt > 1):
                lst.append(cnt)
             cnt > 1 cnt 1 lst.append(cnt) lst.append lst append cnt cnt = 1 cnt 1 if(cnt > 1):
        lst.append(cnt)
        
     cnt > 1 cnt 1 lst.append(cnt) lst.append lst append cnt ans = 0 ans 0 for i in lst:
        ans += K*(i//2)
     i lst ans += K*(i//2) ans K*(i//2) K i//2 i 2 if(S[0] != S[-1]):
        print(ans)
    else:
        a = 0
        b = 0
        for i in range(len(S)):
            if(tmp != S[i]):
                break
            a += 1
        for i in S[::-1]:
            if(tmp != i):
                break
            b += 1
        print(ans+((a+b)//2-(a//2+b//2))*(K-1)) S[0] != S[-1] S[0] S 0 S[-1] S -1 print(ans) print ans a = 0 a 0 b = 0 b 0 for i in range(len(S)):
            if(tmp != S[i]):
                break
            a += 1
         i range(len(S)) range len(S) len S if(tmp != S[i]):
                break
             tmp != S[i] tmp S[i] S i break a += 1 a 1 for i in S[::-1]:
            if(tmp != i):
                break
            b += 1
         i S[::-1] S ::-1 -1 if(tmp != i):
                break
             tmp != i tmp i break b += 1 b 1 print(ans+((a+b)//2-(a//2+b//2))*(K-1)) print ans+((a+b)//2-(a//2+b//2))*(K-1) ans ((a+b)//2-(a//2+b//2))*(K-1) (a+b)//2-(a//2+b//2) (a+b)//2 a+b a b 2 a//2+b//2 a//2 a 2 b//2 b 2 K-1 K 1 b = 0 0 b b += 1 1 b K = int(input()) int(input()) K ans = 0 0 ans ans += K*(i//2) K*(i//2) ans cnt = 1 1 cnt cnt = 0 0 cnt tmp = S[i] S[i] tmp a = 0 0 a a += 1 1 a S = input() input() S lst = [] [] lst cnt += 1 1 cnt tmp = S[0] S[0] tmp
S = input()
K = int(input())

if(S.count(S[0]) == len(S)):
    print(len(S)*K//2)
else:
    cnt = 0
    lst = []
    tmp = S[0]
    for i in range(len(S)):
        if(tmp == S[i]):
            cnt += 1
        else:
            tmp = S[i]
            if(cnt > 1):
                lst.append(cnt)
            cnt = 1   
    if(cnt > 1):
        lst.append(cnt)
        
    ans = 0
    for i in lst:
        ans += K*(i//2)
    if(S[0] != S[-1]):
        print(ans)
    else:
        a = 0
        b = 0
        for i in range(len(S)):
            if(tmp != S[i]):
                break
            a += 1
        for i in S[::-1]:
            if(tmp != i):
                break
            b += 1
        print(ans+((a+b)//2-(a//2+b//2))*(K-1))