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 = list(input())
K = int(input())
ans = 0
for i in range(len(S)-1):
    if(S[i] == S[i+1]):
        S[i+1] = "3"
        ans += 1
print(ans * K)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
ans = 0
for i in range(len(S)-1):
    if(S[i] == S[i+1]):
        S[i+1] = "3"
        ans += 1
if(S[0] == S[-1]):
    ans += K - 1
print(ans * K)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
ans = 0
flg = False
flg2 = False
for i in range(len(S)-1):
  #print(i,flg)
  if S[i] == S[i+1]:
    if flg == False:
      ans += 1
      flg = True
    else:
      flg = False  
  else:
    flg = False
  if i == len(S)-2 and S[0] == S[-1] and flg == False:
    flg2 = True
  if len(S) >= 3:
    if i == len(S)-2 and S[0] == S[-1] and flg == True and S[0] == S[-2] and S[0] == S[1] and S[0] == S[2]:
      flg2 = True
  #print(i,flg)
print(ans * K if flg2 == False else ans * K + (K - 1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
ans = 0
flg = False
flg2 = False
for i in range(len(S)-1):
  if S[i] == S[i+1] and flg == False:
    ans += 1
    flg = True
  else:
    flg = False
  if i == len(S)-2 and S[0] == S[-1] and flg == False:
    flg2 = True
print(ans * K if flg2 == False else ans * K + (K - 1))

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
lenS = len(S)
ans = 0
if S.count(S[0]) == lenS:
    ans = (lenS*K)//2
else:
    if S[0] == S[lenS - 1] and lenS > 1:
        if S[0] == S[1]:
            ind = 1
            while(S[ind+1] == S[0]):
                ind += 1
            if ind % 2 == 1:
                S = "*"+S[1:]
                ans += K

        else:
            ans += K-1
            if S[lenS-1] == S[lenS-2]:
                ans += 1
            S = S[:lenS-1]+"*"

    for i in range(lenS - 1):
        if S[i] == S[i + 1]:
            S = S[:i+1] + '*'+S[i+2:]
            ans += K
            # print(S)
            # print(i)


print(ans)

Submission status: Wrong Answer

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

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

print(sumarr)

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


def to_cnt(num):
    if num < 2:
        return 0
    else:
        return int(num / 2)


ans = 0
if S[0] == S[len(S) - 1]:
    ans += to_cnt(sumarr[0])
    ans += to_cnt(sumarr[len(sumarr) - 1])
    connection = to_cnt(sumarr[0] + sumarr[len(sumarr) - 1])
    cnt = sum(map(to_cnt, sumarr[1: len(sumarr) - 1]))
    ans += cnt * K
    ans += connection * (K - 1)
else:
    ans += sum(map(to_cnt, sumarr)) * K

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
lenS = len(S)
ans = 0
if S.count(S[0]) == lenS:
    ans = (lenS*K)//2
else:
    if S[0] == S[lenS - 1] and lenS > 1:
        if S[0] == S[1]:
            ind = 1
            while(S[ind+1] == S[0]):
                ind += 1
            if ind % 2 == 1:
                S = "*"+S[1:]
                ans += K

        else:
            ans += K-1
            S = S[:lenS-1]+"*"

    for i in range(lenS - 1):
        if S[i] == S[i + 1]:
            S = S[:i+1] + '*'+S[i+2:]
            ans += K
            print(S)
            # print(i)


print(ans)

Submission status: Wrong Answer

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

    if S[0] == S[lenS - 1]:
        ans += K-1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
lenS = len(S)
ans = 0
if S.count(S[0]) == lenS and lenS % 2 == 1:
    ans = (lenS*K)//2
else:
    for i in range(lenS - 1):
        if S[i] == S[i + 1]:
            S = S[:i+1] + '*'+S[i+2:]
            ans += K
            # print(S)
            # print(i)

    if S[0] == S[lenS - 1]:
        ans += K-1
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

if len(set(S)) == 1:
  print(math.floor(len(S)*K/2))
  quit()
    
first = S[0]

a = 0
for l in S:
  if l == first:
    a+=1
  else:
    break

last = S[-1]
b = 0
for l in S[::-1]:
  if l == last:
    b+=1
  else:
    break

prev = S[a]
c = 0
for l in S[a+1:-b]:
  if prev == l:
    c += 1
    prev = ""
  else:
    prev = l

d = 0
if first == last:
  d =  math.floor((a+b)/2)
ans = math.floor(a/2) + d*(K-1) + c*K + math.floor(b/2)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
lenS = len(S)
ans = 0
for i in range(lenS - 1):
    if S[i] == S[i + 1]:
        S = S[:i+1] + '*'+S[i+2:]
        ans += K
        # print(S)
        # print(i)

if S[0] == S[lenS - 1]:
    ans += K-1
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

if len(set(S)) == 1:
  print(math.floor((len(S)*K)/2))
  quit()
    
first = S[0]

a = 0
for l in S:
  if l == first:
    a+=1
  else:
    break

last = S[-1]
b = 0
for l in S[::-1]:
  if l == last:
    b+=1
  else:
    break

prev = S[a]
c = 0
for l in S[a+1:-b]:
  if prev == l:
    c += 1
    prev = ""
  else:
    prev = l

d = 0
if first == last:
  d = (a+b)/2

ans = math.floor(a/2) + math.floor(d*(K-1)) + c*K + math.floor(b/2)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

if len(set(S)) == 1:
  print(math.floor(len(S)*K/2))
  quit()
    
first = S[0]

a = 0
for l in S:
  if l == first:
    a+=1
  else:
    break

last = S[-1]
b = 0
for l in S[::-1]:
  if l == last:
    b+=1
  else:
    break

prev = S[a]
c = 0
for l in S[a+1:-b]:
  if prev == l:
    c += 1
    prev = ""
  else:
    prev = l

d = 0
if first == last:
  d = math.floor((a+b)/2)

ans = math.floor(a/2) + d*(K-1) + c*K + math.floor(b/2)
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
a=False
c=0
if len(s)==1:
  c=1
  s="@*{"
  if k%2==0:
    k=float(k/2)
  else:
    k=float((k-1)/2)
if len(s)==2:
  if s[0]==s[1]:
    c+=1
    s="*$"
if len(s)==3:
  if s[0]==s[1] and s[0]==s[2]:
    s="%*}"
    c=4
    k=1
  elif s[0]==s[1] and s[0]!=s[2]:
    s="*`|"
    c+=1
if s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
  s=s[0:len(s)-1]+"("
  c+=1
elif s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
  a=True
  s="|"+s[1:]
  c+=1
if s[len(s)-1]==s[len(s)-2]:
  c+=1
  s=s[0:len(s)-1]+"?"
if s[0]==s[1]:
  c+=1
  s=s[0]+"<"+s[2:]
for i in range(len(s)-2):
  if s[i]==s[i+1]:
    c+=1
    s=s[0:i+1]+">"+s[i+2:]
if a==True:
  c=c*k-1
else:
  c=c*k

print(c)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
a=False
c=0
if len(s)==1:
  c=1
  s="@*{"
  if k%2==0:
    k=k/2
  else:
    k=(k-1)/2
if len(s)==2:
  if s[0]==s[1]:
    c+=1
    s="*$"
if len(s)==3:
  if s[0]==s[1] and s[0]==s[2]:
    s="%*}"
    c=4
    k=1
  elif s[0]==s[1] and s[0]!=s[2]:
    s="*`|"
    c+=1
if s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
  s=s[0:len(s)-2]+"("
  c+=1
elif s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
  a=True
  s="|"+s[1:]
  c+=1
if s[len(s)-1]==s[len(s)-2]:
  c+=1
  s=s[0:len(s)-2]+"?"
if s[0]==s[1]:
  c+=1
  s=s[0]+"<"+s[2:]
for i in range(len(s)-2):
  if s[i]==s[i+1]:
    c+=1
    s=s[0:i+1]+">"+s[i+2:]
if a==True:
  c=c*k-1
else:
  c=c*k

print(c)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
a=False
c=0
if len(s)==1:
  c=1
  s="@*{"
  if k%2==0:
    k=k/2
  else:
    k=(k-1)/2
if len(s)==2:
  if s[0]==s[1]:
    c+=1
    s="*$"
if len(s)==3:
  if s[0]==s[1] and s[0]==s[2]:
    s="%*}"
    c=4
    k=1
  elif s[0]==s[1] and s[0]!=s[2]:
    s="*`|"
    c+=1
if s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
  s=s[0:len(s)-1]+"("
  c+=1
elif s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
  a=True
  s="|"+s[1:]
  c+=1
if s[len(s)-1]==s[len(s)-2]:
  c+=1
  s=s[0:len(s)-1]+"?"
if s[0]==s[1]:
  c+=1
  s=s[0]+"<"+s[2:]
for i in range(len(s)-2):
  if s[i]==s[i+1]:
    c+=1
    s=s[0:i+1]+">"+s[i+2:]
if a==True:
  c=c*k-1
else:
  c=c*k

print(c)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
a=False
c=0
if len(s)==2:
  if s[0]==s[1]:
    c+=1
    s="*@"
if len(s)==3:
  if s[0]==s[1] and s[0]==s[2]:
    s="@*"
    c=4
    k=1
if s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
  s=s[0:len(s)-1]+"@"
  c+=1
elif s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
  a=True
  s="@"+s[1:]
  c+=1
if s[len(s)-1]==s[len(s)-2]:
  c+=1
  s=s[0:len(s)-1]+"@"
for i in range(len(s)-2):
  if s[i]==s[i+1]:
    c+=1
    s=s[0:i+1]+"@"+s[i+2:]
if a==True:
  c=c*k-1
else:
  c=c*k

print(c)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
a=False
c=0
if len(s)==2:
  if s[0]==s[1]:
    c+=1
    s="*@"
if len(s)==3:
  if s[0]==s[1] and s[0]==s[2]:
    s="@*"
    c=4
    k=1
if s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
  s=s[0:len(s)-2]+"@"
  c+=1
elif s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
  a=True
  s="@"+s[1:]
  c+=1
if s[len(s)-1]==s[len(s)-2]:
  c+=1
  s=s[0:len(s)-2]+"@"
for i in range(len(s)-2):
  if s[i]==s[i+1]:
    c+=1
    s=s[0:i+1]+"@"+s[i+2:]
if a==True:
  c=c*k-1
else:
  c=c*k

print(c)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
a=False
c=0
if len(s)==2:
  if s[0]==s[1]:
    c+=1
    s="*@"
if s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
  s=s[0:len(s)-2]+"@"
  c+=1
elif s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
  a=True
  s="@"+s[1:]
  c+=1
if s[len(s)-1]==s[len(s)-2]:
  c+=1
  s=s[0:len(s)-2]+"@"
for i in range(len(s)-2):
  if s[i]==s[i+1]:
    c+=1
    s=s[0:i+1]+"@"+s[i+2:]
if a==True:
  c=c*k-1
else:
  c=c*k

print(c)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
s = input()
k = int(input())
ans = 0
t = [[i, len(list(g))] for i, g in groupby(s)]


for i in t:
    if i[1] > 1:
        ans += i[1]//2

else :
    ans *= k

if len(t)>1 and t[0][0] == t[-1][0] and (t[0][1] + t[-1][1])%2 == 0:
    ans += k-1
elif len(t) == 1 and t[0][1] ==1 :
    ans += k//2


print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
a=False
c=0
if s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
  s=s[0:len(s)-2]+"@"
  c+=1
elif s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
  a=True
  s="@"+s[1:]
  c+=1
if s[len(s)-1]==s[len(s)-2]:
  c+=1
  s=s[0:len(s)-2]+"@"
for i in range(len(s)-2):
  if s[i]==s[i+1]:
    c+=1
    s=s[0:i+1]+"@"+s[i+2:]
if a==True:
  c=c*k-1
else:
  c=c*k

print(c)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
s = input()
k = int(input())
ans = 0
t = [[i, len(list(g))] for i, g in groupby(s)]


for i in t:
    if i[1] > 1:
        ans += i[1]//2

else :
    ans *= k

if len(t)>1 and t[0][0] == t[-1][0] and (t[0][1] + t[-1][1])%2 == 0:
    ans += k-1
elif len(t) == 1:
    if t[0][1] %2 ==1:
        ans += 1


print(ans)

Submission status: Wrong Answer

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

s=s+s[0]
p=s[0]
cnt=0
for i in range(1,len(s)):
	if s[i]==p:
		cnt+=1
		p=''
	else:
		p=s[i]

print(cnt*K)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
s = input()
k = int(input())
ans = 0
t = [[i, len(list(g))] for i, g in groupby(s)]


for i in t:
    if i[1] > 1:
        ans += i[1]//2

else :
    ans *= k

if len(t)>1 and t[0][0] == t[-1][0] and (t[0][1] + t[-1][1])%2 == 0:
    ans += k-1

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
count = 0
if k>=2 and len(s)>=2:
    l = s*2
    for i in range(len(l)-1):
        if l[i]==l[i+1]:
            count+=1
            l[i+1]='*'
    count*=k//2
    if k%2!=0:
        m = list(l[-1])+s
        for i in range(len(m)-1):
            if m[i]==m[i+1]:
                count+=1
                m[i+1]='*'
elif len(s)>=2:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
            s[i+1]='*'
print(count)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
L = len(S)
 
sum = 0
x = 1
if S[0] != S[-1]:
  for i in range(0, L-1):
    if S[i] == S[i+1]:
      x += 1
    else:
      sum += (x // 2)*K
      x = 1
  sum += (x // 2)*K
  print(sum)
else:
  for i in range(0, L-1):
    if S[i] == S[i+1]:
      x += 1
    else:
      sum += (x // 2)
      break
  y = x
  x = 1
  for i in range(y, L-1):
    if S[i] == S[i+1]:
      x += 1
    else:
      sum += (x // 2)*K
      x = 1
  sum += (x // 2)
  sum += ((x+y) // 2) * (K-1)
  print(sum)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
count = 0
if k>=2 and len(s)>=2:
    l = s*2
    for i in range(len(l)-1):
        if l[i]==l[i+1]:
            count+=1
            l[i+1]='*'
    count*=k//2
    if k%2!=0:
        m = list(l[-1])+s
        for i in range(len(m)-1):
            if m[i]==m[i+1]:
                count+=1
                m[i+1]='*'
elif len(s)>=2:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
            s[i+1]='*'
else:
    count = k-1
print(count)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
count = 0
if k>=2:
    l = s*2
    for i in range(len(l)-1):
        if l[i]==l[i+1]:
            count+=1
            l[i+1]='*'
    count*=k//2
    if k%2!=0:
        m = list(l[-1])+s
        for i in range(len(m)-1):
            if m[i]==m[i+1]:
                count+=1
                m[i+1]='*'
elif len(s)>=2:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
            s[i+1]='*'
print(count)

Submission status: Wrong Answer

Solution code:
s,k=input(),int(input())
c = 0
r = 0
ss = 0
l = 1
for c1, c2 in zip(s, s[1:]):
    if c1 == c2:
        c += 1
    else:
        r += (c+1)//2
        if ss == 0:
            ss = c+1
        l = c+1
        c = 0
if c:
    r += (c+1)//2
    l = c+1
    if ss == 0:
        ss = c+1
r *= k
if ss == len(s):
    r = (k*ss)//2
elif s[0] == s[-1] and (ss*l) % 2:
    r+=(k-1)
print(r)

Submission status: Wrong Answer

Solution code:
s,k=input(),int(input())
c = 0
r = 0
ss = 0
l = 1
for c1, c2 in zip(s, s[1:]):
    if c1 == c2:
        c += 1
    else:
        r += (c+1)//2
        if ss == 0:
            ss = c+1
        l = c+1
        c = 0
if c:
    r += (c+1)//2
    l = c+1
    if ss == 0:
        ss = c+1
r *= k
if ss == len(s):
    r = (len(s))//2
if s[0] == s[-1] and (ss*l) % 2:
    r+=(k-1)
print(r)

Submission status: Wrong Answer

Solution code:
s,k=input(),int(input())
c = 0
r = 0
ss = 0
l = 1
for c1, c2 in zip(s, s[1:]):
    if c1 == c2:
        c += 1
    else:
        r += (c+1)//2
        if ss == 0:
            ss = c+1
        l = c+1
        c = 0
if c:
    r += (c+1)//2
    l = c+1
    if ss == 0:
        ss = c+1
r *= k
if s[0] == s[-1] and (ss*l) % 2:
    r+=(k-1)
print(r)

Submission status: Wrong Answer

Solution code:
s,k=input(),int(input())
c = 0
r = 0
ss = 0
l = 1
for c1, c2 in zip(s, s[1:]):
    if c1 == c2:
        c += 1
    else:
        r += (c+1)//2
        if ss == 0:
            ss = c+1
        l = c+1
        c = 0
if c:
    r += (c+1)//2
    l = c+1
    if ss == 0:
        ss = c+1
r *= k
if s[0] == s[-1] and (ss*l) % 2:
    r+=(k-1)

Submission status: Wrong Answer

Solution code:
s,k=input(),int(input())
c = 0
r = 0
ss = 0
l = 1
for c1, c2 in zip(s, s[1:]):
    if c1 == c2:
        c += 1
    else:
        r += (c+1)//2
        c = 0
        if ss == 0:
            ss = c+1
        l = c+1
if c:
    r += (c+1)//2
    l = c+1
    if ss == 0:
        ss = c+1
r *= k
if s[0] == s[-1] and ss*l % 2:
    r+=(k-1)
print(r)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
count = 0
if k>=2:
    l = s*2
    for i in range(len(l)-1):
        if l[i]==l[i+1]:
            count+=1
            l[i+1]='_'
    count*=k//2
    if k%2!=0:
        m = list(l[-1])+s
        for i in range(len(m)-1):
            if m[i]==m[i+1]:
                count+=1
                m[i+1]='_'
elif len(s)>=2:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
            s[i+1]='_'
print(count)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
count = 0
stock = 0
if k>=2:
    l = s*2
    for i in range(len(l)-1):
        if l[i]==l[i+1]:
            count+=1
            l[i+1]='_'
    stock=count//2
    count*=k//2
    if k%2!=0:
        count+=stock
else:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
            s[i+1]='_'
print(count)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
L = len(S)
 
sum = 0
x = 1
if L == 1:
  print(K//2)
elif L == 2 and S[0] == S[1]:
  print(K)
elif L == 2:
  print(0)
elif S[0] != S[-1]:
  for i in range(0, L-1):
    if S[i] == S[i+1]:
      x += 1
    else:
      sum += (x // 2)*K
      x = 1
  sum += (x // 2)*K
  print(sum)
else:
  for i in range(0, L-1):
    if S[i] == S[i+1]:
      x += 1
    else:
      sum += (x // 2)
      break
  y = x
  x = 1
  for i in range(y, L-1):
    if S[i] == S[i+1]:
      x += 1
    else:
      sum += (x // 2)*K
      x = 1
  sum += (x // 2)
  sum += ((x+y) // 2) * (K-1)
  print(sum)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
L = len(S)
 
sum = 0
x = 1
if L == 1:
  print(K//2)
elif L == 2 and S[0] == S[1]:
  print(K)
elif L == 2 and S[0] != S[1]:
  print(0)
elif S[0] != S[-1]:
  for i in range(0, L-1):
    if S[i] == S[i+1]:
      x += 1
    else:
      sum += (x // 2)*K
      x = 1
  sum += (x // 2)*K
  print(sum)
else:
  for i in range(0, L-1):
    if S[i] == S[i+1]:
      x += 1
    else:
      sum += (x // 2)
      break
  y = x
  x = 1
  for i in range(y, L-1):
    if S[i] == S[i+1]:
      x += 1
    else:
      sum += (x // 2)*K
      x = 1
  sum += (x // 2)
  sum += ((x+y) // 2) * (K-1)
  print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
L = len(S)
 
sum = 0
x = 1
if L == 1:
  print(K//2)
elif L == 2 and S[0] == S[1]:
  print(K)
elif L == 2:
  print(0)
elif S[0] != S[-1]:
  for i in range(0, L-1):
    if S[i] == S[i+1]:
      x += 1
    else:
      sum += (x // 2)*K
      x = 1
  sum += (x // 2)*K
  print(sum)
else:
  for i in range(0, L-1):
    if S[i] == S[i+1]:
      x += 1
    else:
      sum += (x // 2)
      break
  y = x
  x = 1
  for i in range(y, L-1):
    if S[i] == S[i+1]:
      x += 1
    else:
      sum += (x // 2)*K
      x = 1
  sum += (x // 2)
  sum += ((x+y) // 2) * (K-1)
  print(sum)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
L = len(S)
 
sum = 0
x = 1
if L == 1:
  print(K//2)
elif L == 2 and S[0] == S[1]:
  print(K)
elif L == 2:
  print(0)
elif S[0] != S[-1]:
  for i in range(0, L-1):
    if S[i] == S[i+1]:
      x += 1
    else:
      sum += (x // 2)*K
      x = 1
  sum += (x // 2)*K
  print(sum)
else:
  for i in range(0, L-1):
    if S[i] == S[i+1]:
      x += 1
    else:
      sum += (x // 2)
    break
  y = x
  x = 1
  for i in range(y, L-1):
    if S[i] == S[i+1]:
      x += 1
    else:
      sum += (x // 2)*K
      x = 1
  sum += (x // 2)
  sum += ((x+y) // 2) * (K-1)
  print(sum)

Submission status: Wrong Answer

Solution code:
#A
s = input()
k = int(input())
s_sum = 0

s_f = 1
s_l = 1


if s[0] == s[-1]:
    for i in range(len(s)):
        if i != 0:
            if s[i] == s[i-1]:
                s_f += 1
            else:
                break
                
    
    for i in range(len(s)-1 , -1, -1):
        if i != len(s)-1:
            if s[i] == s[i+1]:
                s_l += 1
            else:
                break
                
    
                
                
    if s_f == len(s):
        print((k * len(s)) // 2)
        
    else:
        n = 1
        is_not_first = False
        for i in range(len(s)):
            if i != 0:
                if s[i] == s[i-1]:
                    n += 1
                else:
                    if not is_not_first:
                        is_not_first = True
                        n = 1
                    else:
                        if n != 1:
                            if n % 2 == 0:
                                s_sum += (n / 2)
                            else:
                                s_sum += ((n - 1)/ 2)
                            n = 1

        x1 = (s_f // 2 + s_l // 2 + s_sum) * k
        x2 = ((s_f + s_l) // 2) + (k-1)
        
        print(x1 + x2)
        

else:   
    n = 1
    for i in range(len(s)):
        if i != 0:
            if s[i] == s[i-1]:
                n += 1
            else:
                if n != 1:
                    if n % 2 == 0:
                        s_sum += (n / 2)
                    else:
                        s_sum += ((n - 1)/ 2)
                    n = 1
                    

        if i == (len(s) - 1):
            if n != 1:
                if n % 2 == 0:
                    s_sum += (n / 2)
                else:
                    s_sum += ((n - 1)/ 2)
                    

    print(int(s_sum * k))

Submission status: Wrong Answer

Solution code:
import re

def nchars(s, n):
    """文字列 s に、同じ文字が n 個以上連続している部分文字列を見つける
    """
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  # カンマを取ると n 個ちょうどになる
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]
S = input()
K = int(input())

con = list(nchars(S, 1))

if len(con)==1:
    print(K*int(len(S)/2))

else:
    cons = []
    for coni in con:
        cons.append(int(len(coni)/2))

    c1 = cons[0]

    c2 = 0
    for i in range(len(cons)):
        if i != 0 and i != len(cons)-1:
            c2 += cons[i]

    if con[0][0]==con[len(cons)-1][0]:
        c3 = int(len(con[0]+con[len(cons)-1])/2)
    else:
        c3 = int(len(con[0])/2) + int(len(con[len(cons)-1])/2)

    c4 = int(cons[len(cons)-1])

    print(int(c1 + c2*K + c3 *(K-1) + c4))

Submission status: Wrong Answer

Solution code:
import sys

S = list(map(str, input()))
K = int(input())

if len(list(set(S))) == 1:
	print((len(S)*K)//2)
	sys.exit()

if K == 1:
	tmp = S[0]
	cnt = 0
	for i in range(1,len(S)):
		if S[i] == tmp:
			cnt += 1
			tmp = "#"
		else:
			tmp = S[i]
	print(cnt)
	sys.exit()

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

	if S[0] == tmp:
		ans = cnt * K + (K-1)
	else:
		ans = cnt * K
	print(ans)

Submission status: Wrong Answer

Solution code:
import sys

S = list(map(str, input()))
K = int(input())

if len(list(set(S))) == 1:
	print((len(S)*K)//2)
	sys.exit()

if K == 1:
	tmp = S[0]
	cnt = 0
	for i in range(1,len(S)):
		if S[i] == tmp:
			cnt += 1
			tmp = "#"
		else:
			tmp = S[i]
	print(cnt)
	sys.exit()

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

	if S[0] == tmp:
		cnt += 1
	print(cnt*K)

Submission status: Wrong Answer

Solution code:
import re

def nchars(s, n):
    """文字列 s に、同じ文字が n 個以上連続している部分文字列を見つける
    """
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  # カンマを取ると n 個ちょうどになる
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

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

con = list(nchars(S, 1))

if len(con)==1:
    print(K*int(len(S)/2))

else:
    cons = []
    for coni in con:
        cons.append(int(len(coni)/2))

    c1 = cons[0]

    c2 = 0
    for i in range(len(cons)):
        if i != 0 and i != len(cons)-1:
            c2 += cons[i]

    if con[0][0]==con[len(cons)-1][0]:
        c3 = int(len(con[0]+con[len(cons)-1])/2)
    else:
        c3 = int(len(con[0])/2) + int(len(con[len(cons)-1])/2)

    c4 = int(cons[len(cons)-1])

    print(int(c1 + c2*K + c3 *(K-1) + c4))

Submission status: Wrong Answer

Solution code:
import sys

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

if len(list(set(S))):
	print((len(S)*K)//2)
	sys.exit()

if K == 1:
	tmp = S[0]
	cnt = 0
	for i in range(1,len(S)):
		if S[i] == tmp:
			cnt += 1
			tmp = "#"
		else:
			tmp = S[i]
	print(cnt)
	sys.exit()

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

	if S[0] == tmp:
		cnt += 1
	print(cnt*K)

Submission status: Wrong Answer

Solution code:
import re

def nchars(s, n):
    """文字列 s に、同じ文字が n 個以上連続している部分文字列を見つける
    """
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  # カンマを取ると n 個ちょうどになる
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]
S = input()
K = int(input())

con = list(nchars(S, 1))

if len(con)==1:
    print(K*int(len(S)/2))

else:
    cons = []
    for coni in con:
        cons.append(int(len(coni)/2))

    c1 = cons[0]

    c2 = 0
    for i in range(len(cons)):
        if i != 0 and i != len(cons)-1:
            c2 += cons[i]

    c3 = int(len(con[0]+con[len(cons)-1])/2)

    c4 = int(cons[len(cons)-1])

    print(int(c1 + c2*K + c3 *(K-1) + c4))

Submission status: Wrong Answer

Solution code:
import sys

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

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

if K == 1:
	tmp = S[0]
	cnt = 0
	for i in range(1,len(S)):
		if S[i] == tmp:
			cnt += 1
			tmp = "#"
		else:
			tmp = S[i]
	print(cnt)
	sys.exit()

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

	if S[0] == tmp:
		cnt += 1
	print(cnt*K)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
N = len(S)
 
if(N==1):
  print(K//2)
elif(N==2):
  if(S[0]==S[1]):
    print(K)
  else:
    print(0)
else:
  temp = [S[0]]
  long = []
  long_count = []
  for i in range(1,N):
    if(S[i]==S[i-1]):
      temp.append(S[i])
      if(i == N-1):
        long.append(len(temp))
        long_count.append(len(temp)//2)
    else:
      long.append(len(temp))
      long_count.append(len(temp)//2)
      temp = [S[i]]
      if(i == N-1):
        long.append(1)
        long_count.append(0)
  x = sum(long_count)
  
  if(S[0]!=S[N-1]):
    print(x * K)
  else:
    a = long[0] + long[len(long)-1]
    if(a%2==0):
      print(x * K + K - 1)
    else:
      print(x * K)

Submission status: Wrong Answer

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

if(N==1):
  print(K//2)
elif(N==2):
  if(S[0]==S[1]):
    print(K)
  else:
    print(0)
else:
  temp = [S[0]]
  long = []
  long_count = []
  for i in range(1,N):
    if(S[i]==S[i-1]):
      temp.append(S[i])
      if(i == N-1):
        long.append(len(temp))
        long_count.append(len(temp)//2)
    else:
      long.append(len(temp))
      long_count.append(len(temp)//2)
      temp = [S[i]]
      if(i == N-1):
        long.append(1)
        long_count.append(0)
  x = sum(long_count)
  
  if(S[0]!=S[N-1]):
    print(x * K)
  else:
    a = long[0] + long[len(long)-1]
    if(a%2==0):
      print(x * K + K - 1)
    else:
      print(x * K)

Submission status: Wrong Answer

Solution code:
s = input()
s = s + "1"
k = int(input())
ans = 0
lis = []
tem = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    tem += 1
  else:
    lis.append(tem)
    tem = 1
if s[0] == s[-2]:
  t = lis[0]+lis[-1]
  for i in range(1,len(lis)-1):
    if lis[i] % 2 == 0:
      ans += lis[i]//2
    else:
      ans += (lis[i]-1)//2
  ans*= k
  if t%2 == 0:
    ans += (k-1)*t//2
  else:
    ans += (k-1)*(t-1)//2
  if lis[0]%2 == 0:
    ans += (k-1)*lis[0]//2
  else:
    ans += (k-1)*(lis[0]-1)//2
  if lis[-1]%2 == 0:
    ans += (k-1)*lis[-1]//2
  else:
    ans += (k-1)*(lis[-1]-1)//2
else:
  for item in lis:
    if item % 2 == 0:
      ans += item//2
    else:
      ans += (item-1)//2
  ans *= k
if len(lis) == 1:
  anse = (len(s)-1)*k
  if anse%2 == 0:
    ans = anse//2
  else:
    ans =(anse-1)//2
print(ans)

Submission status: Wrong Answer

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

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

if K > 1 and S[-1] == S[0] and len(S) > 2 and tmp != "#":
	cnt += 1

print(cnt * K)

Submission status: Wrong Answer

Solution code:
#A
s = input()
k = int(input())
s_sum = 0

s_f = 1
s_l = 1

if s[0] == s[-1]:
    
    for i in range(len(s)):
        if i != 0:
            if s[i] == s[i-1]:
                s_f += 1
            else:
                break
    
    for i in range(len(s)-1 , -1, -1):
        if i != len(s)-1:
            if s[i] == s[i+1]:
                s_l += 1
            else:
                break
if s_f == len(s) and len(s) % 2 == 1:
    print((k * len(s)) / 2)
else:   
    if s_f + s_l % 2 == 0 and s_f != 1 and s_l != 1:
        s_sum += 1

    n = 1
    for i in range(len(s)):
        if i != 0:
            if s[i] == s[i-1]:
                n += 1
            else:
                if n != 1:
                    if n % 2 == 0:
                        s_sum += (n / 2)
                    else:
                        s_sum += ((n - 1)/ 2)
                    n = 1

        if i == (len(s) - 1):
            if n != 1:
                if n % 2 == 0:
                    s_sum += (n / 2)
                else:
                    s_sum += ((n - 1)/ 2)

    print(int(s_sum * k))