Module Module1

    Sub Main()

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

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

        For i = 2 To Len(S)
            If Mid(S, i, 1) = Mid(S, i - 1, 1) Then
                c += 1
                i += 1
            End If
        Next
        If (Mid(S, Len(S), 1) <> Mid(S, Len(S) - 1, 1)) And (Mid(S, Len(S), 1) = Left(S, 1)) Then t = 1
        c += t

        Dim ans As Long = c * K

        If t = 1 Then ans -= 1

        Console.WriteLine(ans)
        'Console.ReadLine()

    End Sub

End Module
