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())
c=""
pre_c=""
ans=0

#パターン1 先頭と最後尾文字が異なる場合
if s[0]!=s[-1]:
  for c in s:
    #flagは前文字の変更の有無
    if pre_c==c and not(flag):
      ans+=1
      flag=True
    else:
      flag=False
    pre_c=c
      
  print(ans*k);exit()

#全文字等しい場合、回答は(文字の長さ×繰り返し回数÷2)
if len(set(s))==1:
  print(len(s)*k//2);exit()
  
pre_c=s[0]
i=1
top=1
c=s[1]
while(pre_c==c):
  top+=1
  pre_c=c
  i+=1
  c=s[i]
  
pre_c=s[-1]
i=-2
bot=1
c=s[-2]
while(pre_c==c):
  bot+=1
  pre_c=c
  i-=1
  c=s[i]

pre_c=""
for c in s:
  if c==pre_c:
    ans+=1
    flag=True
  else:
    flag=False
  pre_c=c
  
if top%2==1 and bot%2==1:
  ans=ans*k+k-1
else:
  ans*=k
  
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
key = s[0]
count = 1
sum_count = 0
list1=[]
ans = 0
ans2 =0
for i in range(1,len(s)):
    if key == s[i]:
        count += 1
    else:
        list1.append(count)
        count = 1
        key = s[i]
list1.append(count)
if len(list1) == 1:
    print(list1[0]*k//2)
elif s[0] == s[len(s)-1]:
    ans += (list1[0]+list1[len(list1)-1])//2*(k-1)
    for i in range(1,len(list1)-1):
        ans2 += list1[i]//2
    print(ans2*k+ans+list1[0]//2*2)
else:
    for i in range(len(list1)):
        ans += list1[i]//2
    print(ans*k)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
count1=1
tc=0
for i in  range(len(s)-1):
    if(s[i]==s[i+1]):
        count1=count1+1
    else:
        #print(count1)
        if(count1>2):
            tc=tc+count1//2
            count1=1
        elif(count1==2):
            tc=tc+count1-1
            count1=1
        else:
            count1=1
if(count1>2):
    tc=tc+count1//2
elif(count1==2):
     tc=tc+count1-1
print(k*tc)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
count1=1
tc=0
for i in  range(len(s)-1):
    if(s[i]==s[i+1]):
        count1=count1+1
    else:
        #print(count1)
        if(count1>2):
            tc=tc+count1//2
            count1=1
        elif(count1==2):
            tc=tc+count1
        else:
            count1=1
#print(tc)        
print(tc*k)

Submission status: Wrong Answer

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

now = s[0]
connect = 1
ans = []
for char in s[1:]:
  if char == now:
    connect += 1
  else:
    ans.append(connect//2)
    now = char
    connect = 1
else:
  for char in s:
    if char == now:
      connect += 1
    else:
      ans.append(connect//2)
      break
print(sum(ans)*n if (len(set(s))) != 1 else len(s)//2*n)

Submission status: Wrong Answer

Solution code:

def main():
    s_list=[]
    s_con=0
    s_num=0

    String = input()
    num = int(input())
    
    for s in String:
        s_list.append(s)
    
    for i in range(len(s_list)-1):
        if s_list[i] == s_list[i+1]:
            s_list[i+1] = None
            s_con = s_con + 1
        
    if s_list[0] == s_list[len(s_list)-1]:
        s_num = num - 1

    print(s_con * num + s_num)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
cnt=0
flag=True
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        if flag:
            cnt+=1
            flag=False
        else:
            flag=True
    else:
        flag=True
print(cnt*k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

if __name__ == '__main__':

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

	leng = len(S)
	ans = 0

	#１文字である場合
	if leng == 1:
		ans = 0
	#全部同じ文字である場合
	elif S.count(S[0]) == leng:
		ans = int(leng*K/2)
	else:
		#隣り合った文字はＮ文字で置き換える文字はＭ文字か計算する
		start = ""
		cnt = 0
		rep = 0
		for x,y in enumerate(S):
			if x == 0:
				start = y
			else:
				if start == y:
					cnt += 1
				else:
					#同じ文字あり
					if cnt > 0:
						cnt += 1	#最初を追加
						rep += int(cnt/2)
						cnt = 0	#初期化

					start = y
		#後処理
		if cnt > 0:
			cnt += 1	#最初を追加
			rep += int(cnt/2)

		#先頭と末尾が同じ文字である場合
		if S[0] == S[leng-1]:

			#先頭文字での置き換え文字数
			cnt1 = 1
			smoji = S[0]
			for x in range(1,leng):
				if S[0] == S[x]:
					cnt1 += 1
					smoji += S[0]
				else:
					break
			moto1 = int(cnt1/2)


			#末尾文字での置き換え文字数
			cnt2 = 1
			#文字列反転
			S = S[::-1]
			smoji += S[0]
			for x in range(1,leng):
				if S[0] == S[x]:
					cnt2 += 1
					smoji += S[0]
				else:
					break
			moto2 = int(cnt2/2)

			#先頭と末尾を合わせたものを置き換えた文字数
			slen = len(smoji)
			moto3 = int(slen/2)

			kekka = (moto1 + moto2) - moto3
			kekka = kekka * (K -1)

			ans = rep * K - kekka
		else:
			ans = rep * K

	print(ans)

Submission status: Wrong Answer

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


def main():
    from math import ceil

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

    prev = s[0]
    count = 1
    pair = list()

    # 文字と連続する回数を数える
    for cur in s[1:]:
        if cur == prev:
            count += 1
        else:
            pair.append((prev, count))
            prev = cur
            count = 1

    if count >= 1:
        pair.append((prev, count))

    # Sの文字が1種類かどうか
    if len(pair) == 1:
        if k % 2 == 0:
            print(len(s) // 2 * k)
        else:
            print((len(s) * (k - 1)) // 2 + ceil(len(s) / 2))
    else:
        first = pair[0]
        last = pair[-1]
        ans = 0

        # 両端が同じ文字の種類
        if first[0] == last[0]:
            for a, count in pair[1:-1]:
                ans += count // 2

            print(ans * k + first[1] // 2 + last[1] // 2 + (first[1] + last[1]) // 2 * (k - 1))
        else:
            for a, count in pair:
                ans += count // 2

            print(ans * k)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

my_lists = input()
lst = list(my_lists)
n = int(input())


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

if (count+1 == len(lst)):
    print(int(len(lst) * n / 2))
    exit(0)


flg = False
count = 0
for i in range(1,len(lst),1):
    if (flg == True):
        flg = False
        continue
    if (lst[i-1] == lst[i]):
        if (len(lst)-1 >= i+1):
            if(lst[i] == lst[i+1]):
                flg = True
                count += 1
            else:
                count += 1
        else:
            count += 1

count = count * n
if(len(lst) >= 3):
    if(lst[0] == lst[len(lst)-1]):
        if((lst[0] != lst[1]) and (lst[len(lst)-1] != lst[(len(lst)-2)])):
            count = count + n -1


print(count)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

my_lists = input()
lst = list(my_lists)
n = int(input())


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

if (count+1 == len(lst)):
    print(int(len(lst) * n / 2))
    exit(0)


flg = False
count = 0
for i in range(1,len(lst),1):
    if (flg == True):
        flg = False
        continue
    if (lst[i-1] == lst[i]):
        if (len(lst)-1 >= i+1):
            if(lst[i] == lst[i+1]):
                flg = True
                count += 1
            else:
                count += 1
        else:
            count += 1

count = count * n

if(lst[0] == lst[len(lst)-1]):
    if((lst[0] != lst[1]) and (lst[len(lst)-1] != lst[(len(lst)-2)])):
        count = count + n -1


print(count)

Submission status: Wrong Answer

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


def main():
    from math import ceil

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

    prev = s[0]
    count = 1
    pair = list()

    # 文字と連続する回数を数える
    for cur in s[1:]:
        if cur == prev:
            count += 1
        else:
            pair.append((prev, count))
            prev = cur
            count = 1

    if count >= 1:
        pair.append((prev, count))

    # Sの文字が1種類かどうか
    if len(pair) == 1:
        if k % 2 == 0:
            print(len(s) // 2 * k)
        else:
            print((len(s) * (k - 1)) // 2 + ceil(len(s) / 2))
    else:
        first = pair[0]
        last = pair[-1]
        ans = 0

        # 両端が同じ文字の種類かつ，奇数個
        if first[0] == last[0] and (first[1] % 2 == 1 and last[1] % 2 == 1):
            for a, count in pair[1:-1]:
                ans += count // 2

            print(ans * k + first[1] // 2 + last[1] // 2 + (first[1] + last[1]) // 2 * (k - 1))
        else:
            for a, count in pair:
                ans += count // 2

            print(ans * k)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import groupby
s = input()
k = int(input())
ans = 0
t = [[i, len(list(g))] for i, g in groupby(s)]


for i in t:
    if i[1] > 1:
        ans += i[1]//2

else :
    ans *= k

if len(t)>1 and t[0][0] == t[-1][0] and (t[0][1] + t[-1][1])%2 == 0:
    ans += k-1
elif len(t) == 1 and t[0][1]==1 :
    ans += t[0][1]*k//2


print(ans)

Submission status: Wrong Answer

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

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

prevc = None
firstc = None
first_count = 0
increment = 0  # 増分
tmp_count = 1
for i in range(len(S) - 1):
    if firstc is None:
        firstc = S[i]
    if prevc == S[i]:
        tmp_count += 1
    else:
        if i != 0 and first_count == 0:
            first_count = tmp_count
        increment += (tmp_count // 2)
        tmp_count = 1

    prevc = S[i]

# 最後一個拾うの忘れずに
increment += (tmp_count // 2)


if firstc == prevc:
    # odd + oddで結合するときだけ変更箇所が１増える
    if first_count % 2 != 0 and tmp_count % 2 != 0:
        increment += 1

result = increment * K
print(result)

Submission status: Wrong Answer

Solution code:

def main():
    s_list=[]
    s_con=0

    String = input()
    num = int(input())
    
    for s in String:
        s_list.append(s)
    
    for i in range(len(s_list)-1):
        if s_list[i] == s_list[i+1]:
            s_list[i+1] = None
            s_con = s_con + 1
        
    if s_list[0] == s_list[len(s_list)-1]:
        s_con = s_con + 1

    print(s_con * num)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

def main():
    s_list=[]
    s_con=0

    String = input()
    num = int(input())
    
    for s in String:
        s_list.append(s)
    
    for i in range(len(s_list)-1):
        if s_list[i] == s_list[i+1]:
            s_list[i+1] = None
            s_con = s_con + 1
        
        if s_list[0] == s_list[len(s_list)-1]:
            s_con = s_con + 1

    print(s_con * num)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import os
import time

def main():
    Str = ""
    s_list=[]
    s_con=0

    String = input()
    num = int(input())
    
    for s in String:
        s_list.append(s)
    
    for i in range(len(s_list)-1):
        if s_list[i] == s_list[i+1]:
            s_list[i+1] = None
            s_con = s_con + 1
    print(s_con * num)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def count(t):
    uniqued_t = [t[0]]
    cnt = [1]
    for ti in t[1:]:
        if ti == uniqued_t[-1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
            uniqued_t.append(ti)
    return sum(i // 2 for i in cnt)

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

if len(s) > 1:
    t1 = count(s)
    t2 = count(s * 2)
    print(t1+(t2-t1)*(k-1))
else:
    print(k // 2)

Submission status: Wrong Answer

Solution code:
def count(t):
    uniqued_t = [t[0]]
    cnt = [1]
    for ti in t[1:]:
        if ti == uniqued_t[-1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
            uniqued_t.append(ti)
    return sum(i // 2 for i in cnt)

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

t1 = count(s)
t2 = count(s * 2)

print(t1+(t2-t1)*(k-1))

Submission status: Wrong Answer

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

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

current_char = ""
count1 = 0
count2 = 0

for s in S:
    if current_char == s:
        count1 += 1
        current_char = ""
    else:
        current_char = s


current_char = ""
for s in S[1:] + S[0]:
    if current_char == s:
        count2 += 1
        current_char = ""
    else:
        current_char = s   

print(count1*(int(K / 2) + K % 2) + count2*int(K / 2))

Submission status: Wrong Answer

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

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

current_char = ""
count = 0

for s in S:
    if current_char == s:
        count += 1
        current_char = ""
    else:
        current_char = s

print(count*K)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
if len(set(s)) == 1:
    print((len(s)*k)//2)
else:
    l_list = []
    check = s[0]
    cnt = 1
    for i in s[1:]:
        if check == i:
            cnt += 1
        else:
            l_list.append(cnt)
            check = i
            cnt = 1
    if cnt > 1:
        l_list.append(cnt)
    ans = 0
    for i, l in enumerate(l_list):
        if 0 < i < len(l_list)-1:
            ans += (l//2)*k
        else:
            ans += l//2
    if s[0] == s[-1]:
        ans += ((l_list[0]+l_list[-1])//2)*(k-1)
    print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
 
if len(S) == 1:
    print(K // 2)
    exit()

chkd, flg = 0, 1
cnt = 0
cnt_list =[]
 
for i in range(1, len(S)):
    cnt += 1
    if chkd == 1:
        chkd = 0
        continue
    if S[i] == S[i-1]:
        cnt_list.append(cnt)
        chkd = 1
    else:
        flg = 0
 
# 2個連続の場合
S2 = S*2
chkd = 0
cnt = 0
cnt_list2 =[]
 
for i in range(1, len(S2)):
    cnt += 1
    if chkd == 1:
        chkd = 0
        continue
    if S2[i] == S2[i-1]:
        cnt_list2.append(cnt)
        chkd = 1

if flg: # 全部同じ場合
    print(len(S)*K // 2)
elif S[0] == S[-1]:
    print(len(cnt_list) + (len(cnt_list2)-len(cnt_list)) * (K - 1))
else :
    print(len(cnt_list)*K)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
 
if len(S) == 1:
    print(K // 2)
    exit()

chkd, flg = 0, 1
cnt = 0
cnt_list =[]
 
for i in range(1, len(S)):
    cnt += 1
    if chkd == 1:
        chkd = 0
        continue
    if S[i] == S[i-1]:
        cnt_list.append(cnt)
        chkd = 1
    else:
        flg = 0
 
# 2個連続の場合
S = S*2
chkd = 0
cnt = 0
cnt_list2 =[]
 
for i in range(1, len(S)):
    cnt += 1
    if chkd == 1:
        chkd = 0
        continue
    if S[i] == S[i-1]:
        cnt_list2.append(cnt)
        chkd = 1

if flg: # 全部同じ場合
    print(len(S)*K // 2)
elif S[0] == S[-1]:
    print(len(cnt_list) + (len(cnt_list2)-len(cnt_list)) * (K - 1))
else :
    print(len(cnt_list)*K)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
 
if len(S) == 1:
    print(K // 2)
    exit()
 
flg = 1
cnt = 0
cnt_list =[]
 
for i in range(1, len(S)):
    cnt += 1
    if S[i] == S[i-1]:
        cnt_list.append(cnt+1)
    else:
        flg = 0
 
if flg:
    print(len(S)*K // 2)
elif S[0] == S[-1] and not (cnt_list[0] % 2 and (len(S) - cnt_list[-1] + 1) % 2):
    print(len(cnt_list)*K + K - 1)
else :
    print(len(cnt_list)*K)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
 
if len(S) == 1:
    print(K // 2)
    exit()

flg = 1
cnt = 0
cnt_list =[]

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

if flg:
    print(len(S)*K // 2)
elif S[0] == S[-1] and cnt_list[0] % 2 and cnt_list[-1] % 2:
    print(len(cnt_list)*K + K - 1)
else :
    print(len(cnt_list)*K)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
 
if len(S) == 1:
    print(K // 2)
    exit()

flg = 1
cnt = 0
cnt_list =[]

for i in range(1, len(S)):
    cnt += 1
    if S[i] == S[i-1]:
        print("ok")
        cnt_list.append(cnt+1)
    else:
        flg = 0

if flg:
    print(len(S)*K // 2)
elif S[0] == S[-1] and cnt_list[0] % 2 and cnt_list[-1] % 2:
    print(len(cnt_list)*K + K - 1)
else :
    print(len(cnt_list)*K)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
 
if len(S) == 1:
    print(K // 2)
else :
    chkd = 0
    flg = 1
    cnt = 0
    cnt_list =[]
    
    for i in range(1, len(S)):
        cnt += 1
        if flg == 1:
            chkd = 0
            continue
        if S[i] == S[i-1]:
            cnt_list.append(cnt+1)
            chkd = 1
        else:
            flg = 0
    
    if flg:
        print(len(S)*K // 2)
    elif S[0] == S[-1] and cnt_list[0] % 2 and cnt_list[-1] % 2:
        print(len(cnt_list)*K + K - 1)
    else :
        print(len(cnt_list)*K)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
 
if len(S) == 1:
    print(K // 2)
else :
    chkd = 0
    flg = 1
    cnt = 0
    cnt_list =[]
    
    for i in range(1, len(S)):
        cnt += 1
        if flg == 1:
            chkd = 0
            continue
        if S[i] == S[i-1]:
            cnt_list.append(cnt)
            chkd = 1
        else:
            flg = 0
    
    if flg:
        print(len(S)*K // 2)
    elif S[0] == S[-1] and cnt_list[0] % 2 and cnt_list[-1] % 2:
        print(len(cnt_list)*K + K - 1)
    else :
        print(len(cnt_list)*K)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
 
if len(S) == 1:
    print(K // 2)
else :
    chkd = 0
    flg = 1
    cnt = 0
    cnt_list =[]
    
    for i in range(1, len(S)):
        cnt += 1
        if flg == 1:
            chkd = 0
            continue
        if S[i] == S[i-1]:
            cnt_list.append(cnt)
            chkd = 1
        else:
            flg = 0
    
    if flg:
        print(len(S)*K // 2)
    elif S[0] == S[-1] and cnt_list[0] % 2 and cnt_list[-1] % 2:
        print(len(cnt_list2)*K + K - 1)
    else :
        print(len(cnt_list)*K)

Submission status: Wrong Answer

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

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

pre_s = ''
flag1 = 0
flag2 = 0
flag = True

pre_s = S[0]
flag1 = 1
for s in S[1:]:
    if pre_s == s:
        flag1 += 1
    else:
        break

if S[-1] == S[0]:
    pre_s = S[-1]
    flag2 = 1
    for i, s in enumerate(S[::-1]):
        if i == 0:
            continue
        if pre_s == s:
            flag2 += 1
        else:
            break

    # if flag1 > 0 and flag1 % 2 == 0 and flag2 % 2 != 0:
    if flag1 > 0 and flag1 % 2 == 0:
        flag = False

pre_s = ''
rep_count = 0
    

for s in S:
    if pre_s == s:
        rep_count += 1
        pre_s = s.upper()
    else:
        pre_s = s

rep_count *= K
if S[0] == pre_s and flag:
    rep_count += K - 1


print(rep_count)

Submission status: Wrong Answer

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

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

pre_s = ''
flag1 = 0
flag2 = 0
flag = True

pre_s = S[0]
flag1 = 1
for s in S[1:]:
    if pre_s == s:
        flag1 += 1
    else:
        break

if S[-1] == S[0]:
    pre_s = S[-1]
    flag2 = 1
    for i, s in enumerate(S[::-1]):
        if i == 0:
            continue
        if pre_s == s:
            flag2 += 1
        else:
            break

    if flag1 > 0 and flag1 % 2 == 0 and flag2 % 2 != 0:
        flag = False

pre_s = ''
rep_count = 0
    

for s in S:
    if pre_s == s:
        rep_count += 1
        pre_s = s.upper()
    else:
        pre_s = s

rep_count *= K
if S[0] == pre_s and flag:
    rep_count += K - 1


print(rep_count)

Submission status: Wrong Answer

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

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

pre_s = ''
flag1 = 0
flag2 = 0
flag = True

pre_s = S[0]
flag1 = 1
for s in S[1:]:
    if pre_s == s:
        flag1 += 1
    else:
        break

if S[-1] == S[0]:
    pre_s = S[-1]
    flag2 = 1
    for i, s in enumerate(S[::-1]):
        if i == 0:
            continue
        if pre_s == s:
            flag2 += 1
        else:
            break

    if flag1 % 2 == 0 and flag2 % 2 != 0:
        flag = False

pre_s = ''
rep_count = 0
    

for s in S:
    if pre_s == s:
        rep_count += 1
        pre_s = s.upper()
    else:
        pre_s = s

rep_count *= K
if S[0] == pre_s and flag:
    rep_count += K - 1


print(rep_count)

Submission status: Wrong Answer

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

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

pre_s = ''
flag1 = 0
flag2 = 0
flag = True

pre_s = S[0]
flag1 = 1
for s in S[1:]:
    if pre_s == s:
        flag1 += 1
    else:
        break

if S[-1] == S[0]:
    pre_s = S[-1]
    flag2 = 1
    for i, s in enumerate(S[::-1]):
        if i == 0:
            continue
        if pre_s == s:
            flag2 += 1
        else:
            break

    if flag1 + flag2 % 2 == 0:
        flag = False

pre_s = ''
rep_count = 0
    

for s in S:
    if pre_s == s:
        rep_count += 1
        pre_s = s.upper()
    else:
        pre_s = s

rep_count *= K
if S[0] == pre_s and flag:
    rep_count += K - 1


print(rep_count)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
bottom_char = s[-1]
predecessor = bottom_char
bottom_seq = 0
seq = 0
counter = 0
size = len(s)
pointer = 1

while not pointer == size + 1 and s[-pointer] == bottom_char:
    pointer += 1
    bottom_seq += 1
seq = bottom_seq

for i in range(pointer, size + 1):
    if predecessor == s[-i]:
        seq += 1
    else:
        counter += seq // 2
        predecessor = s[-i]
        seq = 1
counter += seq // 2

#print(bottom_seq, seq, counter)
if predecessor == bottom_char:
    print(counter * k - (k - 1) * (seq // 2 + bottom_seq // 2 - (seq + bottom_seq) // 2))
else:
    print(counter * k)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
bottom_char = s[-1]
predecessor = bottom_char
bottom_seq = 0
seq = 0
counter = 0
size = len(s)
pointer = 1

while s[-pointer] == bottom_char and not pointer == size:
    pointer += 1
    bottom_seq += 1
seq = bottom_seq

for i in range(pointer, size + 1):
    if predecessor == s[-i]:
        seq += 1
    else:
        counter += seq // 2
        predecessor = s[-i]
        seq = 1
counter += seq // 2

if predecessor == bottom_char:
    print(counter * k - (k - 1) * (seq // 2 + bottom_seq // 2 - (seq + bottom_seq) // 2))
else:
    print(counter * k)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
count = []
now = 1
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        now += 1
    else:
        count.append(now)
        now = 1
count.append(now)
if len(count) == 1:
    ans = (count[0] * k) // 2
else:
    if s[0] == s[-1]:
        temp = 0
        for i in count:
            temp += i // 2
        ans = (temp * k) - ((count[0] // 2) + (count[1] // 2)  - ((count[0] + count[1]) // 2)) * (k - 1)
    else:
        ans = sum([c // 2 for c in count]) * k
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
count = []
now = 1
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        now += 1
    else:
        count.append(now)
        now = 1
count.append(now)
if len(count) == 1:
    ans = (count[0] * k) // 2
else:
    if s[0] == s[-1]:
        temp = 0
        for i in count:
            temp += i // 2
        ans = (temp * k) - ((count[0] // 2) + (count[1] // 2)  - (count[0] + count[1]) // 2) * (k - 1)
    else:
        ans = sum([c // 2 for c in count]) * k
print(ans)

Submission status: Wrong Answer

Solution code:
def find(s):
    if s[0]!=s[-1]:
        need=0
        ignore=0
        for i in range(len(s)):
            if i==ignore:
                continue
            if s[i]==s[i-1]:
                need+=1
                ignore=i+1
        return need
    else:
        ans=[]
        need=1
        ignore=0
        for i in range(len(s)):
            if i==ignore:
                continue
            if s[i]==s[i-1]:
                need+=1
                ignore=i+1
        if ignore==len(s):
            ans+=[need-1]
        else:
            ans+=[need]
        s=s[::-1]
        need=1
        ignore=0
        for i in range(len(s)):
            if i==ignore:
                continue
            if s[i]==s[i-1]:
                need+=1
                ignore=i+1
        if ignore==len(s):
            ans+=[need-1]
        else:
            ans+=[need]            
        ans+=[need]
        return min(ans)
        
        
def findout(s,K):
    if len(s)==1:
        return K//2
    if len(s)==2:
        if s[0]==s[1]:
            return K
    if s[0]==s[-1]:
        return K*find(s)-1
    return K*find(s)
    
s=input()
K=int(input())
print(findout(s,K))

Submission status: Wrong Answer

Solution code:
def find(s):
    need=0
    ignore=0
    for i in range(len(s)):
        if i==ignore:
            continue
        if s[i]==s[i-1]:
            need+=1
            ignore=i+1
    return need
def findout(s,K):
    if len(s)==1:
        return K//2
    if len(s)==2:
        if s[0]==s[1]:
            return K
    
    return K*find(s)
    
s=input()
K=int(input())
print(findout(s,K))

Submission status: Wrong Answer

Solution code:
import math
def num_of_changes(chuoi):
    tmp = chuoi[0]
    dem=0
    res=0
    for i in chuoi:
        if tmp==i:
            dem+=1
        else:
            res+=math.floor(dem/2)
            dem=1
            tmp = i
    res+=math.floor(dem/2)
    return res
s = input()
k = int(input())
ss = s+s

fir = num_of_changes(s)
sec = num_of_changes(ss)
print(fir+(sec-fir)*(k-1)+1)

Submission status: Wrong Answer

Solution code:
import math
def num_of_changes(chuoi):
    tmp = chuoi[0]
    dem=0
    res=0
    for i in chuoi:
        if tmp==i:
            dem+=1
        else:
            res+=math.floor(dem/2)
            dem=1
            tmp = i
    res+=math.floor(dem/2)
    return res
s = input()
k = int(input())
ss = s+s

fir = num_of_changes(s)
sec = num_of_changes(ss)
print(fir+(sec-fir)*(k-1)-1)

Submission status: Wrong Answer

Solution code:
S=input()
N=int(input())
a=len(S)
b=0
for i in range(a-1):
 if S[i]==S[i+1]:
  b+=0.5
 else:
  b=int(b+0.5)
b=int(b+0.5)
S2=S*2
a2=a*2
b2=0
for i in range(a2-1):
 if S2[i]==S2[i+1]:
  b2+=0.5
 else:
  b2=int(b2+0.5)
b2=int(b2+0.5)
c=(b2-b*2)*(N-1)+b*N
print(c)

Submission status: Wrong Answer

Solution code:
import math
def num_of_changes(chuoi):
    tmp = chuoi[0]
    dem=0
    res=0
    for i in chuoi:
        if tmp==i:
            dem+=1
        else:
            res+=math.floor(dem/2)
            dem=1
            tmp = i
    res+=math.floor(dem/2)
    return res
s = input()
k = int(input())
ss = s+s

fir = num_of_changes(s)
sec = num_of_changes(ss)
print(fir+(sec-fir)*(k-1))

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
SS = S[::-1]

count = 0
l = len(S)
check = True
ff = 1
while ff < l:
    if S[ff] == S[0]:
        ff += 1
    else:
        break
ll = 1
while ll < l:
    if SS[ll] == SS[0]:
        ll += 1
    else:
        break

if S[0] != SS[0]:
    ff = 0
    ll = 0

if ff == l:
    if l == 1:
        print(K // 2)
    elif l % 2 == 0:
        print(K)
    else:
        print(l * K // 2)
    exit()

i = ff
c = 1
while i < l - ll - 1:
    if S[i] == S[i + 1]:
        c += 1
    else:
        count += c // 2
        c = 1
    i += 1
count += c // 2

# print(count, ff, ll)

print(K * count + (K - 1) * ((ff + ll) // 2) + ff // 2 + ll // 2)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
SS = S[::-1]

count = 0
l = len(S)
check = True
ff = 1
while ff < l:
    if S[ff] == S[0]:
        ff += 1
    else:
        break
ll = 1
while ll < l:
    if SS[ll] == SS[0]:
        ll += 1
    else:
        break

if S[0] != SS[0]:
    ff = 0
    ll = 0

if ff == l:
    if l % 2 == 0:
        print(K // 2)
    else:
        print(l // 2 + (K - 1) // 2)
    exit()

i = ff
c = 1
while i < l - ll - 1:
    if S[i] == S[i + 1]:
        c += 1
    else:
        count += c // 2
        c = 1
    i += 1
count += c // 2

# print(count, ff, ll)

print(K * count + (K - 1) * ((ff + ll) // 2) + ff // 2 + ll // 2)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
SS = S[::-1]

count = 0
l = len(S)
check = True
ff = 1
while ff < l:
    if S[ff] == S[0]:
        ff += 1
    else:
        break
ll = 1
while ll < l:
    if SS[ll] == SS[0]:
        ll += 1
    else:
        break

if S[0] != SS[0]:
    ff = 0
    ll = 0

if ff == l:
    if l % 2 == 0:
        print(ll // 2 * K)
    else:
        print(ll // 2 * K + K - 1)
    exit()

i = ff
c = 1
while i < l - ll - 1:
    if S[i] == S[i + 1]:
        c += 1
    else:
        count += c // 2
        c = 1
    i += 1
count += c // 2

# print(count, ff, ll)

print(K * count + (K - 1) * ((ff + ll) // 2) + ff // 2 + ll // 2)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
SS = S[::-1]

count = 0
l = len(S)
check = True
ff = 1
while ff < l:
    if S[ff] == S[0]:
        ff += 1
    else:
        break
ll = 1
while ll < l:
    if SS[ll] == SS[0]:
        ll += 1
    else:
        break

if S[0] != SS[0]:
    ff = 0
    ll = 0

if ff == l:
    print(l//2 * K)
    exit()

i = ff
c = 1
while i < l - ll - 1:
    if S[i] == S[i + 1]:
        c += 1
    else:
        count += c // 2
        c = 1
    i += 1
count += c // 2

# print(count, ff, ll)

print(K * count + (K - 1) * ((ff + ll) // 2) + ff // 2 + ll // 2)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
SS = S[::-1]

count = 0
l = len(S)
check = True
ff = 1
while ff < l:
    if S[ff] == S[0]:
        ff += 1
    else:
        break
ll = 1
while ll < l:
    if SS[ll] == SS[0]:
        ll += 1
    else:
        break

if S[0] != SS[0]:
    ff = 0
    ll = 0

if ff == l:
    print(l//2 * K)
    exit()

i = ff
c = 0
while i < l - ll - 1:
    if S[i] == S[i + 1]:
        c += 1
    else:
        count += c // 2
        c = 0
    i += 1

# print(count, ff, ll)

print(K * count + (K - 1) * ((ff + ll) // 2) + ff // 2 + ll // 2)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
SS = S[::-1]

count = 0
l = len(S)
check = True
ff = 1
while ff < l:
    if S[ff] == S[0]:
        ff += 1
    else:
        break
ll = 1
while ll < l:
    if SS[ll] == SS[0]:
        ll += 1
    else:
        break

if S[0] != SS[0]:
    ff = 0
    ll = 0

if ff == l:
    print(l//2 * K)
    exit()

i = ff

while i < l - ll - 1:
    if S[i] == S[i + 1]:
        count += 1
        i += 2
    else:
        i += 1

# print(count, ff, ll)

print(K * count + (K - 1) * ((ff + ll) // 2) + ff // 2 + ll // 2)