import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = input()
    k = int(input())

    lens = len(s)
    if len(s) == 1:
        print(k // 2)
        sys.exit()

    if k == 1:
        r2 = 0
        rt = 1
        c = ""
        flag = False
        for se in s:
            if c == se:
                flag = True
                rt += 1
            else:
                c = se
                if flag:
                    r2 += rt // 2
                    rt = 1
                    flag = False
        r2 += rt // 2
        print(r2)
        sys.exit()

    s_daburi = 0
    s_last = s[-1]
    while s_daburi < lens:
        if s[s_daburi] == s_last:
            s_daburi += 1
        else:
            break
    s1 = s + s_last * s_daburi

    r2 = 0
    rt = 1
    c = ""
    flag = False
    for se in s1:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
    r2 += rt // 2

    if s_daburi == lens:
        if k % 2 == 0:
            r = r2 * (k // 2)
            print(r)
            sys.exit()
        else:
            r = r2 * (k // 2) + lens//2
            print(r)
            sys.exit()

    r = r2
    s2 = s[s_daburi:] + s_last * s_daburi
    r2 = 0
    rt = 1
    c = ""
    flag = False
    for se in s2:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
    r2 += rt // 2

    s3 = s[s_daburi:]
    r3 = 0
    rt = 1
    c = ""
    flag = False
    for se in s3:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r3 += rt // 2
                rt = 1
                flag = False
    r3 += rt // 2
    if k == 2:
        print(r + r3)
    else:
        print(r + r3 + r2 * (k-2))



if __name__ == '__main__':
    main() import sys sys read = sys.stdin.read read sys.stdin.read sys.stdin sys stdin read readlines = sys.stdin.readlines readlines sys.stdin.readlines sys.stdin sys stdin readlines def main():
    s = input()
    k = int(input())

    lens = len(s)
    if len(s) == 1:
        print(k // 2)
        sys.exit()

    if k == 1:
        r2 = 0
        rt = 1
        c = ""
        flag = False
        for se in s:
            if c == se:
                flag = True
                rt += 1
            else:
                c = se
                if flag:
                    r2 += rt // 2
                    rt = 1
                    flag = False
        r2 += rt // 2
        print(r2)
        sys.exit()

    s_daburi = 0
    s_last = s[-1]
    while s_daburi < lens:
        if s[s_daburi] == s_last:
            s_daburi += 1
        else:
            break
    s1 = s + s_last * s_daburi

    r2 = 0
    rt = 1
    c = ""
    flag = False
    for se in s1:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
    r2 += rt // 2

    if s_daburi == lens:
        if k % 2 == 0:
            r = r2 * (k // 2)
            print(r)
            sys.exit()
        else:
            r = r2 * (k // 2) + lens//2
            print(r)
            sys.exit()

    r = r2
    s2 = s[s_daburi:] + s_last * s_daburi
    r2 = 0
    rt = 1
    c = ""
    flag = False
    for se in s2:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
    r2 += rt // 2

    s3 = s[s_daburi:]
    r3 = 0
    rt = 1
    c = ""
    flag = False
    for se in s3:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r3 += rt // 2
                rt = 1
                flag = False
    r3 += rt // 2
    if k == 2:
        print(r + r3)
    else:
        print(r + r3 + r2 * (k-2)) main s = input() s input() input k = int(input()) k int(input()) int input() input lens = len(s) lens len(s) len s if len(s) == 1:
        print(k // 2)
        sys.exit()

     len(s) == 1 len(s) len s 1 print(k // 2) print k // 2 k 2 sys.exit() sys.exit sys exit if k == 1:
        r2 = 0
        rt = 1
        c = ""
        flag = False
        for se in s:
            if c == se:
                flag = True
                rt += 1
            else:
                c = se
                if flag:
                    r2 += rt // 2
                    rt = 1
                    flag = False
        r2 += rt // 2
        print(r2)
        sys.exit()

     k == 1 k 1 r2 = 0 r2 0 rt = 1 rt 1 c = "" c "" flag = False flag False for se in s:
            if c == se:
                flag = True
                rt += 1
            else:
                c = se
                if flag:
                    r2 += rt // 2
                    rt = 1
                    flag = False
         se s if c == se:
                flag = True
                rt += 1
            else:
                c = se
                if flag:
                    r2 += rt // 2
                    rt = 1
                    flag = False
         c == se c se flag = True flag True rt += 1 rt 1 c = se c se if flag:
                    r2 += rt // 2
                    rt = 1
                    flag = False
         flag r2 += rt // 2 r2 rt // 2 rt 2 rt = 1 rt 1 flag = False flag False r2 += rt // 2 r2 rt // 2 rt 2 print(r2) print r2 sys.exit() sys.exit sys exit s_daburi = 0 s_daburi 0 s_last = s[-1] s_last s[-1] s -1 while s_daburi < lens:
        if s[s_daburi] == s_last:
            s_daburi += 1
        else:
            break
     s_daburi < lens s_daburi lens if s[s_daburi] == s_last:
            s_daburi += 1
        else:
            break
     s[s_daburi] == s_last s[s_daburi] s s_daburi s_last s_daburi += 1 s_daburi 1 break s1 = s + s_last * s_daburi s1 s + s_last * s_daburi s s_last * s_daburi s_last s_daburi r2 = 0 r2 0 rt = 1 rt 1 c = "" c "" flag = False flag False for se in s1:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
     se s1 if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
     c == se c se flag = True flag True rt += 1 rt 1 c = se c se if flag:
                r2 += rt // 2
                rt = 1
                flag = False
     flag r2 += rt // 2 r2 rt // 2 rt 2 rt = 1 rt 1 flag = False flag False r2 += rt // 2 r2 rt // 2 rt 2 if s_daburi == lens:
        if k % 2 == 0:
            r = r2 * (k // 2)
            print(r)
            sys.exit()
        else:
            r = r2 * (k // 2) + lens//2
            print(r)
            sys.exit()

     s_daburi == lens s_daburi lens if k % 2 == 0:
            r = r2 * (k // 2)
            print(r)
            sys.exit()
        else:
            r = r2 * (k // 2) + lens//2
            print(r)
            sys.exit()

     k % 2 == 0 k % 2 k 2 0 r = r2 * (k // 2) r r2 * (k // 2) r2 k // 2 k 2 print(r) print r sys.exit() sys.exit sys exit r = r2 * (k // 2) + lens//2 r r2 * (k // 2) + lens//2 r2 * (k // 2) r2 k // 2 k 2 lens//2 lens 2 print(r) print r sys.exit() sys.exit sys exit r = r2 r r2 s2 = s[s_daburi:] + s_last * s_daburi s2 s[s_daburi:] + s_last * s_daburi s[s_daburi:] s s_daburi: s_daburi s_last * s_daburi s_last s_daburi r2 = 0 r2 0 rt = 1 rt 1 c = "" c "" flag = False flag False for se in s2:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
     se s2 if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
     c == se c se flag = True flag True rt += 1 rt 1 c = se c se if flag:
                r2 += rt // 2
                rt = 1
                flag = False
     flag r2 += rt // 2 r2 rt // 2 rt 2 rt = 1 rt 1 flag = False flag False r2 += rt // 2 r2 rt // 2 rt 2 s3 = s[s_daburi:] s3 s[s_daburi:] s s_daburi: s_daburi r3 = 0 r3 0 rt = 1 rt 1 c = "" c "" flag = False flag False for se in s3:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r3 += rt // 2
                rt = 1
                flag = False
     se s3 if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r3 += rt // 2
                rt = 1
                flag = False
     c == se c se flag = True flag True rt += 1 rt 1 c = se c se if flag:
                r3 += rt // 2
                rt = 1
                flag = False
     flag r3 += rt // 2 r3 rt // 2 rt 2 rt = 1 rt 1 flag = False flag False r3 += rt // 2 r3 rt // 2 rt 2 if k == 2:
        print(r + r3)
    else:
        print(r + r3 + r2 * (k-2)) k == 2 k 2 print(r + r3) print r + r3 r r3 print(r + r3 + r2 * (k-2)) print r + r3 + r2 * (k-2) r + r3 r r3 r2 * (k-2) r2 k-2 k 2 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    s = input()
    k = int(input())

    lens = len(s)
    if len(s) == 1:
        print(k // 2)
        sys.exit()

    if k == 1:
        r2 = 0
        rt = 1
        c = ""
        flag = False
        for se in s:
            if c == se:
                flag = True
                rt += 1
            else:
                c = se
                if flag:
                    r2 += rt // 2
                    rt = 1
                    flag = False
        r2 += rt // 2
        print(r2)
        sys.exit()

    s_daburi = 0
    s_last = s[-1]
    while s_daburi < lens:
        if s[s_daburi] == s_last:
            s_daburi += 1
        else:
            break
    s1 = s + s_last * s_daburi

    r2 = 0
    rt = 1
    c = ""
    flag = False
    for se in s1:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
    r2 += rt // 2

    if s_daburi == lens:
        if k % 2 == 0:
            r = r2 * (k // 2)
            print(r)
            sys.exit()
        else:
            r = r2 * (k // 2) + lens//2
            print(r)
            sys.exit()

    r = r2
    s2 = s[s_daburi:] + s_last * s_daburi
    r2 = 0
    rt = 1
    c = ""
    flag = False
    for se in s2:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
    r2 += rt // 2

    s3 = s[s_daburi:]
    r3 = 0
    rt = 1
    c = ""
    flag = False
    for se in s3:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r3 += rt // 2
                rt = 1
                flag = False
    r3 += rt // 2
    if k == 2:
        print(r + r3)
    else:
        print(r + r3 + r2 * (k-2)) def main():
    s = input()
    k = int(input())

    lens = len(s)
    if len(s) == 1:
        print(k // 2)
        sys.exit()

    if k == 1:
        r2 = 0
        rt = 1
        c = ""
        flag = False
        for se in s:
            if c == se:
                flag = True
                rt += 1
            else:
                c = se
                if flag:
                    r2 += rt // 2
                    rt = 1
                    flag = False
        r2 += rt // 2
        print(r2)
        sys.exit()

    s_daburi = 0
    s_last = s[-1]
    while s_daburi < lens:
        if s[s_daburi] == s_last:
            s_daburi += 1
        else:
            break
    s1 = s + s_last * s_daburi

    r2 = 0
    rt = 1
    c = ""
    flag = False
    for se in s1:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
    r2 += rt // 2

    if s_daburi == lens:
        if k % 2 == 0:
            r = r2 * (k // 2)
            print(r)
            sys.exit()
        else:
            r = r2 * (k // 2) + lens//2
            print(r)
            sys.exit()

    r = r2
    s2 = s[s_daburi:] + s_last * s_daburi
    r2 = 0
    rt = 1
    c = ""
    flag = False
    for se in s2:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
    r2 += rt // 2

    s3 = s[s_daburi:]
    r3 = 0
    rt = 1
    c = ""
    flag = False
    for se in s3:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r3 += rt // 2
                rt = 1
                flag = False
    r3 += rt // 2
    if k == 2:
        print(r + r3)
    else:
        print(r + r3 + r2 * (k-2)) main read = sys.stdin.read sys.stdin.read read readlines = sys.stdin.readlines sys.stdin.readlines readlines
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = input()
    k = int(input())

    lens = len(s)
    if len(s) == 1:
        print(k // 2)
        sys.exit()

    if k == 1:
        r2 = 0
        rt = 1
        c = ""
        flag = False
        for se in s:
            if c == se:
                flag = True
                rt += 1
            else:
                c = se
                if flag:
                    r2 += rt // 2
                    rt = 1
                    flag = False
        r2 += rt // 2
        print(r2)
        sys.exit()

    s_daburi = 0
    s_last = s[-1]
    while s_daburi < lens:
        if s[s_daburi] == s_last:
            s_daburi += 1
        else:
            break
    s1 = s + s_last * s_daburi

    r2 = 0
    rt = 1
    c = ""
    flag = False
    for se in s1:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
    r2 += rt // 2

    if s_daburi == lens:
        if k % 2 == 0:
            r = r2 * (k // 2)
            print(r)
            sys.exit()
        else:
            r = r2 * (k // 2) + lens//2
            print(r)
            sys.exit()

    r = r2
    s2 = s[s_daburi:] + s_last * s_daburi
    r2 = 0
    rt = 1
    c = ""
    flag = False
    for se in s2:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
    r2 += rt // 2

    s3 = s[s_daburi:]
    r3 = 0
    rt = 1
    c = ""
    flag = False
    for se in s3:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r3 += rt // 2
                rt = 1
                flag = False
    r3 += rt // 2
    if k == 2:
        print(r + r3)
    else:
        print(r + r3 + r2 * (k-2))



if __name__ == '__main__':
    main()
