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())
if len(S)==1:
    print(len(S)*K//2)
elif K==1:
    i=0
    count=0
    while i<len(S)-1:
        if S[i]==S[i+1]:
            count+=1
            i+=2
        else:
            i+=1
    print(count)

else:
    s=""
    s+=S*2
    i=0
    count=0
    c=0
    while i<len(s):
        if i==len(s)-1:
            if s[i]==s[0]:
                count+=1
                if s[0]==s[1]:
                    count-=1
            i+=1
        elif s[i]==s[i+1]:
            count+=1
            i+=2
        else:
            i+=1
    if K%2==0:
        print((count-c)*(K//2))
    else:
        i=0
        Count=0
        while i<len(S)-1:
            if S[i]==S[i+1]:
                Count+=1
                i+=2
            else:
                i+=1
        print(count*(K//2)+Count)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
count = 0
C = 0
change = 0
A =[]
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
    A.append(count)
    count = 0
    C = 0 
if count == 1:
  change += 1
elif count%2 == 0:
  change += count//2
else:
  change += (count+1)//2

if count != 0:
  A.append(count)
A.append(1)
if C%2 == 0 and A[0]%2 == 0 and s[0] == s[n-1]:
  print(change*k + k-1)
else:
  print(change*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
if s[-1]==0 and s[-2]!=0:
  ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    s = input()
    len_s = len(s)
    k = int(input())
    li = [1] * len_s + [0]
    if len_s == 1:
        return k // 2
    if len_s == 2:
        if s[0] == s[1]:
            return k
        return 0
    if s[0] != s[-1]:
        cnt = 0
        flg = False
        for i in range(0, len_s - 1):
            if s[i] == s[i + 1]:
                if flg:
                    flg = False
                else:
                    flg = True
                    cnt += 1
        return cnt * k
    s += s
    cnt = 0
    flg = False
    for i in range(0, len_s):
        if s[i] == s[i + 1]:
            if flg:
                flg = False
            else:
                flg = True
                cnt += 1
    return cnt * k - (s[0] == s[-1])
print(solve())

Submission status: Wrong Answer

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

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

s_dict = dict()
for i,one in enumerate(s):
    s_dict[one] = i
    
if len(s_dict) == 1:
    print((len(s)*k)//2)
else:
    for one in s[1:]:
        if tmp == one:
            counter += 1
        else:
            #counter_list.append((counter+1)//2)
            counter_list.append(counter+1)
            counter = 0
            tmp = one
    #counter_list.append((counter+1)//2)
    counter_list.append(counter+1)

    sum_counter = sum(counter_list)
    if s[0] == s[-1]:
        tmp_counter_list = counter_list[:-1]
        tmp_counter_list.append(counter_list[-1]+counter_list[0])
        tmp_counter_list = [one//2 for one in tmp_counter_list]
        last_counter_list = [one//2 for one in counter_list]
        print(sum(tmp_counter_list)*(k-1) + sum(last_counter_list))
    else:
        last_counter_list = [one//2 for one in counter_list]
        print(sum(last_counter_list)*k)

Submission status: Wrong Answer

Solution code:
import sys,queue,copy
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
INF = float('inf')

S = list(input())
K = int(input())
i = 0
ans = 0

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

while i+1 < len(S):
    tempc= 1
    while S[i] == S[i+1]:
        tempc += 1
        if i+2 < len(S):
            i += 1
        else:
            break

    ans += tempc //2
    if i+2 >= len(S):
        break
    i += 1

j=2
frag = 0
if S[0] == S[-1] and len(S) != 1 and K >1:
    tempc = 1
    while S[-1] == S[-j]:
        tempc += 1
        if (j+1) <= len(S):
            j += 1
        else:
            break

    frag += tempc%2

print((ans+frag)*K-frag)

Submission status: Wrong Answer

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

ops = 0
i = 1

while i < len(s):
    if s[i-1] == s[i]:
        ops += 1
        i += 1
    i += 1

i = 1

ops2 = 0

ss = s + s

while i < len(ss):
    if ss[i-1] == ss[i]:
        ops2 += 1
        i += 1
    i += 1

diff = ops2 - 2 * ops

ops = k * ops + (k-1) * diff

print(ops)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

# ----------
# ts1 = list('issii')
# tk1 = 2
# ts2 = list('qq')
# tk2 = 81
# ts3 = list('cooooooooonteeeeeeeeeest')
# tk3 = 999993333
# ----------
# S = ts3
# K = tk3
# ----------


def s_change(S):
    s_henkan = 0
    for i in range(1,len(S)):
#         print(S[i])
        if S[i] == S[i-1]:
#             print(S[i-1],S[i])
            S[i] = '1'
            s_henkan += 1
    return(S,s_henkan)
# print(S)
# print(s_change(S))
        
henkan = 0
    
if len(S) == 1:
    henkan = K // 2
elif len(S) == 2:
    if S[0] == S[1]:
        henkan = K
    else:
        henkan = 0
else:
#     print(S)
    SSSS = s_change(S)
    henS = SSSS[0]
    s_henkan = SSSS[1]
#     print(henS,henS[len(henS)-1])
#     print(s_henkan)
    
    if henS[0] == henS[len(henS)-1]:
        henkan = s_henkan * K + (K-1)
    else:
        henkan = s_henkan * K

print(henkan)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
S2 = S[:] * 7

if len(S) == 1:
    print(K//2)
    exit()
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()
cons3 = 0
for i in range(len(S2) - 1):
    if S2[i] == S2[i+1]:
        cons3 += 1
        S2[i+1] = '_'
if cons3 != cons * 7 + cons2 * 6:
    minus = 1
else:
    minus = 0
print(cons3 * (K // 7) + cons * (K%7) - minus * (K//7))

Submission status: Wrong Answer

Solution code:
S = list(str(input()))
N = len(S)
K = int(input())

ans1 = 0
old = ""
flag = 0
for i in range(N):
    if old == "":
        old = S[i]
    else:
        if old == S[i]:
            old = ""
            ans1+=1
        else:
            old = S[i]
            
    if i == N-1:
        if old == S[i]:
            flag = 1

if flag == 0:
    print(ans1*K)
else:
    ans2 = 0
    old = ""
    for i in range(N):
        if i == 0:
            if S[0] == S[-1]:
                if flag == 1:
                    ans2+=1
                else:
                    old = S[0]
        elif old == "":
            old = S[i]
        else:
            if old == S[i]:
                old = ""
                ans2+=1
            else:
                old = S[i]
    k = K//2
    print(ans1*(K-k)+ans2*k)

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
check1=0
check1+=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
check2=0
check2+=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

# print(check1,check2,ans)
if K==1:
    print(check1)
if K==2:
    print(check2)
if K>2:
    print((check2-check1)*(K-1)+check1)

Submission status: Wrong Answer

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

n = len(s)
cnt = 1
arr = []

# 配列全体のループ
for i in range(n):
    try:
        if s[i] == s[i+1]: cnt += 1
        else: arr.append(cnt) ; cnt = 1
    except: arr.append(cnt)

if len(arr) == 1 : ans = len(s)*k -1
else:
    if s[0] == s[n-1] : arr[0],arr[len(arr)-1] = 0,arr[0]+arr[len(arr)-1]
    ans = 0
    for i in range(len(arr)): ans += arr[i]//2
    ans *= k
    if arr[0]==0 and arr[len(arr)-1]%2==0 : ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
# import math
# import numpy as np
# from functools import lru_cache
import string

args = sys.argv
if len(args) == 2:
  from IPython import embed
  em = True
else:
  em = False

# sys.setrecursionlimit(10000)

#### input
S = list(input())
K = int(input())
if len(S) == 1:
  print(0)
  exit()
# a, b = map(int, input().split())
# a = list(map(int, input().split()))
# a = list(map(lambda x: int(x)*(-1), a))  # 各要素を-1倍


# n = int(input())
# t = [int(input()) for i in range(n)]
if em: sys.stdin = open('/dev/tty')

#### function
# @lru_cache(maxsize=10000)

#### process
# if em: embed()
last_chk = 0
letters = string.ascii_lowercase
score = 0
for i in range(0, len(S) - 2):
  # print(S)
  if S[i] == S[i + 1]:
    S[i + 1] = letters.strip(S[i]).strip(S[i + 2])[0]
    score = score + 1

if S[-2] == S[-1]:
  S[-1] = letters.strip(S[-2]).strip(S[0])[0]
  score = score + 1
  # last_chk = 1
else:
  if S[-1] == S[0]:
    S[-1] = letters.strip(S[-2]).strip(S[0])[0]
    score = score + 1
    last_chk = 1

total = score * K
if last_chk == 1: total = total - 1
print(total)


# score = 0
# i = 0
# last_chk = 0
# while True:
#   if S[i] == S[i + 1]:    # 次と同じなら
#     if i == len(S) - 2:    # 末尾だったらスコア増えない
#       score = score + 1
#       break
#     elif i == len(S) - 3:
#       if S[i + 1] == S[i + 2]:
#         score = score + 1
#         if S[0] == S[-1]:
#           score = score + 1
#         break
#     else:
#       score = score + 1
#       i = i + 2
#   else:
#     i = i + 1

# print(score*K)


## heapsort, O(logN)
# import heapq
# heapq.heapify(A)
# min = heapq.heappop(A)
# heapq.heappush(A, new_element)

Submission status: Wrong Answer

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

if s[0] != s[-1]:
    for i in range(len(s)-1):
        if s[i] == s[i + 1]:
            s[i+1] = "OK"
            ans += 1
    print(ans * k)

else:
    if len(set(s)) == 1:
        if len(s) % 2 == 0:
            print((len(s) // 2) * k)
        else:
            print(len(s) * (k // 2) if k %
                  2 == 0 else len(s) * (k // 2) + (len(s) // 2))
    else:
        mae = 1
        for i in range(len(s) - 1):
            if s[i] == s[i + 1]:
                mae += 1
            else:
                break

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

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

        ans_ = 0
        for i in range(mae, len(s) - ushiro):
            if s[i] == "OK":
                ans_ += 1
        print(((mae + ushiro) // 2 * (k - 1)), ans_ * (k - 1), ans)
        print(((mae + ushiro) // 2 * (k - 1)) + ans_ * (k - 1) + ans)

Submission status: Wrong Answer

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

if len(s) == 1:
    print(k//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
    
f = 0
if (ngongo > 1 or ngongongo > 1) and ngongo %2 == 1 and ngongongo %2 == 1 and s[0] == s[-1]:
    count += 1
    if ngongo%2 == 1:
        f += 1

print(count*k-f)

Submission status: Wrong Answer

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

sl = list(s)
cnt = 1
i = 0
su = 0
tmp = "0"
f = 0

for i in range(len(s)):
  if sl[i] == tmp:
    cnt += 1
  else:
    su += int(cnt / 2)
    cnt = 1
    tmp = sl[i]

if sl[0] == sl[-1]:
  f = 1

t = k * (su + f)

print(t)

Submission status: Wrong Answer

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

count = 0
i=0
join_flag =0
join_n = 0
if len(s)==1:
  print(k//2)
  
else:
  while i<len(s)-1:
    if s[i] == s[i+1]:
      count+=1
      i+=2
    else:
      i+=1
  
  if (s[-1] == s[0]) :
    join_flag =1
    
  if join_flag:  
    count_len = 1
    for i in range(len(s)-1):
      if s[-1-i]==s[-2-i]:
        count_len += 1
      else:
        break
    if count_len%2 ==1 and len(s)>2:
      join_n = k//2

  print(count*k + join_n)

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

if len(s) > 1 and new_l[0] == new_l[-1] and s[0] != s[1]:
    result += k - 1
print(result)

Submission status: Wrong Answer

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

S += "1"
l = len(S)
pair = []
current = S[0]
seq = 1
for i in range(1, l):
    if(i == l):
        pair.append(seq)
    elif(S[i] == current):
        seq += 1
    else:
        pair.append(seq)
        seq = 1
        current = S[i]

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

print(ans)

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
    #後ろから同じ文字をカウント
    Sr = S[::-1]
    same_s = 0
    for i in range(len(Sr)):
        if Sr[0] == Sr[i]:
            same_s += 1
        else:
            break
    
    if same_s % 2 == 1:
        result += K - 1

else:
    result += K//2

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a = len(S)
b = len(set(S))

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

n = (a-b)//2
if (a-b) % 2 == 1:
    n += 1
elif ans == 0:
    n = 0 


print(n*K)

Submission status: Wrong Answer

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

pre_str = ''
count = 1
ret = 0
for a in list(S):
    if pre_str == a:
        count += 1
    else:
        ret += int(count / 2)
        count = 1
        pre_str = a
ret += int(count / 2)
ret = ret*K
if len(S) == 1:
    ret += int(K / 2)
elif len(S) > 2 and S[0] != S[1] and S[-1] != S[-2] and S[0] == S[-1]:
    ret += K - 1
print(ret)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
s.append('-1')
ran = []
counter = 0
while counter < len(s)-1:
    j = counter +1
    while s[counter] == s[j]:
        j += 1
    ran.append([s[counter], j - counter])
    counter = j
counter = 0
result = 0
if k >= 2:
    if len(ran) >= 2:
        if ran[0][0] == ran[-1][0]:
            result += ((ran[0][1]+ran[-1][1])//2)*(k-1)
            if ran[-1][1] != 1:
                result += ran[-1][1]//2
            if ran[0][1] != 1:
                result += ran[0][1]//2
        else:
            result += (ran[0][1]//2 + ran[-1][1]//2)*k
    else:
        if ran[0][1]%2 == 0:
            result += (ran[0][1]//2)*k
        else:
            result += ((ran[0][1]*2))*(k//2) + ran[0][1]*(k%2)
    for  i in range(1, len(ran)-1):
        result += ((ran[i][1])//2)*k
    print(result)
else:
    for  i in range(len(ran)):
        result += (ran[i][1])//2
    print(result)

Submission status: Wrong Answer

Solution code:
s = list(map(list, input().split()))[0]
k = int(input())
ans = 0
flg = False
if len(s) == 1:
    print(k//2)
else:
    for i in range(len(s))[:-1]:
        if flg == True:
            flg = False
            continue
        elif s[i]==s[i+1]:
            ans += 1
            flg = True

    if flg == False and s[0] == s[-1]:
        ans += 1

    if s[-1] != s[-2]:
        print(ans * k -1)    
    else:
        print(ans * k)

Submission status: Wrong Answer

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

ans = 0
rep = 1
first_rep = 1

tmp = None
for i in s:
    if tmp:
        if tmp == i:
            first_rep += 1
        else:
            break
    else:
        tmp = i


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 += rep // 2

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


print(ans * k + start_eq_end)

Submission status: Wrong Answer

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

if k == 1:
    cnt1 = 0
    cnt2 = 0
    for i in range(1,n-1):
        if i%2 == 0:
            if s[i] == s[i-1] or s[i] == s[i+1]:
                cnt1 += 1
        else:
            if s[i] == s[i-1] or s[i] == s[i+1]:
                cnt2 += 1
    print(min(cnt1,cnt2))
else:
    s += s
    s1 = ''
    cnt1 = 0
    s2 = ''
    cnt2 = 0
    for i in range(2*n):
        if i < 2*n - 1 and i > 0:
            if i%2 == 0:
                s2 += s[i]
                if s[i] == s[i-1] or s[i] == s[i + 1]:
                    s1 += '0'
                else:
                    s1 += s[i]
            else:
                s1 += s[i]
                if s[i] == s[i-1] or s[i] == s[i + 1]:
                    s2 += '0'
                else:
                    s2 += s[i]
        elif i == 2*n -1 :
            if i%2 == 0:
                s2 += s[i]
                if s[i] == s[i-1]:
                    s1 += '0'
                else:
                    s1 += s[i]
            else:
                s1 += s[i]
                if s[i] == s[i-1]:
                    s2 += '0'
                else:
                    s2 += s[i]
        else:
            if i%2 == 0:
                s2 += s[i]
                if s[i] == s[i + 1]:
                    s1 += '0'
                else:
                    s1 += s[i]
            else:
                s1 += s[i]
                if s[i] == s[i + 1]:
                    s2 += '0'
                else:
                    s2 += s[i]
    s1_arr = [s1[:n].count('0'),s1[n:].count('0')]
    s2_arr = [s2[:n].count('0'),s2[n:].count('0')]
    print(min(s1_arr[0]*(k-1) + s1_arr[1],s2_arr[0]*(k-1) + s2_arr[1]))

Submission status: Wrong Answer

Solution code:
S=list(str(input()))
K=int(input())
num=0
i=0
lst=[]
def dp(i,lst):
  if i==len(S)-1:
    return lst
  if S[i]!=S[i+1]:
    return dp(i+1,lst)
  j=i+1
  while j<=len(S)-1  and S[i]==S[j]:
    j+=1
  lst.append(list(S[i:j]))
  return dp(j-1,lst)
if len(S)>=2:
  L=dp(i,lst)
  for i in range(len(L)):
    num+=(len(L[i])//2)
  print((num)*K)
else:
  print(K//2)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
count = 0
if k >= 3:
    t1 = s * 5
    for i in range(len(t1) - 1):
        if t1[i] == t1[i + 1]:
            t1.pop(i + 1)
            t1.insert(i + 1, "")
            count += 1
    if count % 5 == 0:
        count = (count / 5) * k
    else:
        count = ((count + 2) / 5) * k - 2
else:
    t1 = s * k
    for i in range(len(t1) - 1):
        if t1[i] == t1[i + 1]:
            t1.pop(i + 1)
            t1.insert(i + 1, "")
            count += 1
print(int(count))

Submission status: Wrong Answer

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

count = 0

if len(S)%2 == 1:
    for i in range( len(S)//2 ):
        if S[2*i+1] == S[2*i] or S[2*i+1] == S[2*i+2]:
            count +=1
else:
    for i in range( len(S)//2-1):
        if S[2*i] == S[2*i+1]:
            count +=1
        
print(count*K)

Submission status: Wrong Answer

Solution code:
S = str(input())
K = int(input())
C = i = 0

if len(S) == 1:
    C = int(K / 2)
else:
    while i + 1 < len(S):
        if S[i] == S[i + 1]:
            C += 1
            i += 1
        i += 1

    if (S[0] == S[-1]) & (S[-1] != S[-2]):
        C = C * K + K - 1
    else:
        C *= K
print(C)

Submission status: Wrong Answer

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

prev = ""
count1 = 0
flag = 0
for i in s:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count1 += 1
        flag = 1
    prev = i

prev = s[0]
count2 = 0
flag = 0
for i in s[1:]:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count2 += 1
        flag = 1
    prev = i

ret = count1 + (k-1) * count2

print(ret)

Submission status: Wrong Answer

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

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

check = [0 for _ in range(len(S))]

if S[0] == S[-1]:
    if K >= 2:
        check[0] = 1

for i in range(1, len(S)):
    if S[i - 1] == S[i]:
        if check[i - 1] == 0:
            check[i] = 1

print(sum(check) * K)

Submission status: Wrong Answer

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

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

if s[0] != s[-1]:
    count = 1
    box = []
    for i in range(len(s)-1):
        if s[i+1] == s[i]:
            count += 1
        else:
            box.append(count)
            count = 1
    box.append(count)

    ans = 0
    for b in box:
        ans += b // 2
    print(ans * k)
    exit()

flag = 0
word = s[0]
for si in s:
    if si != word:
        flag = 1

if flag == 0:
    print(len(s) * k // 2)
    exit()

if k == 1:
    count = 1
    box = []
    for i in range(len(s) - 1):
        if s[i + 1] == s[i]:
            count += 1
        else:
            box.append(count)
            count = 1
    box.append(count)

    ans = 0
    for b in box:
        ans += b // 2
    print(ans)
    exit()


count = 1
box = []
for i in range(len(s)-1):
    if s[i+1] == s[i]:
        count += 1
    else:
        box.append(count)
        count = 1
box.append(count)

front = box[0] // 2
back = box[-1] // 2

mid = 0
for i in range(len(box)-1):
    if i == 0:
        continue
    mid += box[i] // 2

joint = (box[0] + box[-1]) // 2

print(front + back + mid * k + joint * k-1)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
#true_k = list(s * k )

#s_1 = true_k[0::2]
#s_2 = true_k[1::2]
#s_1 = list(s * k )[0::2]
#s_2 = list(s * k )[1::2]
ans = 0
word = '0' 
for i in s:
    if  word == i:
      word = '0'
      ans +=1
    else:
      word = i 

print(ans*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
if len(set(t[-4:]))==1 and len(s)>3:
    print(ans*k-1)
else:
    print(ans*k)

Submission status: Wrong Answer

Solution code:
t=""
s=input()
c=0
k=int(input())
a=False
for i in range(len(s)-1):
  if s[0]==s[len(s)-1] and s[len(s)-2]!=s[len(s)-1]:
    c+=1
    a=True
  elif s[0]==s[len(s)-1] and s[len(s)-2]==s[len(s)-1]:
    a=True
  elif i<=len(s)-3 and s[i]==s[i+1] and s[i+1]==s[i+2]:
    c+=1
    i+=1
  elif s[i]==s[i+1]:
    c+=1
if a==True:
     c=c*k-1
     print(c)
else:
     c=c*k
     print(c)

Submission status: Wrong Answer

Solution code:
import sys
import fractions
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
 
s = input()
k = INT()
i = 0
count = 0
flag = False
while i < (len(s)-1):
    if s[i] == s[i+1]:
        if i == len(s)-2:
            flag = True
        count += 1
        i += 2
    else:
        i += 1
count *= k

if s[0] == s[-1] and not flag:
    count += (k-1)

print(count)

Submission status: Wrong Answer

Solution code:
def solve():
    s = input()
    len_s = len(s)
    s += s
    k = int(input())
    li = [1] * len_s + [0]
    if len_s == 1:
        return k // 2
    if len_s == 2:
        if s[0] == s[1]:
            return k
        return 0
    if s[0] != s[-1]:
        cnt = 0
        flg = False
        for i in range(0, len_s - 1):
            if s[i] == s[i + 1]:
                if flg:
                    flg = False
                else:
                    flg = True
                    cnt += 1
        return cnt * k
    cnt = 0
    flg = False
    for i in range(0, len_s):
        if s[i] == s[i + 1]:
            if flg:
                flg = False
            else:
                flg = True
                cnt += 1
    return cnt * k - (s[0] == s[-1])
print(solve())

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

if s1 == S[0] and not prev_rewrite:
    ans += (K - 1) // 2

print(ans)

Submission status: Wrong Answer

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

if len(S) == 1:
  print(K//2)
else:
  len_hist = []
  moji_hist = []
  p = []
  pre_s =S[0]
  p.append(pre_s)
  for s in S[1:]:
    if s == pre_s:
      p.append(s)
    else:
      moji_hist.append(p[0])
      len_hist.append(len(p))
      p = [s]
      pre_s = s

  moji_hist.append(s)
  len_hist.append(len(p))
  n_trans_base = sum([l//2 for l in len_hist])
  if moji_hist[0] != moji_hist[-1] or len(S)==2:
    print(n_trans_base * K)
  else:
    join_hist = len_hist[1:-1]
    join_hist.append(len_hist[0] + len_hist[-1])
    n_trans_join = sum([l//2 for l in join_hist])
    print(n_trans_base + n_trans_join *(K-1))

Submission status: Wrong Answer

Solution code:
from itertools import groupby
s = input()
k = int(input())
l = [[k, len(list(g))] for k, g in groupby(s)]
ans = 0
ans2 = 0
for i in range(len(l)):
  if l[i][1] > 1:
    ans += l[i][1] // 2
if len(s) > 2:
  if s[0] != s[1]:
    if s[-1] != s[-2]:
      if s[0] == s[-1]:
        ans2 += k - 1
if len(s) == 1:
  print(k // 2)
else:
  print(ans * k + ans2)

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
i = 0
replace = 0
while i < len(s):
    c = s[i]
    count=0
    for c in s[i+1:-1]:
        if s[i] != c:
            break
        count += 1
    if count > 0:
        if count % 2 == 1:
            replace += (count + 1) / 2
        else:
            replace += (count ) / 2
    i += count + 1
if s[0] != s[-1]:
    print(int(replace * n))
else:
    print(int(replace * n) + n)

Submission status: Wrong Answer

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


count=0
n=len(s)
x=s[0]
y=s[-1]

if s.count(s[0])==n:
    print((n*k)//2)
    exit()

if s[0]!=s[-1]:
    for i in range(1,n):
        if s[i]==s[i-1]:
            count+=1
            s[i]='1'
    print(count*k)


else:
    countA=1
    countB=1
    v=0
    w=0
    for i in range(1,n):
        if s[i]==s[i-1]:
            countA+=1
            
        else:
            v=i
            break
    for i in range(1,n):
        if s[n-1-i]==s[n-1]:
            countB+=1
        else:
            w=n-1-i
            break
    
    for i in range(v,w+1):
        if s[i+1]==s[v]:
            count+=1
            s[i+1]='1'
    print(count*k+countA//2+(countA+countB)*(k-1)//2+countB//2)

Submission status: Wrong Answer

Solution code:
import numpy as np
S = input()
K = int(input())
res = 0
if len(S) == 1:
    res = int(K/2)
if len(S) == 2:
    if S[0] == S[-1]:
        res += K
if len(S) > 2:
    S += S[0]
    n = 0
    while n <= len(S)-2:
        if S[n] == S[n+1]:
            res += K
            n += 1
        n += 1
print(res)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
s_len = len(s)
sum = 0

for i in range(1, s_len):
    if s[i] == s[i-1]:
        sum += 1

print((sum+2)//2 * k)

Submission status: Wrong Answer

Solution code:
S = input().strip()
K = int(input())
if len(S)==1:
    cnt = K//2
else:
    A = []
    cur = 0
    for i in range(1,len(S)):
        if S[i]!=S[i-1]:
            if i-cur>=2:
                A.append([S[i-1],cur,i])
            cur = i
    if S[-1]==S[-2]:
        A.append([S[-1],cur,len(S)])
    cnt = 0
    for j in range(len(A)):
        cnt += (A[j][2]-A[j][1])//2
    if S[0]!=S[-1]:
        cnt = cnt*K
    else:
        if S[0]!=S[1] and S[-1]!=S[-2]:
            cnt = cnt+(cnt+1)*(K-1)
        elif S[0]==S[1] and S[-1]!=S[-2]:
            if (A[0][2]-A[0][1])%2==0:
                cnt = cnt*K
            else:
                cnt = cnt+(cnt+1)*(K-1)
        elif S[0]!=S[1] and S[-1]==S[-2]:
            if (A[-1][2]-A[-1][1])%2==0:
                cnt = cnt*K
            else:
                cnt = cnt+(cnt+1)*(K-1)
        elif S[0]==S[1] and S[-1]==S[-2]:
            if (A[0][2]-A[0][1])%2==0 or (A[-1][2]-A[-1][1])%2==0:
                cnt = cnt*K
            else:
                cnt = cnt+(cnt+1)*(K-1)
print(cnt)

Submission status: Wrong Answer

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

res, flag = 0, False
for i in range(1, len(S)):
    if i > 1 and S[i] == S[i-1] == S[i-2] and flag:
        flag = False
    elif S[i] == S[i-1]:
        res += 1
        flag = True
res *= K
if len(S) > 1 and S[-1] == S[-2]:
    print(res)
    exit()
if S[0] == S[-1]:
    res += K - 1
print(res)

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

if len(s) > 1 and new_l[0] == new_l[-1] and s[0] != s[1]:
    result = +k - 1
print(result)