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())
N = len(S)
counts = 0
count2 = 0
adder = 0
adder2 = 0

if len(S) == 1:
    print(K // 2)
elif len(S) == 2:
    if S[0] == S[1]:
        print(K)
    else:
        print(0)

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



elif K <= 3:
    S_arranged = list(S*K)
    for i in range(len(S_arranged)-2):
        if (S_arranged[i] == S_arranged[i+1]) and (S_arranged[i+1] == S_arranged[i+2]):
            S_arranged[i+1] = "0"
            counts += 1
        
    for i in range(len(S_arranged)-1):
        if S_arranged[i] == S_arranged[i+1]:
            S_arranged[i] = "1"
            counts += 1
    
    print(counts)

elif K % 2 == 0:
    S_arranged = list(S*4)
    for i in range(len(S_arranged) - 2):
        if (S_arranged[i] == S_arranged[i+1]) and (S_arranged[i+1] == S_arranged[i+2]):
            S_arranged[i+1] = "0"
            if i+1 <= len(S)-1:
                adder += 1
            elif i+1 > len(S)*3 -1:
                adder2 += 1
            elif i+1 > len(S) - 1 and i+1 <= len(S)*2 - 1:
                counts +=1
            else:
                count2 +=1

    for i in range(len(S_arranged)-1):
        if S_arranged[i] == S_arranged[i+1]:
            S_arranged[i] = "1"
            if i <= len(S)-1:
                adder += 1
            elif i > len(S)*3 -1:
                adder2 += 1
            elif i > len(S)-1 and i+1 <= len(S)*2-1:
                counts +=1
            else:
                count2 +=1


    if K % 2 == 0:
        print(int(adder + (counts + count2) * ((K-2)/2) + adder2))
        
else:
    S_arranged = list(S*5)
    for i in range(len(S_arranged) - 2):
        if (S_arranged[i] == S_arranged[i+1]) and (S_arranged[i+1] == S_arranged[i+2]):
            S_arranged[i+1] = "0"
            if i+1 <= len(S)-1:
                adder += 1
            elif i+1 > len(S)*4 -1:
                adder2 += 1
            elif i+1 > len(S) - 1 and i+1 <= len(S)*2 - 1:
                counts +=1
            elif i+1 > len(S)*2 and i+1 <= len(S)*3:

                count2 +=1

    for i in range(len(S_arranged)-1):
        if S_arranged[i] == S_arranged[i+1]:
            S_arranged[i] = "1"
            if i <= len(S)-1:
                adder += 1
            elif i > len(S)*4 -1:
                adder2 += 1
            elif i > len(S)-1 and i+1 <= len(S)*2-1:
                counts +=1
            else:
                count2 +=1

    print(int((adder + adder2 + counts*((K-1)/2) + count2*((K-1)/2 -1))))
    print(S_arranged)

Submission status: Wrong Answer

Solution code:
import string


def count_changes(s, k, pool, prev=None):
    if k == 0:
        return 0, None, None
    t = s * k
    count = 0
    i = 0
    for cur in t:
        if cur == prev:
            count += 1
            prev = pool[i]
            i = (i + 1) % length
        else:
            prev = cur
    return count, i, prev


if __name__ == '__main__':
    s = input()
    k = int(input())
    pool = list(set(string.ascii_lowercase) - set(s))
    length = len(pool)
    if k <= 1000:
        print(count_changes(s, k, pool)[0])
    else:
        base_count, i, prev = count_changes(s, 3, pool)
        d, rest = divmod(k, 3)
        res = base_count * d
        if rest:
        	res += count_changes(s, rest, pool, prev)[0]
        elif s[0] == prev:
            res += (d - 1)
        print(res)

Submission status: Wrong Answer

Solution code:
S = list(input())
#取得文字列
K = int(input())
#繰り返し回数

count = 0
befStr = ""


for i in range(1,len(S)):
  befStr = S[i - 1]
  if befStr == S[i]:
    count += 1
    S[i] = "B"

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

Submission status: Wrong Answer

Solution code:
import math

s = input()
k = int(input())
count = 0
i = 0
if k % 2 == 0:
    s *= 2
    k /= 2
else:
    for n in range(1,k):
        if k % n == 0:
            if n > 1:
                s *= n
                k /= n
                break

while i <= len(s):
    tmp = 1
    for j in range(i + 1, len(s)):
        if s[i] == s[j]:
            tmp += 1
        else:
            break
    i += tmp
    tmp //= 2
    count += tmp

print(int(count * k))

Submission status: Wrong Answer

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

def counter_func(string,x):
  try:
    if string[x] == string[x+1]:
      return 1
    else:
      return 0
  except:
    return 0
  
counter = []
count = 0
j = 0
add = 0
while j < length:
  if counter_func(s,j) == 1:
    count += 1
  else:
    counter.append(count)
    count = 0
  j += 1
if s[-1] == s[0] and k > 1:
  add = 1
sum = 0
if len(counter) != 1:
  for i in range(1,len(counter)-1):
    if counter[i] != 0:
      sum += int((counter[i]+1)/2)*k
  if add == 1 and counter[0]%2 == 1:
    sum += int((counter[-1]+1)/2)*(k-1)
    sum += int((counter[-1])/2)
    if counter[0] != 0:
      sum += int((counter[0]+1)/2)*k
  if add == 1 and counter[0]%2 == 0:
    sum += int((counter[0]+1)/2)*(k-1)
    sum += int((counter[0])/2)
    if counter[-1] != 0:
      sum += int((counter[-1]+1)/2)*k
  elif add == 0:
    if counter[-1] != 0:
      sum += int((counter[-1]+1)/2)*k
    if counter[0] != 0:
      sum += int((counter[0]+1)/2)*k
else:
  sum = int((length*k)/2)
print(sum)

Submission status: Wrong Answer

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

count = 0
count2 = 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):
        if S[2*i] == S[2*i+1]:
            count +=1

