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 (Python):
S = input()
K = int(input())

num = 0
tmp = 1
flg = True
for i in range(1, len(S)):
    if S[i] == S[i-1]:
        tmp += 1
    else:
        num += tmp // 2
        if flg:
            fst = tmp   
            flg = False
        tmp = 1
num += tmp // 2

if flg: 
    ans = (len(S) * K) // 2
elif S[0] == S[-1] and tmp % 2 and fst % 2:
    ans = num * K + K - 1
else:
    ans = num * K 

print(ans)

Solution (Python):
s = input().strip()
k = int(input())

head_count = 0
tail_count = 0
cont_count = 0
if s[0] == s[-1]:
    i = 1
    while i < len(s) and s[i] == s[0]:
        i += 1
    if i == len(s):
        print((k * len(s)) // 2)
        exit(0)
    j = len(s) - 2
    while j >= 0 and s[-1] == s[j]:
        j -= 1
    head_count = i // 2
    tail_count = (len(s) - j - 1) // 2
    cont_count = (i + len(s) - j - 1) // 2
    s = s[i:(j + 1)]
char = ''
local_cnt = 0
count = 0
for c in s:
    if c == char:
        local_cnt += 1
    else:
        count += local_cnt // 2
        local_cnt = 1
        char = c
if local_cnt >= 2:
    count += local_cnt // 2

print(head_count + count * k + cont_count * (k - 1) + tail_count)

Solution (Python):
s = input()
k = int(input())
split_s = []
counter = 1
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        split_s.append(counter)
        counter = 1
    else:
        counter += 1
split_s.append(counter)

ans = 0
if len(split_s) == 1:
    print(len(s)*k//2)
elif s[0] != s[-1]:
    
    for i in range(len(split_s)):
        ans += split_s[i]//2
    print(ans*k)
else:
    
    for i in range(1, len(split_s)-1):
        ans += split_s[i]//2
    ans += (split_s[-1]+split_s[0])//2
    ans *= k-1
    for i in range(len(split_s)):
        ans += split_s[i]//2
    print(ans)

Solution (Python):
S = input()
K = int(input())

last_changed = False
x = 0
for a,b in zip(S,S[1:]):
    if a == b and not last_changed:
        x += 1
        last_changed = True
    else:
        last_changed = False

if last_changed or S[0] != S[-1]:
    print(x*K)
    exit()

last_changed = True
y = 1
for a,b in zip(S,S[1:]):
    if a == b and not last_changed:
        y += 1
        last_changed = True
    else:
        last_changed = False

if last_changed:
    m = K//2
    print(y*m + x*(m+K%2))
else:
    print(x + y*(K-1))

Solution (Python):
S = input()
K = int(input())

L = []
temp = S[0]
c = 1
for i in range(1, len(S)):
    if S[i] == temp:
        c += 1
    else:
        L.append(c)
        c = 1
        temp = S[i]
    if i == len(S)-1:
        L.append(c)
        
ans = 0

if S[0] != S[-1]:
    for i in range(len(L)):
        ans += (L[i]//2)
    ans *= K
else:
    if len(L) == 1:
        ans += K*L[0]//2
    elif len(L) == 0:
        ans += K//2
    else:
        for i in range(1, len(L)-1):
            ans += (L[i]//2)
        ans *= K
        ans += L[0]//2
        ans += L[-1]//2
        ans += (L[0]+L[-1])//2*(K-1)
        
print(ans)

Solution (Python):
S = input()
K = int(input())

cnt = 1
ans = 0
cnt2 = 1
flag = True
for i in range(1, len(S)):
  if S[i] == S[i - 1]:
    cnt += 1
    if flag:
      cnt2 += 1
  else:
    ans += cnt // 2
    cnt = 1
    flag = False

ans += cnt // 2
ans *= K
if flag:
  ans = (cnt * K) // 2
elif S[0] == S[-1] and cnt % 2 == 1 and cnt2 % 2 == 1:
  ans += K - 1

print(ans)

Solution (Python):
import collections

s = list(input())
k = int(input())
n = len(s)
ans = 0
if k == 1:
    for i in range(n - 1):
        if s[i] == s[i + 1]:
            ans += 1
            s[i + 1] = -1
    print(ans)
else:
    if collections.Counter(s).most_common()[0][1] == n:
        print(n * k // 2)
    else:
        ans1 = 0
        sd = s[:]
        for i in range(n - 1):
            if sd[i] == sd[i + 1]:
                ans1 += 1
                sd[i + 1] = -1
        s += s
        for i in range(n * 2 - 1):
            if s[i] == s[i + 1]:
                ans += 1
                s[i + 1] = -1
        ans -= ans1
        print(ans * (k - 1) + ans1)

Solution (Python):

S = input()
K = int(input())

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

if S[0] != S[-1]:
    f = 0
    t = 0
    ans = 0
    for k in range(1,len(S)):
        if S[k-1] == S[k] and f == 0:
            f = 1
            t = 2
        elif S[k-1] == S[k] and f == 1:
            t += 1
        else:
            ans += t//2
            t = 0
            f = 0
    ans += t//2
    print(ans*K)
else:
    t = set([str(x) for x in S])
    if len(t) == 1:
        print((len(S)*K)//2)
    else:
        mae = 0
        ushiro = 0
        for k in range(len(S)):
            if S[k] == S[0]:
                mae += 1
            else:
                break
        for k in range(len(S)):
            if S[-k-1] == S[0]:
                ushiro += 1
            else:
                break
        f = 0
        t = 0
        ans = 0
        for k in range(mae,len(S)-ushiro):
            if S[k-1] == S[k] and f == 0:
                f = 1
                t = 2
            elif S[k-1] == S[k] and f == 1:
                t += 1
            else:
                ans += t//2
                t = 0
                f = 0
        ans += t//2
        print(ans*K + mae//2 + ushiro//2 + (K-1)*((mae+ushiro)//2))

Solution (Python):
def f(s):

    ar = list(s)
    
    result = 0

    for i in range(1, len(ar)):
        if ar[i] == ar[i - 1]:
            ar[i] = '.'
            result += 1
    
    return result


s = input()
k = int(input())

if s[0] != s[-1]:
    print(f(s) * k)
else:

    l, r = 0, len(s) - 1

    while l < len(s) and s[l] == s[0]:
        l += 1
    
    while r >= 0 and s[r] == s[-1]:
        r -= 1
    
    l, r = l - 1, r + 1

    if r == 0:
        print((len(s) * k) // 2)
    else:
        print((l + 1) // 2 + (len(s) - r) // 2 + f(s[l + 1 : r]) * k + ((l + 1 + len(s) - r) // 2) * (k - 1))

Solution (Python):
S = input()
K = int(input())

len_array = [0] * 100

s_old = S[0]
count = 0
first_flag = 1
first_count = 0
last_count = 0
for s in S:
    if s_old == s:
        count += 1
    else:
        if first_flag:
            first_count = count
            first_flag = 0
        len_array[count - 1] += 1
        count = 1
    s_old = s
last_count = count
len_array[count - 1] += 1
if count == len(S):
    print(count * K // 2)
    exit()

if S[0] != S[-1]:
    ans = 0
    for i, l in enumerate(len_array):
        ans += (i + 1) // 2 * l
    print(ans * K)
    exit()
else:
    len_array[first_count - 1] -= 1
    len_array[last_count - 1] -= 1
    ans = 0
    for i, l in enumerate(len_array):
        ans += (i + 1) // 2 * l
    ans = ans * K + ((first_count + last_count) // 2) * (
        K - 1) + first_count // 2 + last_count // 2
    print(ans)
    exit()

Solution (Python):
S = input().strip()
K = int(input())

counts = []
prev = S[0]
count = 1
for c in S[1:]:
	if prev == c:
		count += 1
	else:
		counts.append(count)
		count = 1
	prev = c
if count > 0:
	counts.append(count)

total = 0
if len(counts) == 1:
	total += (counts[0] * K) // 2
elif K > 1 and S[0] == S[-1]:
	for count in counts[1:-1]:
		total += (count // 2) * K
	total += counts[0] // 2
	total += counts[-1] // 2
	total += ((counts[0] + counts[-1]) // 2) * (K - 1)
else:
	for count in counts:
		if count > 1:
			total += (count // 2) * K
print(total)

Solution (Python):
S = input()
K = int(input())

cont = []
n = 1
t = S[0]
for s in S[1:]:
    if s == t:
        n += 1
    else:
        cont.append(n)
        n = 1
    t = s
else:
    cont.append(n)

C = len(cont)
ans = 0
if C == 1:
    ans += (cont[0]  * K // 2)
else:
    for i in range(1, C-1):
        ans += cont[i] // 2
    ans *= K
    ans += cont[0] // 2
    ans += cont[-1] // 2
    if S[0] == S[-1]:
        ans += ((cont[0] + cont[-1]) // 2) * (K-1)
    else:
        ans += (cont[0] // 2) * (K-1)
        ans += (cont[-1] // 2) * (K-1)

print(ans)

Solution (Python):
S = input()
K = int(input())

C = []
c = 0
s = S[0]
for i in range(len(S)):
    if S[i] == s:
        c += 1
    else:
        C.append(c)
        c = 1
        s = S[i]
C.append(c)

ans = 0
if S[0]!=S[-1]:
    for c in C:
        ans += (c//2)*K
else:
    if S == S[0]*len(S):
        ans = (len(S)*K)//2
    else:
        for i in range(1,len(C)-1):
            ans += K*(C[i]//2)
        ans += (K-1)*((C[0]+C[-1])//2)+C[0]//2+C[-1]//2
print(ans)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    s = S()
    k = I()
    n = len(s)
    for i in range(n):
        if s[i] != s[0]:
            break
    else:
        print((k*n)>>1)
        return
    s += s
    t = s[i-1]
    for j in range(n)[::-1]:
        if s[j] != t:
            break
    s = s[i:j+1]
    ans = (i>>1)+((n-1-j)>>1)+((n-1-j+i)>>1)*(k-1)
    i = 0
    n = len(s)
    while i < n:
        t = s[i]
        l = 0
        while i < n and t == s[i]:
            i += 1
            l += 1
        ans += (l >> 1)*k
    print(ans)
    return


def B():

    return


def C():

    return


def D():

    return


def E():

    return


def F():

    return


if __name__ == "__main__":
    A()

Solution (Python):
S = list(input())
K = int(input())

ans = [0] * 3
for i in (0, 1, 2):
    
    ans_tmp = 0
    S_tmp = S * (i + 1)
    cnt = 0
    for j, Sj in enumerate(S_tmp):
        if j == 0:
            cnt = 1
        else:
            if Sj == Sj_prev:
                cnt += 1
            else:
                ans_tmp += cnt // 2
                cnt = 1
        
        Sj_prev = Sj
    else:
        ans_tmp += cnt // 2
    
    ans[i] = ans_tmp

print(ans[0] + (K // 2) * (ans[1] - ans[0]) + ((K - 1) // 2) * (ans[2] - ans[1]))

Solution (Python):
s = input().strip()
k = int(input())


def bf(s):
    last = None
    count = 0
    ans = 0
    for c in s:
        if c != last:
            ans += count // 2
            last = c
            count = 1
        else:
            count += 1

    return ans + count // 2


if k < 10:
    print(bf(s * k))
else:
    if len(set(list(s))) == 1:
        print(len(s) * k // 2)
    else:
        delta = bf(s * 3) - bf(s * 2)
        print(bf(s * 2) + delta * (k - 2))

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

s = input().rstrip()
n = int(input())

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

s += "

k = 0
seq = []
for i, ch in enumerate(s):
    if i == 0:
        prev = ch
        k = 1
        continue
    if prev == ch:
        k += 1
    else:
        seq.append(k)
        k = 1
        prev = ch
    
if len(seq) == 1:
    ans = (seq[0] * n) // 2
    print(ans)
    exit()

if s[0] != s[-2]:
    ans = 0
    for item in seq:
        ans += item // 2
    print(ans * n)
else:
    mid = 0
    for item in seq[1:-1]:
        mid += item // 2
    ans = mid * n + seq[0] // 2 + seq[-1] // 2
    ans += ((seq[0] + seq[-1]) // 2) * (n - 1)
    print(ans)

Solution (Python):
s = list(input())
k = int(input())

def cnt(s):
    v = s[0]
    ans = 0
    c = 0
    for ss in s:
        if ss == v:
            c += 1
        else:
            ans += c // 2
            c = 1
            v = ss
    ans += c // 2
    return ans

if s[0] != s[-1]:
    c = cnt(s) * k
    print(c)
else:
    if len(set(s)) == 1:
        c = (len(s) * k) //2
        print(c)
    else:
        i_nxt = 0
        for i in range(len(s)):
            if s[i] != s[0]:
                i_nxt = i
                break
        s_new = s[i_nxt:] + s[0:i_nxt]
        c = cnt(s_new) * (k-1) + cnt(s[0:i_nxt]) + cnt(s[i_nxt:])
        print(c)

Solution (Python):
Ss = input()
K = int(input())

nums = []
num = 1
SPrev = Ss[0]
for S in Ss[1:]+'$':
    if S == SPrev:
        num += 1
    else:
        nums.append(num)
        num = 1
    SPrev = S


if len(nums) == 1:
    ans = nums[0]*K//2
elif Ss[0] != Ss[-1]:
    ans = 0
    for num in nums:
        ans += num//2
    ans *= K
else:
    ans = 0
    for num in nums[1:-1]:
        ans += num//2
    ans *= K
    ans += nums[0]//2 + nums[-1]//2
    ans += (nums[0]+nums[-1])//2 * (K-1)

print(ans)

Solution (Python):

S = input()
K = int(input())
N = len(S)

prev = S[0]
count_list = []
count=1
for i in range(1,N):
    if prev==S[i]:
        count+=1
    else:
        count_list.append(count)
        prev=S[i]
        count=1
count_list.append(count)

if len(count_list)==1:
    print((count_list[0]*K)//2)
else:
    if S[0]==S[N-1]:
        ans = 0
        for count in count_list[1:-1]:
            ans+=count//2
        ans *= K
        ans += count_list[0]//2
        ans += count_list[-1]//2
        ans += (K-1) * ((count_list[0]+count_list[-1])//2)
        print(ans)
    else:
        ans = 0
        for count in count_list:
            ans+=count//2
        ans *= K
        print(ans)

Solution (Python):
S = input()
K = int(input())

S = S + S + S
i = 1
count = 0
while i < len(S):
  if S[i] == S[i-1]:
    count += 1
    i += 2
    continue
  i += 1

if count % 3 == 0:
  print(count // 3 * K)
elif count % 3 == 1:
  print(count // 3 * K + K // 2)
elif count % 3 == 2:
  print((count+1) // 3 * K - 1)

Solution (Python):
import sys

S = input()

K = int(input())

now = 1
ans = 0

same = False
dic = {}
for i in S:
    if i not in dic:
        dic[i] = 1

if len(dic) == 1:
    print (len(S) * K // 2)
    sys.exit()

for i in range(len(S)-1):

    if S[i+1] == S[i]:
        now += 1

    else:

        ans += now // 2
        now = 1

ans += now // 2



S2 = S + S

now = 1
ans2 = 0
for i in range(len(S2)-1):

    if S2[i+1] == S2[i]:
        now += 1

    else:

        ans2 += now // 2
        now = 1



ans2 += now // 2
sub = ans2 - ans




print (ans + sub * (K-1))

Solution (Python):



import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline



s = input()
k =int(input())

l = len(s)

s0 = s[0]

if all(i==s0 for i in s):
    print(l*k//2)    
else:
    same = (s0 == s[-1])


    now = "AA"
    res = 0
    c = 0
    c0 = 0
    first = 2
    s0 = s+"W"
    for i in s0:
        if now == i:
            c += 1
        else:
            res += c//2
            c = 1
            now = i

    if not same: print(res*k)
    else:
        s = s+s+"W"
        
        res1 = res

        res = 0
        c = 0
        c0 = 0
        first = 2
        for i in s:
            if now == i:
                c += 1
            else:
                res += c//2
                c = 1
                now = i

        res2 = res
        
        print(res1 + (k-1)*(res2-res1))

Solution (Python):
string = input()
K = int(input())
from collections import defaultdict
if len(set(string)) ==1:
    print(K*len(string)//2)
else:
    if(string[0]==string[-1]):
        
        start = string[0]
        startFlag = True
        cnt = defaultdict(int)
        length = 0
        
        for char in string:
            
            if char == start:
                length +=1
                
            else:
                if startFlag:
                    startlen = length
                    startFlag = False
                cnt[length] +=1
                start = char
                length = 1
        else:
            
            cnt[startlen] -= 1
            cnt[startlen +length] += 1
        print(sum([(key//2)*value*K for key,value in cnt.items()])-(startlen+length)//2+startlen//2+length//2)
    else:
        
        start = string[0]
        cnt = defaultdict(int)
        length = 0
        for char in string:
            
            if char == start:
                length +=1
                
            else:
                cnt[length] +=1
                start = char
                length = 1
        else:
            
            cnt[length] += 1
        print(sum([(key//2)*value*K for key,value in cnt.items()]))

Solution (Python):
S = input()
K = int(input())
num = [1]
p = S[0]
for i in range(1, len(S)):
    if S[i] == p:
        num[-1] += 1
    else:
        num.append(1)
        p = S[i]
if len(num) == 1:
    print(len(S)*K // 2)
elif S[0] != S[-1]:
    print( sum( [num[i]//2 for i in range(len(num))] ) * K )
else:
    num_s = num[1:-1] + [num[0] + num[-1]]
    ans = sum( [num_s[i]//2 for i in range(len(num_s))] ) * (K-1)
    ans += sum( [num[i]//2 for i in range(len(num))] )
    print(ans)

Solution (Python):
s=list(input())
t=[]
k=int(input())
n=len(s)
for i in range(n):
    t.append(s[i])
count=0
for i in range(1,n):
    if s[i]==s[i-1]:
        count+=1
        s[i]="!"
if s[0]==s[n-1]:
    t[0]="!"
    cnt=1
    for i in range(1,n):
        if t[i]==t[i-1]:
            cnt+=1
            t[i]="!"
    if cnt==count:
        print(count*k)
    elif t[0]==t[n-1]:
        print(cnt*(k//2)+count*(k-k//2))
    else:
        print(count+cnt*(k-1))
else:
    print(count*k)

Solution (Python):
S = input()
K = int(input())

i=0
a=0

while i<len(S):
  if i==len(S)-1:
    
    break
  if S[i]==S[i+1]:
    a += 1
    i += 2
  else:
    i += 1
else:
  print(a*K)
  exit()
  
i=-1
b=0

while i<len(S):
  if i==len(S)-1:
    
    print(a+b*(K-1))
    exit()
  if S[i]==S[i+1]:
    b += 1
    i += 2
  else:
    i += 1
else:
  print(a*((K+1)//2) + b*((K-1)//2))
  exit()

Solution (Python):
s = input()
k = int(input())

flag = True
for i in range(len(s) - 1):
    if s[i] != s[i + 1]:
        flag = False
        break
if flag == True:
    print(len(s) * k // 2)
else:
    seq = []
    num = 1
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            num += 1
        else:
            seq.append(num)
            num = 1
    seq.append(num)
    count = 0
    if s[len(s) - 1] == s[0]:
        for i in range(len(seq) - 2):
            count += ((seq[i + 1] // 2) * k)
        count += (((seq[0] + seq[len(seq) - 1]) // 2) * (k - 1))
        count += (seq[0] // 2)
        count += (seq[len(seq) - 1] // 2)
    else:
        for i in seq:
            count += (i // 2) * k
    print(count)

Solution (Python):
s=input()
sng=len(s)
k=int(input())
answer=0

if s[0]!=s[-1]:
    swit=0
    for i in range(sng-1):
        if s[i]==s[i+1]:
            if swit==0:
                answer+=1
                swit=2
            else:
                swit+=1
                if swit%2==0:
                    answer+=1
        else:
            swit=0
    answer*=k
    print(answer)
else:
    now=0
    while s[now]==s[0]:
        now+=1
        if now==sng:
            break
    
    if now==sng:
        print((sng*k)//2)
    
    else:
        now2=sng-1
        while s[now2]==s[0]:
            now2-=1
            if now2==sng:
                break
        
        kaeshi=s[now:now2+1]
        swit=0
        for i in range(len(kaeshi)-1):
            if kaeshi[i]==kaeshi[i+1]:
                if swit==0:
                    answer+=1
                    swit=2
                else:
                    swit+=1
                    if swit%2==0:
                        answer+=1
            else:
                swit=0
        answer*=k
        
        kaeshi2=now+sng-now2-1
        
        answer+=((kaeshi2//2)*(k-1))
        answer+=(now//2)
        answer+=(sng-now2-1)//2
        print(answer)

Solution (Python):
def rle(s):
    n = len(s)
    if n == 0:
        return []
    res = []
    prev = s[0]
    count = 1
    index = 0
    while index < n:
        index += 1
        if index < n:
            if s[index] == prev:
                count += 1
                continue
        res.append([prev, count])
        if index < n:
            prev = s[index]
            count = 1
    return res


s = input().rstrip()
k = int(input())
counts = rle(s)
if len(counts) == 1:
    res = (counts[0][1] * k) // 2
else:
    res = counts[0][1] // 2
    res += counts[-1][1] // 2
    for c, v in counts[1:-1]:
        res += v // 2 * k
    if counts[0][0] == counts[-1][0]:
        res += (counts[0][1] + counts[-1][1]) // 2 * (k - 1)
    else:
        res += counts[0][1] // 2 * (k - 1) + counts[-1][1] // 2 * (k - 1)
print(res)

Solution (Python):
s = input()
k = int(input())
p = s[0]
loop = 0
tmp = 1
first_tmp = 0
for c in s[1:]:
    if c == p:
        tmp += 1
    else:
        loop += tmp // 2
        if first_tmp == 0:
            first_tmp = tmp
        tmp = 1
    p = c
loop += tmp // 2
ans = loop * k
if first_tmp == 0 and tmp % 2 == 1:
    ans += k // 2
elif s[0] == s[-1] and first_tmp % 2 == 1 and tmp % 2 == 1:
    ans += k - 1
print(ans)

Solution (Python):
s = list(input())
n = int(input())

pre = ''
count = 0
for i in s:
    if pre == i:
        count+=1
        pre = ''
    else:
        pre = i

if n == 1:
    print(count)
    exit()

count2 = 0
for i in s:
    if pre == i:
        count2+=1
        pre = ''
    else:
        pre = i

if n == 2:
    print(count + (n-1) * count2)
    exit()

count3 = 0
for i in s:
    if pre == i:
        count3+=1
        pre = ''
    else:
        pre = i

if count2 == count3:
    print(count + (n-1) * count2)
else:
    print(count + ((n-1)//2 + (n-1)%2) * count2 + ((n-1)//2)*count3)

Solution (Python):
from itertools import*
s=input()
k=int(input())
x=y=0
g=[len(list(v))for k,v in groupby(s)]
for c in g:
	x += c//2
if s[-1]==s[0]:
	if g[-1]%2==0 or g[0]%2==0:
		pass
	elif len(s)==1:
		y=k//2
	elif len(s)==g[0]:
		y=k//2
	else:
		y=k-1
print(x*k+y)

Solution (Python):

import sys
def input():
	return sys.stdin.readline().strip()

S = input()
K = int(input())

mozi = list(S)
num = 0

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

if mozi[0] != mozi[-1]:
	print(num*K)
	exit()

mozi2 = list(S)
mozi2[0] = "A"
num2 = 1
for i in range(1, len(S)):
	if mozi2[i] == mozi2[i - 1]:
		mozi2[i] = "A"
		num2 += 1

if mozi[0] != mozi2[-1]:
	n2 = K//2
	n1 = K - n2
	print(num*n1 + num2*n2)
else:
	print(num + (K - 1)*num2)

Solution (Python):
S = input()
K = int(input())
def calc(s):
    a = 0
    i = 1
    while i < len(s):
        if s[i] == s[i-1]:
            a += 1
            i += 2
        else:
            i += 1
    return a

A = calc(S)
B = calc(S*2)
C = calc(S*3)
D = calc(S*4)
if K <= 10:
    print(calc(S*K))
elif K % 2 == 1:
    print(A + (C-A) * (K-1) // 2)
else:
    print(B + (D-B) * (K-2) // 2)

Solution (Python):
S = input()
K = int(input())

w = None
N = []
for c in S:
    if c!=w:
        w=c
        N.append(1)
    else:
        N[-1]+=1

ans = 0
if len(N)==1:
    ans = (N[0]*K)//2
elif S[0]!=S[-1]:
    for n in N:
        ans += n//2
    ans *= K
else:
    ans += N[0]//2 + N[-1]//2
    ans += ((N[0]+N[-1])//2)*(K-1)
    for n in N[1:-1]:
        ans += (n//2)*K

print(ans)

Solution (Python):
from itertools import groupby
S = input()
K = int(input())
a1 = 0
for v, g in groupby(S):
    n = len(list(g))
    a1 += n // 2

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

a2 = 0
for v, g in groupby(S+S):
    n = len(list(g))
    a2 += n // 2

print(a1 + (a2-a1)*(K-1))

Solution (Python):
s = raw_input()
k = input()

if len(set(s)) == 1:
    print len(s) * k / 2
else:
    n = len(s)
    a = [1]
    for i in xrange(1, n):
        if s[i] == s[i - 1]:
            a[-1] += 1
        else:
            a.append(1)
    ans = 0
    if s[0] == s[-1]:
        ans += a[0] / 2 + a[-1] / 2 + (a[0] + a[-1]) / 2 * (k - 1)
        a = a[1:-1]
    ans += sum(x / 2 for x in a) * k
    print ans

Solution (Python):
import sys
s=input()
k=int(input())
l=[]
ct=1
ans=0
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    ct+=1
  else:
    l.append(ct)
    ct=1
l.append(ct)
if len(l)==1:
  print((len(s)*k)//2)
  sys.exit()
for i in range(1,len(l)-1):
  ans+=l[i]//2
ans*=k
if s[0]==s[-1]:
  ans+=((l[0]+l[-1])//2)*(k-1)
  ans+=l[0]//2
  ans+=l[-1]//2
else:
  ans+=(l[0]//2)*k
  ans+=(l[-1]//2)*k
print(ans)

Solution (Python):
S = input()
K = int(input())

pre_s = ""
ls = []
temp = 1
for s in S:
    if s == pre_s:
        temp += 1
    else:
        ls.append((pre_s,temp))
        temp = 1
    pre_s = s
ls.append((pre_s,temp))

if len(ls)==2:
    s,l = ls[1]
    print((l*K)//2)
    exit()
ans = 0
if S[0] != S[-1]:
    for s,l in ls[1:]:
        ans += l//2
    ans *= K
else:
    for s,l in ls[2:-1]:
        ans += l//2
    ans *= K
    s0,l0 = ls[1]
    s1,l1 = ls[-1]
    ans += l0//2
    ans += l1//2
    ans += (K-1)*((l0+l1)//2)
print(ans)

Solution (Python):
S = list(input())
K = int(input())

L = len(S)

a = 1
B = []
for i in range(L-1):
    if S[i] == S[i+1]:
        a += 1
    else:
        B.append(a)
        a = 1
B.append(a)

ans = 0
if S[0] != S[-1]:
    for b in B:
        ans += b // 2
    ans *= K
elif len(B) == 1:
    ans = L*K//2
else:
    for i in range(1, len(B)-1):
        ans += B[i]//2
    ans *= K
    ans += (B[0]+B[-1])//2 * (K-1)
    ans += B[0] // 2
    ans += B[-1] // 2

print(ans)

Solution (Python):
s = input()
k = int(input())
prev1 = ""
prev2 = s[0]
a = 0
b = 0
flag = False
flag2 = False
for i, c in enumerate(s):
    if c == prev1:
        a += 1
        prev1 = ""
    else:
        prev1 = c
        if i == len(s)-1 and c == s[0]:
            flag = True
    if c == prev2:
        b += 1
        prev2 = ""
    else:
        prev2 = c
        if i == len(s)-1 and c == s[0]:
            flag2 = True

ans = 0
if flag:
    if flag2:
        ans = a + b*(k-1)
    else:
        ans = a*((k+1)//2) + b*(k-(k+1)//2)
else:
    ans = k*a
print(ans)

Solution (Python):
def main():
    S = input()
    K = int(input())
    seq = []
    prev = S[0]
    cnt = 1
    for c in S[1:]:
        if c == prev:
            cnt += 1
        else:
            seq.append(cnt)
            cnt = 1
            prev = c
    seq.append(cnt)
    ans = 0
    for s in seq[1:len(seq)-1]:
        ans += s//2 * K
    if len(seq) == 1:
        ans = seq[0] * K // 2
    elif S[0] == S[-1]:
        ans += (seq[0] + seq[-1])//2 * (K-1)
        ans += seq[0]//2 + seq[-1]//2
    else:
        ans += seq[0]//2 * K
        ans += seq[-1]//2 * K
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
s = input()
k = int(input())

counter = [1]
before = s[0]
for i in range(1, len(s)):
    if s[i] == before:
        counter[-1] += 1
    else:
        counter.append(1)
    before = s[i]


if s[0] == s[-1] and len(counter) >= 2:
    c_tmp = counter[0] + counter[-1]
    btw_sum = c_tmp // 2
    tot = 0
    for i in range(len(counter)):
        if i != 0 and i != len(counter) - 1:
            tot += (counter[i] // 2) * k
        else:
            tot += counter[i] // 2
    tot += btw_sum * (k - 1)

elif s[0] == s[-1] and len(counter) == 1:
    tot = (len(s) * k) // 2
else:
    tot = 0
    for i in range(len(counter)):
        tot += (counter[i] // 2) * k

print(tot)

Solution (Python):
S = input()
K = int(input())

ans1 = 0
prev = '
for i in range(len(S)):
    if S[i] == prev:
        ans1 += 1
        prev = '
    else:
        prev = S[i]

if prev != S[0]:
    print(ans1 * K)
    exit()

ans2 = 0
for i in range(len(S)):
    if S[i] == prev:
        ans2 += 1
        prev = '
    else:
        prev = S[i]

if prev == S[0]:
    print(ans1 + ans2 * (K-1))
else:
    print(ans1 * (K - K // 2) + ans2 * (K // 2))

Solution (Python):
S = raw_input()
K = input()

L = []
c = 0
for i in range(len(S)+1):
  if i==len(S):
    L += [c]
    continue
  if i==0:
    c = 1
    continue
  if S[i]==S[i-1]:
    c += 1
  else:
    L += [c]
    c = 1

if len(L)==1:
  print len(S)*K/2
elif S[0]==S[-1]:
  print L[0]/2+L[-1]/2+sum(l/2 for l in L[1:-1])*K+(L[0]+L[-1])/2*(K-1)
else:
  print sum(l/2 for l in L)*K

Solution (Python):
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
    if f:
        print('Yes')
    else:
        print('No')
def Y(f):
    if f:
        print('YES')
    else:
        print('NO')

s = input()
n = int(input())

if s[0] != s[-1]:
    g = gb(list(s))
    res = 0
    for k, v in g:
        a = len(list(v))
        res += a // 2
    print(res * n)
else:
    l = []
    g = gb(list(s))
    for k, v in g:
        a = len(list(v))
        l.append(a)
    if len(l) == 1:
        print((l[0] * n) // 2)
    else:
        rst = 0
        for i in range(1, len(l) - 1):
            rst += (l[i]) // 2
        sm = (l[0] + l[-1]) // 2
        pp = (l[0] // 2) + (l[-1] // 2)
        print(rst * n + sm * (n - 1) + pp)

Solution (Python):
s=input()
k=int(input())
if len(set(list(s)))==1:print((len(s)*k)//2);exit()
t=[1]
for i in range(1,len(s)):
  if s[i-1]==s[i]:t[-1]+=1
  else:t.append(1)
a=0
for i in t:a+=(i//2)*k
if s[0]==s[-1]:
  if t[0]%2==t[-1]%2==1:a+=k-1
print(a)