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:
st = input()
s = [i for i in st]
k = int(input())
l = len(s)
c=0
i=0
while i<l-1:
    if i+1 <=l-1 and s[i]==s[i+1]:
        s[i+1]='|'
        c+=1
        i+=1
    else:
        i+=1

# print(c)
c*=k
if k>1:
    a = s[0]
    if a==s[-1]:
        c+=k-1
print(c)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
d = [0 for _ in range(100)]
ans = 0
l = len(S)
for i in range(l-1):
    if i == 0 and S[i] == S[i+1]:
        ans += 1
        d[0] = 1
    if i > 0 and S[i] == S[i+1] and d[i-1] == 0:
        ans += 1
        d[i] = 1
ans = ans * K

if S[0] == S[-1] and d[l-2] == 0 and d[0] == 0:
    ans += K -1

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.insert(場所,要素)
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
T = stdin.readline().rstrip()
num = int(stdin.readline().rstrip())
ch = ''
count = 0
forcount = 0
changed = False
for t in T:
    if (ch == t and not changed):
        count += 1
        changed = True
    elif (changed):
        changed = False
    if (forcount == len(T) - 1 and ch == T[0] and not changed):
        count += num-1
    ch = t
    forcount += 1
count *= num

print(count)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    S = input().strip()
    K = int(input())

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

    count1 = 0
    now_count = 1
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            now_count += 1
        else:
            count1 += now_count // 2
            now_count = 1
    count1 += now_count // 2

    doubleS = S * 2
    count2 = 0
    now_count = 1
    for i in range(len(doubleS) - 1):
        if doubleS[i] == doubleS[i + 1]:
            now_count += 1
        else:
            count2 += now_count // 2
            now_count = 1
    count2 += now_count // 2

    ans = count1 + (count2 - count1) * (K - 1)
    print(ans)



    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import groupby

