qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
S = input()
K = int(input())

a = S[0]
c = 0
g = []

for i in range(len(S)):
    if a == S[i]:
        c += 1
    else:
        g.append(c)
        a = S[i]
        c = 1

g.append(c)

if len(g) == 1:
    c = len(S) * K / 2
elif S[0] == S[-1]:
    c = int(g[0] / 2)
    c += int(g[-1] / 2)

    for i in range(1, len(g) - 1):
        c += int(g[i] / 2) * K
else:
    c = 0
    for i in g:
        c += int(i / 2) * K


print(int(c))



# Fixed code:
S = input()
K = int(input())

a = S[0]
c = 0
g = []

for i in range(len(S)):
    if a == S[i]:
        c += 1
    else:
        g.append(c)
        a = S[i]
        c = 1

g.append(c)

if len(g) == 1:
    c = len(S) * K / 2
elif S[0] == S[-1]:
    c = int(g[0] / 2)
    c += int(g[-1] / 2)
    c += int((g[0]+g[-1]) / 2) * (K-1)

    for i in range(1, len(g) - 1):
        c += int(g[i] / 2) * K
else:
    c = 0
    for i in g:
        c += int(i / 2) * K


print(int(c))
# Buggy code:
def main():
    S = input()
    K = int(input())
    a = list(S)
    cnt = 0
    if len(set(a))==1 and len(a) != 1:
        cnt = (len(a)*K)//2
        print(cnt)
    elif len(a) ==1:
        cnt += K//2
        print(cnt)
    else:
        temp = 0
        temp_2 = 0
        i = 0
        while a[i] == a[i+1]:
            temp += 1
            i += 1
        j = len(a) - 1
        while a[j] == a[j-1]:
            temp_2 += 1
            j -= 1
        for k in range(i+1,j-1):
            if a[k+1] == a[k]:
                a[k+1] = str(k)
                cnt += 1
        cnt *= K
        cnt += temp//2
        cnt += temp_2//2
        
        if a[0] == a[-1]:
            temp_3 = (temp + temp_2)//2
            cnt += temp_3 * (K-1)

        print(cnt)

    
if __name__ == '__main__':
    main()

# Fixed code:
def main():
    S = input()
    K = int(input())
    a = list(S)
    cnt = 0
    if len(set(a))==1:
        cnt = (len(a)*K)//2
    elif a[0] != a[-1]:
        for l in range(len(a)-1):
            if a[l+1] == a[l]:
                a[l+1] = str(l)
                cnt += 1
        cnt *= K
    else:
        temp = 1
        temp_2 = 1
        i = 0
        while a[i] == a[i+1]:
            temp += 1
            i += 1
        j = len(a) - 1
        while a[j] == a[j-1]:
            temp_2 += 1
            j -= 1
        for k in range(i+1,j-1):
            if a[k+1] == a[k]:
                a[k+1] = str(k)
                cnt += 1
        cnt *= K
        cnt += temp//2
        cnt += temp_2//2
        temp_3 = (temp + temp_2)//2
        cnt += temp_3 * (K-1)


    print(cnt)

    
if __name__ == '__main__':
    main()
# Buggy code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: map(str, sys.stdin.buffer.readline().split())
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

s = rr()
k = ri()
cnt = 0
i = 0
if len(set(s)) == 1:
  print(int(s*k/2))
  exit()
while i < len(s)-1:
  if s[i] == s[i+1]:
    cnt += 1
    i += 1
  i += 1
print(cnt)
cnt1 = 0
i1 = 0
s *= 2
while i1 < len(s)-1:
  if s[i1] == s[i1+1]:
    cnt1 += 1
    i1 += 1
  i1 += 1
print(cnt1)
print((cnt1 - cnt)*(k-1) + cnt)



# Fixed code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: map(str, sys.stdin.buffer.readline().split())
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

s = rr()
k = ri()
cnt = 0
i = 0
if len(set(s)) == 1:
  print(int(len(s)*k/2))
  exit()
