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())
cnt=1
l=[]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        cnt+=1
    else:
        l.append(cnt)
        cnt=1
l.append(cnt)
loop=0
ans=0
for i in l:
    if i>1:
        ans+=i//2
if s[-1]==s[0]:
    if l[0]*l[-1]%2==1:
        loop=1
print(ans*k+loop*(k-1))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
cnt=1
l=[]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        cnt+=1
    else:
        l.append(cnt)
        cnt=1
l.append(cnt)
loop=0
ans=0
for i in l:
    if i>1:
        ans+=i//2
if s[-1]==s[0]:
    if l[0]==l[-1]==1:
        loop=1
print(ans*k+loop*(k-1))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
cnt=1
l=[]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        cnt+=1
    else:
        l.append(cnt)
        cnt=1
l.append(cnt)
loop=0
ans=0
for i in l:
    if i>1:
        ans+=i//2
if l[-1]==l[0]==1:
    loop=1
print(ans*k+loop*(k-1))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
cnt=1
l=[]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        cnt+=1
    else:
        l.append(cnt)
        cnt=1
l.append(cnt)
loop=0
ans=0
for i in l:
    if i>1:
        ans+=i//2
if s[-1]==s[0] and l[0]==1:
    if l[-1]>1 and l[-1]%2==0:
        loop=0
    else:
        loop=1
print(ans*k+loop*(k-1))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
cnt=1
l=[]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        cnt+=1
    else:
        l.append(cnt)
        cnt=1
l.append(cnt)
loop=0
ans=0
for i in l:
    if i>1:
        ans+=i//2
if s[-1]==s[0]:
    if l[-1]>1 and l[-1]%2==0:
        loop=0
    else:
        loop=1
print(ans*k+loop*(k-1))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
cnt=1
l=[]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        cnt+=1
    else:
        l.append(cnt)
        cnt=1
l.append(cnt)
loop=0
ans=0
for i in l:
    if i>1:
        ans+=i//2
if l[-1]>1 and l[-1]%2==1:
    loop=1
