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())
N=len(S)
count=1
countlist=[]
anssub=0
for i in range(N-1):
  if S[i]==S[i+1]:
    count+=1
  else: 
    countlist+=[count]
    count=1
if S[N-2]!=S[N-1]:
  count=1
countlist+=[count]  
for i in range(len(countlist)):
  if i!=0 and i!=len(countlist)-1:
    if countlist[i]!=1:
      anssub+=countlist[i]//2
a=countlist[0]+countlist[-1]
if S[0]==S[-1]:
  anssub2=a//2
else:
  anssub2=0
  if countlist[0]!=1:
    anssub2=countlist[0]//2
  if countlist[-1]!=1:
    anssub2=countlist[-1]//2
  
b=countlist[0]
c=countlist[-1]
anssub3=0
if b!=1:
  anssub3+=b//2
if c!=1:
  anssub3+=c//2
  
ans=anssub*K+anssub2*(K-1)+anssub3
if len(countlist)==1:
  ans=countlist[0]*K//2
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
N=len(S)
count=1
countlist=[]
anssub=0
for i in range(N-1):
  if S[i]==S[i+1]:
    count+=1
  else: 
    countlist+=[count]
    count=1
if S[N-2]!=S[N-1]:
  count=1
countlist+=[count]  
for i in range(len(countlist)):
  if i!=0 and i!=len(countlist)-1:
    if countlist[i]!=1:
      anssub+=countlist[i]//2
a=countlist[0]+countlist[-1]
anssub2=0
if a!=1:
  anssub2+=a//2
if S[0]!=S[-1]:
  if countlist[0]!=1:
    anssub2+=countlist[0]//2
  if countlist[-1]!=1:
    anssub2+=countlist[-1]//2
  
b=countlist[0]
c=countlist[-1]
anssub3=0
if b!=1:
  anssub3+=b//2
if c!=1:
  anssub3+=c//2
  
ans=anssub*K+anssub2*(K-1)+anssub3
if len(countlist)==1:
  ans=countlist[0]*K//2
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
N=len(S)
count=1
countlist=[]
anssub=0
for i in range(N-1):
  if S[i]==S[i+1]:
    count+=1
  else: 
    countlist+=[count]
    count=1
if S[N-2]!=S[N-1]:
  count=1
countlist+=[count]  
for i in range(len(countlist)):
  if i!=0 and i!=len(countlist)-1:
    if countlist[i]!=1:
      anssub+=countlist[i]//2
a=countlist[0]+countlist[-1]
anssub2=0
if a!=1:
  anssub2+=a//2
if S[0]!=S[-1]:
  if countlist[0]!=1:
    anssub2+=countlist[0]//2
  if countlist[i]!=1:
    anssub2+=countlist[-1]//2
  
b=countlist[0]
c=countlist[-1]
anssub3=0
if b!=1:
  anssub3+=b//2
if c!=1:
  anssub3+=c//2
  
ans=anssub*K+anssub2*(K-1)+anssub3
if len(countlist)==1:
  ans=countlist[0]*K//2
print(ans)

Submission status: Wrong Answer

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

b=countlist[0]
c=countlist[-1]
anssub3=0
if b!=1:
  anssub3+=b//2
if c!=1:
  anssub3+=c//2
  
ans=anssub*K+anssub2*(K-1)+anssub3
if len(countlist)==1:
  ans=countlist[0]*K//2
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
S2 = S+S
K = int(input())
N = len(S)
c1 = 0

for i in range(N-1):
  if S[i] == S[i+1]:
    S[i+1] = "."
    c1 += 1
    
c2 = 0
for i in range(N*2-1):
  if S2[i] == S2[i+1]:
    S2[i+1] = "."
    c2 += 1
    
c2 *= K//2
if S2[0] == S2[-1] != ".":
  c2 += K-1
  
if K%2 == 1:
  c2 += c1
  
print(c2)

Submission status: Wrong Answer

