Buggy python submission (verdict: Runtime Error):
s = list(input())
k = int(input())
S = s
cnt = 0
cnt_2 = 0
flow = 0
flow_2 = 0


for i in range(len(s)):
    if s[flow] == s[flow+1]:
        cnt += 1
        flow += 2
    else:
        flow += 1

    if flow >= len(s):
        break
# --------------------------

for i in range(len(s)):
    S.append(s[i])

for i in range(len(S)):
    if S[flow_2] == S[flow_2+1]:
        cnt_2 += 1
        flow_2 += 2
    else:
        flow_2 += 1

    if flow_2 >= len(S):
        break

if k == 1:
    print(cnt)
else:
    print(cnt + (cnt_2 - cnt) * (k-1))

    

Fixed submission:
s = list(input())
k = int(input())
S = s.copy()
S_3 =s.copy()
cnt = 0
cnt_2 = 0
cnt_3 = 0


for i in range(1, len(s)):
    if s[i-1] == s[i]:
        cnt += 1
        s[i] = "A"

# --------------------------

for i in range(len(s)):
    S.append(S[i])

for i in range(1, len(S)):
    if S[i-1] == S[i]:
        cnt_2 += 1
        S[i] = "A"

# if k == 1:
#     print(cnt)
# else:
#     print(cnt + (cnt_2 - cnt) * (k-1))

# ---------------------------------------

for i in range(len(S)):
    S_3.append(S_3[i])

for i in range(1, len(S_3)):
    if S_3[i-1] == S_3[i]:
        cnt_3 += 1
        S_3[i] = "A"

# --------------------------------------

if k == 1:
    print(cnt)
elif k == 2:
    print(cnt_2)
elif k == 3:
    print(cnt_3)
elif cnt_2 - cnt == cnt_3 - cnt_2:
    print(cnt + (cnt_2 - cnt) * (k-1))
else:
    if k % 2 == 0:
        print(int(cnt + (cnt_2 - cnt) * (k / 2) + (cnt_3 - cnt_2) * (k / 2 - 1)))
    else:
        print(int(cnt + (cnt_2 - cnt) * ((k - 1) / 2) + (cnt_3 - cnt_2) * ((k - 1) / 2)))

Buggy python submission (verdict: Runtime Error):
s = list(input())
k = int(input())
S = s
cnt = 0
cnt_2 = 0
flow = 0
flow_2 = 0


for i in range(len(s)):
    if s[flow] == s[flow+1]:
        cnt += 1
        flow += 2
    else:
        flow += 1

    if flow >= len(s)-2:
        break
# --------------------------

for i in range(len(s)):
    S.append(s[i])

for i in range(len(S)):
    if S[flow_2] == S[flow_2+1]:
        cnt_2 += 1
        flow_2 += 2
    else:
        flow_2 += 1

    if flow_2 >= len(S)-2:
        break

if k == 1:
    print(cnt)
else:
    print(cnt + (cnt_2 - cnt) * (k-1))


Fixed submission:
s = list(input())
k = int(input())
S = s.copy()
S_3 =s.copy()
cnt = 0
cnt_2 = 0
cnt_3 = 0


for i in range(1, len(s)):
    if s[i-1] == s[i]:
        cnt += 1
        s[i] = "A"

# --------------------------

for i in range(len(s)):
    S.append(S[i])

for i in range(1, len(S)):
    if S[i-1] == S[i]:
        cnt_2 += 1
        S[i] = "A"

# if k == 1:
#     print(cnt)
# else:
#     print(cnt + (cnt_2 - cnt) * (k-1))

# ---------------------------------------

for i in range(len(S)):
    S_3.append(S_3[i])

for i in range(1, len(S_3)):
    if S_3[i-1] == S_3[i]:
        cnt_3 += 1
        S_3[i] = "A"

# --------------------------------------

if k == 1:
    print(cnt)
elif k == 2:
    print(cnt_2)
elif k == 3:
    print(cnt_3)
elif cnt_2 - cnt == cnt_3 - cnt_2:
    print(cnt + (cnt_2 - cnt) * (k-1))
else:
    if k % 2 == 0:
        print(int(cnt + (cnt_2 - cnt) * (k / 2) + (cnt_3 - cnt_2) * (k / 2 - 1)))
    else:
        print(int(cnt + (cnt_2 - cnt) * ((k - 1) / 2) + (cnt_3 - cnt_2) * ((k - 1) / 2)))

Buggy python submission (verdict: Runtime Error):
s = list(input())
k = int(input())
S = s
cnt = 0
cnt_2 = 0
flow = 0
flow_2 = 0


for i in range(len(s)):
    if s[flow] == s[flow+1]:
        cnt += 1
        flow += 2
    else:
        flow += 1

    if flow >= len(s)-1:
        break
# --------------------------

for i in range(len(s)):
    S.append(s[i])

