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

def main():
    input = sys.stdin.readline
    S = str(input().strip())
    K = int(input())

    ans = 0
    if len(S) == 1:
        return K // 2
    
    if len(S) == 2:
        if S[0] == S[-1]:
            return K
        else:
            return 0
    
    cnt = 0
    T = S[0]
    for s in S[1:]:
        if s == T[-1]:
            cnt += 1
            T += '_'
        else:
            T += s
    
    ans = cnt * K
    if T[0] == T[-1]:
        ans += K - 1 
    return ans

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
N = len(S)
cnt = 0
flg1 = False
flg2 = False
if N == 1:
    print(K//2)
    exit()
if S[0] == S[N-1]:
    cnt += 1
    flg1 = True
for i in range(N-1):
    if flg2:
        flg2 = False
        continue
    if (i == N - 2) and flg1:
        break
    if S[i] == S[i+1]:
        cnt += 1
        flg2 = True
# print(cnt)
print(cnt*K)

Submission status: Wrong Answer

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

cnt = 0
tmp = 1
for i in range(1, len(S)):
    if S[i - 1] == S[i]:
       tmp += 1
    elif tmp >= 2:
        cnt += tmp // 2
        tmp = 1
    else:
        tmp = 1

if tmp >= 2:
    cnt += 1

#tmp1 = cnt
#if S[0] == S[-1]:
#    if S[-2] != S[-1]:
#        cnt += 1

print((cnt * (K)))

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
a = []
ans = 0
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] :
        count += 1
    else:
        if count!=0:
            ans += (count+1)//2
            count = 0
if count !=0:
    ans += (count+1)//2 
ans = ans*K
  

print(ans)

Submission status: Wrong Answer

Solution code:
S = str(input())
K = int(input())
tmp = 1
cnt = 0
for i in range(1, len(S)):
    if S[i-1] == S[i]:
        tmp += 1
    else:
        cnt += tmp // 2
        tmp = 1
