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())
s = list(S)
c1 = 0
for i in range(len(s)-1):
    if s[i+1] == s[i]:
        c1 += 1
        s[i+1] = 0
s = list(S*2)
c2 = 0
for i in range(len(s)-1):
    if s[i+1] == s[i]:
        c2 += 1
        s[i+1] = 0
print(c1+(c2-c1)*(K-1))

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
s = S*2
c1 = 0
c2 = 0
for i in range(2*len(S)-1):
    if s[i+1] == s[i]:
        s[i+1] = 0
        if i<len(S)-1:
            c1 += 1
        c2 += 1
print(c1+(c2-c1)*(K-1))

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
s = S*2
c1 = 0
c2 = 0
for i in range(2*len(S)-1):
    if s[i+1] == s[i]:
        s[i+1] = 0
        if i<len(S):
            c1 += 1
        c2 += 1
print(c1+(c2-c1)*(K-1))

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
s = S*2
c1 = 0
c2 = 0
for i in range(2*len(S)-1):
    if s[i] == s[i-1]:
        s[i] = 0
        if i<len(S):
            c1 += 1
        c2 += 1
print(c1+(c2-c1)*(K-1))

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
import copy
num=1
liS=[]

for i in range(len(S)-1):
    if S[i]==S[i+1]:
        num+=1
    else:
        liS.append(num)
        num=1
liS.append(num)



liSR=copy.copy(liS)
liSR[0]+=liSR[-1]
del liSR[-1]



if liSR!=[] and S[0]==S[-1]:
    for j in range(len(liS)):
        liS[j]=liS[j]//2
    for k in range(len(liSR)):
        liSR[k]=liSR[k]//2

    print(sum(liS)*(K-1)+sum(liSR))

elif liSR!=[] and S[0]!=S[-1]:
    for j in range(len(liS)):
        liS[j]=liS[j]//2
    print(sum(liS)*K)

