def main():
    s=input()
    k=int(input())
    if s.count(s[0])==len(s):
        print(len(s)*k//2)
    else:
        ans=0
        cnt=1
        res=[0,0]
        t=s+"X"
        flg=0
        for i in range(len(s)):
            if t[i]==t[i+1]:
                cnt+=1
            else:
                if flg==0:
                    res[0]=cnt
                    flg=1
                elif i==len(s)-1:
                    res[1]=cnt
                ans+=cnt//2
                cnt=1
        ans*=k
        if s[0]==s[-1] and res[0]%2==1 and res[1]%2==1:
            ans+=k-1
        print(ans)
if __name__=="__main__":
    main() def main():
    s=input()
    k=int(input())
    if s.count(s[0])==len(s):
        print(len(s)*k//2)
    else:
        ans=0
        cnt=1
        res=[0,0]
        t=s+"X"
        flg=0
        for i in range(len(s)):
            if t[i]==t[i+1]:
                cnt+=1
            else:
                if flg==0:
                    res[0]=cnt
                    flg=1
                elif i==len(s)-1:
                    res[1]=cnt
                ans+=cnt//2
                cnt=1
        ans*=k
        if s[0]==s[-1] and res[0]%2==1 and res[1]%2==1:
            ans+=k-1
        print(ans) main 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:
        ans=0
        cnt=1
        res=[0,0]
        t=s+"X"
        flg=0
        for i in range(len(s)):
            if t[i]==t[i+1]:
                cnt+=1
            else:
                if flg==0:
                    res[0]=cnt
                    flg=1
                elif i==len(s)-1:
                    res[1]=cnt
                ans+=cnt//2
                cnt=1
        ans*=k
        if s[0]==s[-1] and res[0]%2==1 and res[1]%2==1:
            ans+=k-1
        print(ans) 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 ans=0 ans 0 cnt=1 cnt 1 res=[0,0] res [0,0] 0 0 t=s+"X" t s+"X" s "X" flg=0 flg 0 for i in range(len(s)):
            if t[i]==t[i+1]:
                cnt+=1
            else:
                if flg==0:
                    res[0]=cnt
                    flg=1
                elif i==len(s)-1:
                    res[1]=cnt
                ans+=cnt//2
                cnt=1
         i range(len(s)) range len(s) len s if t[i]==t[i+1]:
                cnt+=1
            else:
                if flg==0:
                    res[0]=cnt
                    flg=1
                elif i==len(s)-1:
                    res[1]=cnt
                ans+=cnt//2
                cnt=1
         t[i]==t[i+1] t[i] t i t[i+1] t i+1 i 1 cnt+=1 cnt 1 if flg==0:
                    res[0]=cnt
                    flg=1
                elif i==len(s)-1:
                    res[1]=cnt
                 flg==0 flg 0 res[0]=cnt res[0] res 0 cnt flg=1 flg 1 elif i==len(s)-1:
                    res[1]=cnt
                 i==len(s)-1 i len(s)-1 len(s) len s 1 res[1]=cnt res[1] res 1 cnt ans+=cnt//2 ans cnt//2 cnt 2 cnt=1 cnt 1 ans*=k ans k if s[0]==s[-1] and res[0]%2==1 and res[1]%2==1:
            ans+=k-1
         s[0]==s[-1] and res[0]%2==1 and res[1]%2==1 s[0]==s[-1] and res[0]%2==1 s[0]==s[-1] s[0] s 0 s[-1] s -1 res[0]%2==1 res[0]%2 res[0] res 0 2 1 res[1]%2==1 res[1]%2 res[1] res 1 2 1 ans+=k-1 ans k-1 k 1 print(ans) print ans if __name__=="__main__":
    main() __name__=="__main__" __name__ "__main__" main() main def main():
    s=input()
    k=int(input())
    if s.count(s[0])==len(s):
        print(len(s)*k//2)
    else:
        ans=0
        cnt=1
        res=[0,0]
        t=s+"X"
        flg=0
        for i in range(len(s)):
            if t[i]==t[i+1]:
                cnt+=1
            else:
                if flg==0:
                    res[0]=cnt
                    flg=1
                elif i==len(s)-1:
                    res[1]=cnt
                ans+=cnt//2
                cnt=1
        ans*=k
        if s[0]==s[-1] and res[0]%2==1 and res[1]%2==1:
            ans+=k-1
        print(ans) def main():
    s=input()
    k=int(input())
    if s.count(s[0])==len(s):
        print(len(s)*k//2)
    else:
        ans=0
        cnt=1
        res=[0,0]
        t=s+"X"
        flg=0
        for i in range(len(s)):
            if t[i]==t[i+1]:
                cnt+=1
            else:
                if flg==0:
                    res[0]=cnt
                    flg=1
                elif i==len(s)-1:
                    res[1]=cnt
                ans+=cnt//2
                cnt=1
        ans*=k
        if s[0]==s[-1] and res[0]%2==1 and res[1]%2==1:
            ans+=k-1
        print(ans) main
def main():
    s=input()
    k=int(input())
    if s.count(s[0])==len(s):
        print(len(s)*k//2)
    else:
        ans=0
        cnt=1
        res=[0,0]
        t=s+"X"
        flg=0
        for i in range(len(s)):
            if t[i]==t[i+1]:
                cnt+=1
            else:
                if flg==0:
                    res[0]=cnt
                    flg=1
                elif i==len(s)-1:
                    res[1]=cnt
                ans+=cnt//2
                cnt=1
        ans*=k
        if s[0]==s[-1] and res[0]%2==1 and res[1]%2==1:
            ans+=k-1
        print(ans)
if __name__=="__main__":
    main()