Problem:
Score : 300 points

Problem Statement

Given is a string S. Let T be the concatenation of K copies of S.
We can repeatedly perform the following operation: choose a character in T and replace it with a different character.
Find the minimum number of operations required to satisfy the following condition: any two adjacent characters in T are different.

Constraints

1 \leq |S| \leq 100

S consists of lowercase English letters.

1 \leq K \leq 10^9

K is an integer.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the minimum number of operations required.

Sample Input 1

issii
2

Sample Output 1

4

T is issiiissii. For example, we can rewrite it into ispiqisyhi, and now any two adjacent characters are different.

Sample Input 2

qq
81

Sample Output 2

81

Sample Input 3

cooooooooonteeeeeeeeeest
999993333

Sample Output 3

8999939997

Solution in Go (1.6) (judge verdict: Wrong Answer)

package main

import (
        "bufio"
        "fmt"
        "os"
        "strconv"
        "strings"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int              { return readIntArray()[0] }
func readInt2() (int, int)      { a := readIntArray(); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(); return a[0], a[1], a[2] }
func readIntArray() []int {
        a := make([]int, 0, 1000)
        sc.Scan()
        for _, v := range strings.Split(sc.Text(), " ") {
                vv, _ := strconv.Atoi(v)
                a = append(a, vv)
        }
        return a
}
func readString() string        { return readStringArray()[0] }
func readStringArray() []string { sc.Scan(); return strings.Split(sc.Text(), " ") }

func main() {
        s := readString()
        k := readInt()

        var count int
        var prev rune
        for _, r := range s {
                if prev == r {
                        count++
                        prev = 0
                } else {
                        prev = r
                }
        }

        // a x3 -> aaa -> aba
        if len(s) == 1 {
                fmt.Println(k / 2)
                return
        }

        // aa x3 -> aaaaaa -> ababab
        if len(s) == 2 && s[0] == s[1] {
                fmt.Println(k)
                return
        }

        // aaa x3 -> aaaaaaaaa -> abcabcabc
        if len(s) == 3 && s[0] == s[1] && s[0] == s[2] {
                fmt.Println(2 * k)
                return
        }

        var joinChange int
        if s[0] == s[len(s)-1] && s[len(s)-1] != s[len(s)-2] {
                joinChange = 1
        }

        fmt.Println(count*k + joinChange*(k-1))
}