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



Sample input:
issii
2


Sample output:
4

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ans=0
cnt=1
add=0
for i in range(1,len(s)):
  if s[i-1] == s[i]:
    cnt+=1
  else:
    ans+=cnt//2
    cnt=1
  if s[0] == s[-1] and i == (len(s)-1) and cnt%2==1:
    ans+=cnt//2
    add=1
  elif i == (len(s)-1) and cnt>=2:
    ans+=cnt//2
print(ans*k+add)

Submission status: Wrong Answer

Solution code:
s = input()
k = input()

s = list(s)
ans = 0
for i in range(0, len(s)-1):
    if s[i] == s[i+1]:
        ans += 1
        if (i+2 <= len(s)-1) and (s[i+1] == s[i+2]):
            s[i+1] = "0"

ans *= int(k)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
count = 0
C = 0
change = 0
for i in range(n-1):
  if s[i] == s[i+1]:
    count += 1
    C += 1
  else:
    if count == 1:
      change += 1
    elif count%2 == 0:
      change += count//2
    else:
      change += (count+1)//2
    count = 0
    C = 0 
if count == 1:
  change += 1
elif count%2 == 0:
  change += count//2
else:
  change += (count+1)//2

if C%2 != 0 or C == 0:
  print(change*k)
else:
  print(change*k + k-1)

Submission status: Wrong Answer

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

x = [0]*len(s)
for i in range(len(s)-1):
    if (s[i] == s[i+1]) and x[i] == 0:
        x[i+1] = 1
y = 0
if (k > 1) and (s[0] == s[-1]) and (x[-1] == 0):
    y = k - 1

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