if tmp > 1:
    if tmp == len(S):
        print((len(S) * K) // 2)
        exit()
    else:
        cnt += tmp//2
if S[0] == S[-1]:
    if len(S) == 1:
        print(K//2)
    elif S[0] != S[1] and S[-1] != S[-2]:
        print(cnt * K + K - 1)
    else:
        print(cnt * K)
else:
    print(cnt * K)

Submission status: Wrong Answer

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

if len(S) == 1:
    print(K//2)
elif len(set(S)) == 1:
    print(len(S)*K//2)
else:
    c = 0
    flg = False
    for i in range(len(S)-1):
        if S[i] == S[i+1] and flg is False:
            c += 1
            flg = True
        else:
            flg = False

    if flg is False and S[-1] == S[0]:
        j = 1
        if len(S) >= 4 and S[0] != S[1]:
            j = 0

    else:
        j = 0

    print(c*K+j*(K-1))
    # print(c, j)

Submission status: Wrong Answer

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

ans = 0
i=0
S=S+S
while i<len(S)-1:
    renzoku=1
    x=i
    while S[x] == S[i+1]:
        renzoku+=1
        if i+2 < len(S):
            i=i+1
        else:
            break

    if renzoku >1:
        ans+=renzoku//2
    i+=1
    
print(ans*(K//2))

Submission status: Wrong Answer

Solution code:
from itertools import groupby
s = list(input())
k = int(input())

G = []
for key, group in groupby(s):
    G += [list(group)]

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

elif s[0]!=s[-1]:
    for g in G:
        count += len(g)//2
    print(count*k)

else:
    d = len(G[0]+G[-1])//2-(len(G[0])//2) - (len(G[-1])//2)
    for g in G:
        count += len(g)//2
    print(count*k + d*(k-1))

Submission status: Wrong Answer

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

ans = 0
now = 0
flag = True

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

for i in range(len(s)):
    #print(i,now)
    if now >= len(s) - 1:
        break
    if s[now] == s[now+1]:
       ans += 1
       now += 2
       if now+1 == len(s) -1:
           flag = False
    else:
        now += 1

if flag == True:
    if s[0] == s[-1]:
        flag = True
    else:
        flag = False

#print(flag)
if len(s) == 2:
    print(ans*k)
else:
    print(ans*k+flag*(k-1))
#print(ans,ans*k,ans*k+flag*(k-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s) - 1
count = 1
output = 0
last = 0
tmp = 0

for i in range(n):
    if s[i] == s[i + 1]:
        count += 1

    if s[i] != s[i + 1]:
        output += count // 2
        count = 1

if s[0] == s[-1]:
    for i in range(n):
        if s[i] == s[0]:
            count += 1

        else:
            tmp = i
            break

output += count // 2
count = 1

for i in range(tmp, n):
    if s[i] == s[i + 1]:
        count += 1

    if s[i] != s[i + 1]:
        last += count // 2
        count = 1

last += count // 2

print(output * (k - 1) + last)

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
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
print(ans*K)

Submission status: Wrong Answer

Solution code:
s = input()
length = len(s)
k = int(input())
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
#print(start)
#print(end)
if(s[0] == s[-1]):print( (ans*k)+int((start+end)/2)*k +int(start/2) +int(end/2)-1)
else:print((int(end/2)+int(start/2)+ans)*k)

Submission status: Wrong Answer

Solution code:
#A問題
S = list(str(input()))
K = int(input())

if K == 1:
    ans = 0
    old = ""
    for s in S:
        if old == "":
            old = s
        else:
            if old == s:
                ans+=1
                old = ""
            else:
                old = s
    print(ans)
else:
    ans = 0
    old = ""
    T = S+S
    flag = 0
    for i,t in enumerate(T):
        if old == "":
            old = t
            if i == len(T)-1:
                flag = 1
        else:
            if old == t:
                ans+=1
                old = ""
            else:
                old = t
                if i == len(T)-1:
                    flag = 1
                
    if K%2 == 0:
        print(ans*(K//2))
    else:
        ans2 = 0
        old = ""
        for i in range(len(S)):
            if i == 0:
                if len(S) > 1 and S[0] == S[-1] and flag == 1:
                    old = ""
                    ans2+=1
                else:
                    old = S[i]
            elif old == "":
                old = S[i]
            else:
                if old == S[i]:
                    ans2+=1
                    old = ""
                else:
                    old = S[i]
        print(ans*(K//2) + ans2)

Submission status: Wrong Answer

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

is_same = False
b = ''
count = 0
tail = False
for c in s:
  if c == b and not is_same:
    count += 1
    is_same = True
  else:
    is_same = False
  b = c
else:
  if s[0] == s[-1] and not is_same:
    tail = True
ans = count * k
if tail:
  ans += k-1
print(ans)

Submission status: Wrong Answer

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

ans = 0
if len(S) == 1:
  ans = K // 2
elif len(S) == 2:
  if S[0] == S[1]:
    ans = K
else:
  cnt = 1
  for i in range(1, len(S) - 1):
    if S[i - 1] == S[i]:
      cnt += 1
    else:
      ans += (cnt // 2) * K
      cnt = 1
  ans += (cnt // 2) * K

  if S[0] == S[-1]:
    if S[-1] == S[-2]:
      ans += K
    else:
      ans += K - 1
  
  if cnt == len(S) - 1 and S[0] == S[-1]:
    ans = (len(S) * K) // 2

print(ans)

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
    elif len(a) ==1:
        cnt += K//2
    else:

        for i in range(len(a)-1):
            if a[i+1] == a[i]:
                a[i+1] = str(i)
                cnt += 1
        cnt *= K
        if a[0] == a[-1] and len(a) > 1:
            cnt += K-1
    print(cnt)

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

print(cn*k)

Submission status: Wrong Answer

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

T = S * 2

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

# 2bai
countB = 0
for i in range(len(T) - 1):
    if T[i] == T[i + 1]:
        countB += 1
        T[i + 1] = 'A'

if K > 1:
    if K % 2 == 1:
        print(K//2*countB+countA)
    else:
        print(K//2*countB)
else:
    print(countA)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

tmp = ""
cnt = 0
ans = 0
for s in S:
    if s == tmp:
        cnt += 1
    else:
        ans += cnt//2
        cnt = 1
    tmp = s
ans *= K
first_cnt = 0
if S[0] == S[-1]:
    for s in S:
        if s == S[0]:
            first_cnt += 1
        else:
            break
    if first_cnt == len(S):
        ans += (first_cnt*K)//2 
    else:
        ans += (cnt+first_cnt)//2 * (K-1)
        ans += cnt//2
else:
    ans += cnt//2

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
length = len(s)
k = int(input())
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
print(start)
print(end)
if(s[0] == s[-1]):print( (ans*k)+int((start+end)/2)*k +int(start/2) +int(end/2)-1)
else:print((int(end/2)+int(start/2)+ans)*k)

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
ss=s+s
tmp1=0
tmps=""
for i in s:
    if tmps==i:
        tmp1+=1
        tmps=""
    else:
        tmps=i
tmp2=0
tmps=""
for i in ss:
    if tmps==i:
        tmp2+=1
        tmps=""
    else:
        tmps=i
sa=tmp2-tmp1
print(tmp1+sa*(n-1))

Submission status: Wrong Answer

Solution code:
import string


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


if __name__ == '__main__':
    s = input()
    k = int(input())
    pool = list(set(string.ascii_lowercase) - set(s))
    length = len(pool)
    if k <= 2:
        print(count_changes(s, k, pool))
    else:
        base_count = count_changes(s, 3, pool)
        d, rest = divmod(k, 3)
        print(base_count * d + count_changes(s, rest, pool))

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
    if 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
    if 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
if 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:
import sys

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

li = [0 for i in range(len(s)+1)]
wrd = [i for i in s]
wrd.append(wrd[0])

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

if k == 1:
    for i in range(len(s)-1):
        if wrd[i]==wrd[i+1] and li[i]==0:
            li[i+1] = 1
    ans = 0    
    for i in range(len(s)+1):
        if li[i] == 1:
            ans += 1
    print(ans)
    sys.exit()

for i in range(len(s)):
    if wrd[i]==wrd[i+1] and li[i]==0:
        li[i+1] = 1

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

ans *= k

if li[len(s)]==1 and k>=2:
    ans -= 1
    
print(ans)

Submission status: Wrong Answer

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

x = [0]*len(s)
for i in range(len(s)-1):
    if (s[i] == s[i+1]) and x[i] == 0:
        x[i+1] = 1
y = 0
if (k > 1) and (s[0] == s[-1]) and (x[-1] == 0):
    y = k - 1

print(sum(x)*k + y)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
fi=0
se=0
t=s+s
n=len(s)
now=1
for i in range(1,n):
  if s[i]==s[i-1]:
    now+=1
  else:
    fi+=now//2
    now=1
fi+=now//2
now=1
for i in range(1,n*2):
  if t[i]==t[i-1]:
    now+=1
  else:
    se+=now//2
    now=1
se+=now//2
ans=(se-fi)*(k-1)+fi
#print(se,fi)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
cnt = 0
i = 0
while i < len(s)-1:
  if s[i] == s[i+1]:
    i += 2
    cnt += 1
  elif s[i] != s[i+1]:
    i += 1


if s[0] == s[-1]:
  print(cnt*k + k-1)

else:
  print(cnt*k)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

S = str(input())
n = len(S)
K = I()

num = 0
flag = False
for i in range(1,n):
    if S[i]==S[i-1] and flag==False:
        num += 1
        flag = True
    else:
        flag = False

if flag==False and S[0]==S[-1]:
    num2 = 1
    flag2 = False
    for i in range(2,n):
        if S[i]==S[i-1] and flag2==False:
            num2 += 1
            flag2 = True
        else:
            flag2 = False
    if flag2==False:
        print(num+num2*(K-1))
        exit()
    else:
        print(num2*(K//2) + num*(K-K//2))
        exit()
else:
    print(num*K)

Submission status: Wrong Answer

Solution code:
import sys

S = input()
K = int(input())
N = len(S)
Ans = 0
i = 0
wcount = 0

if N == 1:
  KK = K // 2
  Ans = Ans + KK
  print(Ans)
  sys.exit()

for p in range(0,N-1):
  if S[p] != S[p+1]:
    wcount = wcount + 1
    
if wcount == 0:
  KK = N * K // 2
  Ans = Ans + KK
  print(Ans)
  sys.exit()
  
while i < N-1:
  if S[i] == S[i+1]:
    Ans = Ans + 1
    i = i + 2
  else:
    i = i + 1

Ans = Ans * K

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

print(Ans)

Submission status: Wrong Answer

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


pre = ""
count = 0
first = S[0]
last = S[len(S)-1]
flag = False
for i in range(len(S)):
    if i == len(S) - 1:
        if pre == "":
            flag = True
    if pre != S[i]:
        pre = S[i]

    elif pre == S[i]:
        count += 1
        pre = ""


        # count += 1
count *= int(K)
if flag:
    count += 1
print(count)

Submission status: Wrong Answer

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

if S[0] == S[len(S)-1]:
    before = ""
    cnt = 0
    x = 0
    head_size = 0
    tail_size = 0
    head = S[0]
    for s in S:
        if head == s:
            head_size += 1
        else:
            break

    for s in S[head_size:]:
        if before == s:
            cnt+=1
        else:
            x += (cnt//2)
            cnt = 1
            before = s
    tail_size = cnt
    x += ((head_size + tail_size)//2)
    ans = K * x

    # 先頭数えてない分
    ans += (head_size//2)

    # 最後数えすぎ分を減らす
    ans -= ((head_size + tail_size)//2)
    ans += (tail_size//2)

    print(ans)

else:
    before = ""
    cnt = 0
    x = 0
    for s in S:
        if before == s:
            cnt+=1
        else:
            x += (cnt//2)
            cnt = 1
            before = s
    x += (cnt//2)

    print((K*x))

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy

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

A = np.zeros(1)
j = 0 

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        A[j] += 1
    else:
        j += 1
        A = np.append(A, 0)

ans = 0

if np.size(A) == 1:
    ans = (len(S) * K) // 2
    
else:   
    B = copy.deepcopy(A)
    if S[0] == S[len(S)-1]:
        B[0] += A[0]+A[-1]+1

    A = A + 1
    A = np.delete(A, np.size(A)-1)
    B = B + 1

    ans = np.sum(A // 2) + np.sum(B // 2) * (K-1)

print(int(ans))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if len(S) == 1:
    print(K//2)
elif len(set(S)) == 1:
    print(len(S)*K//2)
else:
    c = 0
    flg = False
    for i in range(len(S)-1):
        if S[i] == S[i+1] and flg is False:
            c += 1
            flg = True
        else:
            flg = False

    if flg is False and S[-1] == S[0] and S[0] != S[1]:
        j = 1

    else:
        j = 0

    print(c*K+j*(K-1))
    # print(c, j)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    S = input()
    K = int(input())

    ans = 0
    if S[0] == S[-1]:
        ans = 1
        S = S[1:]

    l, prev = 1, ''
    for s in S:
        if s == prev:
            l += 1
        else:
            ans += l // 2
            l = 1
        prev = s

    print(ans * K)


main()

Submission status: Wrong Answer

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

box = ""
count=0

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

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
s = s + [s[0]]

count = 0

if len(s) == 1 and k == 1:
    print(0)

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

print(count * k)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
def unit(s):
    """sの両端を外した状態でいくつ変えるか
    """
    count = 0
    prev = s[0]
    for c in s[1:]:
        if c==prev:
            count += 1
            prev = None
        else:
            prev = c
    return count
if len(s)==2:
    if s[0]==s[1]:
        print(k)
    else:
        print(0)
elif len(s)==1:
    print(k//2)
elif not s:
    print(0)
elif s[0]!=s[-1]:
    result = k * unit(s[1:-1])
    print(result)
else:
    s0 = unit(s[1:-1])
    s1 = unit(s[1:])
    s2 = unit(s[:-1])
    s3 = unit(s)
    result = min(s1*(k-1)+s3+(k-1), s2*(k-1)+s3+(k-1))
    print(result)

Submission status: Wrong Answer

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

ans = 0
i=0
while i<len(S)-1:
    renzoku=1
    x=i
    while S[x] == S[i+1]:
        renzoku+=1
        if i+2 < len(S):
            i=i+1
        else:
            break

    if renzoku >1:
        ans+=renzoku//2
    i+=1
    
print(ans*K)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def f(s):
    i = 0
    n = 0
    while i < len(s)-1:
        if s[i] == s[i+1]:
            n += 1
            i += 2
        else:
            i += 1
    return n

def main():
    S = input().strip()
    K = int(input())
    if len(S) == 1:
        print(K//2)
        return
    a1 = f(S)
    a2 = f(S*2)
    ans = K * a1
    if a1*2 != a2:
        ans += K-1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

L = [i for i in S]


if len(S) == 1:
    if K == 1:
        print(0)
    elif K == 2:
        print(1)
    elif K == 3:
        print(2)
    else:
        print(K//2)
    sys.exit()

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

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

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
a = s + s[0]
prev = a[0]
c = 0
for b in list(a)[1:]:
  if b == prev:
    c += 1
    prev = "0"
  else:
    prev = b
t = 0
if len(a) > 2:
  if a[-2] == a[-1]:
    t = -1
  if a[-1] == a[-2] and a[-3] == a[-1]:
    t = 0
print(c*k + t)

Submission status: Wrong Answer

Solution code:
# A - Connection and Disconnection
s = input()
k = (int)(input())

beforeStr = ''
count = 0

firstChar = s[0]
endChar = s[len(s) -1]

list_s = list(s)

for i in range(len(s)):

    if i == (len(s) - 1) and firstChar == endChar:
        count += 1
        break
    if beforeStr == list_s[i]:
        count += 1
        list_s[i] = 'Z'
    beforeStr = list_s[i]

print(count * k)

Submission status: Wrong Answer

Solution code:
s, k = input(), int(input())
char=[]
prev = "0"
cnt = 0
for i in s:
    if i==prev: cnt+=1
    else: char.append(cnt);cnt=1
    prev = i
char.append(cnt)

if s[0]==s[-1]:
    tmp = char.pop(1)
    char[-1] += tmp
    ans = tmp//2
    for i in char: ans += i//2
    ans *= k-1
    char[-1] -= tmp
    for i in char: ans += i//2

else:
    ans = 0
    for i in char: ans += i//2
    ans *= k

if len(set(s))==1: ans = len(s)*k//2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

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

N = len(S)
ans = 0
last_same = False
if N==1:
    print(K//2)
    exit()


pre = S[0]
p = False
for i in range(1,N):
    if p:
        pre = S[i]
        p = False
        continue
    s = S[i]
    if pre==s:
        ans += 1
        p = True
        if i==N-1:
            last_same = True
    pre = s

l_same = False
if not last_same:
    if S[0]==S[-1]:
        ans += 1
        l_same = True

ANS = ans*K
if l_same:
    ANS -= 1
print(ANS)

Submission status: Wrong Answer

Solution code:
s = [c for c in input()]
k = int(input())

#print(s)

if len(s) == len(set(s)):
    print(0)
    
elif len(s)==1:
    print(k-1)

elif s[0] != s[-1]:
    c = 0
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            c = c + 1
            s[i] = 'Z'
    print(c*k)

else:
    c = 0
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            c = c + 1
            s[i] = 'Z'
    if s[-1] == 'Z':
        print(c*k)
    else:
        print(c*k + k - 1)

Submission status: Wrong Answer

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

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

#print(change)

ret = 0
if len(change) >= 3:

    for i in range(1, len(change) - 1):
        ret += change[i] // 2 * k
    
    if s[0] == s[-1]:
        ret += (change[0] + change[-1]) // 2 * (k - 1) + change[0] // 2 + change[-1] // 2
    else:
        ret += (change[0] // 2 + change[-1] // 2) * k
elif len(change) == 2:
    ret = (change[0] // 2 + change[1]) * k
else:
    ret = change[0] * k // 2

print(ret)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
cnt = 0
seg = 0
end = 0
flg = True
for i in range(1,len(S)-2):
  if S[i - 1] == S[i] and flg:
    cnt += 1
    flg = False
  elif flg == False:
    flg = True
  

if S[0] == S[len(S) - 1]:
  seg = K - 1
if S[len(S) - 1] == S[len(S) - 2]:
  end = 1
print(cnt * K + seg + end)

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
cnt = 0
for i in range(1,len(s)):
  if s[i-1] == s[i]:
    t = list(s)
    t[i] = "A"
    cnt += 1
    s = "".join(t)
if s[0] == s[-1]:
  print(cnt*n+n-1)
else:
  print(cnt*n)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
c = 0
b = 0
t = 0
for ci in s:
    if ci == s[0]:
        t += 1
    else:
        break
memo = [0]
for c1, c2 in zip(s[:], s[1:]):
    if not memo[-1] and c1 == c2:
        c += 1
        memo.append(1)
    else:
        memo.append(0)
if not memo[-1] and s[-1] == s[0] and t % 2:
    b = 1
print(k * c + b * (k - 1))

Submission status: Wrong Answer

Solution code:
from sys import stdin

S = stdin.readline().rstrip()
K = int(stdin.readline().rstrip())
ans_odd = 0
ans_even = 0
changed_odd = [False] * len(S)
changed_even = [False] * len(S)

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

for i in range(1, len(S)):
    if S[i] == S[i - 1] and not changed_odd[i - 1]:
        ans_odd += 1
        changed_odd[i] = True

if S[0] == S[len(S) - 1] and not changed_odd[len(S) - 1]:
    ans_odd += 1
    changed_even[0] = True

for i in range(1, len(S)):
    if S[i] == S[i - 1] and not changed_even[i - 1]:
        ans_even += 1
        changed_even[i] = True

if K % 2 == 0:
    print((ans_odd + ans_even) * (K // 2))
else:
    print((ans_odd + ans_even) * (K // 2) + ans_even)

Submission status: Wrong Answer

Solution code:
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

s = ns()
k = ni()

w = s[0]
a = []
count = 1
for i in s[1:]:
    if w == i:
        count += 1
    else:
        a.append(count)
        count = 1
        w = i
if s.count(s[0]) == len(s):
    ans = len(s) * k // 2
elif w != s[0]:
    a.append(count)
    ans = 0
    for i in a:
        ans += i // 2
    ans = ans * k
else:
    al = a[0]
    ar = count
    ans = 0
    for i in a[1:]:
        ans += i // 2
    ans = ans * k
    ans += al //2 + ar //2
    ans += (al + ar) * (k -1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
ans = 0
if len(S) == 1:
  print(K//2);exit()
elif len(S) == 2:
  if S[0] ==  S[1]:
    ans += 1
else:
  for i in range(0,len(S)-2,1):
    s = S[i:i+3]
    if s[0] == s[1] and s[1] == s[2]:
      ans += 1
      S[i+1] = "0"
    elif s[0] == s[1]:
      ans += 1
      S[i+1] = "0"
    elif s[1] == s[2]:
      ans += 1
      S[i+2] = "0"
if S[0] == S[-1]:
  print(ans*K+1)
else:
  print(ans*K)

Submission status: Wrong Answer

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

if C%2 != 0:
  print(change*k)
else:
  print(change*k + k-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

ans = count * k

if s[0] == s[-1]:
    tail = 1  
    for i in range(len(s) - 2, 0, -1):
        if s[i] == s[-1]:
            tail += 1
        else:
            break
    
    if tail % 2 == 1:
        print(ans + (k - 1))
    
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
cnt = 0
cntw = 0
i = 0

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

while True:
    if len(s)-1 < i:
        break
    if len(s)-1 == i:
        if s[i] == s[0]:
            cntw = 1
    elif s[i] == s[i+1]:
        cnt+= 1
        i += 1
    i += 1


ans = cnt*k+cntw*(k-1)
print(ans)