for i in range(len(S)):
    S.append(S[i])
    
print(S)

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]:
            count2 +=1
else:
    for i in range(len(S)//2):
        if S[2*i] == S[2*i+1]:
            count2 +=1

print(count + (K-1)*(count2-count))

Submission status: Wrong Answer

Solution code:
S = input()
K = input()
# for i in range(int(K)):
#     T = T + S

list_str = list(S)

a = len(S)
a = a - 1
n = 0
p = 0
o = 0
if list_str[0] == list_str[a]:
  if list_str[0] != list_str[a-1]:
    o = o + 1
for u in range(a):
  if list_str[n] == list_str[n+1]:
    p = p + 1
    list_str[n+1] = "1"
  n = n + 1
p = p*int(K)
o = (o*int(K))
if o != 0:
  p = int(p) + int(float(o)) -1

print(p)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
def main():
    input = sys.stdin.readline
    S = input().strip()
    K = input()
    ans = np.zeros(1, dtype="int64")
    len_S = len(S)
    if len_S != 1:
        char_S = []
        cnts_S = []
        #char_S.append(S[0])
        cnt = 0
        for i in range(len_S - 1):
            #print(i+1)
            #print(len_S-1)
            #print(char_S)
            #print(cnts_S)
            if cnt == 0:
                if S[i] == S[i+1]:
                    cnt += 1
                    if i + 1 == len_S - 1:
                        char_S.append(S[i])
                        cnts_S.append(cnt)
                else:
                    char_S.append(S[i])
                    cnts_S.append(cnt)
                    cnt = 0
                    if i + 1 == len_S - 1:
                        char_S.append(S[i+1])
                        cnts_S.append(cnt)
            elif cnt == 1:
                char_S.append(S[i])
                cnts_S.append(cnt)
                cnt = 0
                if i + 1 == len_S - 1:
                    char_S.append(S[i+1])
                    cnts_S.append(cnt)

        cnts_repeat = np.count_nonzero(cnts_S)

        ans[0] = np.int64(cnts_repeat)
        ans[0] *= np.int64(K)
        #print(cnts_repeat)
        if S[-1] == S[0]:
            if cnts_S[0] + cnts_S[-1] == 0:
                ans[0] += np.int64(K) - np.int64(1)
            elif cnts_S[0] + cnts_S[-1] == 1:
                if S.count(S[0]) == len_S:
                    ans[0] += np.int64(K) - np.int64(1)
                elif S[0] == S[1] == S[2] == S[-1]:
                    ans[0] += np.int64(K) - np.int64(1)
                elif S[0] == S[-1] == S[-2] == S[-3]:
                    ans[0] += np.int64(K) - np.int64(1)
            else:
                pass
        if len(list(set(S))) == 26:
            ans += 1
    else:
        if np.mod(np.int64(K),2) == 0:
            ans[0] = np.int64(K) // 2
        else:
            ans[0] = (np.int64(K) - 1) // 2
    print(ans[0])
    #print(cnts_S)
    #print(char_S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

memc = s[0]
resnum = 0
t = s + s[0]
a = []
for c in t:
    if c == memc:
        resnum +=1
    else:
        a += [int((resnum+1)/2)]
        memc = c
        resnum = 0
a += [int((resnum+1)/2)]
a[0] -=1
# print(a)
res = 0

# if len(s) == 1:
#     res = int(k/2)
# elif a[-1] == 1 and s[0] == s[-1]:
#     res = (sum(a[0:len(a)-1])) * k + (k-1)
# else:
#     res =  sum(a)*k
#print(res)

if len(a)>1 and a[-1]==1 and a[-1]!=a[-2]:
    res = (sum(a[0:len(a)-1])) * k + (k-1)
else:
    res = sum(a)*k
print(res)

Submission status: Wrong Answer

Solution code:
a = input()
j = int(input())

# is0i0is0i0
# print(a, len(a))
i = 0
c = 0
prev = False
for x in a:
  # print(prev)
  if c > 0:
    # print(x, a[c-1], c, prev, x == a[c-1] and not prev)
    if x == a[c-1] and not prev:
      i += 1
      prev = True
      c += 1
      continue
  if c != len(x):
    prev = False
  # print("c++", c)
  c +=1 

# If the first and last characters are the same
if a[0] == a[-1]:
  # If the string repeats but does not contain any consecutive characters, e.g aba*2
  if (i==0) and j>1: 
    print(j-1)
  else: 
    print(i*j)
else:
  print(i*j)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    N = len(S)
    ans = 0
    from collections import Counter
    if N == 1:
        return print(K//2)
    elif N == 2:
        if S[0] == S[1]:
            return print(K)
        else: return print(0)
    #odd = Counter(S[0::2]).most_common()
    #even = Counter(S[1::2]).most_common()
    changing_odd = 0
    changing_even = 0
    

    if N&1:
        for i in range(N)[2:N-2:2]:
            if S[i-1] == S[i] or S[i] == S[i+1]:
                changing_odd += 1
        else:
            if S[0] == S[1]:
                changing_odd += 1
            if S[N-2] == S[N-1]:
                changing_odd += 1
        for i in range(N)[1::2]:
            if S[i-1] == S[i] or S[i] == S[i+1]:
                changing_even += 1
        if changing_odd <= changing_even:
            ans += changing_odd * (N - N//2)
            ans += changing_even * (N//2)
        elif changing_odd > changing_even:
            ans += changing_odd * (N//2)
            ans += changing_even * (N - N//2)
    else:
        for i in range(N)[2::2]:
            if S[i-1] == S[i] or S[i] == S[i+1]:
                changing_odd += 1
        else:
            if S[0] == S[1]:
                changing_odd += 1
        for i in range(N)[1:N-2:2]:
            if i != N-1 and S[i-1] == S[i] or S[i] == S[i+1]:
                changing_even += 1
        else:
            if S[N-2] == S[N-1]:
                changing_even += 1
        if changing_odd <= changing_even:
            ans = changing_odd * K
        elif changing_odd > changing_even:
            ans = changing_even * K

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if LS==1:
    if K==1:
        print(0)
        exit()
    else:
        print(K//2)
        exit()

cnt=1
ans1=0
c=[]
for i in range(1,LS-1):
    if S[i-1]==S[i]:
        cnt+=1
    elif cnt!=1:
        ans1+=cnt//2
        c.append(cnt)
        cnt=1

if K==1:
    if S[-2]==S[-1]:
        cnt+=1
        ans1+=cnt//2
        print(ans1)
        exit()

if S[-2] == S[-1]:
    cnt += 1
    c.append(cnt)
    if cnt % 2 == 0:
        if ans1 != 0:
            ans1 += cnt // 2
            ans1 = ans1 * K
        else:
            ans1 = (cnt // 2) * K
    elif cnt % 2 == 1 and S[0] == S[-1]:
        if ans1 != 0:
            if c[0] % 2 == 0:
                ans1 += cnt // 2
                ans1 = ans1 * K
            else:
                ans1 += cnt // 2 + 1
                ans1 = ans1 * K - 1
        else:
            ans1 = (cnt // 2) * K + K - 1
    elif cnt % 2 == 1 and S[0] != S[-1]:
        ans1 += cnt // 2
        ans1 = ans1 * K
else:
    ans1 += cnt // 2

    if S[0] == S[-1]:
        if ans1!=0 and c[0]%2==0:
            ans1=ans1*K
        else:
            ans1 = ans1*K+K - 1
    else:
        ans1 = ans1 * K


print(ans1)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    a = list(S)
    cnt = 0
    if len(set(a))==1 and len(a) != 1:
        cnt = (len(a)*K)//2
        print(cnt)
    elif len(a) ==1:
        cnt += K//2
        print(cnt)
    else:
        temp = 1
        temp_2 = 1
        i = 0
        while a[i] == a[i+1]:
            temp += 1
            i += 1
        j = len(a) - 1
        while a[j] == a[j-1]:
            temp_2 += 1
            j -= 1
        for k in range(i+1,j-1):
            if a[k+1] == a[k]:
                a[k+1] = str(k)
                cnt += 1
        cnt *= K
        cnt += temp//2
        cnt += temp_2//2
        
        if a[0] == a[-1]:
            temp_3 = (temp + temp_2)//2
            cnt += temp_3 * (K-1)

        print(cnt)

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=input()
d= [c  for c in s]
n=int(input())
l=len(d)
count=0
for i in range(l-2):
  if i==0 and d[0]==d[l-1] and d[i]==d[i+1]:
    d[0]="1"
    count+=1
  if d[i]==d[i+1]:
    if d[i]!=d[i+2]:
       d[i]="1"
       count+=1
    elif d[i]==d[i+2]:
      d[i+1]="1"
      count+=1
if l>=3:
  if d[l-1]!=d[l-2] and d[0]==d[l-1]:
    count*=n
    count+=n-1
  elif d[l-2]==d[l-1] and d[l-3]!=d[l-2]:
    count+=1
    count*=n
  else:
    count*=n
if l==2 and s[0]==s[1]:
  count=n
print(count)

Submission status: Wrong Answer

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

def len_checker(S,r):
    count = 1
    if r == 0:
        icon = S[0]
        for j in range(1,len(S)):
            if S[j] == icon:
                count += 1
            else:
                break
    elif r == 1:
        icon = S[len(S)-1]
        for j in range(1,len(S)):
            jj = len(S) - j -1
            if S[jj] == icon:
                count += 1
            else:
                break
#     print(S,r,count)
    return(count)

def s_change(S):
    s_henkan = 0
    L = len(S) -1
#     print(S,S[0],S[L])
    if S[0] == S[L]:
        cf = len_checker(S,0)
        rf = len_checker(S,1)
#         print("cf:",cf,"rf:",rf)
        if cf % 2 == 1 and rf % 2 == 0:
            S[L] = 2
            s_henkan += 1
#             pass
        else:
            S[0] = '2'
            s_henkan += 1
#     print("mit:",S)
    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)

        
henkan = 0
    
if len(S) == 1:
    henkan = K // 2
elif len(S) == 2:
    if S[0] == S[1]:
        henkan = K
    else:
        henkan = 0
else:
    SSSS = s_change(S)
#     print("SSSS: ",SSSS)
    henS = SSSS[0]
    s_henkan = SSSS[1]
    
    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 = input()
length = len(s)
k = int(input())
if(len(s)==1):
    print(int(k/2))
    exit()
start = 0
end = 0
t = 0
last = 0
count = 0
ans = 0
b4 = s[0]
for c in s:
    if(b4!=c):
        if(last==0):
            start=t
            t=1
            last = 1
        else:
            ans+=int(t/2)
            t=1
    else:
        t+=1
    count+=1
    b4=c
end = t
if(s[0]==s[-1] and start==1 and start==end):print(int(start/2) + int(end/2) + (ans)*k + int(start/end)*(k-1))
else:print((int(start/2) + int(end/2) + ans)*k)

Submission status: Wrong Answer

Solution code:
S = list(input())
#取得文字列
K = int(input())
#繰り返し回数

count = 0
befStr = ""


for i in range(1,len(S)):
  befStr = S[i - 1]
  if befStr == S[i]:
    count += 1
    S[i] = "B"
    
if K!=1 and len(S) != 1 and S[0] == S[len(S)-1]:
  print(count*K + K -1)
elif len(S) == 1:
  print(K//2)
else:
  print(count*K)

Submission status: Wrong Answer

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

count = 0
S = S + "0"

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

S = S[:-1] #最後の0を削除

if len(S) == 1:
    result = 0
elif len(S) == 2:
    result = count * K
else: #S[0]からの連続文字列数とS[-1]からの連続文字列数がどちらも奇数ならば「+ 1 × (K-1)」が必要
    if S[0] == S[-1]:
        len_first = 1
        len_last = 1
        i = 0
        flag = 0
        while S[i] == S[i+1]:
            len_first += 1
            i += 1
            if i == len(S)-1:
                flag = 1
                len_last = len_first
                break

        if flag == 0: 
            len_last = 1
            i = -1
            while S[i] == S[i-1]:
                len_last += 1
                i -= 1
        
        #print(len_first)
        #print(len_last)
        
        
        if len_first % 2 == 1 and len_last % 2 == 1:
            result = count * K + (K-1)
        else:
            result = count * K
    else:
        result = count * K


print(result)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ans=0
cnt=1
add=False
lead=1
if len(s)==1:
  print(k//2)
  exit()
for i in range(1,len(s)):
  if s[i-1] == s[i]:
    lead+=1
  else:
    break
for i in range(1,len(s)):
  if s[i-1] == s[i]:
    cnt+=1
  else:
    ans+=cnt//2
    cnt=1
  if s[0] == s[-1] and lead%2!=0 and cnt%2==1 and i == (len(s)-1) and s.count(s[0])!=len(s):
    ans+=cnt//2
    add=True
  elif i == (len(s)-1):
    ans+=cnt//2
if add:
  print((ans*k)+1*(k-1))
else:
  print(ans*k)

Submission status: Wrong Answer

Solution code:
S = list(input()) * 2
K = int(input())
Len_S2 = len(S)
Len_S1 = Len_S2 // 2
count1 = 0
count2 = 0
tmp = all(c == S[0] for c in S[:Len_S1:])
for i in range(Len_S2-1):
    if S[i] == S[i+1]:
        if i < Len_S1 - 1:
            count1 += 1
        if i < Len_S2:
            count2 += 1
        S[i+1] = "1"
diff = count2 - count1
print(diff)
if tmp and K >= 3 and Len_S1 % 2 != 0:
    print((count1 + (diff - 1) * (K-1)) + (1 * (K // 2)))
else:
    print(count1 + diff * (K-1))

Submission status: Wrong Answer

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

cnt = 0
i = 0

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

    else:
        i += 1

print(cnt*K)

Submission status: Wrong Answer

Solution code:
import copy
S=list(input())
SS=copy.deepcopy(S)
K=int(input())
c=0
cc=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:
  SS[0]="!"
  for i in range(1,len(S)):
    if SS[i]==SS[i-1]:
      SS[i]="!"
      cc+=1
  if S[1]=="!":
    print(c+(K-1)*cc+K-1)
  else:
    print(c+(K-1)*c+K-1)

Submission status: Wrong Answer

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

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

another_c = ''
cnt = 0


t = list(s)
start = t[0]
#for i, c in enumerate(t):
for i in range(len(t)):
    c = t[i]
    prev_c = t[i-1]
    if i == len(t)-1:
        if k == 1:
            next_c = ''
        else:
            next_c = start
    else:
        next_c = t[i+1]
    if i > 0 and c == prev_c:
        another_c = chr(ord(c) + 1)
        if ord(another_c) > ord('z'):
            another_c = chr(ord(another_c)-26)
        if next_c == another_c:
            another_c = chr(ord(another_c) + 1)
        t[i] = another_c
        cnt = cnt + 1
    else:
        another_c = ''
    #print(i, prev_c, c, next_c, "->", another_c) 

#print("".join(t))
end = t[-1]

if k > 2:
    cnt2 = 0
    t = list(s)
    #for i, c in enumerate(t):
    for i in range(len(t)):
        c = t[i]
        if i == 0:
            prev_c = end
        else:
            prev_c = t[i-1]
        if i == len(t)-1:
            next_c = start
        else:
            next_c = t[i+1]
        if c == prev_c:
            another_c = chr(ord(c) + 1)
            if ord(another_c) > ord('z'):
                another_c = chr(ord(another_c)-26)
            if next_c == another_c:
                another_c = chr(ord(another_c) + 1)
            t[i] = another_c
            cnt2 = cnt2 + 1
        else:
            another_c = ''
        #print(i, prev_c, c, next_c, "->", another_c) 
    cnt = cnt + (cnt2 * (k-2))
    #print("".join(t))

if k > 1:
    t = list(s)
    #for i, c in enumerate(t):
    for i in range(len(t)):
        c = t[i]
        if i == 0:
            prev_c = end
        else:
            prev_c = t[i-1]
        if i == len(t)-1:
            next_c = ''
        else:
            next_c = t[i+1]
        if c == prev_c:
            another_c = chr(ord(c) + 1)
            if ord(another_c) > ord('z'):
                another_c = chr(ord(another_c)-26)
            if next_c == another_c:
                another_c = chr(ord(another_c) + 1)
            t[i] = another_c
            cnt = cnt + 1
        else:
            another_c = ''
        #print(i, prev_c, c, next_c, "->", another_c) 
    #print("".join(t))



print(cnt)

Submission status: Wrong Answer

Solution code:
s=str(input())
k=int(input())
cnt=0
a=0

for i in range(len(s)):
  if s[i-1] == s[i]:
    cnt+=1
if s[0] == s[-1]:
  a=k-1
if s[0] != s[-1]:
  a=0

print(cnt*k+a)

Submission status: Wrong Answer

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

#print(link_S)
#S = S.append(S[len(S)-1])
i = 0
sum = 1
total_sum = 0
sum_ketu = 0
j = 0
add_sum = 1
if len(S) == 1:
    print( K -1)
    exit()
    
while(1):
    if i == len(S)-1:
        if S[i] == S[0]:
            while( j <= len(S)-2):
                if S[j] == S[j+1]:
                    add_sum += 1
                    j += 1
                else:
                    break
        if (sum % 2 == 1) and (add_sum % 2 == 1):
            sum += 1
            sum_ketu = -1
        break
    if S[i] == S[i+1]:
     #   print("i is", i)
     #   print("S[i] is", S[i], "S[i+1] is", S[i+1])
        sum += 1
     #   print(sum)
        i += 1
    else:
        total_sum += sum // 2
        sum = 1
        i += 1
        
total_sum += sum // 2
#print("test", 3 //2 )
#print(sum_ketu)
#print(total_sum)
print(total_sum * K + sum_ketu)

Submission status: Wrong Answer

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

def counter(string):
    count = 0
    answer = 0
    prev = ""
    for index,sss in enumerate(string):
        if prev == "" or sss == prev:
            count+=1
            if count == 2: 
                answer+=1
                count=0
                string[index] = "1"
        else:
            count=1
        prev = sss
    return answer,string

kk = k//2
ss = s + s
sss = s + ss
if k%2 == 0: 
    answer, string = counter(ss)
    if string[0] == string[-1]:
        print(answer*kk+kk-1)
    else:
        print(answer*kk)
else:
    answer, string = counter(s)
    answer3,string3 = counter(sss)
    answer2, string2 = counter(ss)
    if k >= 3:
        if string2[0] == string2[-1]:
            print(answer2*(kk-1) + answer3 + kk-1)
        else:
            print(answer2*(kk-1) + answer3 )
    else:    
        if string2[0] == string2[-1]:
            if string[0] == string2[-1]: 
                print(answer2*kk + answer + kk)
            else:
                print(answer2*kk + answer + kk-1)

        else:
            if string[0] == string2[-1]: 
                print(answer2*kk + answer + 1)
            else:
                print(answer2*kk + answer)

Submission status: Wrong Answer

Solution code:
s = list(input())
s2= s+s
n = int(input())
c1=0
ss ='abc'
add1=0
if len(s)>1:
    if len(s)%2==1:
        if s[0] == s[-1]and s[0]!=s[1]:
            add1 = 1
for i in range(1,len(s)):
    # print(s[i],s[i-1])
    if(i+1<len(s)):
        if s[i-1]==s[i] and s[i]==s[i+1]:
            c1 += 1
            for v in ss:
                if v!=s[i]:
                    s[i]=v
                    break
        elif s[i - 1] == s[i]:
            c1 += 1
            for v in ss:
                if v != s[i -1] and v!=s[i+1]:
                    s[i] = v
                    break
    else:
        if s[i - 1] == s[i]:
            c1 += 1
            for v in ss:
                if v != s[i -1]:
                    s[i] = v
                    break

c2=0
add2=0
# print(s2)
if s2[0] == s2[-1] and s2[-1]!=s2[-2]:
    add2 = 1
for i in range(1,len(s2)):
    if(i+1<len(s2)):
        if s2[i-1]==s2[i] and s2[i]==s2[i+1]:
            for v in ss:
                if v!=s2[i]:
                    s2[i]=v
                    break
            c2+=1
        elif s2[i - 1] == s2[i]:
            for v in ss:
                if v != s2[i -1] and v!=s2[i+1]:
                    s2[i] = v
                    break
            c2+=1
    else:
        if s2[i - 1] == s2[i]:
            for v in ss:
                if v != s2[i -1]:
                    s2[i] = v
                    break
            c2+=1
if n==1:
    print(c1)
    exit()
elif(n==2):
    print(c2)
    exit()
res = 0
add=0
# print(s)
# print(s2)
# print('c1:',c1,'c2',c2)
if len(s)&1:
    run = n-1
    if run%2==0:
        time = run//2
        res= c2*time
        res+= add2*(time-1)
        res+=c1+add1
    else:
        time = n//2
        res = c2*time
        res += (time-1)*add2
else:
    if(n%2==0):
        time = n//2
        res=time*c2
        res+=add2*(time-1)
    else:
        time = n//2
        res=c2*time
        res+=(time-1)*add2
        res+=c1+add2


print(res)

Submission status: Wrong Answer

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

if LS==1:
    if K==1:
        print(0)
        exit()
    else:
        print(K//2)
        exit()

cnt=1
ans1=0
c=[]
for i in range(1,LS-1):
    if S[i-1]==S[i]:
        cnt+=1
    elif cnt!=1:
        ans1+=cnt//2
        c.append(cnt)
        cnt=1

if K==1:
    if S[-2]==S[-1]:
        cnt+=1
        ans1+=cnt//2
        print(ans1)
        exit()

if S[-2] == S[-1]:
    cnt += 1
    c.append(cnt)
    if cnt % 2 == 0:
        if ans1 != 0:
            ans1 += cnt // 2
            ans1 = ans1 * K
        else:
            ans1 = (cnt // 2) * K
    elif cnt % 2 == 1 and S[0] == S[-1]:
        if ans1 != 0:
            if c[0] % 2 == 0:
                ans1 += cnt // 2
                ans1 = ans1 * K
            else:
                ans1 += cnt // 2 + 1
                ans1 = ans1 * K - 1
        else:
            ans1 = (cnt // 2) * K + K - 1
    elif cnt % 2 == 1 and S[0] != S[-1]:
        ans1 += cnt // 2
        ans1 = ans1 * K
else:
    ans1 += cnt // 2

    if S[0] == S[-1]:
        if ans1!=0 and c[0]%2==0:
            ans1=ans1
        else:
            ans1 = ans1*K+K - 1
    else:
        ans1 = ans1 * K


print(ans1)

Submission status: Wrong Answer

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


def count(s):
    s_length = len(s)
    s_types = len(set(s))
    if s_length == s_types:
        return 0
    if s_length == 2:
        if s_types == 1:
            return 1
        else:
            return 0
    else:
        i = 0
        replace = 0
        while i < s_length:
            chunk = s[i:i + 3]
            chunk_types = len(set(chunk))
            if len(chunk) == 1:
                break
            elif len(chunk) == 2:
                if chunk_types == 1:
                    replace += 1
                    break
                else:
                    break
            else:
                if chunk_types == 1:
                    replace += 1
                    i += 2
                elif chunk_types == 2:
                    if chunk[0] == chunk[1]:
                        replace += 1
                        i += 2
                    elif chunk[1] == chunk[2]:
                        replace += 1
                        i += 3
                    else:
                        i += 2
                else:
                    i += 2

    return replace


# assert (count('aa') == 1)
# assert (count('ab') == 0)
#
# assert (count('aaa') == 1)
# assert (count('aab') == 1)
# assert (count('abb') == 1)
# assert (count('aba') == 0)
#
# assert (count('aaaa') == 2)
# assert (count('aaab') == 1)
# assert (count('baaa') == 1)
# assert (count('abaa') == 1)
# assert (count('abab') == 0)


def check(s, k):
    s_length = len(s)
    s_types = len(set(s))
    if (s_types == 1) or (s_length == 1):
        return s_length * k // 2
    elif s_types == s_length:
        return 0
    elif s_length == 2:
        if s[0] == s[1]:
            return k
        else:
            return 0
    elif s[0] == s[-1] and s[-1] != s[-2] and s[0] != s[1]:
        return count(s) * k + (k - 1)
    else:
        return count(s) * k


print(check(S, K))

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
if len(S) == 1:
  print((len(S) * K) // 2)
  exit()
if len(S) == 2:
  if S[0] == S[1]:
    ans = K
  else:
    ans = 0
  print(ans)
  exit()
SS = S + S
cntSS = 0
flg = True
for i in range(1,len(SS)):
  if SS[i - 1] == SS[i] and flg:
    cntSS += 1
    flg = False
  elif flg == False:
    flg = True
    
cntS = 0
flg = True
for i in range(1,len(S)):
  if S[i - 1] == S[i] and flg:
    cntS += 1
    flg = False
  elif flg == False:
    flg = True

ans = (cntS + (cntSS - cntS) * (K - 1))
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
if len(s)==1:
    print(k//2)
else:
    count=0
    i=0
    while(i<len(s)-1):
        if s[i]==s[i+1]:
            count+=1
            i+=2
        else:
            i+=1
    if k==1:
        print(count)
    elif s[0]==s[-1]:
        if len(s)<=2:
            print(count*k)
        elif len(s)<=3:
            if s[-1]!=s[-2]:
                print(count*k+k-1)
            elif s[-3]==s[-2]==s[-1]:
                print(count*k+k//2)
            else:
                print(count*k)
        elif s[-3]!=s[-2]==s[-1]:
            print(count*k)
        else:
            print(count*k+k//2)
    else:
        print(count*k)

Submission status: Wrong Answer

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

count=0
s=s*3
for i in range(1,n*3):
    if s[i]==s[i-1]:
        s[i]="A"

S=list([s[n*i:n*(i+1)] for i in range(3)])
A,B,C=S[0].count("A"),S[1].count("A"),S[2].count("A")

if k==1:print(A)
elif k==2:print(A+B)
else:print(A+(B*(k-2))+C)