print(ans*k+loop*(k-1))

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
if len(S) == 1:
    print(K//2)
    exit()
count = 0
for i in range(1,len(S)):
    if S[i-1] != '○' and S[i-1] == S[i]:
        S[i] = '○'
        count += 1
if S[0] == S[-1] and S[-1] != '○':
    S[-1] = '○'
    count += 1
print(count*K)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
head = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        head += 1
    else:
        break
tail = 0
for i in range(len(s)-1):
    if s[len(s)-i-1] == s[len(s)-i-2]:
        tail += 1
    else:
        break
count = 0
tmp = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        tmp += 1
    else:
        count += tmp//2
        tmp = 1
count += tmp//2

if len(set(s))==1:
    print(len(s)*k//2)
else:
    if s[0] != s[1]:
        print(count*k)
    else:
        print(count*k-(head//2-tail//2+(head+tail)//2)*(k-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# A - Connection and Disconnection
# https://atcoder.jp/contests/agc039/tasks/agc039_a

S = input()
k = int(input())

SS = list(S + S)

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

print(((ans - 1) // 2 + 1) * k)

Submission status: Wrong Answer

Solution code:
# A - Connection and Disconnection
# https://atcoder.jp/contests/agc039/tasks/agc039_a

S = input()
k = int(input())

SS = list(S + S)

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

print(ans // 2 * k)

Submission status: Wrong Answer

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

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

N = len(S)

T = S + S

count1 = 0
for i in range(N - 1):
    if T[i] == T[i + 1]:
        T[i + 1] = '*'
        count1 += 1

count2 = 0
if K >= 2:
    for i in range(N - 1, 2 * N - 1):
        if T[i] == T[i + 1]:
            T[i + 1] = '*'
            count2 += 1
    ans = (count1 + count2) * (K // 2) + count1 * (K % 2)
    if T[0] == T[-1]:
        ans += (K // 2) - 1
    if K % 2 == 1 and T[-1] == T[0] and T[N - 1] == T[0]:
        ans += 1
    print (ans)

else:
    print (count1)

Submission status: Wrong Answer

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

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

N = len(S)

T = S + S

count1 = 0
for i in range(N - 1):
    if T[i] == T[i + 1]:
        T[i + 1] = '*'
        count1 += 1

count2 = 0
if K >= 2:
    for i in range(N - 1, 2 * N - 1):
        if T[i] == T[i + 1]:
            T[i + 1] = '*'
            count2 += 1
    ans = (count1 + count2) * (K // 2) + count1 * (K % 2)
    if T[0] == T[-1]:
        ans += (K // 2) - 1
    if K % 2 == 1 and T[-1] == S[0]:
        ans += 1
    print (ans)

else:
    print (count1)

Submission status: Wrong Answer

Solution code:
S = list(input())
import copy
T = copy.copy(S)
K = int(input())
N = len(S)
ans = 0


  
for i in range(N-1):
  if S[i] == S[i+1]:
    ans += 1
    S[i+1] = '0'
    
if K >1 and S[-1] == T[0]:
  ans += K-1
  T[0] = '0'
  
for i in range(N-1):
  if T[i] == T[i+1]:
    ans += K-1
    T[i+1] = '0'
    

print(ans)

Submission status: Wrong Answer

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

ans+=cont//2
print(ans*K)

Submission status: Wrong Answer

Solution code:
S = input().strip()
K = int(input())
T1 = S
N1 = len(T1)
cur = T1[0]
cnt = 1
ans1 = 0
for i in range(1,N1):
    if T1[i]==cur:
        cnt += 1
    else:
        ans1 += cnt//2
        cur = T1[i]
        cnt = 1
ans1 += cnt//2
T2 = S*2
N2 = len(T2)
cur = T2[0]
cnt = 1
ans2 = 0
for i in range(1,N2):
    if T2[i]==cur:
        cnt += 1
    else:
        ans2 += cnt//2
        cur = T2[i]
        cnt = 1
ans2 += cnt//2
d = ans2-ans1
if N1>1:
    print(ans1+d*(K-1))
else:
    print(K//2)

Submission status: Wrong Answer

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

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

N = len(S)

T = S + S

count1 = 0
for i in range(N - 1):
    if T[i] == T[i + 1]:
        T[i + 1] = '*'
        count1 += 1

count2 = 0
if K >= 2:
    for i in range(N - 1, 2 * N - 1):
        if T[i] == T[i + 1]:
            T[i + 1] = '*'
            count2 += 1
    ans = (count1 + count2) * (K // 2) + count1 * (K % 2)
    if T[0] == T[-1]:
        ans += (K // 2) - 1
    if K % 2 == 1 and T[-1] == S[0] and T[0] == S[-1]:
        ans += 1
    print (ans)

else:
    print (count1)

Submission status: Wrong Answer

Solution code:
S = input().strip()
K = int(input())
T1 = S
N1 = len(T1)
cur = T1[0]
cnt = 1
ans1 = 0
for i in range(1,N1):
    if T1[i]==cur:
        cnt += 1
    else:
        ans1 += cnt//2
        cur = T1[i]
        cnt = 1
ans1 += cnt//2
T2 = S*2
N2 = len(T2)
cur = T2[0]
cnt = 1
ans2 = 0
for i in range(1,N2):
    if T2[i]==cur:
        cnt += 1
    else:
        ans2 += cnt//2
        cur = T2[i]
        cnt = 1
ans2 += cnt//2
d = ans2-ans1
print(ans1+d*(K-1))

Submission status: Wrong Answer

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

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

N = len(S)

T = S + S

count1 = 0
for i in range(N - 1):
    if T[i] == T[i + 1]:
        T[i + 1] = '*'
        count1 += 1

count2 = 0
if K >= 2:
    for i in range(N - 1, 2 * N - 1):
        if T[i] == T[i + 1]:
            T[i + 1] = '*'
            count2 += 1
    ans = (count1 + count2) * (K // 2) + count1 * (K % 2)
    if T[0] == T[-1]:
        ans += (K // 2) - 1 + K % 2
    print (ans)

else:
    print (count1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import *

S = input()[:-1]
K = int(input())

if S==S[0]*len(S):
    print(len(S)*K//2)
    exit()
    
l = []
cnt = 1

for i in range(len(S)-1):
    if S[i]!=S[i+1]:
        l.append((S[i], cnt))
        cnt = 1
    else:
        cnt += 1
    
l.append((S[-1], cnt))

if K==1 or l[0][0]!=l[-1][0]:
    ans = 0
    
    for _, c in l:
        ans += c//2
else:
    ans = (l[0][1]+l[-1][1])//2
    
    for _, c in l[1:-1]:
        ans += c//2

print(ans*K)

Submission status: Wrong Answer

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

S1 = list(S)
cnt1 = 0
for i in range(1, len(S1)):
    if S1[i] == S1[i - 1]:
        S1[i] = '*'
        cnt1 += 1

S2 = list(S) * 2
cnt2 = 0
for i in range(1, len(S2)):
    if S2[i] == S2[i - 1]:
        S2[i] = '*'
        cnt2 += 1

# print("#", S1, S2)
# print("#", cnt1, cnt2)
ans = cnt1 + (cnt2 - cnt1) * (K - 1)
print(ans)

Submission status: Wrong Answer

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

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

N = len(S)

T = S + S

count1 = 0
for i in range(N - 1):
    if T[i] == T[i + 1]:
        T[i + 1] = '*'
        count1 += 1

count2 = 0
if K >= 2:
    for i in range(N - 1, 2 * N - 1):
        if T[i] == T[i + 1]:
            T[i + 1] = '*'
            count2 += 1
    ans = (count1 + count2) * (K // 2) + count1 * (K % 2)
    if T[0] == T[-1]:
        ans += (K // 2)
    print (ans)

else:
    print (count1)

Submission status: Wrong Answer

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

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

N = len(S)

T = S + S

count1 = 0
for i in range(N - 1):
    if T[i] == T[i + 1]:
        T[i + 1] = '*'
        count1 += 1

count2 = 0
if K >= 2:
    for i in range(N - 1, 2 * N - 1):
        if T[i] == T[i + 1]:
            T[i + 1] = '*'
            count2 += 1
    ans = (count1 + count2) * (K // 2) + count1 * (K % 2)
    if T[0] == T[-1]:
        ans += 1
    print (ans)

else:
    print (count1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import *

S = input()[:-1]
K = int(input())

if S==S[0]*len(S):
    print(len(S)*K//2)
    exit()
    
l = []
cnt = 1

for i in range(len(S)-1):
    if S[i]!=S[i+1]:
        l.append((S[i], cnt))
        cnt = 1
    else:
        cnt += 1

if K==1 or l[0][0]!=l[-1][0]:
    ans = 0
    
    for _, c in l:
        ans += c//2
else:
    ans = (l[0][1]+l[-1][1])//2
    
    for _, c in l[1:-1]:
        ans += c//2

print(ans*K)

Submission status: Wrong Answer

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

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

ss = s + s

shoko = 0
prev = ''
cnt = 0
for i in range(len(s)):
    if s[i] == prev:
        cnt += 1
    else:
        shoko += cnt // 2
        cnt = 1
    prev = s[i]
shoko += cnt // 2

kosa = 0
prev = ''
cnt = 0
for i in range(len(ss)):
    if ss[i] == prev:
        cnt += 1
    else:
        kosa += cnt // 2
        cnt = 1
    prev = ss[i]
kosa += cnt // 2
kosa -= shoko

print(shoko + (k-1)*kosa)

Submission status: Wrong Answer

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

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

N = len(S)

T = S + S

count1 = 0
for i in range(N - 1):
    if T[i] == T[i + 1]:
        T[i + 1] = '*'
        count1 += 1

count2 = 0
if K >= 2:
    for i in range(N - 1, 2 * N - 1):
        if T[i] == T[i + 1]:
            T[i + 1] = '*'
            count2 += 1
    ans = (count1 + count2) * (K // 2) + count1 * (K % 2)
    print (ans)

else:
    print (count1)

Submission status: Wrong Answer

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

ss = s + s

shoko = 0
prev = ''
cnt = 0
for i in range(len(s)):
    if s[i] == prev:
        cnt += 1
    else:
        shoko += cnt // 2
        cnt = 1
    prev = s[i]
shoko += cnt // 2

kosa = 0
prev = ''
cnt = 0
for i in range(len(ss)):
    if ss[i] == prev:
        cnt += 1
    else:
        kosa += cnt // 2
        cnt = 1
    prev = ss[i]
kosa += cnt // 2
kosa -= shoko

print(shoko + (k-1)*kosa)

Submission status: Wrong Answer

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

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

N = len(S)

count = 0
for i in range(N - 1):
    if S[i] == S[i + 1]:
        S[i + 1] = '*'
        count += 1

count *= K

if S[N - 1] == S[0]:
    count += K - 1

print (count)

Submission status: Wrong Answer

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

ans = 0
i = 1
if s.count(s[0]) == len(s):
    print(len(s) * k // 2)
    exit()
while i < len(s):
    cnt = 1
    if s[i] == s[i - 1] and i < len(s):
        i += 1
        cnt += 1
    ans += cnt // 2
    i += 1

cnt1 = 1
cnt2 = 1
if s[0] == s[len(s) - 1]:
    i = len(s) - 1
    while i != 0 and s[i] == s[i - 1]:
        cnt1 += 1
        i -= 1
    i = 0
    while i != len(s) - 1 and s[i] == s[i + 1]:
        cnt2 += 1
        i += 1
    cnt = cnt1 + cnt2
print(ans * k - (cnt1 // 2 + cnt2 // 2 - cnt // 2) * (k - 1))

Submission status: Wrong Answer

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

ans = 0
i = 1
if s.count(s[0]) == len(s):
    print(len(s) * k // 2)
    exit()
while i < len(s):
    cnt = 1
    if s[i] == s[i - 1] and i < len(s):
        i += 1
        cnt += 1
    ans += cnt // 2
    i += 1

cnt1 = 1
cnt2 = 1
if s[0] == s[len(s) - 1]:
    i = len(s) - 1
    while i != 0 and s[i] == s[i - 1]:
        cnt1 += 1
        i -= 1
    i = 0
    while i != len(s) - 1 and s[i] == s[i + 1]:
        cnt2 += 1
        i += 1
    cnt = cnt1 + cnt2
print(ans * k + (cnt1 // 2 + cnt2 // 2 - cnt // 2) * (k - 1))

Submission status: Wrong Answer

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

INNER = 0
  
if len(set(list(S))) == 1:
  print(K*len(S)//2)
else:
  only_S = 0
  count_same_from_start = 0
  flag_same_from_start = 0
  count_same_from_end = 0
  flag_same_from_end = 0
  
  
  i = 0
  while i < len(S)-1:
    if S[i] == S[i+1]:
      INNER += 1
      i += 1
    i += 1
  
  if (S[0] != S[-1])or(S[0]==S[1])or(S[len(S)-1]==S[len(S)-2]):#最初の文字と最後の文字が違うか、最後の2文字が同じなら、
    print(INNER*K)
  else:#最後の二文字が違うが、最初の文字と最後の文字が同じなら
    print(INNER*K + K-1)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
  
if len(set(list(S))) == 1:
  print(K*len(S)//2)
else:
  INNER = 0
  flag = 0
  
  i = 0
  while i < len(S)-1:
    if S[i] == S[i+1]:
      INNER += 1
      if i == len(S)-2:
        flag = 1
      i += 1
      
    i += 1

  if (S[0] != S[-1])or(flag==1):
    print(INNER*K)
  else:
    print(INNER*K + K-1)

Submission status: Wrong Answer

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

if len(S) == 1:
  print(K//2)
else:
  INNER = 0

  i = 0
  while i < len(S)-1:
    if S[i] == S[i+1]:
      INNER += 1
      i += 1
    i += 1

  if (S[0] != S[-1])or(S[-1]==S[-2]):#最初の文字と最後の文字が違うか、最後の2文字が同じなら、
    print(INNER*K)
  else:#最後の二文字が違うが、最初の文字と最後の文字が同じなら
    print(INNER*K + K-1)

Submission status: Wrong Answer

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

ans = 0
i = 1
while i < len(s):
    cnt = 1
    if s[i] == s[i - 1] and i < len(s):
        i += 1
        cnt += 1
    ans += cnt // 2
    i += 1
cnt = 0
if s[0] == s[len(s) - 1] and s[len(s) - 1] != s[len(s) - 2]:
    cnt += 1
print(ans * k + cnt * (k - 1))

Submission status: Wrong Answer

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

ans = 0
i = 1
while i < len(s):
    cnt = 1
    if s[i] == s[i - 1] and i < len(s):
        i += 1
        cnt += 1
    ans += cnt // 2
    i += 1
if s[0] == s[len(s) - 1] and s[len(s) - 1] != s[len(s) - 2]:
    ans += 1
print(ans * k)

Submission status: Wrong Answer

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

ans = 0
i = 1
while i < len(s):
    cnt = 1
    if s[i] == s[i - 1] and i < len(s):
        i += 1
        cnt += 1
    ans += cnt // 2
    i += 1
print(ans * k)

Submission status: Wrong Answer

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

flag = []

N = len(S)
for i in range(N):
    if i == N - 1:
        if S[i] == S[0]:
            flag.append(1)
        else:
            flag.append(0)
    else:
        if S[i]==S[i+1]:
            flag.append(1)
        else:
            flag.append(0)

flag_2 = []
for i in range(N):
    flag_2.append(0)

for i in range(N):
    if flag[i] == 1:
        k = 0
        count = 0
        while((i == 0 or flag[i-1] == 0) and (i + k) < N and flag[i + k] == 1):
            k += 1
            count += 1
        flag_2[i] = count

#print("flag",flag)
#print("flag2", flag_2)

ans = 0
cara = set()
for i in range(N):
    cara.add(S[i])
if len(cara) == 1:
    ans = N*K//2
else:

    if(S[0] != S[N-1]):
        for i in range(N-1):
            ans += (flag_2[i] + 1)//2

        ans = ans * K

    else:
        last = 0
        for i in range(N):
            if(flag_2[N - 1- i] != 0):
                last = N - 1 - i
                temp = flag_2[0] + flag_2[last] + 2
                break
        ans += temp//2 * (K - 1)
        for i in range(1, last):
            ans += (flag_2[i] + 1)//2 * K

print(ans)

Submission status: Wrong Answer

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

flag = []

N = len(S)
for i in range(N):
    if i == N - 1:
        flag.append(0)
    else:
        if S[i]==S[i+1]:
            flag.append(1)
        else:
            flag.append(0)

flag_2 = []
for i in range(N):
    flag_2.append(0)

for i in range(N):
    if flag[i] == 1:
        k = 0
        count = 0
        while((i == 0 or flag[i-1] == 0) and (i + k) < N and flag[i + k] == 1):
            k += 1
            count += 1
        flag_2[i] = count

ans = 0
cara = set()
for i in range(N):
    cara.add(S[i])
if len(cara) == 1:
    ans = N*K//2
else:

    if(S[0] != S[N-1]):
        for i in range(N):
            ans += (flag_2[i] + 1)//2

        ans = ans * K

    else:
        last = 0
        for i in range(N):
            if(flag_2[N - 1- i] != 0):
                last = N - 1 - i
                temp = flag_2[0] + flag_2[last] + 2
                break
        ans += temp//2 * (K - 1)
        for i in range(1, last):
            ans += (flag_2[i] + 1)//2 * K

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

sum_cnt *= K
if S[0] == S[-1] and S[-1] != S[-2]:
    sum_cnt += K-1
print(sum_cnt)

Submission status: Wrong Answer

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

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

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

sum_cnt *= K
if S[0] == S[-1]:
    sum_cnt += K-1
print(sum_cnt)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

flag = []

N = len(S)
for i in range(N):
    if i == N - 1:
        if S[i] == S[0]:
            flag.append(1)
        else:
            flag.append(0)
    else:
        if S[i]==S[i+1]:
            flag.append(1)
        else:
            flag.append(0)

flag_2 = []
for i in range(N):
    flag_2.append(0)

for i in range(N):
    if flag[i] == 1:
        k = 0
        count = 0
        while((i == 0 or flag[i-1] == 0) and (i + k) < N and flag[i + k] == 1):
            k += 1
            count += 1
        flag_2[i] = count


ans = 0
cara = set()
for i in range(N):
    cara.add(S[i])
if len(cara) == 1:
    ans = N*K//2
else:

    if(S[0] != S[N-1]):
        for i in range(N):
            ans += (flag_2[i] + 1)//2

        ans = ans * K

    else:
        last = 0
        for i in range(N):
            if(flag_2[N - 1- i] != 0):
                last = N - 1 - i
                temp = flag_2[0] + flag_2[last] + 2
                break
        ans += temp//2 * (K - 1)
        for i in range(1, last):
            ans += (flag_2[i] + 1)//2 * K

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    S = input()
    K = int(input())
    if S[0] != S[-1]:
        ans = 0
        before = 0
        i = 0
        while i + 1 < len(S):
            while i + 1 < len(S) and S[i] == S[i + 1]:
                i += 1
            ans += (i + 1 - before)//2
            i += 1
            before = i
        print(ans*K)
    else:
        if len(set(S)) == 1:
            print(K*len(S)//2)
        else:
            i = 0
            while i + 1 < len(S) and S[i] == S[i + 1]:
                i += 1
            cut = i + 1
            L = (i + 1)//2
            i += 1
            
            before = 0
            R = 0
            while i + 1 < len(S):
                while i + 1 < len(S) and S[i] == S[i + 1]:
                    i += 1
                R += (i + 1 - before)//2
                i += 1
                before = i
            
            S = S[cut:] + S[:cut]
            ans = 0
            before = 0
            i = 0
            while i + 1 < len(S):
                while i + 1 < len(S) and S[i] == S[i + 1]:
                    i += 1
                ans += (i + 1 - before)//2
                i += 1
                before = i
            ans = ans*(K - 1) + R + L
            print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    S = input()
    K = int(input())
    if S[0] != S[-1]:
        ans = 0
        before = 0
        i = 0
        while i + 1 < len(S):
            while i + 1 < len(S) and S[i] == S[i + 1]:
                i += 1
            ans += (i + 1 - before)//2
            i += 1
            before = i
        print(ans*K)
    else:
        if len(set(S)) == 1:
            print(K*len(S)//2)
        else:
            i = 0
            while i + 1 < len(S) and S[i] == S[i + 1]:
                i += 1
            cut = i + 1
            L = (i + 1)//2
            i += 1
            
            before = 0
            R = 0
            while i + 1 < len(S):
                while i + 1 < len(S) and S[i] == S[i + 1]:
                    i += 1
                R += (i + 1 - before)//2
                i += 1
                before = i
            
            S = S[cut:] + S[:cut]
            print(S)
            ans = 0
            before = 0
            i = 0
            while i + 1 < len(S):
                while i + 1 < len(S) and S[i] == S[i + 1]:
                    i += 1
                ans += (i + 1 - before)//2
                i += 1
                before = i
            ans = ans*(K - 1) + R + L
            print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    S = input()
    K = int(input())
    flag = False
    if S[0] == S[-1]:
        if len(set(S)) == 1:
            ans = K*len(S)//2
            print(ans)
            return
        else:
            i = 0
            flag = True
            while i < len(S) and S[i] == S[i + 1]:
                i += 1
            S = S[i + 1:] + S[:i + 1]
    L,R,ans = 0,0,0
    first = True
    before = 0
    i = 0
    while i + 1 < len(S):
        while i + 1 < len(S) and S[i] == S[i + 1]:
            i += 1
        if first:
            L = (i + 1 - before)//2
            first = False
        ans += (i + 1 - before)//2
        if i + 1 == len(S):
            R = (i + 1 - before)//2
        i += 1
        before = i
    
    ans = ans*(K - 1) + R + L if flag else ans*K
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

s = list(map(str, input().rstrip()))
k = int(input())
connection = False

if all([x == s[0] for x in s]):
    print(len(s) * k // 2)
    sys.exit()

cnt = 0
if s[0] == s[-1] and k != 1:
    connection = True
    cnt = 2
    start = 1
    goal = 1
    x = s[0]

    for i in s[1:]:
        if i == x:
            cnt += 1
            start += 1
        else:
            break

    for i in s[:-1][::-1]:
        if i == x:
            cnt += 1
            goal += 1
        else:
            break

d = defaultdict(int)

if connection:
    ss = s[:start]
    sg = s[-goal:]
    s = s[start:-goal]
    
prev = s[0]
tmp = 1
for i, x in enumerate(s[1:]):
    if prev == x and i == (len(s) - 2):
        tmp += 1
        d[tmp] += 1
    elif prev == x:
        tmp += 1
    else:
        d[tmp] += 1
        prev = x
        tmp = 1

if connection:
    d[cnt] += 1

ans = 0
for key, val in d.items():
    if key == 1:
        continue
    else:
        ans += key // 2 * val * k

if connection:
    ans -= cnt // 2
    ans += len(ss) + len(sg) - 2

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

s = list(map(str, input().rstrip()))
k = int(input())
connection = False

if all([x == s[0] for x in s]):
    print(len(s) * k // 2)
    sys.exit()

cnt = 0
if s[0] == s[-1]:
    connection = True
    cnt = 2
    start = 1
    goal = 1
    x = s[0]

    for i in s[1:]:
        if i == x:
            cnt += 1
            start += 1
        else:
            break

    for i in s[:-1][::-1]:
        if i == x:
            cnt += 1
            goal += 1
        else:
            break

d = defaultdict(int)

if connection:
    ss = s[:start]
    sg = s[-goal:]
    s = s[start:-goal]
prev = s[0]
tmp = 1

for i, x in enumerate(s[1:]):
    if prev == x and i == (len(s) - 2):
        tmp += 1
        d[tmp] += 1
    elif prev == x:
        tmp += 1
    else:
        d[tmp] += 1
        prev = x
        tmp = 1

if connection:
    d[cnt] += 1

ans = 0
for key, val in d.items():
    if key == 1:
        continue
    else:
        ans += key // 2 * val * k

if connection:
    ans -= cnt // 2
    ans += len(ss) + len(sg) - 2

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

s = list(map(str, input().rstrip()))
k = int(input())

if all([x == s[0] for x in s]):
    print(len(s) * k // 2)
    sys.exit()

cnt = 0
if s[0] == s[-1]:
    cnt = 2
    start = 1
    goal = 1
    x = s[0]

    for i in s[1:]:
        if i == x:
            cnt += 1
            start += 1
        else:
            break

    for i in s[:-1][::-1]:
        if i == x:
            cnt += 1
            goal += 1
        else:
            break

d = defaultdict(int)

if cnt > 0:
    s = s[start:-goal]
prev = s[0]
tmp = 1

for i, x in enumerate(s[1:]):
    if prev == x and i == (len(s) - 1):
        tmp += 1
        d[tmp] += 1
    elif prev == x:
        tmp += 1
    else:
        d[tmp] += 1
        prev = x
        tmp = 1

if cnt > 0:
    d[cnt] += 1

ans = 0
for key, val in d.items():
    if key == 1:
        continue
    else:
        ans += (key) // 2 * val * k

if cnt > 0:
    ans -= cnt // 2

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
num = len(s)
ans = 0
flag = True
for i in range(1,num):
    if s[i] == s[i-1] and flag:
        flag = False
        ans += 1
    else:
        flag = True
ans *= k

if s[-1] == s[0] and flag:
    if num == 1:
        ans += k//2
    else:
        ans += k-1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
num = len(s)
ans = 0
flag = True
for i in range(1,num):
    if s[i] == s[i-1] and flag:
        flag = False
        ans += 1
    else:
        flag = True
ans *= k

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

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
num = len(s)
ans = 0
flag = True
for i in range(1,num):
    if s[i] == s[i-1] and flag:
        flag = False
        ans += 1
    else:
        flag = True
     
if s[-1] == s[0] and flag:
    ans += 1

print(ans*k)