s = list(input())
k = int(input())
x = 0
if len(s) == 1:
    print(k // 2)
else:  
    for key, value in groupby(s):
        x += len(list(value)) // 2
    if s[0] == s[-1] and s[0] != s[1] and s[-2] != s[-1]:
        x += 1
    print(x * k)

Submission status: Wrong Answer

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


result = 0

# S内の重複
dup_c = 0
c_list = ['XXXXX']
for s in S:
    if c_list[0] == s:
        dup_c += 1
        c_list = ['XXXXX']
    else:
        c_list[0] = s
result = dup_c * K

# 間の重複
if len(S) > 1:
    if S[0] == S[len(S)-1]:
        if S[1] != S[0] and S[len(S)-2] != S[0]:
            result += K - 1

print(result)

Submission status: Wrong Answer

Solution code:
s=list(input())
ss=s*2
k=int(input())
cnt1=0
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        cnt1+=1
        s[i+1]='.'
cnt2=0
if s[0]==s[-1]:
    cnt2=1

cnt3,cnt4=0,0
for i in range(len(ss)-1):
    if ss[i]==ss[i+1]:
        cnt3+=1
        ss[i+1]='.'
cnt4=0
if ss[0]==ss[-1]:
    cnt4=1

if cnt1+cnt2==cnt3+cnt4:
    print((cnt1*k)+(cnt2*(k-1)))
else:
    print(((cnt3+cnt4)//2)*k)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(int(1e6))

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

count = 0
s1 = ''
s2 = ''
s3 = ''
prev_rewrite = False
for s2 in S:
    if s1 == s2 and not prev_rewrite:
        code = ord(s2) + 1
        s3 = chr(code) if code <= ord('z') else 'a'
        count += 1
        prev_rewrite = True
    else:
        s3 = s2
        prev_rewrite = False

    s1 = s3

ans = count * K
print(ans)

Submission status: Wrong Answer

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

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

zcount=0
ju=0
for i in range(len(S)):
  if S[i]==S[0]:
    zcount+=1
    if i==len(S)-1:
      ju=1
  else:
    break

if ju==0:
  for i in reversed(range(len(S))):
    if S[i]==S[0]:
      zcount+=1
    else:
      break
  
if S[0]==S[1]:
  S[0]="#"
for i in range(1,len(S)):
  if S[i-1]==S[i]:
    S[i]="#"

ans=S.count("#")
if S[0]=="#" and zcount%2==1:
  ans-=1
print(ans*K)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ans=0
if k%2==1:
  cnt=1
  for i in range(1,len(s)):
    if s[i]==s[i-1]:
      cnt+=1
    else:
      ans+=cnt//2
      cnt=1
  ans+=cnt//2
t=s+s
cnt=1
tmp=0
for i in range(1,len(t)):
  if t[i]==t[i-1]:
    cnt+=1
  else:
    tmp+=cnt//2
    cnt=1
tmp+=cnt//2
ans+=tmp*(k//2)
flag=True
if cnt>=2:
  flag=False
if flag==True:
  cnt1=1
  for i in range(1,len(s)):
    if s[i]==s[i-1]:
      cnt1+=1
    else:
      break
  cnt2=1
  for i in range(1,len(s)):
    if s[-i]==s[-(i+1)]:
      cnt2+=1
    else:
      break
  if s[0]==s[-1]:
    ans+=(cnt1+cnt2)//2
print(ans)

Submission status: Wrong Answer

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

if len(s) == 1:
  print(k // 2)
else:
  cnt = 0
  p = 1
  while p < len(s):
    if s[p-1] == s[p]:
      cnt += 1
      p += 1
    p += 1

  cnt2 = 0
  if s[0] == s[-1]:
    cnt2 += 1

  cnt3 = 0
  if s[-2] == s[-1]:
    cnt3 += 1
    
  cnt4 = 0
  cnt5 = 0
  if len(s) > 2:
    if cnt2 == 1 and s[-1] == s[-2] == s[-3]:
      cnt4 = 1
      if len(s) > 3:
        if s[-1] == s[-2] == s[-3] == s[-4]:
          cnt4 = 0

      
  ans = k*cnt + (k - 1)*cnt2 - (k - 1)*cnt3 + (k - 1)*cnt4
  print(ans)

Submission status: Wrong Answer

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

S.extend(S)

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

if K%2 ==0:
	count = count*K/2
else:
	count = count*(K-1)/2 + count//2

if S[0] == S[-1] and K>=2:
	if S[-1] == '?':
		count += K-1

print(int(count))

Submission status: Wrong Answer

Solution code:
import random
import string

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

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

print(num_changes * K)

Submission status: Wrong Answer

Solution code:
# At GrandContest 039 A
def f(s, k):
    # min num of operations required to make s*k any two adj chars different
    n = len(s)
    s = list(s)
    icount, ecount = 0, 0
    for i in range(n - 1):
        if s[i] == s[i + 1]:
            s[i + 1] = '_'
            icount += 1
    if s[0] == s[-1]:
        ecount += 1
    icount *= k
    if k > 1:
        ecount *= (k - 1)
    return icount + ecount

# a
# aa => a_
# aba => a_a
# aaa => a__
# aaaa => a__

assert f("a", 2) == 1
assert f("aa", 1) == 1
assert f("issii", 2) == 4
assert f("qq", 81) == 81
assert f("cooooooooonteeeeeeeeeest", 999993333) == 8999939997

s = input()
k = int(input())
ans = f(s, k)
print(ans)

Submission status: Wrong Answer

Solution code:
S=list(input())
K=int(input())
c=0
if len(S)==1:
  if K==1:
    print(0)
    exit()
  else:
    print(K//2)
    exit()
for i in range(1,len(S)):
  if S[i]==S[i-1]:
    S[i]="!"
    c+=1
if S[0]!=S[-1]:
  print(c*K)
else:
  print(c*K+K-1)

Submission status: Wrong Answer

Solution code:
#coding: utf-8

S=list(input())
K=int(input())
n=len(S)*K

if len(S)==1:
	
	print(n//2 if n%2==0 else (n-1)//2)
	exit()

c = 0
if S[0] == S[-1]:
	c+=K
	S[0] = "!"

for i in range(1,len(S)):
	if S[i]==S[i-1]:
		c+=K
		S[i] = "?"
		
print(c)

Submission status: Wrong Answer

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

s_pre = s[0]
cnt = 1
s2 = []
for x in s[1:]:
    if s_pre == x:
        cnt += 1
    else:
        s2 += [cnt]
        cnt = 1
        s_pre = x
s2 += [cnt]

def div2(x):
    return x//2

if len(s2) == 1:
    print((s2[0]*k)//2)

elif s[0] == s[-1]:
    print(s2[0]//2 + s2[-1]//2 + (s2[0]+s2[-1])//2 + sum(map(div2, s2[1:-1]))*k)

else:
    print(sum(map(div2, s2))*k)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
cnt = 0
for i in range(len(S)-1):
    if (S[i]==S[i+1])&(S[i]!=S[i-1]):
        cnt += K
print(cnt)

Submission status: Wrong Answer

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

singleCnt = 0
doubleCnt = 0
if S[0] != S[-1]:
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      S[i+1] = "1" # かぶらない文字に変換
      singleCnt += 1
  ans = singleCnt * K
  
elif S[0] == S[-1]:
  S2 = S * 2
  for i in range(len(S2)-1):
    if S2[i] == S2[i+1]:
      S2[i+1] = "1" # かぶらない文字に変換
      doubleCnt += 1
  ans = doubleCnt * K // 2 + singleCnt
  
print(ans)

Submission status: Wrong Answer

Solution code:
def li():
    return list(map(input().split()))


if __name__ == "__main__":
    s = input()
    k = int(input())

    count = 0
    first = s[0]
    same_count_start = 0
    before = ""
    for si in s:
        if before == si:
            count += 1
            before = ""
        else:
            before = si
    if si == first:
        same_count_start += 1

    is_corner = before == s[0] and k > 1
    corner_count = k - 1 if is_corner else 0
    print(count * k + corner_count)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ans=0
tmp=0
before=s[0]
t=0
flag=0
tmp2=0
hoge=0
for i in range(len(s)-1):
    if before==s[i+1]:
        t+=1
    else:
        if flag==0 or i==len(s)-2:
            hoge+=t
            flag=1
        else:
            tmp+=-(-t//2)
        t=0
        before=s[i+1]
tmp2=tmp-(-(hoge+1)//2)
tmp+=-(-t//2)
if s[0]==s[-1]:
    print(tmp2*(k-1)+tmp)
else:
    print(tmp*k)

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]:
    cnt+=1

ans = cnt*K
print(ans)

Submission status: Wrong Answer

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

idx = 0
res = 0
while idx+1 < len(S):
  if S[idx] == S[idx+1]:
    res += 1
    idx += 2
  else:
    idx += 1

res *= K

if len(S) >=3 and S[0] == S[-1] and S[0] != S[1] and S[-2] != S[-1]:
  res += K-1

if len(S) == 1:
  res = K // 2

print(res)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

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

if(len(s) == 1 and k > 1):
    print( int(k / 2) )
elif(len(s) == 1 and k == 1):
    print(0)
else:
    chenge_count = 0
    count_tmp = 0
    for i in range(1, len(s)):
        if( s[i] == s[i-1] ):
            count_tmp += 1
        elif(s[i] != s[i-1]):
            count_tmp += 1
            chenge_count += int(count_tmp / 2)
            count_tmp = 0
    if(s[0] == s[-1] and k > 1):
        chenge_count += 1
    print(chenge_count * k)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
p=s[0]
cnt=1
q=[]
for i in range(len(s)-1):
	if s[i+1]==p:
		cnt+=1
	else:
		q.append(cnt//2)
		cnt=1
		p=s[i+1]
q.append(cnt//2)
import copy
qq=copy.copy(q)
for i in range(len(s)):
	if s[i]==p:
		cnt+=1
	else:
		qq[-1]=(cnt//2)
		cnt=0
		break
if cnt>0:
	print(len(s)*k//2)
	exit()
qq[0]-=q[0]
ans=0
ans+=(k-1)*sum(qq)
ans+=sum(q)
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ds=0
dt=0
cnt=0
cnt2=0
#moji=[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]
st=s+s
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    cnt+=1
    if cnt==1:
      ds+=1
    if cnt==2:
      cnt=0
  else:
    cnt=0
cnt=0
for i in range(len(st)-1):
  if st[i]==st[i+1]:
    cnt+=1
    #print("ifi",i,cnt)
    if cnt==1:
      #print("i",i)
      dt+=1
    if cnt==2:
      cnt=0
  else:
    cnt=0
d=dt-ds
ans=ds+d*(k-1)
#print("ds",ds)
#print("dt",dt,st)
print(ans)

Submission status: Wrong Answer

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

mae=s[0]
f=0
cn=0
for i in range(1,le):
    if i==le-1:
        if k==1:
            break
        if s[le-1]==s[0]:
            cn+=1
            break
    if f==1:
        f=0
        mae=s[i]
        continue
    if mae==s[i]:
        cn+=1
        f=1
        mae=s[i]
        continue
    mae=s[i]

print(cn*k)

Submission status: Wrong Answer

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

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

if s[0] == s[-1] and s[0] != s[1] and s[-1] != s[-2]:
    count = 1
else:
    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
    
if ngongo %2 == 1 and ngongongo %2 == 1 and s[0] == s[-1]:
    count += 1

print(count*k)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
ans = 0
prev = S[0]
left = 0
cnt = 1
for i in range(1, len(S)):
    if prev!=S[i]:
        prev = S[i]
        ans += cnt//2
        cnt = 1
    else:
        cnt += 1
if cnt!=1:
    ans += cnt//2
print(ans*K)

Submission status: Wrong Answer

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

if l == 1:
    print(K // 2)
    exit()

if l == 2:
    if S[0] == S[1]:
        print(K)
    else:
        print(0)
    exit()

ans_i = 0
ans_j = 0
i = 2
j = 1

if l % 2 == 0:
    while j < l - 1:
        if S[j - 1] != S[j] and S[j] != S[j + 1]:
            j += 2
        else:
            ans_j += 1
            j += 2
    if S[-2] == S[-1] or S[-1] == S[0]:
        ans_j += 1

    while i < l:
        if S[i - 1] != S[i] and S[i] != S[i + 1]:
            i += 2
        else:
            ans_i += 1
            i += 2
    ans = min(ans_i, ans_j)
    print(ans * K)

else:
    while j < l:
        if S[j - 1] != S[j] and S[j] != S[j + 1]:
            j += 2
        else:
            ans_j += 1
            j += 2

    while i < l - 1:
        if S[i - 1] != S[i] and S[i] != S[i + 1]:
            i += 2
        else:
            ans_i += 1
            i += 2
    if S[-2] == S[-1] or S[-1] == S[0]:
        ans_i += 1
    ans = min(ans_i, ans_j)
    print(ans * K)

Submission status: Wrong Answer

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

counter = 0
tmp = s[0]
counter_list = []

for one in s[1:]:
    if tmp == one:
        counter += 1
    else:
        counter_list.append((counter+1)//2)
        counter = 0
        tmp = one
counter_list.append((counter+1)//2)

sum_counter = sum(counter_list)
if s[0] == s[-1]:
    if counter % 2 != 0:
        print(sum_counter*k)
    else:
        print(sum_counter*k + k -1)
else:
    print(sum_counter*k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
n=len(s)
ss=s[0]
li=[]
check=0
for i in range(n-1):
    if s[i+1]==s[i]:
        check+=1
    elif s[i+1]!=s[i]:
        li.append(check)
        check=0
li.append(check)

ans=0
for i in li:
    ans+=(i+1)//2
ans*=k

aa=0
for i in range(n-1):
    if s[i+1]==s[i]:
        aa+=1
    
if aa==n-1:
    ans=(n*k)//2
#elif s[0]==s[-1]:

#a=li[0]+li[-1]+2
#    ans=ans+(a//2)*(k-1)
#    ans=ans-(li[0]


    
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
s = list(input())
k = int(input())
n = len(s)
if s.count(s[0]) == n:
    print(n * k // 2)
    exit()
c = 0
for i in range(n - 1):
    if s[i + 1] == 'X':
        continue
    if s[i] == s[i + 1]:
        s[i + 1] = 'X'
        c += 1
print(c * k + (s[0] == s[-1]) * (k - 1))

Submission status: Wrong Answer

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

if len(S) == 1:
    print(K//2)
    exit()
minus = 0
if len(S) >= 3 and S[0] == S[1] == S[-1]:
    if S[0] != S[2]:
        minus = 1
cons = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cons += 1
        S[i+1] = '_'
cons2 = int(S[0] == S[-1])
if K == 1:
    print(cons)
    exit()
print(cons * K + cons2 * (K-1) - minus * (K-1))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
if len(s)==1:
  print(k//2)
else:
  ans=0
  chg=0
  for i in range(1,len(s)):
    if chg==0 and s[i-1]==s[i]:
      ans+=1
      chg=1
    else:
      chg=0
  ans2=1
  chg2=1
  for i in range(1,len(s)):
    if chg2==0 and s[i-1]==s[i]:
      ans2+=1
      chg2=1
    else:
      chg2=0
  if s[0]!=s[-1] or chg==1:
    print(k*ans)
  else:
    print((k-1)*ans2+ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
pre_character = ''
S_list=list(S)
def get_abc(s1,s2):
    if s1 == 'a':
        if s2 == 'b':
            return 'c'
        else:
            return 'b'
    elif s1 == 'b':
        if s2 == 'a':
            return 'c'
        else:
            return 'a'
    else:
        if s2 == 'a':
            return 'b'
        else:
            return 'a'
        
s_len = len(S)
count = 0
for i in range(s_len):
    if pre_character == S_list[i]:
        count += 1
        if (s_len - 1) != i:
            S_list[i] = get_abc(pre_character,S_list[i+1])
        else:
            S_list[i] = get_abc(pre_character,S_list[0])
    pre_character = S_list[i]
if S_list[0] == S_list[-1]:
    print((count+1)*K - 1)
else:
    print(count*K)

Submission status: Wrong Answer

Solution code:
s=list(input())
k=int(input())
a,b=0,0
S=s*2

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

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

    
if k%2==0:
    print(b*(k//2))
else:    
    print(b*(k//2)+a)

Submission status: Wrong Answer

Solution code:
import math as m

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


#S = 'iii'
#K = 4

change = 0

# odd_ptn
c_odd = 0
sl_odd = list(S)
for i in range(len(sl_odd)):
    if i == len(sl_odd)-1:
        continue
    if sl_odd[i] == sl_odd[i+1]:
        c_odd = c_odd + 1
        sl_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_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'

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

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
S = [ord(s)-97 for s in readline().strip()]
K = int(readline())

if len(S) == 1:
    ans = K//2
else:
    dp = [1]*26
    dp[S[0]] = 0
    inf = 10**9
    
    for s in S[1:]:
        dp2 = [inf]*26
        for i in range(26):
            for j in range(26):
                if i == j:
                    continue
                dp2[i] = min(dp2[i], 1+dp[j])
        
        for j in range(26):
            if s == j:
                continue
            dp2[s] = min(dp2[s], dp[j])
        
        dp = dp2[:]
    
    ans = inf
    for i in range(26):
        if i == S[0]:
            continue
        ans = min(ans, dp[i])
    ans = ans*(K-1) + min(dp)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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

    print(ans*k)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
counter = 0
if k >= 2:
    s.append(s[0])
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        counter += 1
        s[i+1] = '-1'
result = counter * k
if s[0] == '-1':
    result -= 1
print(result)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

s = input()
k = int(input())
n = len(s)

if n > 1:
    a = [(c, len(list(g))) for c, g in groupby(s)]

    if len(a) == 1:
        print(n * k // 2)
    else:
        answer = sum([i[1] // 2 for i in a]) * k

        if s[0] == s[-1] and a[0][1] % 2 == 1 and a[-1][1] % 2 == 1:
            answer += k - 1            

        print(answer)
else:
    print(n // 2)

Submission status: Wrong Answer

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

box = ""
count=0

for i in S:
  if box == i:
    count += 1
    box = ""
  else:
   	box = i
    
if box == S[0]:
  count += 1
  ans = count*K-1
else:
  ans = count*K
  
print(ans)

Submission status: Wrong Answer

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

# now_s = S[0]
# for i in range(1, len(S)):
#     if now_s == S[i]:
#         cnt += 1
#     now_s = S[i]

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


cnt = 0
ruisekiwa = [1]
now_s = S[0]
for i in range(1, len(S)):
    if now_s == S[i]:
        ruisekiwa[-1] += 1
    else:
        ruisekiwa.append(1)
    now_s = S[i]

if len(ruisekiwa) == 1:
    if ruisekiwa[0] % 2 == 0:
        print(ruisekiwa[0]//2*K)
        exit()
    for i in range(1, K+1):
        if i % 2 == 1:
            cnt += ruisekiwa[0]-2
        else:
            cnt += ruisekiwa[0]-1
    print(cnt)
    exit()


for i in range(len(ruisekiwa)):
    cnt += ruisekiwa[i]//2

cnt = cnt * K

if S[0] == S[-1] and S[-2] != S[-1]:
    cnt += K-1

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

L = [i for i in S]


if len(S) == 1:
    print(K//2+K%2)
    sys.exit()

count = 0
tmp = S[0]
for i in range(1, len(S)):
    if S[i] == tmp:
        count += 1
        S[i] = "A"
        tmp = S[i]
    else:
        tmp = S[i]

count2 = 0
if S[0] == S[-1]:
    L[0] = "A"
    count2 += 1
    tmp = L[0]
    for i in range(1, len(L)):
        if L[i] == tmp:
            count2 += 1
            L[i] = "A"
            tmp = L[i]
        else:
            tmp = L[i]
    print((K//2)*count2 + (K//2+K%2)*count)
else:
    print(count * K)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
pre_character = ''
S_list=list(S)
def get_abc(s1,s2):
    if s1 == 'a':
        if s2 == 'b':
            return 'c'
        else:
            return 'b'
    elif s1 == 'b':
        if s2 == 'a':
            return 'c'
        else:
            return 'a'
    else:
        if s2 == 'a':
            return 'b'
        else:
            return 'a'
        
s_len = len(S)
count = 0
for i in range(s_len):
    if pre_character == S_list[i]:
        count += 1
        if (s_len - 1) != i:
            S_list[i] = get_abc(pre_character,S_list[i+1])
        else:
            S_list[i] = get_abc(pre_character,S_list[0])
    pre_character = S_list[i]
if S_list[0] == S_list[-1]:
    print((count+1)*K - 1)
else:
    print(count*K)
print(S_list)

Submission status: Wrong Answer

Solution code:
import math
S=list(input())
K=int(input())
count = 0
ans = 0
flag = False
firstCount = 0
firstChart = ""
for i in range(1,len(S)):
  if S[i-1] == S[i]:
    count += 1
  else:
    if flag == False:
      firstCount = 0
      firstChart = S[i-1]
    flag = True
    ans += math.ceil(count/2)*K
    count = 0

ans += math.ceil(count/2)
    
if flag:
  if firstChart == S[len(S)-1]:
    ans += math.ceil((firstCount + count)/2)*(K-1)
else:
  ans += math.ceil(count/2)*(K-1) 
print(ans)

Submission status: Wrong Answer

Solution code:
import math

S = input()
K = int(input())
#print(S)
cnt = 1
ans = 0
for i in range(1,len(S)):
    if S[i] == S[i-1]:
        cnt += 1
    else:
        ans += cnt //2 
        cnt = 1
ans += cnt //2 
#print("ans", ans)    
ans *= K
#print("ans*K",ans)
if S[0] == S[-1]:
    cntf = 1
    cnte = 1
    for i in range(1,len(S)):
        #print(S[i], S[i-1] )
        if S[i] == S[i-1]:
            cntf += 1
        else:
            break
    #print("---------------")
    for i in range(1,len(S)):
        #print(S[-i], S[-i+1] )
        if S[-i-1] == S[-i]:
            cnte += 1
        else:
            break
    #print(cnte, cntf)
    if cnte % 2 ==1 and cntf % 2 ==1:
        #print("bbbb")
        ans += (K-1)  
print(ans)

Submission status: Wrong Answer

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

count = 0
flag = 0
S = S + S[0]

for i in range(0, len(S) - 1):
    if S[i] == S[i + 1]:
        if flag == 0:
            count += 1
            flag = 1
        else:
            flag = 0
    else:
        flag = 0

if flag == 1:
    print(count * K - 1)
else:
    print(count * K)

Submission status: Wrong Answer

Solution code:
def solve(s, k):
    
    s_mod = [""] * len(s)
    pre = ""
    ans = 0
    for i, s_i in enumerate(s):
        if pre == s_i:
            ans += 1
            pre = ""
            s_mod[i] = ""
        else:
            pre = s_i
            s_mod[i] = s_i
    ans *= k
    if s_mod[0] == s_mod[len(s)-1]:
        ans += k - 1

    print(ans)

if __name__ == '__main__':
    s = input().strip()
    k = int(input().strip())
    solve(s, k)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
N = len(S)
cnt = 0
flg1 = False
flg2 = False
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:
s = input()
k = int(input())

ans = 0
b = None
for c in s:
    if b == c:
        ans += 1
        b = None
    else:
        b = c

if k == 1:
    print(ans)
else:
    if s[-1] != s[0]:
        print(ans * k)
    else:
        odd = ans
        even = 0
        for c in s:
            if b == c:
                even += 1
                b = None
            else:
                b = c

        if len(s) > 2 and s[-2] != s[-1]:
            print(even * (k - 1) + odd)
        else:
            print(even * (k // 2) + odd * (k - k // 2))

Submission status: Wrong Answer

Solution code:
s = list(input())
t = int(input())
ans=0

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

ans = ans * t

if s[0] == s[-1]:
    ans = ans + t -1

print(ans)

Submission status: Wrong Answer

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

l = list(s)

count = 0
new_l = l.copy()
for i, c in enumerate(s[1:]):
    if c == new_l[i]:
        new_l[i + 1] = 0
        count += 1
result = count * k
print(result)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
ans = 0
flg = 0
for i in range(1, len(S)):
    if S[i] == S[i-1]:
        ans += 1
        S[i] = None
ans *= K
if S[-1] == S[0] and S[0] != None:
    ans += (K-1)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
ret = 0
t = 0
if k > 0:
    for j in range(1, 100):
        if j >= len(s):
            break
        for i in range(len(s)-j):
            for u in range(j):
                if s[i + u] != s[i + u + 1]:
                    break
                if u == j-1:
                    if j % 2==1:
                        t += 1
                    else:
                        t -= 1
    ret += t * k
    if len(s) > 2:
        if s[0] == s[-1] and s[-2] != s[-1]:
            ret += (k - 1)

print(ret)

Submission status: Wrong Answer

Solution code:
s=str(input())
k=int(input())
t=s*2

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

ans_=0
a_=1
for i in range(len(t)-1):
    if t[i]==t[i+1]:
        a_+=1
    else:
        ans_+=a_//2
        a_=1
ans_+=a_//2
#print(ans_)
print(ans+(k-1)*(ans_-ans))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  s = input().strip()
  k = int(input())
  mode = s[0] == s[-1]

  pre = 1
  idx = 1

  while idx < len(s) and s[idx] == s[0]:
    pre += 1
    idx += 1

  s = s[idx:]

  if len(s) == 0:
    print(pre * k // 2)
    return

  post = 1
  idx = -2

  while idx >= -len(s) and s[idx] == s[-1]:
    post += 1
    idx -= 1

  s = s[:idx + 1]

  required = 0
  count = 1

  for i in range(1, len(s)) :
    print(s[i])
    if s[i - 1] == s[i]:
      count += 1
    else:
      print('->', count)
      required += count // 2
      count = 1

  required += count // 2
  required *= k
  required += pre // 2
  required += post // 2

  if mode:
    required += ((pre + post) // 2) * (k - 1)
  else:
    required += (pre // 2 + post // 2) * (k - 1)

  print(required)


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

ans = 0
rep = 1
for i in range(0, len(s) - 1):
    current = s[i]
    next = s[i+1]
    if current == next:
        rep += 1
    else:
        if rep > 1:
            ans += rep // 2
            rep = 1

if rep > 1:
    ans += 1

start_eq_end = 0
if len(s) > 2 and s[0] == s[-1]:
    if rep % 2 != 0:
        start_eq_end = k - 1


print(ans * k +  start_eq_end)

Submission status: Wrong Answer

Solution code:
t=str(input())
k=int(input())
L = len(t)
tmp = t[0]
n = 0 #change
flag = 0
for i in range(1,L):
  if flag==1:
    flag=0
  elif t[i]==tmp:# and flag==0:
    n+=1
    flag=1  
  tmp=t[i]
ans=k*n
if L>2:
  if t[0]==t[-1] and t[-2]!=t[-1]:
    ans+=k-1
print(ans)

Submission status: Wrong Answer

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

check = ""
check_cnt = 0
ans1 = 0
for i in range(len(s)):
    if check_cnt == 0:
        check = s[i]
        check_cnt += 1
        continue
    if check == s[i]:
        check_cnt += 1
        continue
    else:
        check = s[i]
        if check_cnt == 1:
            pass
        elif check_cnt%2 == 0:
            ans1 += check_cnt//2
        else:
            ans1 += (check_cnt - 1)//2
    check_cnt = 1
else:
    if check_cnt == 1:
        pass
    elif check_cnt%2 == 0:
        ans1 += check_cnt//2
    else:
        ans1 += (check_cnt - 1)//2
    
cnt2 = 0
cnt3 = 0

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

add = 0
if cnt2%2 == 1 and cnt3%2 == 1:
    add = 1
    
print(ans1 * k + add * (k-1))