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:
import sys
readline=sys.stdin.buffer.readline
 
S=readline().rstrip().decode("utf-8")
K=int(readline())
N=len(S)
#print("SK:",S*K)
 
if len(set(S))==1:
  answer=N*K//2
else:
  P=[0] #point
  C=[] #continuous
  S=S+"X"
  
  for i in range(N):
    if S[i]!=S[i+1]:
      P.append(i+1)
  for i in range(len(P)-1):
    C.append(P[i+1]-P[i])
  #print("C:",C)
    
  answer=0
  if S[0]==S[-1]:
    for i in range(1,len(C)-1):
      answer+=c//2
    answer*=K
    answer+=C[0]//2+C[-1]//2+(C[0]+C[1])//2*(K-1)
  else:
    for c in C:
      answer+=c//2
    answer*=K
print(answer)

Submission status: Wrong Answer

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

S=readline().rstrip().decode("utf-8")
K=int(readline())
N=len(S)
#print("SK:",S*K)

if len(set(S))==1:
  answer=N*K//2
else:
  P=[0] #point
  C=[] #continuous
  S=S+"X"
  
  for i in range(N):
    if S[i]!=S[i+1]:
      P.append(i+1)
  for i in range(len(P)-1):
    C.append(P[i+1]-P[i])
  #print("C:",C)
    
  answer=0
  if S[0]==S[-1]:
    1
  else:
    for c in C:
      answer+=c//2
    answer*=K
print(answer)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter

def count(s):
    cnt = 1
    res = 0
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            cnt += 1
        else:
            res += cnt//2
            cnt = 1
    res += cnt//2
    return res

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

cs = count(s)
cs2 = count(s+s)
print((cs2-cs)*(k-1) + cs)

Submission status: Wrong Answer

Solution code:
l=list(input())
k=int(input())
r=0
for i in range(1, len(l)):
  if(l[i-1] == l[i]):
    l[i] = "_"
    r += 1
r *= k
if(l[0]==l[-1]):
  r += k - 1
print(r)

Submission status: Wrong Answer

Solution code:
S = input()
S2 = S + S
K = int(input())
n = len(S2)
i = 0
s = 0
while i < n-1 :
    x = S2[i]
    y = S2[i+1]
    i += 1
    if x == y:
        s += 1
        i += 1
p = s//2
q = s-p
ans = p + q*(K-1)
print(ans)

Submission status: Wrong Answer

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

t1 = s + "#"
t2 = s * 2 +"#"
# t3 = s * 3 + "#"
# t4 = s * 4 + "#"

def f(text):
    start, end = 0, 0
    rc = []

    while start != len(text)-1:
        if text[start] == text[end]:
            end += 1
        else:
            rc.append(end-start)
            start = end

    return(rc)