Solution code:
S = input()
k = int(input())
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():]
a = list(nchars(S,2))
#print(a)
cnt = 0
#print(len(a))
#print(a[0])
for i in range(len(a)):
    cnt = cnt + (len(a[i])//2)

if (S[0])==(S[len(S)-1]):
    print(k//2+(cnt*k))
else:
    print(cnt*k)

Submission status: Wrong Answer

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

for i in range(N-1):
  if S[i] == S[i+1]:
    S[i+1] = "."
    c += 1
    
c *= K
if S[0] == S[-1]:
  c += K-1
  
print(c)

Submission status: Wrong Answer

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

ans = 0

if len(set(S)) == 1:
    ans = K * len(S) // 2
    print(ans)
    sys.exit()
    
if S[0] == S[-1]:
    if S[-2] == S[-1]:    
        ans = K
        if S[-3] == S[-2]:
            ans += K - 1
            S[-2] = -1
        else:
            S[-1] = -1
    else:
        ans = K - 1
        S[-1] = -1

j = 0
like = []

for i in range(len(S) - 1):
    if S[i] == S[i + 1]:
        if len(like) == j:
            like.append(2)
        else:
            like[j] += 1
    else:
        like.append(1)
        j += 1

for l in like:
    ans += l // 2 * K

print(ans)

Submission status: Wrong Answer

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

  if S[0] == S[-1]:
    ans += K-1
  ans *= K 

print(ans)

Submission status: Wrong Answer

Solution code:
S = str(input())
K = int(input())
count,ans = 1,0

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

print(ans)

Submission status: Wrong Answer

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

ans = 0

if len(set(S)) == 1:
    ans = K * len(S) // 2
    print(ans)
    sys.exit()
    
if S[0] == S[-1]:
    if S[-2] == S[-1]:
        ans = K
        S[-1] = -1
    else:
        ans = K - 1
        S[-1] = -1

j = 0
like = []

for i in range(len(S) - 1):
    if S[i] == S[i + 1]:
        if len(like) == j:
            like.append(2)
        else:
            like[j] += 1
    else:
        like.append(1)
        j += 1

for l in like:
    ans += l // 2 * K

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
ss = s + s
sss = s + s + s
k = int(input())
n = 0
nn = 0
nnn = 0
s = list(s)
for i in range(1,len(s)):
  if s[i-1] == s[i]:
    n += 1
    s[i] = '.'
ss = list(ss)
for i in range(1,len(ss)):
  if ss[i-1] == ss[i]:
    nn += 1
    ss[i] = '.'
sss = list(sss)
for i in range(1,len(sss)):
  if sss[i-1] == sss[i]:
    nn += 1
    sss[i] = '.'
a = nn-n*2
if sss == n*3+a*(2):
  print(n*k+a*(k-1))
else:
  print((len(s)*k)//2)

Submission status: Wrong Answer

Solution code:
S = input()
k = int(input())
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():]
a = list(nchars(S,2))
#print(a)
cnt = 0
#print(len(a))
#print(a[0])
for i in range(len(a)):
    cnt = cnt + (len(a[i])//2)
print(cnt*k)

Submission status: Wrong Answer

Solution code:
s = input()
ss = s + s
k = int(input())
n = 0
nn = 0
s = list(s)
for i in range(1,len(s)):
  if s[i-1] == s[i]:
    n += 1
    s[i] = '.'
ss = list(ss)
for i in range(1,len(ss)):
  if ss[i-1] == ss[i]:
    nn += 1
    ss[i] = '.'
a = nn-n*2
print(n*k+a*(k-1))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = 0
nn = 0
for i in range(1,len(s)):
  if s[i-1] == s[i]:
    n += 1
    s[i] = '.'
s.extend(s)
for i in range(1,len(s)):
  if s[i-1] == s[i]:
    nn += 1
    s[i] = '.'
print(n*k+nn*(k-1))

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
def seqcnt(s):
    cnt=1
    ans=0
    bk=''
    for c in s+' ':
        if bk==c:
            cnt+=1
        else:
            ans+=(cnt)//2
            cnt=1
        bk=c
    return ans

cnt=seqcnt(s)
cnt2=seqcnt(s*2)    
if len(set(list(s)))==1:
    if len(s)%2==0:
        print(cnt*k)
    else:
        print(cnt*(k//2)+(cnt2-cnt)*(k-k//2))
else:
    print(cnt+(cnt2-cnt)*(k-1))

Submission status: Wrong Answer

Solution code:
A=list(input())
n=int(input())
tmp=0
if len(set(A)) == 1:
   print(len(A)*n//2)
   exit()
for i in range(len(A)-1):
   if A[i] == A[i+1]:
      A[i+1]=1
      tmp+=1
tmp2=0
if A[0] == A[-1]:
   tmp2=n-1
print(tmp*n+tmp2)

Submission status: Wrong Answer

Solution code:
A=list(input())
n=int(input())
tmp=0
for i in range(len(A)-1):
   if A[i] == A[i+1]:
      A[i+1]=1
      tmp+=1
if A[0] == A[-1]:
   tmp += 1
print(tmp*n)

Submission status: Wrong Answer

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

n = len(s)
if len(list(set(s))) == 1:
    print(n*k//2)
    exit()

n1 = 0
n2 = 0
s = s + s

for i in range(2*n - 1):
    if s[i] == s[i+1]:
        s[i+1] = "?"
        if i < n:
            n1 += 1
        else:
            n2 += 1

ans = n1 + n2*(k-1)
print(ans)

Submission status: Wrong Answer

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

n = len(s)
ans = 0

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
s=list(input())
s2=s+s
count1=0
count2=0
k=int(input())
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    s[i+1]="X"
    count1+=1
for i in range(len(s2)-1):
  if s2[i]==s2[i+1]:
    s2[i+1]="X"
    count2+=1
if len(set(s))==1:
  print(int(len(s)*k/2))
else:
  print(count1+(k-1)*(count2-count1))

Submission status: Wrong Answer

Solution code:
s=list(input())
s2=s+s
count1=0
count2=0
k=int(input())
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    s[i+1]="X"
    count1+=1
for i in range(len(s2)-1):
  if s2[i]==s2[i+1]:
    s2[i+1]="X"
    count2+=1
print(count1+(k-1)*(count2-count1))

Submission status: Wrong Answer

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

C0 = []
cnt = 1
for i in range(1,N):
    if S[i]==S[i-1]:
        cnt+=1
        if i==N-1:
            C0.append(cnt)
    else:
        C0.append(cnt)
        cnt = 1
out0 = 0
for m in C0:
    out0 += m//2

if S[0]!=S[-1]:
    out = out0*K
elif N==1:
    out = K//2
else:
    X = (C0[0] + C0[-1])//2
    Y = C0[0]//2 + C0[-1]//2
    out = (out0-Y)*K
    out += X*(K-1)
    out += Y
print(out)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
from itertools import groupby as gb
l=[(a,len(list(b))) for a,b in gb(s)]
k=int(input())
if s[-1]==s[0]:
    ans=sum(v//2 for kf,v in l[1:-1])
    if len(l)!=1:print(ans*k+l[0][1]//2+l[-1][1]//2+(k-1)*(l[-1][1]+l[0][1])//2)
    else:print(l[0][1]*k//2)
else:
    print(sum(v//2 for kf,v in l)*k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
if not s[0]==s[-1]:
  count1=0
  for i in range(len(s)-1):
    if s[i]==s[i+1]:
      s[i+1]=1
      count1+=1
  print(k*count1)
else:
  copy_list=s.copy()
  s[-1]=0
  count2=0
  for i in range(len(s)-1):
    if s[i]==s[i+1]:
      s[i+1]=1
      count2+=1
  count3=0
  for j in range(len(copy_list)-1):
    if copy_list[j]==copy_list[j+1]:
      copy_list[j+1]=4
      count3+=1
  print(count3+(k-1)*count2+k-1)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
import collections
co = collections.Counter(list(s))
n = len(s)
if len(co.values())==1:
    print(n*k//2)
    exit()
prev = ""
cnt = 0
for i in range(n):
    if s[i] == prev:
        cnt+=1
        prev=""
    else:
        prev=s[i]
bf = 0
af = 0
if s[0] == s[-1]:
    for i in range(n):
        if s[i] ==s[0]:
            bf+=1
        else:break
    for i in range(n):
        if s[-i-1] ==s[-1]:
            af+=1
        else:break
cnt = cnt - (bf//2 + af//2)
print(cnt*k + (bf+af)*(k-1)//2 +bf//2 + af//2)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
import collections
co = collections.Counter(list(s))
n = len(s)
if len(co.values())==1:
    print(n*k//2)
    exit()
prev = ""
cnt = 0
for i in range(n):
    if s[i] == prev:
        cnt+=1
        prev=""
    else:
        prev=s[i]


if s[0] == prev: #prev:: s[-1] or ""
    f = 1
else:
    f=0
print(cnt*k + f*(k-1))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
cnt = 0
if len(s) == 1:
    print(k//2)
    exit()
for i in range(1,len(s)):
    if s[i] == s[i-1]:
        s[i] = '#'
        cnt += 1
ans = cnt * k
#print(s)
if s[0] == s[-1]:
    ans += k-1
    #print(k-1)

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
if len(s)==1:
  print(k//2)
  exit()
c=[]
c_=1
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    c_+=1
  else:
    c.append(c_)
    c_=1
c.append(c_)
if len(c)==1:
  print((c[0]*k)//2)
elif s[0]==s[-1]:
  ans=sum([c_//2 for c_ in c[1:-1]])*k
  ans+=c[0]//2
  ans+=c[-1]//2
  ans+=((c[0]+c[-1])*(k-1))//2
  print(ans)
else:
  print(sum([c_//2 for c_ in c])*k)
#print(c)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
if len(s)==1:
  print((k-1)//2)
  exit()
c=[]
c_=1
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    c_+=1
  else:
    c.append(c_)
    c_=1
c.append(c_)
if len(c)==1:
  print((c[0]*k)//2)
elif s[0]==s[-1]:
  ans=sum([c_//2 for c_ in c[1:-1]])*k
  ans+=c[0]//2
  ans+=c[-1]//2
  ans+=((c[0]+c[-1])*(k-1))//2
  print(ans)
else:
  print(sum([c_//2 for c_ in c])*k)
#print(c)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
if len(s)==1:
  print(k-1)
  exit()
c=[]
c_=1
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    c_+=1
  else:
    c.append(c_)
    c_=1
c.append(c_)
if len(c)==1:
  print((c[0]*k)//2)
elif s[0]==s[-1]:
  ans=sum([c_//2 for c_ in c[1:-1]])*k
  ans+=c[0]//2
  ans+=c[-1]//2
  ans+=((c[0]+c[-1])*(k-1))//2
  print(ans)
else:
  print(sum([c_//2 for c_ in c])*k)
#print(c)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
l = 1
ans = 0
c = []

for i in range(len(s)-1):
  if s[i] == s[i+1]:
    l += 1
  else:
    if c == []:
      c.append(l)
    ans += l//2
    l = 1
    
ans += l//2
if c == []:
  c.append(l)
ans *= k
if s[0] == s[-1] and l%2 == 1 and c[0]%2 == 1:
  ans += k//2
  
print(ans)

Submission status: Wrong Answer

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

def co(x):
    X = []
    for i in range(len(x)):
        X.append(x[i])
    n = 0
    for i in range(len(x)-1):
        if X[i] == X[i+1]:
            X[i+1] = 0
            n += 1
    return n

S = co(s)
D = co(s + s)
K = 2*S-D

if len(s) == 1:
    ans = k//2
elif k == 1:
    ans = S
elif K < 0:
    ans = (S-K)*k +K
else:
    ans = S*k - K
print(ans)

Submission status: Wrong Answer

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

def co(x):
    X = []
    for i in range(len(x)):
        X.append(x[i])
    n = 0
    for i in range(len(x)-1):
        if X[i] == X[i+1]:
            X[i+1] = 0
            n += 1
    return n

S = co(s)
D = co(s + s)
K = 2*S-D

if len(s) == 1:
    ans = (k-1)//2
elif k == 1:
    ans = S
elif K < 0:
    ans = (S-K)*k +K
else:
    ans = S*k - K
print(ans)

Submission status: Wrong Answer

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

def co(x):
    X = []
    for i in range(len(x)):
        X.append(x[i])
    n = 0
    for i in range(len(x)-1):
        if X[i] == X[i+1]:
            X[i+1] = 0
            n += 1
    return n

S = co(s)
D = co(s + s)
K = 2*S-D

if k == 1:
    ans = S
else:
    ans = S*k - K
print(ans)

Submission status: Wrong Answer

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

def co(x):
    X = []
    for i in range(len(x)):
        X.append(x[i])
    n = 0
    for i in range(len(x)-1):
        if X[i] == X[i+1]:
            X[i+1] = 0
            n += 1
    return n

S = co(s)
D = co(s + s)
K = 2*S-D

ans = S*k - K
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
a = 0
res = s[0]
total = 0
for i in range(1, len(s)):
    if res == s[i]:
        total += 1
        res = "0"
    else:
        res = s[i]
if len(s)>=3:
    if s[-2] != s[-1] and s[-1] == s[0]:
        total += 1
        a = 1
print(total*k-a)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    if len(S) == 1:
        print(K // 2)
        return
    result = 0
    piyo = 0
    hoge = S[0]
    huga = 1
    first = 0
    for s in S[1:]:
        if s == hoge:
            huga += 1
            if huga % 2 == 0:
                piyo += 1
        else:
            if first == 0:
                first = huga
            hoge = s
            huga = 1
    if first == 0:
        first = huga
    if first % 2 == 1 and huga % 2 == 1 and S[0] == S[-1]:
        result += K - 1
    print(piyo * K + result)
main()

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
result = 0
piyo = 0
hoge = S[0]
huga = 1
first = 0
for s in S[1:]:
    if s == hoge:
        huga += 1
        if huga % 2 == 0:
            piyo += 1
    else:
        if first == 0:
            first = huga
        hoge = s
        huga = 1
if first % 2 == 1 and huga % 2 == 1 and S[0] == S[-1]:
    result += K - 1
print(piyo * K + result)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
result = 0
piyo = 0
hoge = S[0]
huga = 1
for s in S[1:]:
    if s == hoge:
        huga += 1
        if huga % 2 == 0:
            piyo += 1
    else:
        hoge = s
        huga = 1
print(piyo * K)

Submission status: Wrong Answer

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

tmp = int(len(s))
c,c_2 = 0,0
for i in range(0,tmp,2):
    if i == tmp-1:
        break
    if s[i] == s[i+1]:
        c += 1
for i in range(1,tmp,2):
    if i == tmp-1:
        break
    if s[i] == s[i+1]:
        c_2 += 1
c *= k
c_2 *= k
ans = max(c,c_2)
c_3,c_4 = 0,0
if s[0] == s[-1]:
    #s = s[1:]
    s = s[:-1]
    tmp = int(len(s))
    for i in range(0,tmp,2):
        if i == tmp-1:
            break
        if s[i] == s[i+1]:
            c_3 += 1
    for i in range(1,tmp,2):
        if i == tmp-1:
            break
        if s[i] == s[i+1]:
            c_4 += 1
    c_3 *= k
    c_4 *= k
    c_3 += k - 1
    c_4 += k-1
    #print(c_3,c_4)
    ans_2 = max(c_3,c_4)
    ans = max(ans,ans_2)
print(ans)

Submission status: Wrong Answer

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

tmp = int(len(s))
c,c_2 = 0,0
for i in range(0,tmp,2):
    if i == tmp-1:
        break
    if s[i] == s[i+1]:
        c += 1
for i in range(1,tmp,2):
    if i == tmp-1:
        break
    if s[i] == s[i+1]:
        c_2 += 1
c *= k
c_2 *= k
ans = max(c,c_2)
c_3,c_4 = 0,0
if s[0] == s[-1]:
    s = s[1:]
    s = s[:-1]
    tmp = int(len(s))
    for i in range(0,tmp,2):
        if i == tmp-1:
            break
        if s[i] == s[i+1]:
            c_3 += 1
    for i in range(1,tmp,2):
        if i == tmp-1:
            break
        if s[i] == s[i+1]:
            c_4 += 1
    c_3 *= k
    c_4 *= k
    c_3 += k - 1
    c_4 += k-1
    ans_2 = max(c_3,c_4)
    ans = max(ans,ans_2)
print(ans)

Submission status: Wrong Answer

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

l = len(s)
cnt = 0
cnt_list = [0]

for i in range(l-1):#sの中での連続数
    if s[i] == s[i+1]:
        cnt += 1
        cnt_list.append(cnt)
    else:
        cnt = 0
        cnt_list.append(cnt)
#print(cnt_list)

for i in range(l-1):#sの末尾と最初がつながっているとき
    if s[-1] == s[i]:
        cnt += 1
        cnt_list.append(cnt)
    else:
        break
#print(cnt_list)#このときのlで繰り返すと考える
L = len(cnt_list)

if l == 1:
    print(k//2)
elif k == 1:#k = 1の時は関係ないので    
    ans = 0
    for i in cnt_list[:l]:#最初のl文字での回数
        if i % 2 == 1:
            ans += 1
    print(ans)
else:
    cnt_ref = cnt_list[L-l:] #繰り返し部分
    ans_ref = 0
    for i in cnt_ref:
        if i % 2 == 1:
            ans_ref += 1
    num_ref = (k*l-L) // l #num回繰り返す 
    #print("ans_ref =" ,ans_ref)
    
    amari = (k*l-L) % l
    ans_amari = 0
    for i in cnt_ref[:amari]:
        if i % 2 == 1:
            ans_amari += 1
    #print("ans_amari", ans_amari)
    #print("cnt_ref[:amari] = ", cnt_ref[:amari])        
    ans = 0
    for i in cnt_list:
        if i % 2 == 1:
            ans += 1
    #print("ans = ",ans)
    
    ans += ans_amari + ans_ref * num_ref
    print(ans)

Submission status: Wrong Answer

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

l = len(s)
cnt = 0
cnt_list = [0]

for i in range(l-1):#sの中での連続数
    if s[i] == s[i+1]:
        cnt += 1
        cnt_list.append(cnt)
    else:
        cnt = 0
        cnt_list.append(cnt)

#print(cnt_list)

for i in range(l-1):#sの末尾と最初がつながっているとき
    if s[-1] == s[i]:
        cnt += 1
        cnt_list.append(cnt)
    else:
        break
#print(cnt_list)#このときのlで繰り返すと考える
L = len(cnt_list)
            
if k == 1:#k = 1の時は関係ないので    
    ans = 0
    for i in cnt_list[:l]:#最初のl文字での回数
        if i % 2 == 1:
            ans += 1
    print(ans)
else:
    cnt_ref = cnt_list[L-l:] #繰り返し部分
    ans_ref = 0
    for i in cnt_ref:
        if i % 2 == 1:
            ans_ref += 1
    num_ref = (k*l-L)// l #num回繰り返す 
    #print("ans_ref =" ,ans_ref)
    
    amari = (k*l-L) % l
    ans_amari = 0
    for i in cnt_ref[:amari]:
        if i % 2 == 1:
            ans_amari += 1
    #print("ans_amari", ans_amari)
    #print("cnt_ref[:amari] = ", cnt_ref[:amari])        
    ans = 0
    for i in cnt_list:
        if i % 2 == 1:
            ans += 1
    #print("ans = ",ans)
    
    ans += ans_amari + ans_ref * num_ref
    print(ans)

Submission status: Wrong Answer

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

tmp = int(len(s))
c,c_2 = 0,0
for i in range(0,tmp,2):
    if i == tmp-1:
        break
    if s[i] == s[i+1]:
        c += 1
for i in range(1,tmp,2):
    if i == tmp-1:
        break
    if s[i] == s[i+1]:
        c_2 += 1

ans = max(c,c_2)
print(ans*k)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
S += S[0]
s = S[0]
ans = 0
flag = False
c = set()
c.add(s)
for i in range(1, len(S)):
    c.add(S[i])
    if s == S[i]:
        if i == len(S) - 1:
            k = 0
            for j in range(1, len(S)):
                if S[j] == i:
                    k += 1
                else:
                    break
            flag =  (k % 2 == 0)
        ans += 1
        s = '1'
    else:
        s = S[i]
ans = ans * K
if flag:
    ans -= 1
if len(c) == 1:
    print((len(S)-1) * K // 2)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
S += S[0]
s = S[0]
ans = 0
flag = False
for i in range(1, len(S)):
    if s == S[i]:
        if i == len(S) - 1:
            k = 0
            for j in range(1, len(S)):
                if S[j] == i:
                    k += 1
                else:
                    break
            flag =  (k % 2 == 0)
        ans += 1
        s = '1'
    else:
        s = S[i]
ans = ans * K
if flag:
    ans -= 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = list(input())
l = len(s)
k = int(input())
if len(set(s))==1:
  print(int(l//2*k))
  exit()
cou = []

a = s[0]
c = 0
for i in s:
  if i==a:
    c += 1
  else:
    cou.append(c)
    c =1
    a = i
cou.append(c)
cou1 = [i//2 for i in cou]

if s[0]!=s[-1]:
  print(sum(cou1)*k)
else:
  a = int((cou1[0]+cou[-1])//2)
  print(sum(cou1[1:-1])*k+a*(k-1)+cou1[0]+cou1[-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = list(input())

l = len(s)
cou = 0 
k = int(input())

for i in range(0,l-1):
  if s[i]==s[i+1]:
    s[i+1]='-1'
    cou += k
if s[0]!=s[-1]:
  print(cou)
else:
  c = 0
  for i in s:
    if s[0]==i:
      c += 1
    else:
      break
  for i in s[::-1]:
    if s[-1]==i:
      c += 1
    else:
      break
  print(int(cou+(k-1)*c//2))

Submission status: Wrong Answer

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

def separate(s):
	continuous=1
	s_sep=0
	for i in range(len(s)-1):
		if s[i]==s[i+1]:
			continuous+=1
		else:
			s_sep+=continuous//2
			continuous=1
	
	s_sep+=continuous//2
	return s_sep

s1=separate(S)
s2=separate(S*2)
if len(S)>1:
	print(s1+(s2-s1)*(K-1))
else:
	print(len(S)//2)

Submission status: Wrong Answer

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

def separate(s):
	continuous=1
	s_sep=0
	for i in range(len(s)-1):
		if s[i]==s[i+1]:
			continuous+=1
		else:
			s_sep+=continuous//2
			continuous=1
	
	s_sep+=continuous//2
	return s_sep

s1=separate(S)
s2=separate(S*2)
if len(S)>0:
	print(s1+(s2-s1)*(K-1))
else:
	print(len(S)//2)

Submission status: Wrong Answer

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

def separate(s):
	continuous=1
	s_sep=0
	for i in range(len(s)-1):
		if s[i]==s[i+1]:
			continuous+=1
		else:
			s_sep+=continuous//2
			continuous=1
	
	s_sep+=continuous//2
	return s_sep

s1=separate(S)
s2=separate(S*2)
print(s1+(s2-s1)*(K-1))

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

s = ns()
k = ni()
cnt = 1
li = []
prev = '@'
for c in s:
    if c == '@':
        cnt = 1
        prev = c
        continue
    elif prev == c:
        cnt += 1
    else:
        li.append(cnt)
        cnt = 1
        prev = c
else:
    li.append(cnt)
li = li[1:]

ans_ele = 0
ans = 0
if len(set(s)) == 1:
    ans = len(s) * k // 2
elif s[0] == s[-1] and li[0] == 1 and li[-1] == 1 :
    for e in li:
        if e >= 2:
            ans_ele += e // 2
    ans = ans_ele * k + k - 1
else:
    for e in li:
        if e >= 2:
            ans_ele += e // 2
    ans = ans_ele * k
print(ans)

""" same
1 ~ 1 :  + (k - 1)
2 ~ 1 : X
1 ~ 2 : X
2 ~ 2 : X
 and len(li) != 1
"""

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

s = ns()
k = ni()
cnt = 1
li = []
prev = '@'
for c in s:
    if c == '@':
        cnt = 1
        prev = c
        continue
    elif prev == c:
        cnt += 1
    else:
        li.append(cnt)
        cnt = 1
        prev = c
else:
    li.append(cnt)
li = li[1:]

ans_ele = 0
ans = 0
if len(set(s)) == 1:
    ans = len(s) * k // 2
elif s[0] == s[-1]:
    for e in li:
        if e >= 2:
            ans_ele += e // 2
    ans = ans_ele * k + k - 1
else:
    for e in li:
        if e >= 2:
            ans_ele += e // 2
    ans = ans_ele * k
print(ans)

""" same
1 ~ 1 :  + (k - 1)
2 ~ 1 : X
1 ~ 2 : X
2 ~ 2 : X
 and li[0] == 1 and li[-1] == 1 and len(li) != 1 """

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

s = ns()
k = ni()
cnt = 1
li = []
prev = '@'
for c in s:
    if c == '@':
        cnt = 1
        prev = c
        continue
    elif prev == c:
        cnt += 1
    else:
        li.append(cnt)
        cnt = 1
        prev = c
else:
    li.append(cnt)
li = li[1:]

ans_ele = 0
ans = 0
if len(set(s)) == 1:
    ans = len(s) * k // 2
elif s[0] == s[-1] and li[0] == 1 and li[-1] == 1 and len(li) != 1:
    for e in li:
        if e >= 2:
            ans_ele += e // 2
    ans = ans_ele * k + k - 1
else:
    for e in li:
        if e >= 2:
            ans_ele += e // 2
    ans = ans_ele * k
print(ans)

""" same
1 ~ 1 :  + (k - 1)
2 ~ 1 : X
1 ~ 2 : X
2 ~ 2 : X """

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

s = ns()
k = ni()
cnt = 1
li = []
prev = '@'
for c in s:
    if c == '@':
        cnt = 1
        prev = c
        continue
    elif prev == c:
        cnt += 1
    else:
        li.append(cnt)
        cnt = 1
        prev = c
else:
    li.append(cnt)
li = li[1:]

ans_ele = 0
ans = 0
if s[0] == s[-1] and li[0] == 1 and li[-1] == 1 and len(li) != 1:
    for e in li:
        if e >= 2:
            ans_ele += e // 2
    ans = ans_ele * k + k - 1
else:
    for e in li:
        if e >= 2:
            ans_ele += e // 2
    ans = ans_ele * k
print(ans)

""" same
1 ~ 1 :  + (k - 1)
2 ~ 1 : X
1 ~ 2 : X
2 ~ 2 : X """

Submission status: Wrong Answer

Solution code:
def myAnswer(S:list,K:int) -> int:
   if(len(S) == 1): return K // 2
   pre = S.pop(0)
   start = pre
   counter = 0
   # if(pre == S[-1] and S[-1] != S[-2]):
   #    counter += 1

   for s in S:
      if(pre == s):
         counter += 1
         pre = "-"
      else:
         pre = s
   if(start == pre):
      counter += 1
   return counter * K

def modelAnswer():
   return
def main():
   S = list(input())
   K = int(input())
   print(myAnswer(S,K))
if __name__ == '__main__':
   main()

Submission status: Wrong Answer

Solution code:
def myAnswer(S:list,K:int) -> int:
   if(len(S) == 1): return K//2
   if(len(S) == 2): return K
   pre = S.pop(0)
   counter = 0
   if(pre == S[-1] and S[-1] != S[-2]):
      counter += 1

   for s in S:
      if(pre == s):
         counter += 1
         pre = "-"
      else:
         pre = s
   return counter * K

def modelAnswer():
   return
def main():
   S = list(input())
   K = int(input())
   print(myAnswer(S,K))
if __name__ == '__main__':
   main()