while i < len(s)-1:
  if s[i] == s[i+1]:
    cnt += 1
    i += 1
  i += 1
cnt1 = 0
i1 = 0
s *= 2
while i1 < len(s)-1:
  if s[i1] == s[i1+1]:
    cnt1 += 1
    i1 += 1
  i1 += 1
print((cnt1 - cnt)*(k-1) + cnt)
# Buggy code:
s=input()
k=int(input())
a=set(s)
if len(a)==1:print(k*len(s)//2)
else:
  V=[]
  unit=0
  for i in s:
	if len(V)==0 or V[-1][0]!=i:
		V.append([i,1])
	else:
		V[-1][1] += 1
  for i in V:
    unit+=i[1]//2
  ans=unit*k
  if s[0]==s[-1]:
    ans=ans-(V[0][1]//2+V[-1][1]//2-(V[0][1]+V[-1][1])//2)*(k-1)
  print(ans)

# Fixed code:
s=input()
k=int(input())
a=set(s)
if len(a)==1:print(k*len(s)//2)
else:
  V=[]
  unit=0
  for i in s:
    if len(V)==0 or V[-1][0]!=i:
      V.append([i,1])
    else:
      V[-1][1] += 1
  for i in V:
    unit+=i[1]//2
  ans=unit*k
  if s[0]==s[-1]:
    ans=ans-(V[0][1]//2+V[-1][1]//2-(V[0][1]+V[-1][1])//2)*(k-1)
  print(ans)
# Buggy code:
import sys, math; readline = sys.stdin.readline; from collections import deque;

S = readline().rstrip()
K = int(readline())

a = []

_c = None
_count = 0
for c in S:
    if c == _c:
        a[-1] += 1
    else:
        a.append(1)
    _c = c
total = 0

if len(a) >= 2:
    for x in a[1:-1]:
        total += x // 2 * K

    if S[0] == S[-1]:
        total += (a[0] + a[-1]) // 2 * (K - 1)
        total += a[0] // 2 + a[-1] // 2
    else:
        total += (a[0] // 2 + a[-1] // 2) * K
else:
    total = a[0] // 2

print(total)

# Fixed code:
import sys, math; readline = sys.stdin.readline; from collections import deque;

S = readline().rstrip()
K = int(readline())

a = []

_c = None
_count = 0
for c in S:
    if c == _c:
        a[-1] += 1
    else:
        a.append(1)
    _c = c
total = 0

if len(a) >= 2:
    for x in a[1:-1]:
        total += x // 2 * K

    if S[0] == S[-1]:
        total += (a[0] + a[-1]) // 2 * (K - 1)
        total += a[0] // 2 + a[-1] // 2
    else:
        total += (a[0] // 2 + a[-1] // 2) * K
else:
    total = (a[0] * K) // 2

print(total)
# Buggy code:
S = input()
K = int(input())

curr = S[0]
tmp = ""
T = []
for s in S:
    if s == curr:
        tmp += s
    else:
        T.append(tmp)
        curr = s
        tmp = s
T.append(tmp)

if len(T) == 1:
    t = T[0]
    res = 0
    if len(t) == 1:
        res = K // 2
    elif len(t) == 2 and t[0] != t[1]:
        res = 0
    elif len(t) == 2 and t[0] == t[1]:
        res = K
    elif len(t) % 2 == 0:
        res = (len(t) // 2) * K
    else:
        res = (len(t) // 2) * K
        res += K - 1
    print(res)
    exit(0)

res = 0

t_first = T[0]
t_last = T[-1]

if t_first[0] != t_last[0]:
    res += len(t_first) // 2
    res += len(t_last) // 2
else:
    if len(t_first) == 1:
        res += K - 1
        res += (len(t_last) // 2) * K
    elif len(t_last) == 1:
        res += K - 1
        res += (len(t_first) // 2) * K
    elif len(t_first) % 2 != 0 and len(t_last) % 2 != 0:
        res += (len(t_first) // 2) * K
        res += (len(t_last) // 2) * K
        res += K - 1
    else:
        res += (len(t_first) // 2) * K
        res += (len(t_last) // 2) * K

for t in T[1:-1]:
    res += (len(t) // 2) * K

print(res)


# Fixed code:
S = input()
K = int(input())

curr = S[0]
tmp = ""
T = []
for s in S:
    if s == curr:
        tmp += s
    else:
        T.append(tmp)
        curr = s
        tmp = s
T.append(tmp)

if len(T) == 1:
    res = (len(S) * K) // 2
    print(res)
    exit(0)

res = 0
t_first = T[0]
t_last = T[-1]

if t_first[0] != t_last[0]:
    res += (len(t_first) // 2) * K
    res += (len(t_last) // 2) * K
else:
    res += len(t_first) // 2
    res += len(t_last) // 2
    res += (len(t_first + t_last) // 2) * (K - 1)

for t in T[1:-1]:
    res += (len(t) // 2) * K

print(res)
# Buggy code:
s = list(input())
k = int(input())
ans = 0

if s[0] != s[-1]:
    for i in range(len(s)-1):
        if s[i] == s[i + 1]:
            s[i+1] = "OK"
            ans += 1
    print(ans * k)

else:
    if len(set(s)) == 1:
        if len(s) % 2 == 0:
            print((len(s) // 2) * k)
        else:
            print(len(s) * (k // 2) if k %
                  2 == 0 else len(s) * (k // 2) + (len(s) // 2))
    else:
        mae = 1
        for i in range(len(s) - 1):
            if s[i] == s[i + 1]:
                mae += 1
            else:
                break

        ushiro = 1
        for i in range(len(s) - 1, 0, -1):
            if s[i] == s[i - 1]:
                ushiro += 1
            else:
                break

        for i in range(len(s)-1):
            if s[i] == s[i + 1]:
                s[i+1] = "OK"
                ans += 1

        ans_ = 0
        for i in range(mae, len(s) - ushiro):
            if s[i] == "OK":
                ans_ += 1
        print(((mae + ushiro) // 2 * (k - 1)), ans_ * (k - 1), ans)
        print(((mae + ushiro) // 2 * (k - 1)) + ans_ * (k - 1) + ans)


# Fixed code:
s = list(input())
k = int(input())
ans = 0

if s[0] != s[-1]:
    for i in range(len(s)-1):
        if s[i] == s[i + 1]:
            s[i+1] = "OK"
            ans += 1
    print(ans * k)

else:
    if len(set(s)) == 1:
        if len(s) % 2 == 0:
            print((len(s) // 2) * k)
        else:
            print(len(s) * (k // 2) if k %
                  2 == 0 else len(s) * (k // 2) + (len(s) // 2))
    else:
        mae = 1
        for i in range(len(s) - 1):
            if s[i] == s[i + 1]:
                mae += 1
            else:
                break

        ushiro = 1
        for i in range(len(s) - 1, 0, -1):
            if s[i] == s[i - 1]:
                ushiro += 1
            else:
                break

        for i in range(len(s)-1):
            if s[i] == s[i + 1]:
                s[i+1] = "OK"
                ans += 1

        ans_ = 0
        for i in range(mae, len(s) - ushiro):
            if s[i] == "OK":
                ans_ += 1
        print(((mae + ushiro) // 2 * (k - 1)) + ans_ * (k - 1) + ans)
# Buggy code:
S = input()
K = int(input())

if len(set(s)) == 1:
    print(len(S)*K//2)
    exit()

b = [1]
for i in S[:-1]:
    if S[i] == S[i+1]:
        b[-1] += 1
    else:
        b.append(1)

ans = 0
for i in b:
    ans += i//2
ans *= K

if S[0] == S[-1] and b[0]%2 == b[-1]%2 == 1:
    ans += K - 1
print(ans)

# Fixed code:
S = input()
K = int(input())

if len(set(S)) == 1:
    print(len(S)*K//2)
    exit()

b = [1]
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        b[-1] += 1
    else:
        b.append(1)

ans = 0
for i in b:
    ans += i//2
ans *= K

if S[0] == S[-1] and b[0]%2 == b[-1]%2 == 1:
    ans += K - 1
print(ans)
# Buggy code:
s = input()
k = int(input())

if len(s) == 1:
    print(k//2)
    exit(0)

if len(list(set(s))) == 1:
    print((len(s)//2)*(k+1))
    exit(0)

count = 0
    
ngo = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        ngo+=1
    else:
        count += ngo//2
        ngo=1
count += ngo//2

ngongo = 0
while ngongo < len(s) and s[len(s)-ngongo-1] == s[-1]:
    ngongo+=1

ngongongo = 0
while ngongongo < len(s) and s[ngongongo] == s[0]:
    ngongongo += 1
    
f = 0
if ngongo %2 == 1 and ngongongo %2 == 1 and s[0] == s[-1]:
    count += 1
    f += 1

print(count*k-f)

# Fixed code:
s = input()
k = int(input())

if len(s) == 1:
    print(k//2)
    exit(0)

if len(list(set(s))) == 1 and len(s)%2 == 1:
    print((len(s)//2)*k+k//2)
    exit(0)

count = 0
    
ngo = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        ngo+=1
    else:
        count += ngo//2
        ngo=1
count += ngo//2

ngongo = 0
while ngongo < len(s) and s[len(s)-ngongo-1] == s[-1]:
    ngongo+=1

ngongongo = 0
while ngongongo < len(s) and s[ngongongo] == s[0]:
    ngongongo += 1
    
f = 0
if ngongo %2 == 1 and ngongongo %2 == 1 and s[0] == s[-1]:
    count += 1
    f += 1

print(count*k-f)
# Buggy code:
s = [c for c in input()]
k = int(input())

import copy

if len(s) == 1:
    print(k-1)

elif len(s) == len(set(s)):
    print(0)
    
elif s[0] != s[-1]:
    c = 0
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            c = c + 1
            s[i] = 'Z'
    print(c*k)

else: # s[0]==s[-1]
    c = 0
    s2 = copy.copy(s)
    for i in range(1, len(s)):
        if s2[i-1] == s2[i]:
            c = c + 1
            s2[i] = 'Z'
    print(s2)
    if s2[-1] == 'Z':
        print(c*k)
    else:
        c2 = 1
        s[0] = 'Z'
        for i in range(1, len(s)):
            if s[i-1] == s[i]:
                s[i] = 'Z'
                c2 = c2 + 1
        print(s)
        if s[-1] == 'Z':
            if k % 2 == 0:
                print(int((c+c2)*(k/2)))
            else:
                print(int((c+c2)*((k-1)/2)+c))
        else:
            if  k%2 ==0:
                print(int(((c+c2)*(k/2))))
            else:
                print(int((c+c2)*((k-1)/2) + c))

# Fixed code:
s = [c for c in input()]
k = int(input())

import copy

if len(s) == 1:
    print(k//2)

elif len(s) == len(set(s)):
    print(0)
    
elif s[0] != s[-1]:
    c = 0
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            c = c + 1
            s[i] = 'Z'
    print(c*k)

else: # s[0]==s[-1]
    s2 = copy.copy(s)
    c = 0
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            c = c + 1
            s[i] = 'Z'
    if s[-1] == 'Z':
        print(c*k)
    else:
        c2 = 1
        s2[0] = 'Z'
        for i in range(1, len(s)):
            if s2[i-1] == s2[i]:
                s2[i] = 'Z'
                c2 = c2 + 1
        if s2[-1] == 'Z':
            if k % 2 == 0:
                print(int((c+c2)*(k/2)))
            else:
                print(int((c+c2)*((k-1)/2)+c))
        else:
            print(c + c2*(k-1))
# Buggy code:
def input_list():
  return list(map(int, input().split()))


def main():
  s = list(input())
  k = int(input())
  sw = [s[0]]
  num = 0
  numbers = [num]
  for i in range(1, len(s)):
    if s[i-1] != s[i]:
      num += 1
    numbers.append(num)
    if num == 0 and sw[0] == s[i]:
      sw.append(s[i])

  num = 0
  end_w = s[-1]
  ew = []
  for i in range(len(s)-1, -1, -1):
    if end_w != s[i]:
      num += 1
    if num == 0 and end_w == s[i]:
      ew.append(s[i])
  nc = collections.Counter(numbers)
  
  a = 0
  for n,c in nc.items():
    if c == len(s):
      print(len(s))
    if c == 1:
      continue
    if c % 2 == 0:
      a += c // 2
    else:
      a += (c-1)//2
  
  ans = a * k
  b = 0
  if ew[0] == sw[0]:
    haji = len(sw) + len(ew)
    if haji == 2:
      print(ans + haji)
      exit(0)
    
    b = int(len(sw)/2 + len(ew)/2) - haji//2
  print(ans - b)
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

# Fixed code:
def input_list():
  return list(map(int, input().split()))


def main():
  s = list(input())
  k = int(input())
  if len(set(s)) == 1:
    print(int(len(s)*(k/2)))
    exit()
  
  sw = [s[0]]
  num = 0
  numbers = [num]
  for i in range(1, len(s)):
    if s[i-1] != s[i]:
      num += 1
    numbers.append(num)
    if num == 0 and sw[0] == s[i]:
      sw.append(s[i])

  num = 0
  end_w = s[-1]
  ew = []
  for i in range(len(s)-1, -1, -1):
    if end_w != s[i]:
      num += 1
    if num == 0 and end_w == s[i]:
      ew.append(s[i])
  nc = collections.Counter(numbers)
  
  a = 0
  for n,c in nc.items():
    if c == 1:
      continue
    if c % 2 == 0:
      a += c // 2
    else:
      a += (c-1)//2
  
  ans = a * k
  b = 0
  if ew[0] == sw[0]:
    haji = len(sw) + len(ew)
    if haji % 2 == 0:
      print(a * k + (k-1))
      exit()
  print(ans - b)
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()
# Buggy code:
import sys
string = input()
K = int(input())

if len(set(string)) == 1:
    print((K * len(string)) // 2)
    sys.exit()


f = string[0]
l = string[-1]
if f == l:
    first = 1
    for i in range(1, len(string)):
        if string[i] == f:
            first += 1
        else:
            break
    last = 1
    for i in range(len(string) - 2, 0, -1):
        if string[i] == l:
            last += 1
        else:
            break
ans = 0
final = 0
if (first + last) % 2 == 0 and first % 2 and last % 2:
    final = K - 1

string = string + '_'

count = 1
for n in range(1, len(string)):
    if string[n - 1] == string[n]:
        count += 1
    elif string[n - 1] != string[n] or n == len(string) - 1:
        if count >= 2:
            ans += (count // 2)
            #print(f'n: {n}')
            #print(count)
            #print(ans)
        count = 1
print(ans * K + final)

# Fixed code:
import sys
string = input()
K = int(input())

if len(set(string)) == 1:
    print((K * len(string)) // 2)
    sys.exit()


f = string[0]
l = string[-1]
if f == l:
    first = 1
    for i in range(1, len(string)):
        if string[i] == f:
            first += 1
        else:
            break
    last = 1
    for i in range(len(string) - 2, 0, -1):
        if string[i] == l:
            last += 1
        else:
            break
else:
    first = 0
    last = 0

ans = 0
final = 0
if (first + last) % 2 == 0 and first % 2 and last % 2:
    final = K - 1

string = string + '_'

count = 1
for n in range(1, len(string)):
    if string[n - 1] == string[n]:
        count += 1
    elif string[n - 1] != string[n] or n == len(string) - 1:
        if count >= 2:
            ans += (count // 2)
            #print(f'n: {n}')
            #print(count)
            #print(ans)
        count = 1
print(ans * K + final)
# Buggy code:
from sys import stdin

S = stdin.readline().rstrip()
K = int(stdin.readline().rstrip())
ans_odd = 0
ans_even = 0
changed_odd = [False] * len(S)
changed_even = [False] * len(S)

if len(S) == 1:
    print(K // 2)
    exit()

cnt = 1
ans = 0
i = 0
begin = 0
end = 0

start = 0
for i in range(1, len(S)):
    if S[i - 1] != S[i]:
        if start == 0:
            begin += cnt
        else:
            if cnt >= 2:
                print(cnt)
                ans += cnt // 2
        cnt = 1
        start = i
    else:
        cnt += 1
    if i == len(S) - 1:
        end += cnt
        break

if S[0] != S[-1]:
    print(ans * K + (begin // 2) * K + (end // 2) * K)
else:
    print(ans * K + begin // 2 + end // 2 + ((begin + end) // 2) * (K - 1))

# Fixed code:
from sys import stdin

S = stdin.readline().rstrip()
K = int(stdin.readline().rstrip())
ans_odd = 0
ans_even = 0
changed_odd = [False] * len(S)
changed_even = [False] * len(S)

if len(S) == 1:
    print(K // 2)
    exit()

cnt = 1
ans = 0
begin = 0
end = 0

start = 0
for i in range(1, len(S)):
    if S[i - 1] != S[i]:
        if start == 0:
            begin += cnt
        else:
            if cnt >= 2:
                ans += cnt // 2
        cnt = 1
        start = i
    else:
        cnt += 1
    if i == len(S) - 1:
        if start == 0:
            print((cnt * K) // 2)
            exit()
        end += cnt
        break

if S[0] != S[-1]:
    print(ans * K + (begin // 2) * K + (end // 2) * K)
else:
    print(ans * K + begin // 2 + end // 2 + ((begin + end) // 2) * (K - 1))
# Buggy code:
s = input()
k = int(input())
import sys

if s.count(s[0]) == len(s):
  print((len(s) * k) // 2)
  sys.exit()

c_c = 0
c_e = 0
counter = 1

for i in range(-1, -len(s)-1, -1):
  print(s[i])
  if s[0] == s[i]:
    counter += 1
  else:
    break
if counter % 2 == 0:
  c_e = 1

for i in range(len(s) - 1):
  
  if s[i] != s[i+1]:
    counter = 1
  else:
    counter += 1
    if counter % 2 == 0:
      c_c += 1

ans = c_c * k + c_e * (k-1)
print(ans)

# Fixed code:
s = input()
k = int(input())
import sys


if s.count(s[0]) == len(s):
  print((len(s) * k) // 2)
  sys.exit()

c_c = 0
c_e = 0
counter = 1

for i in range(-1, -len(s)-1, -1):
#  print(counter)
  if s[0] == s[i]:
    counter += 1
  else:
    break
if counter % 2 == 0:
  c_e = 1
#print(c_e)
#print()

for i in range(len(s) - 1):
  if s[i] != s[i+1]:
    counter = 1
  else:
    counter += 1
    if counter % 2 == 0:
      c_c += 1
#  print(s[i+1], counter, c_c)

counter = 1
c_f = 0
for i in range(len(s) - 1):
  if s[i] != s[i+1]:
    counter = 1
  else:
    counter += 1
    if counter % 2 == 0:
      c_f += 1
#  print(c_f)
#  print()

ans = (c_c + c_e) * (k-1) + c_f
print(ans)
# Buggy code:
import sys
s = input()
k = int(input())

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


l = 0
while (True):
    if s[l] != s[l+1]:
        break
    if l == len(s)-2:
        print(int((len(s) * k) / 2))
        sys.exit()
    l += 1



j = 0
counta = 1
while (j<=len(s)-2):
    if s[j] == s[j+1]:
        counta += 1
        j += 1
        continue
    else:
        break

print(counta)
if counta % 2 == 0:
    flaga = 0
else:
    flaga = 1
        


countb = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        s = s[:i+1] + "0" + s[i+2:]
        countb += 1


flagb = 0
if s[len(s)-1] == s[0]:
    if flaga == 1:
        countb += 1
        flagb = 1
        
    


if flagb == 0:
    print(countb * k)
else:
    print(countb * k - 1)










 

 


                                        




    




        


    







        



# Fixed code:
import sys
s = input()
k = int(input())

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


l = 0
while (True):
    if s[l] != s[l+1]:
        break
    if l == len(s) - 2:
        print(int((len(s) * k) / 2))
        sys.exit()
    l += 1



j = 0
counta = 1
while (j<=len(s)-2):
    if s[j] == s[j+1]:
        counta += 1
        j += 1
        continue
    else:
        break


if counta % 2 == 0:
    flaga = 0
else:
    flaga = 1
        


countb = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        s = s[:i+1] + "0" + s[i+2:]
        countb += 1


flagb = 0
if s[len(s)-1] == s[0]:
    if flaga == 1:
        countb += 1
        flagb = 1
        
    


if flagb == 0:
    print(countb * k)
else:
    print(countb * k - 1)
# Buggy code:
s=input()
k=int(input())
c=0
b=[]
l=1
r=0
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    c+=1
  else:
    b.append(c)
    l=0
if s[0]==s[-1]:
  c+=b[0]
else:
  b.append(c)
  c=0
if l==1:
  print((len(s)*k)//2)
else:
  if s[0]==s[-1]:
    for i in range(len(b)-1):
      r+=(b[i+1]//2)*k
    print(r+b[0]+b[-1]+(c//2)*(k-1))
  else:
    for i in range(len(b)):
      r+=((b[i]//2)*k)
    print(r)

# Fixed code:
s=input()
k=int(input())
c=1
b=[]
l=1
r=0
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    c+=1
  else:
    b.append(c)
    l=0
    c=1
if s[0]==s[-1]:
  b.append(c)
  c+=b[0]
else:
  b.append(c)
  c=0
if l==1:
  print((len(s)*k)//2)
else:
  if s[0]==s[-1]:
    if len(b)>=2:
      for i in range(len(b)-2):
        r+=(b[i+1]//2)*k
    print(r+b[0]//2+b[-1]//2+(c//2)*(k-1))
  else:
    for i in range(len(b)):
      r+=((b[i]//2)*k)
    print(r)
# Buggy code:
def p(st):
    l=len(st)
    tc=1
    ac=0
    p=s[0]
    for i in range(1,l):
        if st[i]==p:
            tc+=1
        else:
            ac+=tc//2
            tc=1
            p=st[i]
    else:
        ac+=tc//2
    return ac

s=input()
k=int(input())
n=len(s)
if n==1:
    print(k//2)
    exit()
if n==2:
    if s[0]==s[1]:
        print(k)
    else:
        print(0)
    exit()
ac=p(s)
if k>1:
    ac2=p(s+s)
    if ac==ac2:
        print(ac*k)
    elif ac2-ac==1:
        print(ac*k+(k-1))
    elif ac2-ac==2:
        print(ac*k+(k//2))
else:
    print(ac)

# Fixed code:
def p(st):
    l=len(st)
    tc=1
    ac=0
    p=s[0]
    for i in range(1,l):
        if st[i]==p:
            tc+=1
        else:
            ac+=tc//2
            tc=1
            p=st[i]
    else:
        ac+=tc//2
    return ac

s=input()
k=int(input())
n=len(s)
if n==1:
    print(k//2)
    exit()
if n==2:
    if s[0]==s[1]:
        print(k)
    else:
        print(0)
    exit()
ac=p(s)
if k>1:
    ac4=p(s+s+s+s)
    if ac*4==ac4:
        print(ac*k)
    elif ac4-ac*4==3:
        print(ac*k+(k-1))
    elif ac4-ac*4==2:
        print(ac*k+(k//2))
else:
    print(ac)