first = sum([i//2 for i in f(t1)])
dif = sum([i//2 for i in f(t2)]) - sum([i//2 for i in f(t1)])

print(first + dif*(k-1))

Submission status: Wrong Answer

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

t1 = s + "#"
# t2 = s * 2 +"#"
# t3 = s * 3 + "#"
# t4 = s * 4 + "#"

def f(text):
    start, end = 0, 0
    rc = []

    while start != len(text)-1:
        if text[start] == text[end]:
            end += 1
        else:
            rc.append(end-start)
            start = end

    return(rc)

print(sum([i//2 for i in f(t1)])*k)

Submission status: Wrong Answer

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

cnt = []
prev = "?"
for i in s:
    if prev != i:
        cnt.append(1)
    else:
        cnt[-1] += 1
    prev = i

if len(cnt) == 1:
    ans = cnt[0]//2*k
elif s[0] != s[-1]:
    ans = sum([i // 2 for i in cnt])
    ans = ans * k
else:
    a = cnt.pop()
    b = cnt.pop(0)
    ans = sum([i // 2 for i in cnt]) * k
    ans = ans + a // 2 + b // 2 + (a + b) // 2 * (k - 1)
print(ans)

Submission status: Wrong Answer

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

    w = []
    now = "?"
    for i in s:
        if i != now:
            w.append(1)
        elif i == now:
            w[-1] += 1
        now = i

    if len(w) == 1:
        ans = w[0] // 2 * n
    elif s[0] != s[-1]:
        ans = sum([i // 2 for i in w]) * n
    else:
        a = w[0]
        b = w[-1]
        ans = sum([i // 2 for i in w[1:-1]]) * n
        ans += a // 2 + b // 2
        ans += (n - 1) * (a + b) // 2
    return ans


print(calc())

Submission status: Wrong Answer

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


def calc(st):
    w = []
    now = "?"
    for i in st:
        if i != now:
            w.append(1)
        else:
            w[-1] += 1
        now = i
    return sum([i//2 for i in w])


w1 = calc(s)
w2 = calc(s+s)
ans = n//2*w2
if n % 2 != 0:
    ans += w1
print(ans)

Submission status: Wrong Answer

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

w = []
now = "?"
for i in s:
    if i != now:
        w.append(1)
    else:
        w[-1] += 1
    now = i

ans = sum([i // 2 for i in w])
print(ans*n)

Submission status: Wrong Answer

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

_s = input()[:-1]
_k = int(input())


def countdup(S):
    cnt, dup = 0, 1
    for i in range(1, len(S)):
        if S[i] == S[i - 1]:
            dup += 1
        else:
            cnt += dup // 2
            dup = 1

    return cnt + dup // 2


def chker(S, K):
    if len(S) == 1:
        print(K)
        return

    if K == 1:
        print(countdup(S))
        return

    if K % 2 == 0:
        S_2 = S + S
        print(countdup(S_2) * (K // 2))
    else:
        S_2, S_3 = S + S, S + S + S
        cnt_2, cnt_3 = countdup(S_2), countdup(S_3)
        print(cnt_2 * (K // 2 - 1) + cnt_3)


chker(_s, _k)

Submission status: Wrong Answer

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

def cnt(s):
    if len(s)%2==1:
        res = 0
        for i in range(1,len(s)-1,2):
            if s[i-1]==s[i] or s[i]==s[i+1]:
                res += 1
        return res
    
    res = 0
    for i in range(0,len(s),2):
        if (i>0 and s[i-1]==s[i]) or (i<len(s)-1 and s[i]==s[i+1]):
            res += 1
    return res

print(cnt(s) + (cnt(s+s)-cnt(s))*(k-1))

Submission status: Wrong Answer

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

cnt = 0
i = len(s)%2
while i<len(s):
    if s[i-1]==s[i] or s[i]==s[i+1]:
        cnt += 1
    i += 2

print(cnt*k)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

def count(m):
    return sum(m_i//2 for m_i in m)

l = [len(list(g)) for k, g in groupby(S)]
m = [len(list(g)) for k, g in groupby(S*2)]

print(count(l)*K + (count(m)-count(l*2))*(K-1))

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

def count(m):
    return sum(m_i//2 for m_i in m)

l = [len(list(g)) for k, g in groupby(S)]

print(count(l)*K - (count(l*2)-count(l)*2)*(K-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

S_a = ['1'] + S[1:-1] + ['1']

N = len(S)
cnt = 0
cnt_a = 0
for i in range(1, N):
    if S[i] == S[i-1]:
        cnt += 1
        S[i] = '0'
    
for i in range(1, N-1):
    if S_a[i] == S_a[i-1]:
        cnt_a += 1
        S_a[i] = '0'

print(cnt * (K - (K // 2)) + (cnt_a + 2) * (K//2))

Submission status: Wrong Answer

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

S_a = ['0'] + S[1:-1] + ['0']

N = len(S)
cnt = 0
cnt_a = 0
for i in range(1, N):
    if S[i] == S[i-1]:
        cnt += 1
        S[i] = '0'
    
for i in range(1, N):
    if S_a[i] == S_a[i-1]:
        cnt_a += 1
        S_a[i] = '0'

print(2 * cnt + (K - 2) * cnt_a + (K - 1) * int(S[0] == S[-1]))

Submission status: Wrong Answer

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

N = len(S)
cnt = 0
for i in range(1, N):
    if S[i] == S[i-1]:
        cnt += 1
        S[i] = '0'
    
print(K * cnt + (K - 1) * int(S[0] == S[-1]))

Submission status: Wrong Answer

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

N = len(S)
cnt = 0
cnt_rev = 0
for i in range(N):
    if S[i] == S[i-1]:
        cnt += 1
        S[i] = '0'
    
    if S_rev[i] == S_rev[i-1]:
        cnt_rev += 1
        S_rev[i] = '0'

print(K * (min(cnt, cnt_rev)))

Submission status: Wrong Answer

Solution code:
strings = list(input())
k = int(input())
counter = 0
same_starts = 0
for  i in range(len(strings)-1):
    if strings[i] != strings[i+1]:
        break
    same_starts += 1
for  i in range(len(strings)-1):
    if strings[i] == strings[i+1]:
        strings[i+1] = str(counter)
        counter += 1

# 文字列が１種類の時
if (same_starts + 1) == len(strings):
    # 文字列の個数が偶数の時
    if len(strings) % 2 == 0:
        print(k * len(strings)//2)
    else:
    # 文字列が奇数の時
        # 文字列を繰り返す回数が偶数回の時
        if k % 2 == 0:
            print(counter * k // 2 + (counter + 1) * k // 2)
        else:
        # 文字列を繰り返す回数が奇数回の時
            print(counter * ((k - 1) // 2 + 1)+ (counter + 1) * (k - 1)//2)
else:
    if (same_starts+1) % 2 == 0:
        print(counter * k)
    else:
        print((counter+1) * (k-1) + counter)

Submission status: Wrong Answer

Solution code:
strings = list(input())
k = int(input())
counter = 0
same_starts = 0
for  i in range(len(strings)-1):
    if strings[i] != strings[i+1]:
        break
    same_starts += 1
for  i in range(len(strings)-1):
    if strings[i] == strings[i+1]:
        strings[i+1] = str(counter)
        counter += 1

if strings[0] != strings[-1]:
    print(counter * k)

# 文字列が１種類の時
if (same_starts + 1) == len(strings):
    # 文字列の個数が偶数の時
    if len(strings) % 2 == 0:
        print(k * len(strings)//2)
    else:
    # 文字列が奇数の時
        # 文字列を繰り返す回数が偶数回の時
        if k % 2 == 0:
            print(counter * k // 2 + (counter + 1) * k // 2)
        else:
        # 文字列を繰り返す回数が奇数回の時
            print(counter * ((k - 1) // 2 + 1)+ (counter + 1) * (k - 1)//2)
else:
    if (same_starts+1) % 2 == 0:
        print(counter * k)
    else:
        print((counter+1) * (k-1) + counter)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
S2 = S + S
S3 = S + S + S
count1 = 0

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        S[i+1] = '_'
        count1 += 1
count2 = 0

for i in range(len(S2)-1):
    if S2[i] == S2[i+1]:
        S2[i+1] = '_'
        count2 += 1
count3 = 0

for i in range(len(S3)-1):
    if S3[i] == S3[i+1]:
        S3[i+1] = '_'
        count3 += 1        
if K == 1:
    print(count1)
else:
    print(K//2 * count2 + K%2 * (count3-count2))

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
S2 = S + S
S3 = S + S + S
count1 = 0

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        S[i+1] = '_'
        count1 += 1
count2 = 0

for i in range(len(S2)-1):
    if S2[i] == S2[i+1]:
        S2[i+1] = '_'
        count2 += 1
count3 = 0

for i in range(len(S3)-1):
    if S3[i] == S3[i+1]:
        S3[i+1] = '_'
        count3 += 1        
print(count1, count2)
if K == 1:
    print(count1)
else:
    print(K//2 * count2 + K%2 * (count3-count2))

Submission status: Wrong Answer

Solution code:
strings = list(input())
k = int(input())
counter = 0
same_starts = 0
if len(strings) == 1:
    if k % 2 == 0:
        print(k//2)
    else:
        print((k-1)//2)
else:
    for  i in range(len(strings)-1):
        if strings[i] != strings[i+1]:
            break
        same_starts += 1
    for  i in range(len(strings)-1):
        if strings[i] == strings[i+1]:
            strings[i+1] = str(counter)
            counter += 1

    if strings[0] != strings[-1]:
        print(counter * k)

    else:
        if (same_starts+1) % 2 == 0:
            print(counter * k)
        else:
            print((counter+1) * (k-1) + counter)

Submission status: Wrong Answer

Solution code:
strings = list(input())
k = int(input())
counter = 0
same_starts = 0
for  i in range(len(strings)-1):
    if strings[i] != strings[i+1]:
        break
    same_starts += 1
for  i in range(len(strings)-1):
    if strings[i] == strings[i+1]:
        strings[i+1] = str(counter)
        counter += 1

if strings[0] != strings[-1]:
    print(counter * k)

else:
    if (same_starts+1) % 2 == 0:
        print(counter * k)
    else:
        print((counter+1) * (k-1) + counter)

Submission status: Wrong Answer

Solution code:
strings = list(input())
k = int(input())
counter = 0
same_starts = 0
for  i in range(len(strings)-1):
    if strings[i] != strings[i+1]:
        break
    same_starts += 1
for  i in range(len(strings)-1):
    if strings[i] == strings[i+1]:
        strings[i+1] = str(counter)
        counter += 1
if strings[0] is not strings[-1]:
    print(counter * k)

else:
    if same_starts % 2 == 0:
        print(counter * k)
    else:
        print((counter+1) * (k-1) + counter)

Submission status: Wrong Answer

Solution code:
strings = list(input())
k = int(input())
counter = 0
same_starts = 0
for  i in range(len(strings)-1):
    if strings[i] != strings[i+1]:
        break
    same_starts += 1
for  i in range(len(strings)-1):
    if strings[i] == strings[i+1]:
        strings[i+1] = str(counter)
        counter += 1
if strings[0] is not strings[-1]:
    print(counter * k)

else:
    if same_starts % 2 == 0:
        print(counter * k)
    else:
        print((counter+1) * (k-1) + k)

Submission status: Wrong Answer

Solution code:
strings = list(input())
k = int(input())
counter = 0
same_starts = 0
for  i in range(len(strings)-1):
    if strings[i] != strings[i+1]:
        break
    same_starts += 1
for  i in range(len(strings)-1):
    if strings[i] == strings[i+1]:
        strings[i+1] = str(counter)
        counter += 1
if strings[0] is not strings[-1]:
    print(counter * k)

else:
    if same_starts % 2 == 0:
        print(counter * k)
    else:
        print(counter * (k-1) + k)

Submission status: Wrong Answer

Solution code:
strings = list(input())
k = int(input())
counter = 0
for  i in range(len(strings)-1):
    if strings[i] == strings[i+1]:
        strings[i+1] = str(counter)
        counter += 1
if strings[0] is not strings[-1]:
    print(counter * k)
else:
    print(counter * (k + 1))

Submission status: Wrong Answer

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

def OneString(a):
    seq = 0
    seqit = 0
    for i in range(len(a)):
        if i == len(a) - 1:
            seq += (seqit+1)//2
        elif a[i]!=a[i+1]:
            seq += (seqit+1)//2
            seqit = 0
        else:
            seqit += 1
    return seq

def TBodd(a):
    seqnumT = 1
    seqnumB = 1
    if a[0] != a[-1]:
        return False
    for i in range(len(a)-1):
        if a[i]==a[i+1]:
            seqnumT += 1
        else: break
    for i in range(len(a)-2):
        if a[-(i+1)]==a[-(i+2)]:
            seqnumB += 1
        else: break
    if (seqnumT+seqnumB)%2 != 0:
        return False
    else: return True
            

if len(set(ListS)) == 1:
    ans = (len(S)*K)//2
elif TBodd(S):
    ans = (OneString(S) + 1)*K - 1
    print(3)
else: ans = OneString(S)*K
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math
S=input()
K=int(input())
t=[S[0]]
if S.count(S[0])==len(S):
    print(len(S)*K/2)
elif S[0]!=S[-1]:
    for i in range(1,len(S)):
        if S[i]!=S[i-1]:
            t.append(":")
            t.append(S[i])
        else:
            t.append(S[i])
    t="".join(t)
    t=t.split(":")
    coun=0
    for j in t:
        if len(j)>=2:
            coun+=(math.floor(len(j)/2))
    print(int(K*coun))
elif S[0]==S[-1]:
    flag=True
    co=0
    a=[]
    while flag==True:
        a.append(S)
        co+=1
        if co==K:
            flag=False
    S=list("".join(a))
    for i in range(1,len(S)):
        if S[i]!=S[i-1]:
            t.append(":")
            t.append(S[i])
        else:
            t.append(S[i])
    t="".join(t)
    t=t.split(":")
    coun=0
    for j in t:
        if len(j)>=2:
            coun+=(math.floor(len(j)/2))
    print(coun)

Submission status: Wrong Answer

Solution code:
import math
S=input()
K=int(input())
t=[S[0]]
if S.count(S[0])==len(S):
    print(len(S)*K/2)
elif S[0]!=S[-1]:
    for i in range(1,len(S)):
        if S[i]!=S[i-1]:
            t.append(":")
            t.append(S[i])
        else:
            t.append(S[i])
    t="".join(t)
    t=t.split(":")
    print(t)
    coun=0
    for j in t:
        if len(j)>=2:
            coun+=(math.floor(len(j)/2))
    print(int(K*coun))
elif S[0]==S[-1]:
    flag=True
    co=0
    a=[]
    while flag==True:
        a.append(S)
        co+=1
        if co==K:
            flag=False
    S=list("".join(a))
    for i in range(1,len(S)):
        if S[i]!=S[i-1]:
            t.append(":")
            t.append(S[i])
        else:
            t.append(S[i])
    t="".join(t)
    t=t.split(":")
    coun=0
    for j in t:
        if len(j)>=2:
            coun+=(math.floor(len(j)/2))
    print(coun)

Submission status: Wrong Answer

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

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

  else:
    ogl_len = len(S)
    S = S*2
    for i in range(len(S)-1):
      if S[i] == S[i+1]:
        S[i+1] = '*'
    init_cnt = S[:ogl_len].count('*')
    cnt = S[ogl_len:].count('*')
    print(init_cnt + cnt*(K-1))

Submission status: Wrong Answer

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


if K==1:
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      S[i+1] = '*'
  print(S.count('*'))
  
else:
  ogl_len = len(S)
  S = S*2
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      S[i+1] = '*'
  init_cnt = S[:ogl_len].count('*')
  cnt = S[ogl_len:].count('*')
  print(init_cnt + cnt*(K-1))

Submission status: Wrong Answer

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

def OneString(a):
    seq = 0
    seqit = 0
    for i in range(len(a)):
        if i == len(a) - 1:
            seq += (seqit+1)//2
        elif a[i]!=a[i+1]:
            seq += (seqit+1)//2
            seqit = 0
        else:
            seqit += 1
    return seq

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

Submission status: Wrong Answer

Solution code:
s = raw_input()
s+=s[0]
s=list(s)
k = input()
m = 0
X=False
for i in xrange(len(s)-1):
  if s[i]==s[i+1] and s[i]!="-":
    s[i+1]="-"
    m+=1
    if i==len(s)-2:X=True
print k*m-X

Submission status: Wrong Answer

Solution code:
s = str(input())
n = int(input())
num = []
cnt = 1
for i in range(len(s)-1):
    if s[i+1] != s[i]:
        num.append(cnt)
        cnt = 1
    else:
        cnt += 1
num.append(cnt)
ans = 0
for nu in num:
    ans += nu//2
if s[0] != s[-1]:
    ans *= n
else:
    ans -= num[0]//2
    ans -= num[-1]//2
    ans *= n
    ans += num[0]//2
    ans += num[-1]//2
    ans += ((num[0]+num[-1])//2)*(n-1)
print(ans)

Submission status: Wrong Answer

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

count = 0
for i in range(length-1):
    if i == length-1:
        if list_s[length] == list_s[0]:
            count += 1
    elif list_s[i] == list_s[i+1]:
        list_s[i+1] = "X"
        count += 1

count *= k
if list_s[0] == list_s[length-1]:
    count -= 1
print(count)

Submission status: Wrong Answer

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

count = 0
for i in range(length-1):
    if i == length-1:
        if list_s[length] == list_s[0]:
            list_s[length] = "X"
            count += 1
            break
    elif list_s[i] == list_s[i+1]:
        list_s[i+1] = "X"
        count += 1

count = count * k
if list_s[0] == list_s[length-1]:
    count -= 1
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(S: str, K: int):
    #print(S, K, S[0:1]+S[1:2])
    L=len(S)
    a=0
    i=0
    while i<L:
        if S[i:i+1]==S[i+1:i+2]:
            a+=1
            i+=2
        else:
            i+=1

    b=0
    i=0
    while i<L*2:
        if S[(i%L):(i%L+1)]==S[((i+1)%L):((i+1)%L+1)]:
            b+=1
            i+=2
        else:
            i+=1

    if a*2==b:
        #print("eq",a,b,a*K)
        print(a*K)
    else:
        #print("neq",a,b,int(b*K//2))
        print(int(b*K//2))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(S, K)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(S: str, K: int):
    #print(S, K, S[0:1]+S[1:2])
    a=0
    i=0
    while i<len(S):
        if S[i:i+1]==S[i+1:i+2]:
            a+=1
            i+=2
        else:
            i+=1
    print(a*K)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(S, K)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
flag = False
flag2 = False

kaburi1=0
kaburi2=0

d = {}

for s in S:
    if s in d: d[s] += 1
    else: d.update({s:1})

if len(d)==1:
    for k, v in d.items():
        print((v//2)*K)
        exit()

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

    for i in range(0, len(S)):
        if S[i]==S[0]: kaburi1 += 1
        else: break


naibu = 0
l = len(S)
for i in range(l-1):
    if S[i]==S[i+1]:
        naibu += 1
        SS = S[0:i+1] + 'A' + S[i+2:l]
        S = SS


ans = naibu * K
if S[0] == S[l-1]:
    ans += -kaburi1 // 2 + -kaburi2 // 2  + ((kaburi1+kaburi2)//2)*(K-1)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
flag = False
flag2 = False

kaburi1=0
kaburi2=0

d = {}

for s in S:
    if s in d: d[s] += 1
    else: d.update({s:1})

if len(d)==1:
    for k, v in d.items():
        print(v//2)
        exit()

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

    for i in range(0, len(S)):
        if S[i]==S[0]: kaburi1 += 1
        else: break


naibu = 0
l = len(S)
for i in range(l-1):
    if S[i]==S[i+1]:
        naibu += 1
        SS = S[0:i+1] + 'A' + S[i+2:l]
        S = SS


ans = naibu * K
if S[0] == S[l-1]:
    ans += -kaburi1 // 2 + -kaburi2 // 2  + ((kaburi1+kaburi2)//2)*(K-1)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
flag = False
flag2 = False

kaburi1=0
kaburi2=0

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

    for i in range(0, len(S)):
        if S[i]==S[0]: kaburi1 += 1
        else: break


naibu = 0
l = len(S)
for i in range(l-1):
    if S[i]==S[i+1]:
        naibu += 1
        SS = S[0:i+1] + 'A' + S[i+2:l]
        S = SS


ans = naibu * K
if S[0] == S[l-1]:
    ans += -kaburi1 // 2 + -kaburi2 // 2  + ((kaburi1+kaburi2)//2)*(K-1)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
flag = False
flag2 = False

kaburi1=0
kaburi2=0

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

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


naibu = 0
l = len(S)
for i in range(l-1):
    if S[i]==S[i+1]:
        naibu += 1
        SS = S[0:i+1] + 'A' + S[i+2:l]
        S = SS


ans = naibu * K
if S[0] == S[l-1]:
    ans += -kaburi1 // 2 + -kaburi2 // 2  + ((kaburi1+kaburi2)//2)*(K-1)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
flag = False
flag2 = False

kaburi1=0
kaburi2=0

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

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


naibu = 0
l = len(S)
for i in range(l-1):
    if S[i]==S[i+1]:
        naibu += 1
        SS = S[0:i+1] + 'A' + S[i+2:l]
        S = SS


ans = naibu * K
if S[0] == S[l-1]:
    ans += -kaburi1 // 2 + -kaburi2 // 2  - ((kaburi1+kaburi2)//2)*(K-1)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
flag = False
flag2 = False

kaburi1=0
kaburi2=0

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

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


naibu = 0
l = len(S)
for i in range(l-1):
    if S[i]==S[i+1]:
        naibu += 1
        SS = S[0:i+1] + 'A' + S[i+2:l]
        S = SS


ans = naibu * K
if S[0] == S[l-1]:
    ans += kaburi1 // 2 + kaburi2 // 2  - ((kaburi1+kaburi2)//2)*(K-1)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
flag = False
flag2 = False

kaburi1=0
kaburi2=0

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

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


naibu = 0
l = len(S)
for i in range(l-1):
    if S[i]==S[i+1]:
        naibu += 1
        SS = S[0:i+1] + 'A' + S[i+2:l]
        S = SS


ans = naibu * K
if S[0] == S[l-1]:
    ans += kaburi1 // 2 + kaburi2 // 2  + ((kaburi1+kaburi2)//2)*(K-1)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
flag = False
flag2 = False

kaburi1=0
kaburi2=0

#if S[len(S)-2]==S[len(S)-1] or S[0]==S[1]:
if S[len(S)-1] ==S[0]:
    flag = True
    for i in range(len(S)-1, -1, -1):
        if S[i]==S[len(S)-1]: kaburi2 += 1
        else: break

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


naibu = 0
l = len(S)
for i in range(l-1):
    if S[i]==S[i+1]:
        naibu += 1
        SS = S[0:i+1] + 'A' + S[i+2:l]
        S = SS


ans = naibu * K
if flag:
    ans = ans -(kaburi1//2 + kaburi2//2 - (kaburi1+kaburi2)//2)*(K-1)
    print(ans)
else: print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
flag = False
flag2 = False
if S[0]==S[len(S)-1]:
#    ans += K-1
    flag = True

if S[len(S)-2]==S[len(S)-1] or S[0]==S[1]:
    flag2 = True
naibu = 0
l = len(S)
for i in range(l-1):
    if S[i]==S[i+1]:
        naibu += 1
        SS = S[0:i+1] + 'A' + S[i+2:l]
        S = SS


ans = naibu * K
if flag:
    if flag2:
        print(ans)
    else:
        print(ans+1)
else: print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
flag = False
flag2 = False
if S[0]==S[len(S)-1]:
#    ans += K-1
    flag = True

if S[len(S)-2]==S[len(S)-1]:
#    ans += K-1
    flag2 = True
naibu = 0
l = len(S)
for i in range(l-1):
    if S[i]==S[i+1]:
        naibu += 1
        SS = S[0:i+1] + 'A' + S[i+2:l]
        S = SS

ans = naibu * K
if flag:
    if flag2:
        print(ans)
    else:
        print(ans+1)
else: print(ans)

Submission status: Wrong Answer

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

c = 0
chain = 0
for s1, s2 in zip(S[:-1], S[1:]):
  if s1 == s2:
    chain += 1
  else:
    c += (chain+1) // 2
    chain = 0

c += (chain+1) // 2

print(c * K)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
flag = False
flag2 = False
if S[0]==S[len(S)-1]:
#    ans += K-1
    flag = True

if S[len(S)-2]==S[len(S)-1]:
#    ans += K-1
    flag2 = True
naibu = 0
l = len(S)
for i in range(l-1):
    if S[i]==S[i+1]:
        naibu += 1
        SS = S[0:i+1] + 'A' + S[i+2:l]
        S = SS
        print(SS)

ans = naibu * K
if flag:
    if flag2:
        print(ans)
    else:
        print(ans+1)
else: print(ans)

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))



S=one_str()
K=one_int()

before = S[0]
count=1
ranrength = []
for i in S[1:]:
    if before==i:
        count+=1
    else:
        ranrength.append(count)
        count=1
    before=i

ranrength.append(count)

output_count=0
for r in ranrength:
    if r>1:
        output_count += r//2
output_count *= K

if S[0]==S[-1]:
    head=ranrength[0]
    tail=ranrength[-1]
    
    if head>1 and head%2==1 and tail>1 and tail%2==1:
        output_count += (K-1)
print(output_count)