#!/usr/bin/env python3
import sys

def splitSeries(s:str):
    result = []
    last = ""
    count = 0
    for c in s:
        if last == c:
            count+=1
        else:
            if last != "":
                result.append((last,count))
            last = c
            count = 1
    if last != "":
        result.append((last,count))
    return result



def solve(S: str, K: int):
    if len(S) == 1:
        print(K//2)
    else:
        count = 0
        series = splitSeries(S)
        sp = 0
        if len(series) > 1:
            for s in series:
                if s[1] > 1:
                    sp += s[1]//2
            count += sp * K
            if series[0][0] == series[-1][0]:
                count -= (K-1)*(series[0][1]//2 + series[-1][1]//2 - (series[0][1] + series[-1][1])//2)
            print(count)
        else:
            print(series[0][1]*K//2)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(S, K)

if __name__ == '__main__':
    main() import sys sys def splitSeries(s:str):
    result = []
    last = ""
    count = 0
    for c in s:
        if last == c:
            count+=1
        else:
            if last != "":
                result.append((last,count))
            last = c
            count = 1
    if last != "":
        result.append((last,count))
    return result splitSeries result = [] result [] last = "" last "" count = 0 count 0 for c in s:
        if last == c:
            count+=1
        else:
            if last != "":
                result.append((last,count))
            last = c
            count = 1
     c s if last == c:
            count+=1
        else:
            if last != "":
                result.append((last,count))
            last = c
            count = 1
     last == c last c count+=1 count 1 if last != "":
                result.append((last,count))
             last != "" last "" result.append((last,count)) result.append result append (last,count) last count last = c last c count = 1 count 1 if last != "":
        result.append((last,count))
     last != "" last "" result.append((last,count)) result.append result append (last,count) last count return result result s:str s def solve(S: str, K: int):
    if len(S) == 1:
        print(K//2)
    else:
        count = 0
        series = splitSeries(S)
        sp = 0
        if len(series) > 1:
            for s in series:
                if s[1] > 1:
                    sp += s[1]//2
            count += sp * K
            if series[0][0] == series[-1][0]:
                count -= (K-1)*(series[0][1]//2 + series[-1][1]//2 - (series[0][1] + series[-1][1])//2)
            print(count)
        else:
            print(series[0][1]*K//2)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template) solve if len(S) == 1:
        print(K//2)
    else:
        count = 0
        series = splitSeries(S)
        sp = 0
        if len(series) > 1:
            for s in series:
                if s[1] > 1:
                    sp += s[1]//2
            count += sp * K
            if series[0][0] == series[-1][0]:
                count -= (K-1)*(series[0][1]//2 + series[-1][1]//2 - (series[0][1] + series[-1][1])//2)
            print(count)
        else:
            print(series[0][1]*K//2)
     len(S) == 1 len(S) len S 1 print(K//2) print K//2 K 2 count = 0 count 0 series = splitSeries(S) series splitSeries(S) splitSeries S sp = 0 sp 0 if len(series) > 1:
            for s in series:
                if s[1] > 1:
                    sp += s[1]//2
            count += sp * K
            if series[0][0] == series[-1][0]:
                count -= (K-1)*(series[0][1]//2 + series[-1][1]//2 - (series[0][1] + series[-1][1])//2)
            print(count)
        else:
            print(series[0][1]*K//2)
     len(series) > 1 len(series) len series 1 for s in series:
                if s[1] > 1:
                    sp += s[1]//2
             s series if s[1] > 1:
                    sp += s[1]//2
             s[1] > 1 s[1] s 1 1 sp += s[1]//2 sp s[1]//2 s[1] s 1 2 count += sp * K count sp * K sp K if series[0][0] == series[-1][0]:
                count -= (K-1)*(series[0][1]//2 + series[-1][1]//2 - (series[0][1] + series[-1][1])//2)
             series[0][0] == series[-1][0] series[0][0] [0] series 0 0 series[-1][0] [-1] series -1 0 count -= (K-1)*(series[0][1]//2 + series[-1][1]//2 - (series[0][1] + series[-1][1])//2) count (K-1)*(series[0][1]//2 + series[-1][1]//2 - (series[0][1] + series[-1][1])//2) K-1 K 1 series[0][1]//2 + series[-1][1]//2 - (series[0][1] + series[-1][1])//2 series[0][1]//2 + series[-1][1]//2 series[0][1]//2 series[0][1] [0] series 0 1 2 series[-1][1]//2 series[-1][1] [-1] series -1 1 2 (series[0][1] + series[-1][1])//2 series[0][1] + series[-1][1] series[0][1] [0] series 0 1 series[-1][1] [-1] series -1 1 2 print(count) print count print(series[0][1]*K//2) print series[0][1]*K//2 series[0][1]*K series[0][1] [0] series 0 1 K 2 return S: str S K: int K def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(S, K) main def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
     iterate_tokens for line in sys.stdin:
            for word in line.split():
                yield word
     line sys.stdin sys stdin for word in line.split():
                yield word
     word line.split() line.split line split yield word word tokens = iterate_tokens() tokens iterate_tokens() iterate_tokens S = next(tokens) S next(tokens) next tokens K = int(next(tokens)) K int(next(tokens)) int next(tokens) next tokens solve(S, K) solve S K if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def splitSeries(s:str):
    result = []
    last = ""
    count = 0
    for c in s:
        if last == c:
            count+=1
        else:
            if last != "":
                result.append((last,count))
            last = c
            count = 1
    if last != "":
        result.append((last,count))
    return result def splitSeries(s:str):
    result = []
    last = ""
    count = 0
    for c in s:
        if last == c:
            count+=1
        else:
            if last != "":
                result.append((last,count))
            last = c
            count = 1
    if last != "":
        result.append((last,count))
    return result splitSeries def solve(S: str, K: int):
    if len(S) == 1:
        print(K//2)
    else:
        count = 0
        series = splitSeries(S)
        sp = 0
        if len(series) > 1:
            for s in series:
                if s[1] > 1:
                    sp += s[1]//2
            count += sp * K
            if series[0][0] == series[-1][0]:
                count -= (K-1)*(series[0][1]//2 + series[-1][1]//2 - (series[0][1] + series[-1][1])//2)
            print(count)
        else:
            print(series[0][1]*K//2)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template) def solve(S: str, K: int):
    if len(S) == 1:
        print(K//2)
    else:
        count = 0
        series = splitSeries(S)
        sp = 0
        if len(series) > 1:
            for s in series:
                if s[1] > 1:
                    sp += s[1]//2
            count += sp * K
            if series[0][0] == series[-1][0]:
                count -= (K-1)*(series[0][1]//2 + series[-1][1]//2 - (series[0][1] + series[-1][1])//2)
            print(count)
        else:
            print(series[0][1]*K//2)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template) solve def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(S, K) def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(S, K) main
#!/usr/bin/env python3
import sys

def splitSeries(s:str):
    result = []
    last = ""
    count = 0
    for c in s:
        if last == c:
            count+=1
        else:
            if last != "":
                result.append((last,count))
            last = c
            count = 1
    if last != "":
        result.append((last,count))
    return result



def solve(S: str, K: int):
    if len(S) == 1:
        print(K//2)
    else:
        count = 0
        series = splitSeries(S)
        sp = 0
        if len(series) > 1:
            for s in series:
                if s[1] > 1:
                    sp += s[1]//2
            count += sp * K
            if series[0][0] == series[-1][0]:
                count -= (K-1)*(series[0][1]//2 + series[-1][1]//2 - (series[0][1] + series[-1][1])//2)
            print(count)
        else:
            print(series[0][1]*K//2)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(S, K)

if __name__ == '__main__':
    main()