print(sum(x)*k + y)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
N = len(S)
cnt = 0
flg1 = False
flg2 = False
if N == 1:
    print(K//2)
    exit()
if N == 3:
    print((K*3)//2)
    exit()
if S[0] == S[N-1]:
    cnt += 1
    flg1 = True
for i in range(N-1):
    if flg2:
        flg2 = False
        continue
    if (i == N - 2) and flg1:
        break
    if S[i] == S[i+1]:
        cnt += 1
        flg2 = True
# print(cnt)
print(cnt*K)

Submission status: Wrong Answer

Solution code:
a=list(input())
b=int(input())
if len(a)==1:
  print(b//2)
else:
  ans1=0
  ans2=0
  i=0
  j=len(a)-1
  k=0
  while i>len(a):
    if a[0]==a[i]:
      k+=1
      i+=1
    else:
      break
  while 1:
    if i==j:
      break
    if a[0]==a[j]:
      k+=1
      j-=1
    else:
      break
      
  if k%2==0:
    ans2=1 
  for i in range(1,len(a)):
    if a[i]==a[i-1]:
      ans1+=1
      a[i]=str(i%10)
  print(ans1*b+ans2*(b-1))

Submission status: Wrong Answer

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

n = len(s)
s2 = s + s

renzoku = False
taisho = 0
aida = False
for i in range(2*n-1):
    if s2[i] == s2[i+1]:
        if not renzoku:
            renzoku = True
            start_i = i
            count = 0
        count += 1

    elif renzoku:
        renzoku = False
        end_i = i
        count += 1
        #print(start_i, end_i)
        if count % 2 == 1:
            indexs = list(range(start_i+1, end_i, 2))
            taisho += len(indexs)
            #print(indexs)
            if (n-1 in indexs) or (n in indexs):
                aida = True
        elif count % 2 == 0:
            indexs1 = list(range(start_i, end_i, 2))
            indexs2 = list(range(start_i+1, end_i, 2))
            taisho += len(indexs1)
            #print(indexs1)
            all_indexs = indexs1 + indexs2
            if (n-1 in all_indexs) or (n in all_indexs):
                aida = True

if renzoku:
    renzoku = False
    end_i = 2*n - 1
    count += 1
    if count % 2 == 1:
        indexs = list(range(start_i+1, end_i, 2))
        taisho += len(indexs)
        #print(indexs)
        if (n-1 in indexs) or (n in indexs):
            aida = True
    elif count % 2 == 0:
        indexs1 = list(range(start_i, end_i, 2))
        indexs2 = list(range(start_i+1, end_i, 2))
        taisho += len(indexs1)
        #print(indexs1)
        all_indexs = indexs1 + indexs2
        if (n-1 in all_indexs) or (n in all_indexs):
            aida = True


#if True:
if not aida:
    assert taisho % 2 == 0
    hitotsu = taisho // 2
    out = hitotsu * k
else:
    if taisho % 2 == 0: 
        hitotsu = taisho // 2
        out = hitotsu * k
    else:
        hitotsu = (taisho+1) // 2
        out = hitotsu * k - 1


print(out)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
sum_count = 0
count = 1
key = s[0]
flag = True
if s[0] == s[len(s)-1] and s[len(s)-2] != s[len(s)-1]:
    flag = True
    for i in range(1,len(s)):
        if s[i] == key:
            count += 1
        else:
            sum_count += count//2
            key = s[i]
            count = 1
else:
    flag = False
    for i in range(1,len(s)):
        if s[i] == key:
            count += 1
        else:
            sum_count += count//2
            key = s[i]
            count = 1

sum_count += count//2

if flag == True:
    print((sum_count+1)*k)
else:
    print(sum_count*k)

Submission status: Wrong Answer

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

cnt=0
i=1
while i <len(s):
  if i>0:
    if s[i]==s[i-1]:
      cnt+=1
      i+=2
    else:
      i+=1
  
if k==1:
  print(cnt)
  exit()
  
ss=s+s
cntcnt=0
i=1
while i <len(ss):
  if i>0:
    if ss[i]==ss[i-1]:
      cntcnt+=1
      i+=2
    else:
      i+=1
if k==2:
  print(cntcnt)
  exit()
  
sss=s+s+s
cntcntcnt=0
i=1
while i <len(sss):
  if i>0:
    if sss[i]==sss[i-1]:
      cntcntcnt+=1
      i+=2
    else:
      i+=1
if k==3:
  print(cntcntcnt)
  exit()
  
print(cntcnt+(cntcntcnt-cntcnt)*(k-2))

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
count=1
ans=0
old='old'
for x in S:
    if old==x:
        count+=1
    else:
        ans+=count//2
        count=1
    old=x

ans+=count//2
check=0
check+=ans

ans-=count//2

for x in S:
    if old==x:
        count+=1
    else:
        ans+=count//2
        count=1
#     print(count)
    old=x

ans+=count//2
if ans==check*2 and K!=1:
    print(check*K)
if ans==check*2+1 and K!=1:
    print(check*K+1)
if K==1:
    print(check)

Submission status: Wrong Answer

Solution code:
# Setup
import sys
import collections
sys.setrecursionlimit(4100000)

a = input()
b = int(input())

if len(a) == 1:
    print(b//2)
elif len(a) == 2:
    if a[0] == a[1]:
        print(b)
    else:
        print(0)
elif len(a) >= 3:
    oc = []
    prev = None
    ct = 1
    for letter in a:
        if prev == letter:
            ct += 1
        else:
            if prev is not None:
                oc.append(ct)
            ct = 1
            prev = letter
    oc.append(ct)
    freq = 0
    for z in oc:
        if z == 2:
            freq += 1
        elif z >= 3:
            freq += z//2
    # print(oc,freq,freq*b)
    flag = False
    if a[-1] == a[0] and a[-1] == a[-2]:
        flag = True
    if flag:
        print(freq*b+flag-1)
    else:
        print(freq*b)

Submission status: Wrong Answer

Solution code:
a = list(input())
b = int(input())
c = len(a)
sum = 0
for i in range(0,c-1):
  if a[i]==a[i+1]:
    a[i+1]="う"
    sum+=1
print(sum*b)

Submission status: Wrong Answer

Solution code:
ls=list(input())
n=int(input())

ls.append(ls[0])

count=0
dounat=False
for i in range(len(ls)-1):
    a,b=ls[i],ls[i+1]
    if a==b:
        if i == len(ls)-2:
            ls[i]='!'
            dounat=True
        else:
            ls[i+1]='?'
        count+=1
ans = count * n
if dounat:
    ans-=1

if len(ls)==2:
    print(n//2)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        S[i+1] = "1"
        count += 1
print(count*K)

Submission status: Wrong Answer

Solution code:
def read():
    S = str(input().strip())
    K = int(input().strip())
    return S, K

def rle_encode(S):
    S1 = S + '@'
    rle = list()
    head = 0
    for i in range(0, len(S1)):
        if S1[i] != S1[head]:
            rle.append((S1[head], i-head))
            head = i
    return rle

def solve(S, K):
    count = 0
    rle = rle_encode(S)
    for c, n in rle:
        count += n // 2
    count *= K
    if rle[-1][0] == S[0] and rle[-1][1] % 2 == 1:
        count += (K-1)
    return count

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = input()
k = int(input())

tmp_count = 0
continue_str = s[0]
count_in_loop = 0
half_count = 0
for i, si in enumerate(s):
    if continue_str == si:
        tmp_count += 1
    else:
        count_in_loop += tmp_count // 2
        tmp_count = 1
        continue_str = si
    if i == len(s) - 1:
        count_in_loop += tmp_count // 2
        if (tmp_count % 2 == 1) & (si == s[0]):
            half_count = 1
result = count_in_loop * k + half_count * (k-1)
print(result)

Submission status: Wrong Answer

Solution code:
s = input()
num = int(input())

prev = ""

n = 0

if len(s) == 1:
    print(num // 2)
else:
    if len(set(s)) == 1:
        ans = len(s) * num // 2
    
    elif s[0] == s[-1]:
        b = 1
        for i in range(1, len(s)):
            if s[0] == s[i]:
                b += 1
            else:
                start = i
                break
        ss = s[::-1]
        
        c = 1
        for i in range(1, len(s)):
            if ss[0] == ss[i]:
                c += 1
            else:
                end = i
                break
        
        for i in range(start, len(s) - end):
            print(s[i])
            if prev == s[i]:
                n += 1
                prev = ""
            else:
                prev = s[i]
        ans = (b + c) // 2
        ans += b // 2 + c // 2
        ans += n * num

    else:
        for x in s:
            if prev == x:
                n += 1
                prev = ""
            else:
                prev = x
        ans = n * num


    print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
SS=list(S)
n=0
#モノマー内の重複を修正
for i in range(len(S)-1):
    if SS[i]==SS[i+1]:
        SS[i+1]="A"
        n+=1
if SS[0]==SS[-1]:
    n+=1
print(n*K)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
t = s + s[0]
ans = 0
i = 1
while True:
    c = 0
    while True:
        if i>=len(t):
            break
        elif t[i-1] == t[i]:
            i +=2
            c+= 1
        else:
            break
    ans += c
    if i>=len(t):
        break
    i+=1
print(ans * k)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
ans = 0
if len(S) == 1:
  print(K//2);exit()
elif len(S) == 2:
  if S[0] ==  S[1]:
    print(K);exit()
  else:
    print(0);exit()
elif len(S) == 3:
  if S[0] == S[1] and S[1] == S[2]:
    print(3*K//2);exit()
  else:
    print(K);exit()
else:
  for i in range(0,len(S)-2,1):
    s = S[i:i+3]
    if s[0] == s[1] and s[1] == s[2]:
      ans += 1
      S[i+1] = "0"
    elif s[0] == s[1]:
      ans += 1
      S[i+1] = "0"
    elif s[1] == s[2]:
      ans += 1
      S[i+2] = "0"
print(S)
if S[0] == S[-1]:
  print(ans*K+K-1)
else:
  print(ans*K)

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy

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

A = np.zeros(1)
j = 0 

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        A[j] += 1
    else:
        j += 1
        A = np.append(A, 0)

ans = 0

if np.size(A) == 1:
    ans = (len(S) * K) // 2
    
else:   
    A = A + 1
    B = copy.deepcopy(A)
    if S[0] == S[len(S)-1]:
        B[0] = A[0]+A[-1]

    A = np.delete(A, np.size(A)-1)

    ans = np.sum(A // 2) + np.sum(B // 2) * (K-1)

print(int(ans))

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
S = S + S[0]
samecount = 1
count = 0
pre = ''
for s in S:
    if s == pre:
        samecount += 1
    else:
        count += samecount//2
        samecount = 1
    pre = s

ans = K * count
if samecount % 2 == 0:
    ans += K*((samecount-1)//2)
    check = True
    samecount = 0
    pre = S[0]
    for s in S[1:]:
        if s == pre:
            samecount += 1
        else:
            break

    if samecount % 2 == 0:
        pass
    else:
        ans += K-1
else:
    ans += K*(samecount//2)

print(ans)

Submission status: Wrong Answer

Solution code:
def f():
    S = input()
    K = int(input())
    S = list(S)
    if K == 1 and len(S) == 1:
        print(0)
        return
    
    if K == 1 and len(S) != 1:
        ans = 0
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                S[i+1] = '1'
                ans += 1
        print(ans)
        return
    
    if K != 1 and len(S) == 1:
        ans = K // 2
        print(ans)
        return
    
    if K != 1 and len(S) != 1:
        ORG_S = S[:]
        
        # A
        ans_a = 0
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                S[i+1] = str(i)
                ans_a += 1
                
        if S[0] == S[-1]:
            ans_a = ans_a*K + K-1
        else:
            ans_a = ans_a*K
            
            
        # B
        S = ORG_S[:]
        ans_b = 0
        if S[0] == S[1]:
            S[0] = 'X'
            ans_b = 1
        
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                S[i+1] = str(i)
                ans_b += 1
                
        if S[0] == S[-1]:
            ans_b = ans_b*K + K-1
        else:
            ans_b = ans_b*K
        
        ans = min(ans_a, ans_b)
        print(ans)
        return

f()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
S = input()
K = int(input())
fletter = 0 # 最初の文字の連続数を数える
lletter = 0 # 最後の文字の連続数を数える
cletter = 0 # 現在連続している文字の連続数を数える
cng = 0 # 文字変更の必要がある文字をカウント
for i in range(len(S)): # 最初の文字の連続数を数える
    if S[0] == S[i]:
        fletter += 1
    else:
        break
for i in range(len(S)):
    if S[-1] == S[-(i + 1)]:
        lletter += 1
    else:
        break
for i in range(len(S) - 1): # 1文字ずつ連続しているかを判定
    if S[i] == S[i + 1]:
        cletter += 1
    else:
        cng -= - cletter // 2
        cletter = 0
cng -= - cletter // 2 # 最終文字まで到達したら文字変更数の処理
if S[0] == S[-1] and fletter % 2 == 1 and lletter % 2 == 1:
    ans = (cng + 1) * K - 1
else:
    ans = cng * K
print(ans) #解答の出力

Submission status: Wrong Answer

Solution code:
from itertools import groupby

S = input()
N = int(input())

if len(S) == 1:
    print(N-1)
    exit()

if len(S) == 2 and S[0] == S[1]:
    print(N)
    exit()

check = S
check_num = sum(len(list(v))//2 for k, v in groupby(check))
check2 = S * 2
check2_num = sum(len(list(v))//2 for k, v in groupby(check2))
print(check_num*N + (check2_num-2*check_num)*(N-1))

Submission status: Wrong Answer

Solution code:
import sys

str = input()
N = int(input())

cnt = 0

l = len(str)

if str[0] == str[l-1]:
    cnt += 1

for i in range(0,l-3):
    if str[i] == str[i+1]:
        cnt += 1

print(cnt*N)

Submission status: Wrong Answer

Solution code:
S=list(input())
k=int(input())

cnt,ans=0,0
if len(S)==1:
  print(k//2)
  exit()
for i in range(1,len(S)):
  if S[i-1]==S[i]:
    cnt+=1
  else:
    cnt+=1
    ans+=cnt//2
    cnt=0
ans+=(cnt+1)//2
if S[0]==S[-1] and S[-1]!=S[-2]:
  print(ans*k+k-1)
else:
  print(ans*k)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
l=list(s)
if l[0]==l[len(l)-1] and l[len(l)-1]!=l[len(l)-2]:
    x=1
else:
    x=0
for i in range(1,len(l)):
    if l[i-1]==l[i]:
        l[i]=0
        x+=1
print(x*k)

Submission status: Wrong Answer

Solution code:
import math as m

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



# odd_1st_ptn
c_odd_1st = 0
sl_1st_odd = list(S)
for i in range(len(sl_1st_odd)):
    if i == len(sl_1st_odd)-1:
        continue
    if sl_1st_odd[i] == sl_1st_odd[i+1]:
        c_odd_1st = c_odd_1st + 1
        sl_1st_odd[i+1] = '8'


# even_ptn

c_even = 0
sl_even = list(S)

for i in range(len(sl_even)):
    if i == 0 and sl_even[0] == sl_1st_odd[-1]:
        c_even = c_even + 1
        sl_even[0] = '8'
    elif i == len(sl_even)-1:
        continue
    elif sl_even[i] == sl_even[i+1] :
        c_even = c_even + 1
        sl_even[i+1] = '8'

# odd_ptn
c_odd = 0
sl_odd = list(S)
for i in range(len(sl_odd)):
    if i == len(sl_odd)-1:
        continue
    if i == 0 and sl_odd[0] == sl_even[-1]:
        c_odd = c_odd + 1
        sl_odd[0] = '8'
    elif sl_1st_odd[i] == sl_odd[i+1]:
        c_odd = c_odd + 1
        sl_odd[i+1] = '8'

print(c_odd_1st + (m.floor((K-1)/2)) * c_odd + m.floor(K/2) * c_even)

Submission status: Wrong Answer

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

if len(S) == 1:
    print(int(K/2))
else:    
    count = 0
    bef = ""
    isbefchange = False
    for i in range(0, len(S)):
        if(isbefchange == False and S[i] == bef):
            count += 1
            isbefchange = True
            bef = S[i]
            continue
        bef = S[i]
        isbefchange = False

    if(isbefchange == False and S[len(S)-1] == S[0]):
        count += 1
    print(count * K)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
count = 0

import sys
if len(s) == 1:
    if k == 1:
        print(0)
    else:
        print('test')
        print(k // 2)
    sys.exit(0)

s = s + [s[0]]
for i in range(0, len(s) - 1):
    if s[i] == s[i+1]:
        s[i+1] = '0'
        count += 1

print(count * k)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
S = input()
K = int(input())
lenS = len(S)

if lenS == 1:
  print(0)
  exit()

cnt1 = 0

idx = 0
for key, values in groupby(S):
  len_values = len(list(values))
  if idx == 0:
    fst_key = key
    fst_len_values = len_values

  if len_values >= 2:
    cnt1 += len_values//2
  idx += 1

if idx == 1:
  print((lenS*K)//2)
  exit()

cnt2 = cnt1
cnt3 = 0
if key == fst_key:
  if fst_len_values >= 2:cnt2 -= fst_len_values//2
  if len_values >= 2:cnt2 -= len_values//2 
  cnt3 = (fst_len_values+len_values)//2
    
print(cnt1 + (cnt2+cnt3)*(K-1))
#print(cnt1, cnt2, K, fst_len_values, len_values)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

before = ""
cnt = 0
idx = 0
for s in S:
    if before == s:
        cnt+=1
        before = ""
    else:
        before = s
cnt *= K

print(cnt)

Submission status: Wrong Answer

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

left = S[0]
right = S[-1]

inside = []
tmp = 1
bef = ""
for idx, val in enumerate(S):
    if idx == 0:
        bef = val
        continue
    if val == bef:
        tmp += 1
    else:
        inside.append(tmp)
        tmp = 1
    bef = val
else:
    inside.append(tmp)

ans = 0
if left == right:
    if len(S) > 2:
        head = inside[0]
        tail = inside[-1]
        center = inside[1:-1]
        init = inside[:-1]
        last = inside[1:]
        joint = head + tail

        init_op = 0
        last_op = 0
        for i in init:
            if i != 1:
                init_op += i //2
        for i in last:
            if i != 1:
                last_op += i //2
        joint_op = joint // 2
        center_op = 0
        for i in center:
            if i != 1:
                center_op += i //2

        if K == 1:
            ans = init_op + tail // 2
        else:
            ans += init_op
            ans += last_op
            ans += joint_op * (K - 1)
            ans += center_op * (K - 2)
        print(ans)
    elif len(S) == 1:
        print(K // 2)
    elif len(S) == 2:
        print(K)
else:
    for i in inside:
        if i != 1:
            ans += i //2
    print(ans * K)

Submission status: Wrong Answer

Solution code:
s = str(input())
k=int(input())



if len(s)==1:
    if k<=2:
        ans = 0
    else:
        ans = k//2
elif len(s)==2:
    if s[0]==s[1]:
        ans = k
    else:
        ans = 0
else:
    if k == 1:
        ans = 0
        bef = ""
        befchen = False
        trignum = 0
        for i in range(len(s)):
            now = s[i]
            if bef==now:
                if befchen == False:
                    ans += 1
                    befchen = True
                    trignum = i
            if  befchen == True:
                if trignum == i-1:
                    befchen = False
            bef = now

    elif k >=2:
        ans = 0
        bef = ""
        befchen = False
        trignum = 0
        for i in range(len(s)):
            now = s[i]
            if bef==now:
                if befchen == False:
                    #print(now)
                    ans += 1
                    befchen = True
                    trignum = i
            if  befchen == True:
                if trignum == i-1:
                    befchen = False
            bef = now
        
        if s[0]==s[-1]:
            if befchen == False:
                ans += 1

        #print(ans)
        ans *= k

print(ans)

Submission status: Wrong Answer

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

if len(S) == 1:
  print(K//2)
  exit()
  
SR=S+[S[0]]
cnt=0
for i in range(len(S)-1):
  if SR[i]==SR[i+1]==SR[i+2]:
    SR[i+1]=0
    cnt+=1

for i in range(len(S)):
  if SR[i]==SR[i+1]:
    SR[i]=0
    cnt+=1
    
if SR[-2]==0 and S[-1]!=S[-2]:
  ans = cnt*K-1
else:
  ans = cnt*K
print(ans)

Submission status: Wrong Answer

Solution code:
import random
import string

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

prev_c = ''
num_changes = 0
if S[0] == S[-1]:
    num_changes += 1
    prev_c = 'replaced'

for i, c in enumerate(S[1:]):
    if c == prev_c:
        num_changes += 1
        prev_c = 'replaced'
    else:
        prev_c = c

print(num_changes * K)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
lists=[]
for i in range(len(s)):
    lists.append(s[i]) 
lists.append("good")
if len(s)>=2:
    sums=0
    cnt=1
    for j in range(len(s)):
        if lists[j]!=lists[j+1]:
            if cnt==1:
                pass
            elif cnt>=2:
                sums+=(cnt//2)
                cnt=1
        elif lists[j]==lists[j+1]:
            cnt+=1     
    if lists[-1]==lists[-2] and cnt%2==0:
        pass
         
    if lists[-1]==lists[-2] and cnt%2!=0:
        if lists[-1]==lists[0]:
            sums+=1
        else:
            pass
    if lists[-1]!=lists[-1]:
        if lists[-1]==lists[0]:
            sums+=1
        else:
            pass

    print(sums*k)
 
elif len(s)==1:
    if k%2==0:
        print(k//2)
    else:
        print((k-1)//2)

Submission status: Wrong Answer

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

prev = S[0]
cnt = 1
ans = 0
for c in S[1:]:
    if c == prev:
        cnt += 1
    elif cnt >= 2:
        ans += cnt // 2
        cnt = 1
    prev = c
else:
    flag = False
    if S[0] == S[-1]:
        cnt += 1
        if cnt % 2 == 0: 
            flag = True
    if cnt >= 2:
        ans += cnt // 2
        
if flag:
    print(ans * K - 1)
else:
    print(ans * K)

Submission status: Wrong Answer

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

N=len(S)
t=S[0]
cnt=0
arr=[]
for s in S[1:N]:
    if t==s:
        cnt+=1
    else:
        if cnt!=0:
            arr.append((cnt+1)//2)
        cnt=0
    t=s
arr.append((cnt+1)//2)
print((sum(arr))*K)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

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

N = len(S)
ans = 0
last_same = False
if N==1:
    print(K//2)
    exit()
for i in range(1,N):
    if S[i]!=S[i-1]:
        break
    else:
        print(N*K//2)
        exit()
pre = S[0]
p = False
for i in range(1,N):
    if p:
        pre = S[i]
        p = False
        continue
    s = S[i]
    if pre==s:
        ans += 1
        p = True
        if i==N-1:
            last_same = True
    pre = s

l_same = False
if not last_same:
    if S[0]==S[-1]:
        ans += 1
        l_same = True

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
L = len(S)
a = S[0]
i = 0
C = []
if L == 1:
    C = [1]
while i < L-1:
    count = 1
    b,c = S[i],S[i+1]
    i+= 1
    while b == c:
        count += 1
        if i == L-1:
            break
        b,c = S[i],S[i+1]
        i += 1
    C.append(count)
if a != S[L-1]:
    num = 0
    for co in C:
        num += co//2
    print(int(num*K))
else:
    num1 = 0
    for co in C:
        num1 += co//2
    num2 = (C[len(C)-1]+1)//2
    for co in C[:len(C)-1]:
        num2 += co//2
    print(int(num1+num2*(K-1)))

Submission status: Wrong Answer

Solution code:
X=input()
a=int(input())
count=0
ans=0
z=list(X)
for i in range(len(z)-1):
    if z[i]==z[i+1]:
        z[i+1]=0
        count=count+1
ans=count*a
print(ans)

Submission status: Wrong Answer

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

T = list(S)
cnt = 0

for i in range(len(T)):
  if i == 0:
    continue
  if T[i] == T[i-1]:
    T[i] = '_'
    cnt += 1

if T[0] == T[len(T)-1]:
  cnt += 1
  cnt = cnt * K - 1
else:
  cnt = cnt * K

print(cnt)

Submission status: Wrong Answer

Solution code:
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()
tc=1
ac=0
p=s[0]
for i in range(1,n):
    if s[i]==p:
        tc+=1
    else:
        ac+=tc//2
        tc=1
        p=s[i]
else:
    ac+=tc//2
ans=ac*k
if s[0]==s[-1]:
    if s[0]!=s[1] and s[-1]!=s[-2]:
        ans+=k-1
print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
K = input()
K = int(K)

# T = N*K
# print(T)

#print(len(N))
count = 0
sub = 1
set = "T"
T_set = 1
for xi in range(len(N)-1):
    if N[xi] == N[xi+1]:
        sub = sub +1
    else:
        if set == "T":
            T_set = sub
        count = count + int(sub/2)
        set = "F"
        sub = 1

count = count + int(sub/2)

if set == "T":
    ans = int(len(N)*K/2)
else:
    ans = count*K
    if N[0] == N[len(N)-1]:
        ans = ans +int((sub+T_set)/2)
    else:
        ans = ans +int((sub)/2)

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-

s = input()
k = int(input())
flag = 1
lenth = 1
ans = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        lenth += 1
    else :
        flag = 0
    if flag == 0:
       ans += lenth//2
       lenth = 1
       flag = 1
ans += lenth//2
lenth = 1
flag = 1

ji = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        lenth += 1
    else :
        flag = 0
    if flag == 0:
       # print(lenth)
       if lenth%2 == 1:
            ji += 1
       break
if lenth%2 == 1:
    ji += 1
lenth = 1
flag = 1
for i in range(len(s)-1):

    if s[len(s)-i-1] == s[len(s)-1-(i+1)]:
        lenth += 1
    else :
        flag = 0
    if flag == 0:
       if lenth%2 == 1:
            ji += 1
       break
if lenth%2 == 1:
    ji += 1
ans = ans*k
# print(ans, ji)
if ji == 2:
    ans = ans+k-1
print(ans)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	s = input()
	k = int(input())
	s_ = [[s[0],1]]
	ct = 0
	for i in s[1:-1]:
		if(s_[-1][0] == i):
			s_[-1][1] += 1
		else:
			s_.append([i,1])
	for i in s_:
		if(i[1] > 1):
			ct += math.ceil((i[1] - 1)/2)
	ct *= k
	if((len(s) - 1) % 2 == 1 and len(s_ ) == 1):
		print((len(s) - 1) * k // 2)
	else:
		print(ct)


def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Wrong Answer

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

   
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:
    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:
        print(c*k + k - 1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
s=list(input())
k=int(input())
cnt=1
cnt2=0
tmp=0
flg=0
flg2=0
for i in range(len(s)):
    if tmp==s[i]:
        cnt+=1
    else:
        cnt2+=cnt//2
        cnt=1
    tmp=s[i]
cnt2+=cnt//2
if len(s)==1:
    flg2=1

elif s[0]==s[-1]:
    m=0
    cnt3=0
    while s[m]==s[0]:
        cnt3+=1
        m+=1
        if m==len(s)-1:
            cnt+=3
            break
    n=1
    cnt4=0
    while s[-n]==s[0]:
        cnt4+=1
        n+=1
        if n==len(s):
            cnt4+=1
            break
    if cnt3%2==1 and cnt4%2==1:
        flg=1

if flg==1:
    ans=cnt2*k+k-1
elif flg2==1:
    ans=k//2
else:
    ans=cnt2*k
    
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ans=0
s=s*2
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    s=s[:(i+1)]+'0'+s[(i+2):]
    ans+=1
print(ans*k*0.5 if k%2==0 else ans*k*0.5-0.5)

Submission status: Wrong Answer

Solution code:
s=str(input())
k=int(input())

if k>=2:
    sl=list(s)
    ss=list(s+s)
    cnt=0
    for i in range(len(ss)-1):
        if ss[i]==ss[i+1]:
            cnt+=1
            ss[i+1]="?"
    cnt2=0
    for i in range(len(sl)-1):
        if sl[i]==sl[i+1]:
            cnt2+=1
            sl[i+1]="?"
    if s[0]==s[-1] and ss[-1]!="?" and k%2==1:
        print((k//2)*cnt+(k%2)*cnt2+1)
    else:
        print((k//2)*cnt+(k%2)*cnt2)

else:
    cnt=0
    sl=list(s)
    for i in range(len(sl)-1):
        if sl[i]==sl[i+1]:
            cnt+=1
            sl[i+1]="?"
    print(cnt)