else:
    print((sum(liS)*K)//2)

Submission status: Wrong Answer

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

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

ans += cnt*k

if ans > 0:
    s +="#"

else:
    if s[0] == s[-1]:
        ans +=k-1

print(ans)

Submission status: Wrong Answer

Solution code:
def solver(s, k):
    res = 0
    cnt = [1]
    for i in range(1, len(s)):
        if s[i] == s[i - 1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
    for x in cnt:
        res += (x // 2) * k

    if cnt == len(s): #全部同じ場合はここで返す
        return (len(s) * k) // 2

    if s[0] == s[-1]:
        res -= (cnt[0] // 2) * (k - 1) + (cnt[-1] // 2) * (k - 1)
        res += ((cnt[0] + cnt[-1]) // 2) * (k - 1)
    return res

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

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

#ss = s
#kk = k
print(solver(s, k))
#print(solver2(ss, kk))

#　ランダムな英小文字列の生成
import random
import string

# n := 文字列の長さ
def randomCharacter(n):
   alphabet_m = string.ascii_lowercase
   return ''.join([random.choice(alphabet_m) for _ in range(n)])


#for i in range(40):
#    if i == 0:
#        st = 'aaaaaaaaa'
#    elif i == 1:
#        st = 'a'
#    else:
#        l = random.randrange(1, 10)
#        st = randomCharacter(l)
#    sstt = st
#    cnt = 4
#    cnst_st = st[:]
#    res1 = solver(st, cnt)
#    res2 = solver2(sstt, cnt)
#    if res1 == res2:        
#        print("OK!")
#    else:
#        print(''.join(cnst_st), res1, res2)

Submission status: Wrong Answer

Solution code:
def solver(s, k):
    res = 0
    cnt_continue = 1
    for i in range(1, len(s)):
        if s[i] == s[i - 1]:
            cnt_continue += 1
        else:
            res += (cnt_continue // 2) * k
            cnt_continue = 1

    res += (cnt_continue // 2) * k

    if cnt_continue == len(s): #全部同じ場合はここで返す
        return (len(s) * k) // 2

    if s[0] == s[-1]:
        
        #最初のやつと同じものの個数
        first_equal = 0
        for i in range(len(s)):
            if s[i] == s[0]:
                first_equal += 1
            else:
                break
        
        #最後のやつと同じものの個数
        last_equal = 0
        for i in range(-1, -len(s)-1, -1):
            if s[i] == s[-1]:
                last_equal += 1
            else:
                break
        
        res -= (first_equal // 2) * k + (last_equal // 2) * (k - 1)
        res += ((first_equal + last_equal) // 2) * (k - 1)
    return res

def solver2(s, k):
    t = []
    for _ in range(k):
        t += s
    res = 0
    cnt_continue = 1
    for i in range(1, len(t)):
        if t[i] == t[i - 1]:
            cnt_continue += 1
        else:
            res += cnt_continue // 2
            cnt_continue = 1
    res += cnt_continue // 2
    return res

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

#ss = s
#kk = k
print(solver(s, k))
#print(solver2(ss, kk))

#　ランダムな英小文字列の生成
import random
import string

# n := 文字列の長さ
def randomCharacter(n):
   alphabet_m = string.ascii_lowercase
   return ''.join([random.choice(alphabet_m) for _ in range(n)])


#for i in range(40):
#    if i == 0:
#        st = 'aaaaaaaaa'
#    elif i == 1:
#        st = 'a'
#    else:
#        l = random.randrange(1, 10)
#        st = randomCharacter(l)
#    sstt = st
#    cnt = 4
#    cnst_st = st[:]
#    res1 = solver(st, cnt)
#    res2 = solver2(sstt, cnt)
#    if res1 == res2:        
#        print("OK!")
#    else:
#        print(''.join(cnst_st), res1, res2)

Submission status: Wrong Answer

Solution code:
def solver(s, k):
    res = 0
    cnt_continue = 1
    for i in range(1, len(s)):
        if s[i] == s[i - 1]:
            cnt_continue += 1
        else:
            res += cnt_continue // 2 * k
            cnt_continue = 1

    res += cnt_continue // 2 * k

    if cnt_continue == len(s): #全部同じ場合はここで返す
        return len(s) * k // 2

    if len(s) > 1:
        if s[0] == s[-1]:
            
            #最初のやつと同じものの個数
            first_equal = 0
            for i in range(len(s)):
                if s[i] == s[0]:
                    first_equal += 1
                else:
                    break

            #最後のやつと同じものの個数
            last_equal = 0
            for i in range(-1, -len(s)-1, -1):
                if s[i] == s[-1]:
                    last_equal += 1
                else:
                    break
            res -= first_equal // 2 * k + last_equal // 2 * (k - 1)
            res += (first_equal + last_equal) // 2 * (k - 1)
    return res

def solver2(s, k):
    t = []
    for _ in range(k):
        t += s
    res = 0
    cnt_continue = 1
    for i in range(1, len(t)):
        if t[i] == t[i - 1]:
            cnt_continue += 1
        else:
            res += cnt_continue // 2
            cnt_continue = 1
    res += cnt_continue // 2
    return res

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

#ss = s
#kk = k
print(solver(s, k))
#print(solver2(ss, kk))

#　ランダムな英小文字列の生成
import random
import string

# n := 文字列の長さ
def randomCharacter(n):
   alphabet_m = string.ascii_lowercase
   return ''.join([random.choice(alphabet_m) for _ in range(n)])


#for i in range(40):
#    if i == 0:
#        st = 'aaaaaaaaa'
#    else:
#        st = randomCharacter(9)
#    sstt = st
#    cnt = 4
#    cnst_st = st[:]
#    res1 = solver(st, cnt)
#    res2 = solver2(sstt, cnt)
#    if res1 == res2:        
#        print("OK!")
#    else:
#        print(''.join(cnst_st), res1, res2)
#        
#

Submission status: Wrong Answer

Solution code:
import math
from collections import deque


def main():
    s = list(input())
    k = int(input())
    cnt = 0
    for i in range(len(s)-1):
        if s[i + 1] == s[i]:
            cnt += 1
            s[i+1] = "#"
    if s[-1] != "#" and s[-1] == s[0]:
        cnt += 1
    cnt *= k
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
from collections import deque


def main():
    s = list(input())
    k = int(input())
    cnt = 0
    for i in range(len(s)-1):
        if s[i + 1] == s[i]:
            cnt += 1
            s[i+1] = "#"
    if s[-1] == s[0]:
        cnt += 1
    cnt *= k
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
l = [1]*n
'''
S = set(s)
n1 = len(s)
n2 = len(S)
l = [0]*n1

for i in range(n2):
    for j in range(n1):
        temp = 0
        chk = 0
        if s[i] == s[j]:
            l[chk] += 1
        else:
            chk += 1
'''

chk = 0
temp = 0
for i in range(n-1):
    if s[(i+1)%n] == s[i]:
        l[chk] += 1
        if s[0] == s[n-1]:
            temp = 1
    else:
        chk += 1

memo = 0
edge = 0
ans = 0
for i in range(n-1,-1,-1):
    if l[i] != 1 and memo == 0 and temp == 1:
        memo += 1
        edge = i
    ans += k*(l[i]//2)

if temp == 1 and l[1] != 1: 
    if (l[0] + l[edge]) % 2 == 0 and l[0] % 2 == 1:
        ans += k-1
elif temp == 1:
    if l[0] % 2 == 1:
        ans += k//2

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
l = [1]*n
'''
S = set(s)
n1 = len(s)
n2 = len(S)
l = [0]*n1

for i in range(n2):
    for j in range(n1):
        temp = 0
        chk = 0
        if s[i] == s[j]:
            l[chk] += 1
        else:
            chk += 1
'''

chk = 0
temp = 0
for i in range(n-1):
    if s[(i+1)%n] == s[i]:
        l[chk] += 1
        if s[0] == s[n-1]:
            temp = 1
    else:
        chk += 1

memo = 0
edge = 0
ans = 0
for i in range(n-1,-1,-1):
    if l[i] != 1 and memo == 0 and temp == 1:
        memo += 1
        edge = i + 1
    ans += k*(l[i]//2)

if temp == 1: 
    front = 0
    rear = 0
    for i in range(edge):
        if s[i] == s[0]:
            front += 1
    for i in range(edge-1,-1,-1):
        if s[i] == s[edge - 1]:
            rear += 1
    if (front + rear) % 2 == 0 and front % 2 == 1:
        ans += k-1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
l = [1]*n
'''
S = set(s)
n1 = len(s)
n2 = len(S)
l = [0]*n1

for i in range(n2):
    for j in range(n1):
        temp = 0
        chk = 0
        if s[i] == s[j]:
            l[chk] += 1
        else:
            chk += 1
'''

chk = 0
temp = 0
for i in range(n-1):
    if s[(i+1)%n] == s[i]:
        l[chk] += 1
        if s[0] == s[n-1]:
            temp = 1
    else:
        chk += 1

memo = 0
edge = 0
ans = 0
for i in range(n-1,-1,-1):
    if l[i] != 1 and memo == 0 and temp == 1:
        memo += 1
        edge = i + 1
    ans += k*(l[i]//2)

if temp == 1: 
    front = 0
    rear = 0
    for i in range(edge):
        if s[i] == s[0]:
            front += 1
    for i in range(edge-1,-1,-1):
        if s[i] == s[edge - 1]:
            rear += 1
    if (front + rear) % 2 == 0 and front % 2 == 1:
        ans += k-1

print(ans,l)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
ans=0
last=S[0]
cnt=1
if len(set(S))>1:
    for i in range(1,len(S)):
        if S[i]==last:
            cnt+=1
        else:
            ans+=cnt//2
            cnt=1
            last=S[i]
    ans+=cnt//2
    ans*=K
else:
    ans=len(S)*K//2
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
ans=0
moji=S[0]
if len(set(S))>1:
    for i in range(1,len(S)):
        if moji[i-1]==S[i]:
            ans+=1
            moji+='A'
        else:
            moji+=S[i]
    ans*=K
    if moji[0]==moji[-1]:
        ans+=K-1
else:
    ans=len(S)*K//2
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
ans=0
moji=S[0]
for i in range(1,len(S)):
    if moji[i-1]==S[i]:
        ans+=1
        moji+='A'
    else:
        moji+=S[i]
ans*=K
if moji[0]==moji[-1]:
    ans+=K-1
if len(S)>2 and len(set(S))==1 and K>2:
    ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
ans=0
moji=S[0]
for i in range(1,len(S)):
    if moji[i-1]==S[i]:
        ans+=1
        moji+='A'
    else:
        moji+=S[i]
ans*=K
if moji[0]==moji[-1]:
    ans+=K-1
if len(set(S))==1 and K>2:
    ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
ans=0
moji=S[0]
for i in range(1,len(S)):
    if moji[i-1]==S[i]:
        ans+=1
        moji+='A'
    else:
        moji+=S[i]
ans*=K
if moji[0]==moji[-1]:
    ans+=K-1
print(ans)

Submission status: Wrong Answer

Solution code:

S=input()
K=int(input())
li=[0]*3
li1=0
a=False
SSS=S+S+S

if K>=2:
    for i in range(3*len(S)-1):
        if SSS[i]==SSS[i+1]:
            if a==True:
                li[i//len(S)]+=1
                a=False
            else:
                a=True
        else:
            if a==True:
                li[i//len(S)]+=1
            a=False
        if i==3*len(S)-2:
            if a==True:
                li[2]+=1
    if (K-1)%2==0:
        print((li[0]+li[1])*(K-1)//2+li[2])
    else:
        print(li[0]*(((K-1)//2)+1)+li[1]*(((K-1)//2))+li[2])
if K==1:
    for i in range(len(S)-1):
        if S[i]==S[i+1] and a==True:
            a=False
            li1+=1
        else:
            a=True
    print(li1)

Submission status: Wrong Answer

Solution code:

S=input()
K=int(input())
li=[0]*3
li1=0
a=False
SSS=S+S+S

if K>=2:
    for i in range(3*len(S)-1):
        if SSS[i]==SSS[i+1]:
            if a==True:
                li[i//len(S)]+=1
                a=False
            else:
                a=True
        else:
            if a==True:
                li[i//len(S)]+=1
            a=False
        if i==3*len(S)-2:
            if a==True:
                li[2]+=1
    if (K-1)%2==0:
        print((li[0]+li[1])*(K-1)//2+li[2])
    else:
        print(li[0]*(((K-1)//2)+1)+li[1]*(((K-1)//2)+1))
if K==1:
    for i in range(len(S)-1):
        if S[i]==S[i+1] and a==True:
            a=False
            li1+=1
        else:
            a=True
    print(li1)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
li=[0]*3
li1=0
li2=0
a=True
SSS=S+S+S
SS=S+S
if K>=3:
    for i in range(3*len(S)-1):
        if SSS[i]==SSS[i+1] and a==True:
            a=False
            li[i//len(S)]+=1
        else:
            a=True
    print(li[0]+li[1]*(K-2)+li[2])
if K==1:
    for i in range(len(S)-1):
        if S[i]==S[i+1] and a==True:
            a=False
            li1+=1
        else:
            a=True
    print(li1)
if K==2:
    for i in range(2*len(S)-1):
        if SS[i]==SS[i+1] and a==True:
            a=False
            li2+=1
        else:
            a=True
    print(li2)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
li=[0]*3
a=True
ans=0
SSS=S+S+S

if K>=2:
    for i in range(3*len(S)-1):
        if SSS[i]==SSS[i+1] and a==True:
            a=False
            ans+=1
            li[i//len(S)]+=1
        else:
            a=True
    print(li[0]+li[1]*(K-2)+li[2])
if K==1:
    for i in range(len(S)-1):
        if S[i]==S[i+1] and a==True:
            a=False
            ans+=1
            li[i//len(S)]+=1
        else:
            a=True
    print(li[0])

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
li=[0]*3
a=True
ans=0
SSS=S+S+S

if K>=2:
    for i in range(3*len(S)-1):
        print(i,li)
        if SSS[i]==SSS[i+1] and a==True:
            a=False
            ans+=1
            li[i//len(S)]+=1
        else:
            a=True
    print(li[0]+li[1]*(K-2)+li[2])
if K==1:
    for i in range(len(S)-1):
        print(i,li)
        if S[i]==S[i+1] and a==True:
            a=False
            ans+=1
            li[i//len(S)]+=1
        else:
            a=True
    print(li[0])

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
li=[0]*3
a=True
ans=0
SSS=S+S+S

for i in range(3*len(S)-1):
    if SSS[i]==SSS[i+1] and a==True:
        a=False
        ans+=1
        li[i//len(S)]+=1
    else:
        a=True

if K>=2:
    print(li[0]+li[1]*(K-2)+li[2])
if K==1:
    print(li[0])

Submission status: Wrong Answer

Solution code:
def solver(s, k):
    res = 0
    
    for i in range(1, len(s)):
        if s[i] == s[i - 1]:
            s[i] = 'A'
            res += k
    
    if len(s) > 1:
        if s[0] == s[-1]:
            res += k - 1
            if s[0] == s[1]:
                res -= 1
    else:
        res = k // 2
    return res

def solver2(s, k):
    t = []
    for _ in range(k):
        t += s
    res = 0
    for i in range(1, len(t)):
        if t[i] == t[i - 1]:
            t[i] = 'A'
            res += 1
    return res, t

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

# ss = s[:]
# kk = k
print(solver(s, k))
# print(solver2(ss, kk))

Submission status: Wrong Answer

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

ans = 0

for i in range(1, len(s)):
    if s[i] == s[i - 1]:
        s[i] = 'A'
        ans += k

if s[0] == s[-1]:
    ans += k - 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
l = [1]*n
'''
S = set(s)
n1 = len(s)
n2 = len(S)
l = [0]*n1

for i in range(n2):
    for j in range(n1):
        temp = 0
        chk = 0
        if s[i] == s[j]:
            l[chk] += 1
        else:
            chk += 1
'''

chk = 0
temp = 0
for i in range(n):
    if s[(i+1)%n] == s[i]:
        l[chk] += 1
        if s[0] == s[n-1]:
            temp = 1
    else:
        chk += 1

zero = 0
edge = 0
ans = 0
for i in range(n-1,-1,-1):
    if l[i] != 1 and zero == 0 and temp == 1:
        zero += 1
        edge = i
        ans += (k//2)*(l[i]//2) + ((k + 1)//2)*((l[i] - 1)//2)
    else:
        ans += k*(l[i]//2)

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
l = [0]*n
'''
S = set(s)
n1 = len(s)
n2 = len(S)
l = [0]*n1

for i in range(n2):
    for j in range(n1):
        temp = 0
        chk = 0
        if s[i] == s[j]:
            l[chk] += 1
        else:
            chk += 1
'''

chk = 0
temp = 0
for i in range(n):
    if s[(i+1)%n] == s[i]:
        l[chk] += 1
        if s[0] == s[n-1]:
            temp = 1
    else:
        chk += 1

zero = 0
edge = 0
ans = 0
for i in range(n-1,-1,-1):
    if l[i] != 0 and zero == 0 and temp == 1:
        zero += 1
        edge = i
        ans += (k//2)*((l[i] + 1)//2) + ((k + 1)//2)*(l[i]//2)
    else:
        ans += k*((l[i] + 1)//2)

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
l = [0]*n
'''
S = set(s)
n1 = len(s)
n2 = len(S)
l = [0]*n1

for i in range(n2):
    for j in range(n1):
        temp = 0
        chk = 0
        if s[i] == s[j]:
            l[chk] += 1
        else:
            chk += 1
'''

chk = 0
for i in range(n):
    if s[(i+1)%n] == s[i]:
        l[chk] += 1
        if s[0] == s[n-1]:
            temp = 1
    else:
        chk += 1

zero = 0
edge = 0
ans = 0
for i in range(n-1,-1,-1):
    if l[i] != 0 and zero == 0:
        zero += 1
        edge = i
    ans += k*((l[i] + 1)//2)

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
l = [0]*n
'''
S = set(s)
n1 = len(s)
n2 = len(S)
l = [0]*n1

for i in range(n2):
    for j in range(n1):
        temp = 0
        chk = 0
        if s[i] == s[j]:
            l[chk] += 1
        else:
            chk += 1
'''

chk = 0
for i in range(n):
    if s[(i+1)%n] == s[i]:
        l[chk] += 1
        if s[0] == s[n-1]:
            temp = 1
    else:
        chk += 1

zero = 0
edge = 0
ans = 0
for i in range(n-1,-1,-1):
    if l[i] != 0 and zero == 0:
        zero += 1
        edge = i
    ans += k*((l[i] + 1)//2)

print(ans - (l[i]%2 == 1))

Submission status: Wrong Answer

Solution code:
from math import floor
s = input()
k = int(input())
x = s[0]
y = 1
ans = 0
for i in s[1:]:
    if i == x:
        y += 1
    else:
        ans += floor(y / 2)
        x = i
        y = 1
ans += floor(y / 2)
if len(set(s)) == 1 or s[0] != s[-1]:
    print(ans * k)
else:
    x = s[0]
    y = 1
    for i in s[1:]:
        if x == i:
            y += 1
        else:
            a = y
            break
    y = 0
    for i in s[::-1]:
        if x == i:
            y += 1
        else:
            b = y
            break
    print(ans * k - ((floor(a / 2) + floor(b / 2) - floor((a + b) / 2)) * (k - 1)))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s)
if s[0] != s[-1] or k == 1:
    ans = 0
    for i in range(1, n):
        if s[i] == s[i - 1]:
            ans += 1
            s[i] = ""
    print(ans*k)
else:
    cnt = 0
    for i in s[-1::-1]:
        if i == s[-1]:
            cnt += 1
        else:
            break
    if cnt % 2 == 0:
        if s == [s[0]]*n:
            print(n*k//2)
        else:
            ans = 0
            for i in range(1, n):
                if s[i] == s[i - 1]:
                    ans += 1
                    s[i] = ""
            print(ans*k)
    else:
        if s == [s[0]]*n:
            print(n*k//2)
        else:
            ans = 0
            for i in range(1, n):
                if s[i] == s[i -1]:
                    s[i] = ""
                    ans += 1
            print(ans*k - k + 1)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s)
if s[0] != s[-1] or k == 1:
    ans = 0
    for i in range(1, n):
        if s[i] == s[i - 1]:
            ans += 1
            s[i] = ""
    print(ans*k)
else:
    cnt = 0
    for i in s[-1::-1]:
        if i == s[-1]:
            cnt += 1
        else:
            break
    if cnt % 2 == 0:
        ans = 0
        for i in range(1, n):
            if s[i] == s[i - 1]:
                ans += 1
                s[i] = ""
        print(ans*k)
    else:
        if s == [s[0]]*n:
            print(n*k//2)
        else:
            ans = 0
            for i in range(1, n):
                if s[i] == s[i -1]:
                    s[i] = ""
                    ans += 1
            print(ans*k - k + 1)

Submission status: Wrong Answer

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

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

print(ans*k + j*(k - 1))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
ans = 0
j = 0
if len(s) != 1 and s[-1] == s[0] and s[-1] != s[-2]:
    j = 0
for i in range(1, len(s)):
    if s[i] == s[i-1]:
        ans += 1
        s[i] = ""

print(ans*k + j*(k - 1))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
ans = 0
if len(s) == 1:
    print(k - 1)
    exit()
for i in range(1, len(s)):
    if s[i] == s[i -1]:
        ans += 1
        s[i] = ""
j = 0
if s[-1] == s[0]:
    if s[-1] != s[-2]:
        j = 1

print(ans*k - j*(k - 1))

Submission status: Wrong Answer

Solution code:
s = str(input())
k = int(input())
a = s[0]
b = [s[0]]
n = 0
m = 0
for i in range(1, len(s)):
    if a == s[i]:
        a = 0
        n += 1
    else:
        a = s[i]
    b.append(a)
#print(b)
if b[0] == b[len(b)-1]:
    m += 1

print(n*k-m*(k-1))

Submission status: Wrong Answer

Solution code:
from math import floor
s = list(input())
k = int(input())
if len(set(s)) == 1:
    print(floor(len(s) * k / 2))
    exit(0)
s.append(s[0])
x = s[0]
y = 0
z = 0
for i in range(len(s)):
    if s[i] != x:
        z += floor((i - y) / 2)
        x = s[i]
        y = i
z += floor((len(s) - 1 - y) / 2)
print(z * k)

Submission status: Wrong Answer

Solution code:
from math import floor
s = list(input())
k = int(input())
s.append(s[0])
x = s[0]
y = 0
z = 0
for i in range(len(s)):
    if s[i] != x:
        z += floor((i-y) / 2)
        x = s[i]
        y = i
z += floor((len(s)-1-y) / 2)
print(z * k)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
ans = 0
if s[0] == s[-1]:
    s[-1] = '8'
    ans += 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        s[i+1] = '9'
        ans += 1
print(ans * k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

# A - Connection and Disconnection
def count_operation(s, c):
	count_ = s.count(c*2)

	while c*3 in s:
		s = s.replace(c*3, c+'_'+c)

	while c*2 in s:
		s = s.replace(c*2, c+'_')

	return min(count_, s.count('_'))


def is_special_case(c):
	global S

	if S.endswith(c*3):
		return True
	elif S.startswith(c) and S.endswith(c):
		if not S.endswith(c*2):
			return True


import string

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

lower = string.ascii_lowercase

ans = 0
is_special = False

for c in lower:
	ans += count_operation(S+S[0], c) * K

	if is_special_case(c):
		ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
# A - Connection and Disconnection
def count_operation(T, c):
	count_ = T.count(c*2)
	
	T = T.replace(c*3, c+'_'+c)
	T = T.replace(c*2, c+'_')
	
	return min(count_, T.count('_'))



def is_special_case(c):
	global S
	
	if S.endswith(c*3):
		return True
	elif S.startswith(c) and S.endswith(c):
		if not S.endswith(c*2):
			return True


import string

S = input()
K = int(input())
T = S + S[0]

lower = string.ascii_lowercase

ans = 0
is_special = False

for c in lower:
	ans += count_operation(T, c) * K
	
	if is_special_case(c):
		ans -= 1	

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

# A - Connection and Disconnection
def count_operation(T, c):
	count_ = T.count(c*2)

	T = T.replace(c*3, c+'_'+c)
	T = T.replace(c*2, c+'_')

	return min(count_, T.count('_'))


import string

S = input()
K = int(input())
T = S + S[0]

lower = string.ascii_lowercase

ans = 0
is_special_case = False

for c in lower:
	ans += count_operation(T, c)

	if S.startswith(c) and S.endswith(c):
		if not S.endswith(c*2):
			is_special_case = True

ans *= K

if is_special_case:
	ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
# A - Connection and Disconnection
def count_operation(S, c):
	count = S.count(c * 3)
	
	if count > 0:
		S = S.replace(c * 3, c + '_' + c)
	
	count += S.count(c * 2)
	
	return count


import string

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

lower = string.ascii_lowercase
ans = 0

for c in lower:
	ans += count_operation(S + S[0], c) * (K - 1)	
	ans+= count_operation(S, c)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

# A - Connection and Disconnection
def is_special_case(c):
	global T

	if T.endswith(c * 2):
		if not T.endswith(c * 3):
			return True


import string

S = input()
K = int(input())
T = S + S[0]

lower = string.ascii_lowercase
ans = 0
is_special = False

for c in lower:
	ans += T.count(c * 2)

	if is_special_case(c):
		is_special = True

ans *= K

if is_special:
	print(ans - 1)
else:
	print(ans)

Submission status: Wrong Answer

Solution code:
import sys

# A - Connection and Disconnection
import string

S = input()
K = int(input())
T = S + S[0]

lower = string.ascii_lowercase
ans = 0
is_specila_case = False

for c in lower:
	key = c * 2
	ans += T.count(key)

	if T.endswith(key):
		is_specila_case = True

ans *= K

if is_specila_case:
	print(ans - 1)
else:
	print(ans)

Submission status: Wrong Answer

Solution code:
import sys

# A - Connection and Disconnection
import string

S = input()
K = int(input())
T = S + S[0]

lower = string.ascii_lowercase
ans = 0

for c in lower:
	key = c * 2
	ans += T.count(key)

print(ans * K)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = input()
    k = int(input())

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

    if k == 1:
        r2 = 0
        rt = 1
        c = ""
        flag = False
        for se in s:
            if c == se:
                flag = True
                rt += 1
            else:
                c = se
                if flag:
                    r2 += rt // 2
                    rt = 1
                    flag = False
        r2 += rt // 2
        print(r2)
        sys.exit()

    s_daburi = 0
    s_last = s[-1]
    while s_daburi < lens:
        if s[s_daburi] == s_last:
            s_daburi += 1
        else:
            break
    s1 = s + s_last * s_daburi
    s2 = s[s_daburi:]

    r2 = 0
    rt = 1
    c = ""
    flag = False
    for se in s1:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
    r2 += rt // 2

    if s_daburi == lens:
        if k % 2 == 0:
            r = r2 * (k // 2)
            print(r)
            sys.exit()
        else:
            r = r2 * (k // 2) + lens//2
            print(r)
            sys.exit()

    r = r2 * (k - 1)
    r2 = 0
    rt = 1
    c = ""
    flag = False
    for se in s2:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
    r2 += rt // 2
    r += r2
    print(r)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = input()
    k = int(input())

    if len(s) == 1:
        r = k // 2
        print(r)
        sys.exit()
    r1 = s[0] == s[-1]
    if r1 == 1 and s[-1] == s[-2]:
        r1 = 0
    r2 = 0
    rt = 1
    c = ""
    flag = False
    for se in s:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
    r2 += rt // 2
    r = r1 * (k - 1) + r2 * k
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = input()
    k = int(input())

    if len(s) == 1:
        r = k // 2
        print(r)
        sys.exit()
    r1 = s[0] == s[-1]
    if r1 == 1 and s[-1] == s[-2]:
        r1 = 0
    r2 = 0
    rt = 1
    c = ""
    flag = False
    for se in s:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
    r = r1 * (k - 1) + r2 * k
    print(r)

if __name__ == '__main__':
    main()