for i in range(len(S)):
    if S[flow_2] == S[flow_2+1]:
        cnt_2 += 1
        flow_2 += 2
    else:
        flow_2 += 1

    if flow_2 >= len(S)-1:
        break

if k == 1:
    print(cnt)
else:
    print(cnt + (cnt_2 - cnt) * (k-1))






Fixed submission:
s = list(input())
k = int(input())
S = s.copy()
S_3 =s.copy()
cnt = 0
cnt_2 = 0
cnt_3 = 0


for i in range(1, len(s)):
    if s[i-1] == s[i]:
        cnt += 1
        s[i] = "A"

# --------------------------

for i in range(len(s)):
    S.append(S[i])

for i in range(1, len(S)):
    if S[i-1] == S[i]:
        cnt_2 += 1
        S[i] = "A"

# if k == 1:
#     print(cnt)
# else:
#     print(cnt + (cnt_2 - cnt) * (k-1))

# ---------------------------------------

for i in range(len(S)):
    S_3.append(S_3[i])

for i in range(1, len(S_3)):
    if S_3[i-1] == S_3[i]:
        cnt_3 += 1
        S_3[i] = "A"

# --------------------------------------

if k == 1:
    print(cnt)
elif k == 2:
    print(cnt_2)
elif k == 3:
    print(cnt_3)
elif cnt_2 - cnt == cnt_3 - cnt_2:
    print(cnt + (cnt_2 - cnt) * (k-1))
else:
    if k % 2 == 0:
        print(int(cnt + (cnt_2 - cnt) * (k / 2) + (cnt_3 - cnt_2) * (k / 2 - 1)))
    else:
        print(int(cnt + (cnt_2 - cnt) * ((k - 1) / 2) + (cnt_3 - cnt_2) * ((k - 1) / 2)))

Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

s_list = []
times = 0
flow = 0



for i in range(len(s)):
    s_list.append(s[i])


while True:
    if s_list[flow] == s_list[flow + 1]:
        times += 1
        flow += 2
    elif s_list[flow] != s_list[flow + 1]:
        flow += 1

    if flow >= len(s) - 1:
        break

if s.count(s[len(s)-1]) % 2 == 1:
    if s[0] == s[len(s)-1]:
        times += 1



print(times*k)



Fixed submission:
s = list(input())
k = int(input())
S = s.copy()
S_3 =s.copy()
cnt = 0
cnt_2 = 0
cnt_3 = 0


for i in range(1, len(s)):
    if s[i-1] == s[i]:
        cnt += 1
        s[i] = "A"

# --------------------------

for i in range(len(s)):
    S.append(S[i])

for i in range(1, len(S)):
    if S[i-1] == S[i]:
        cnt_2 += 1
        S[i] = "A"

# if k == 1:
#     print(cnt)
# else:
#     print(cnt + (cnt_2 - cnt) * (k-1))

# ---------------------------------------

for i in range(len(S)):
    S_3.append(S_3[i])

for i in range(1, len(S_3)):
    if S_3[i-1] == S_3[i]:
        cnt_3 += 1
        S_3[i] = "A"

# --------------------------------------

if k == 1:
    print(cnt)
elif k == 2:
    print(cnt_2)
elif k == 3:
    print(cnt_3)
elif cnt_2 - cnt == cnt_3 - cnt_2:
    print(cnt + (cnt_2 - cnt) * (k-1))
else:
    if k % 2 == 0:
        print(int(cnt + (cnt_2 - cnt) * (k / 2) + (cnt_3 - cnt_2) * (k / 2 - 1)))
    else:
        print(int(cnt + (cnt_2 - cnt) * ((k - 1) / 2) + (cnt_3 - cnt_2) * ((k - 1) / 2)))

Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

s_list = []
times = 0
flow = 0



for i in range(len(s)):
    s_list.append(s[i])


while True:
    if s_list[flow] == s_list[flow + 1]:
        times += 1
        flow += 2
    elif s_list[flow] != s_list[flow + 1]:
        flow += 1

    if flow >= len(s) - 1:
        break

if s.count(s[len(s)-1]) % 2 == 1 :
    if s[0] == s[len(s)-1]:
        times += 1



print(times*k)



Fixed submission:
s = list(input())
k = int(input())
S = s.copy()
S_3 =s.copy()
cnt = 0
cnt_2 = 0
cnt_3 = 0


for i in range(1, len(s)):
    if s[i-1] == s[i]:
        cnt += 1
        s[i] = "A"

# --------------------------

for i in range(len(s)):
    S.append(S[i])

for i in range(1, len(S)):
    if S[i-1] == S[i]:
        cnt_2 += 1
        S[i] = "A"

# if k == 1:
#     print(cnt)
# else:
#     print(cnt + (cnt_2 - cnt) * (k-1))

# ---------------------------------------

