def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    s=SI()
    k=I()
    u=len(s)
    seq=0
    x=1
    for i in range(u-1):
        if s[i]==s[i+1]:
            x+=1
        else:
            seq+=x//2
            x=1
    seq+=x//2
    #print(seq)
            
    a=1
    for i in range(u-1):
        if s[0]==s[i+1]:
            a+=1
        else:
            break
    b=1
    for i in range(u-1):
        if s[-1]==s[u-1-(1+i)]:
            b+=1
        else:
            break
    #print(a,b)
    if x==u:
        ans=(u*k)//2
    else:
        if s[0]!=s[-1]:
            ans=(seq)*k
        else:
            ans=(seq)*k-(a//2+b//2-(a+b)//2)*(k-1)
    print(ans)
        





if __name__=="__main__":
    main() def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    s=SI()
    k=I()
    u=len(s)
    seq=0
    x=1
    for i in range(u-1):
        if s[i]==s[i+1]:
            x+=1
        else:
            seq+=x//2
            x=1
    seq+=x//2
    #print(seq)
            
    a=1
    for i in range(u-1):
        if s[0]==s[i+1]:
            a+=1
        else:
            break
    b=1
    for i in range(u-1):
        if s[-1]==s[u-1-(1+i)]:
            b+=1
        else:
            break
    #print(a,b)
    if x==u:
        ans=(u*k)//2
    else:
        if s[0]!=s[-1]:
            ans=(seq)*k
        else:
            ans=(seq)*k-(a//2+b//2-(a+b)//2)*(k-1)
    print(ans)
         main import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil,pi,factorial from operator import itemgetter def I(): return int(input())
     I def MI(): return map(int, input().split())
     MI def LI(): return list(map(int, input().split()))
     LI int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input def LI2(): return [int(input()) for i in range(n)]
     LI2 [LI()]for i in range(n) for i in range(n) i range(n) range n for i in range(n) [LI()] LI() LI def MXI(): return [[LI()]for i in range(n)]
     MXI def SI(): return input().rstrip()
     SI def printns(x): print('\n'.join(x))
     printns x x def printni(x): print('\n'.join(list(map(str,x))))
     printni x x inf = 10**17 inf 10**17 10 17 mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 s=SI() s SI() SI k=I() k I() I u=len(s) u len(s) len s seq=0 seq 0 x=1 x 1 for i in range(u-1):
        if s[i]==s[i+1]:
            x+=1
        else:
            seq+=x//2
            x=1
     i range(u-1) range u-1 u 1 if s[i]==s[i+1]:
            x+=1
        else:
            seq+=x//2
            x=1
     s[i]==s[i+1] s[i] s i s[i+1] s i+1 i 1 x+=1 x 1 seq+=x//2 seq x//2 x 2 x=1 x 1 seq+=x//2 seq x//2 x 2 a=1 a 1 for i in range(u-1):
        if s[0]==s[i+1]:
            a+=1
        else:
            break
     i range(u-1) range u-1 u 1 if s[0]==s[i+1]:
            a+=1
        else:
            break
     s[0]==s[i+1] s[0] s 0 s[i+1] s i+1 i 1 a+=1 a 1 break b=1 b 1 for i in range(u-1):
        if s[-1]==s[u-1-(1+i)]:
            b+=1
        else:
            break
    #print(a,b)
     i range(u-1) range u-1 u 1 if s[-1]==s[u-1-(1+i)]:
            b+=1
        else:
            break
    #print(a,b)
     s[-1]==s[u-1-(1+i)] s[-1] s -1 s[u-1-(1+i)] s u-1-(1+i) u-1 u 1 1+i 1 i b+=1 b 1 break if x==u:
        ans=(u*k)//2
    else:
        if s[0]!=s[-1]:
            ans=(seq)*k
        else:
            ans=(seq)*k-(a//2+b//2-(a+b)//2)*(k-1)
     x==u x u ans=(u*k)//2 ans (u*k)//2 u*k u k 2 if s[0]!=s[-1]:
            ans=(seq)*k
        else:
            ans=(seq)*k-(a//2+b//2-(a+b)//2)*(k-1)
     s[0]!=s[-1] s[0] s 0 s[-1] s -1 ans=(seq)*k ans (seq)*k seq k ans=(seq)*k-(a//2+b//2-(a+b)//2)*(k-1) ans (seq)*k-(a//2+b//2-(a+b)//2)*(k-1) (seq)*k seq k (a//2+b//2-(a+b)//2)*(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 k-1 k 1 print(ans) print ans if __name__=="__main__":
    main() __name__=="__main__" __name__ "__main__" main() main def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    s=SI()
    k=I()
    u=len(s)
    seq=0
    x=1
    for i in range(u-1):
        if s[i]==s[i+1]:
            x+=1
        else:
            seq+=x//2
            x=1
    seq+=x//2
    #print(seq)
            
    a=1
    for i in range(u-1):
        if s[0]==s[i+1]:
            a+=1
        else:
            break
    b=1
    for i in range(u-1):
        if s[-1]==s[u-1-(1+i)]:
            b+=1
        else:
            break
    #print(a,b)
    if x==u:
        ans=(u*k)//2
    else:
        if s[0]!=s[-1]:
            ans=(seq)*k
        else:
            ans=(seq)*k-(a//2+b//2-(a+b)//2)*(k-1)
    print(ans)
         def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    s=SI()
    k=I()
    u=len(s)
    seq=0
    x=1
    for i in range(u-1):
        if s[i]==s[i+1]:
            x+=1
        else:
            seq+=x//2
            x=1
    seq+=x//2
    #print(seq)
            
    a=1
    for i in range(u-1):
        if s[0]==s[i+1]:
            a+=1
        else:
            break
    b=1
    for i in range(u-1):
        if s[-1]==s[u-1-(1+i)]:
            b+=1
        else:
            break
    #print(a,b)
    if x==u:
        ans=(u*k)//2
    else:
        if s[0]!=s[-1]:
            ans=(seq)*k
        else:
            ans=(seq)*k-(a//2+b//2-(a+b)//2)*(k-1)
    print(ans)
         main
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    s=SI()
    k=I()
    u=len(s)
    seq=0
    x=1
    for i in range(u-1):
        if s[i]==s[i+1]:
            x+=1
        else:
            seq+=x//2
            x=1
    seq+=x//2
    #print(seq)
            
    a=1
    for i in range(u-1):
        if s[0]==s[i+1]:
            a+=1
        else:
            break
    b=1
    for i in range(u-1):
        if s[-1]==s[u-1-(1+i)]:
            b+=1
        else:
            break
    #print(a,b)
    if x==u:
        ans=(u*k)//2
    else:
        if s[0]!=s[-1]:
            ans=(seq)*k
        else:
            ans=(seq)*k-(a//2+b//2-(a+b)//2)*(k-1)
    print(ans)
        





if __name__=="__main__":
    main()
