Module Module1

    Sub Main()

        Dim S As String = Console.ReadLine()
        Dim K As Long = CLng(Console.ReadLine())

        Dim i As Integer
        Dim c As Integer = 0
        Dim t As Integer = 0

        S = S & Left(S, 1)

        For i = 1 To Len(S) - 1
            If Mid(S, i, 1) = Mid(S, i + 1, 1) Then
                c += 1
                i += 1
            End If
        Next

        If Left(S, 1) = Mid(S, Len(S) - 1, 1) And Mid(S, Len(S) - 2, 1) = Mid(S, Len(S) - 1, 1) Then
            t = -1
        End If

        Dim ans As Long = (c + t) * K

        Console.WriteLine(ans)

    End Sub

End Module