for i in range(len(S)):
    S_3.append(S_3[i])

for i in range(1, len(S_3)):
    if S_3[i-1] == S_3[i]:
        cnt_3 += 1
        S_3[i] = "A"

# --------------------------------------

if k == 1:
    print(cnt)
elif k == 2:
    print(cnt_2)
elif k == 3:
    print(cnt_3)
elif cnt_2 - cnt == cnt_3 - cnt_2:
    print(cnt + (cnt_2 - cnt) * (k-1))
else:
    if k % 2 == 0:
        print(int(cnt + (cnt_2 - cnt) * (k / 2) + (cnt_3 - cnt_2) * (k / 2 - 1)))
    else:
        print(int(cnt + (cnt_2 - cnt) * ((k - 1) / 2) + (cnt_3 - cnt_2) * ((k - 1) / 2)))

Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

s_list = []
times = 0
flow = 0


print(s.count(s[len(s)-1]))

for i in range(len(s)):
    s_list.append(s[i])


while True:
    if s_list[flow] == s_list[flow + 1]:
        times += 1
        flow += 2
    elif s_list[flow] != s_list[flow + 1]:
        flow += 1

    if flow >= len(s) - 1:
        break

if s.count(s[len(s)-1]) % 2 == 1 :
    if s[0] == s[len(s)-1]:
        times += 1



print(times*k)



Fixed submission:
s = list(input())
k = int(input())
S = s.copy()
S_3 =s.copy()
cnt = 0
cnt_2 = 0
cnt_3 = 0


for i in range(1, len(s)):
    if s[i-1] == s[i]:
        cnt += 1
        s[i] = "A"

# --------------------------

for i in range(len(s)):
    S.append(S[i])

for i in range(1, len(S)):
    if S[i-1] == S[i]:
        cnt_2 += 1
        S[i] = "A"

# if k == 1:
#     print(cnt)
# else:
#     print(cnt + (cnt_2 - cnt) * (k-1))

# ---------------------------------------

for i in range(len(S)):
    S_3.append(S_3[i])

for i in range(1, len(S_3)):
    if S_3[i-1] == S_3[i]:
        cnt_3 += 1
        S_3[i] = "A"

# --------------------------------------

if k == 1:
    print(cnt)
elif k == 2:
    print(cnt_2)
elif k == 3:
    print(cnt_3)
elif cnt_2 - cnt == cnt_3 - cnt_2:
    print(cnt + (cnt_2 - cnt) * (k-1))
else:
    if k % 2 == 0:
        print(int(cnt + (cnt_2 - cnt) * (k / 2) + (cnt_3 - cnt_2) * (k / 2 - 1)))
    else:
        print(int(cnt + (cnt_2 - cnt) * ((k - 1) / 2) + (cnt_3 - cnt_2) * ((k - 1) / 2)))

Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

s_list = []
times = 0
flow = 0

#s = s[len(s)-1] + s

print(s.count(s[len(s)-1]))

for i in range(len(s)):
    s_list.append(s[i])


while True:
    if s_list[flow] == s_list[flow + 1]:
        times += 1
        flow += 2
    elif s_list[flow] != s_list[flow + 1]:
        flow += 1

    if flow >= len(s) - 1:
        break

if s.count(s[len(s)-1]) % 2 == 1 :
    if s[0] == s[len(s)-1]:
        times += 1



print(times*k)



Fixed submission:
s = list(input())
k = int(input())
S = s.copy()
S_3 =s.copy()
cnt = 0
cnt_2 = 0
cnt_3 = 0


for i in range(1, len(s)):
    if s[i-1] == s[i]:
        cnt += 1
        s[i] = "A"

# --------------------------

for i in range(len(s)):
    S.append(S[i])

for i in range(1, len(S)):
    if S[i-1] == S[i]:
        cnt_2 += 1
        S[i] = "A"

# if k == 1:
#     print(cnt)
# else:
#     print(cnt + (cnt_2 - cnt) * (k-1))

# ---------------------------------------

for i in range(len(S)):
    S_3.append(S_3[i])

for i in range(1, len(S_3)):
    if S_3[i-1] == S_3[i]:
        cnt_3 += 1
        S_3[i] = "A"

# --------------------------------------

if k == 1:
    print(cnt)
elif k == 2:
    print(cnt_2)
elif k == 3:
    print(cnt_3)
elif cnt_2 - cnt == cnt_3 - cnt_2:
    print(cnt + (cnt_2 - cnt) * (k-1))
else:
    if k % 2 == 0:
        print(int(cnt + (cnt_2 - cnt) * (k / 2) + (cnt_3 - cnt_2) * (k / 2 - 1)))
    else:
        print(int(cnt + (cnt_2 - cnt) * ((k - 1) / 2) + (cnt_3 - cnt_2) * ((k - 1) / 2)))