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:
def check_subseq(s):
    subseq_list = []
    tmp_length = 1
    for i in range(1, len(s)):
        if s[i - 1] == s[i]:
            tmp_length += 1
        else:
            if tmp_length >= 2:
                subseq_list.append(tmp_length)
            tmp_length = 1
        
    if tmp_length >= 2:
        subseq_list.append(tmp_length)

    return subseq_list


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

if s[0] == s[-1]:
    if len(set(s)) == 1:
        print(len(s) * k // 2)
        exit()

    i = 1
    while True:
        if s[i] != s[-1]:
            first_subseq_length = i
            break
        i += 1

    i = 1
    while True:
        if s[-(i + 1)] != s[0]:
            last_subseq_length = i
            break
        i += 1

    print(first_subseq_length, last_subseq_length)
    s = s[first_subseq_length:] + s[:first_subseq_length]
    subseq_list = check_subseq(s)
    ans = sum(map(lambda x: x // 2, subseq_list)) * k
    ans += first_subseq_length // 2 + last_subseq_length // 2 - subseq_list[-1] // 2
else:
    subseq_list = check_subseq(s)
    ans = sum(map(lambda x: x // 2, subseq_list)) * k
print(ans)

Submission status: Wrong Answer

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

cnt=0
i=1
while i <len(s):
  if i>0:
    if s[i]==s[i-1]:
      cnt+=1
      i+=2
    else:
      i+=1
  
if k==1:
  print(cnt)
  exit()
  
ss=s+s
cntcnt=0
i=1
while i <len(ss):
  if i>0:
    if ss[i]==ss[i-1]:
      cntcnt+=1
      i+=2
    else:
      i+=1
if k==2:
  print(cntcnt)
  exit()
  
sss=s+s+s
cntcntcnt=0
i=1
while i <len(sss):
  if i>0:
    if sss[i]==sss[i-1]:
      cntcntcnt+=1
      i+=2
    else:
      i+=1
if k==3:
  print(cntcntcnt)
  exit()

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

print(cntcnt+(cntcntcnt-cntcnt)*(k-2))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(int(1e6))

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

count = 0
s0 = S[0]
s1 = ''
s2 = ''
s3 = ''
prev_rewrite = False
for s2 in S:
    if s1 == s2 and not prev_rewrite:
        code = ord(s2) + 1
        s3 = chr(code) if code <= ord('z') else 'a'
        count += 1
        prev_rewrite = True
    else:
        s3 = s2
        prev_rewrite = False

    s1 = s3
else:
    if s0 == s3 and not prev_rewrite:
        count += 1

ans = count * K
print(ans)

Submission status: Wrong Answer

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

if len(s)==1:
  print(k//2)
else:
  
  if s[0]==s[-1]:
    p+=1

  l=[1]
  for i in range(len(s)-1):
    if s[i]!=s[i+1]:
      l.append(1)
    else:
      l[-1]+=1
  x=[i//2 for i in l]
  y=sum(x)
  if s[-1]==s[-2]:
    print((y-1)*k+p*k)
  else:
    print(y*k+p*(k-1))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if s.count(s[0])==len(s):
        print(len(s)*k//2)
        exit()
    if len(s) <= j:
        break
    if s[j] == s[j - 1]:
        if j == 0:
            n += 1
            if s[j - 1] == s[j - 2] or s[j] == s[j + 1]:
                n -= 1
            j += 1
        else:
            if len(s) > 2:
                m += 1
                j += 1
    j += 1
print(m * k + n * (k - 1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=list(input())
k=int(input())
s=s*1000
ans=0
for i in range(1,len(s)):
    if s[i-1]==s[i]:
        ans+=1
        s[i]="A"
print(int(ans*(k/1000)))

Submission status: Wrong Answer

Solution code:
#import sys

#input = sys.stdin.readline

#import heapq
#import math
#import fractions

#def sosuhante(n):
#    for k in range(2, int(math.sqrt(n))+1):
#        if n% k ==0:
#            return False
#    return True

def main():
#    h,w,a,b = map(int, input().split())
    s = input()
    k= int(input())
    a= []
    b= []
    n=len(s)
    for i in range(n):
        a.append(s[i])
        b.append(s[i])

    a[0]="a"
    if n > 1:
        for i in range(1,n):
            if b[i]==b[i-1]:
                a[i]="a" if a[i-1]=="a" else "b"
            else:
                a[i]="b" if a[i-1]=="a" else "a"
#    print(a)
    temp=1
    henka=0
    if n > 1:
        for i in range(1,n):
            if a[i]==a[i-1]:
                temp+=1
                if i==n-1:
                    henka+=temp//2
                    temp=1
            else:
                henka+=temp//2
                temp=1
    temp=1
    hasi=0
    mae=1
    usiro=1
    if k > 1 and n > 1 and b[0]==b[n-1]:
        for i in range(1,n):
            if a[i]==a[i-1]:
                temp+=1
                if i==n-1:
                    mae=temp
            else:
                mae=temp
                break
        temp=1
        for i in range(n-2,0,-1):
            if a[i]==a[i+1]:
                temp+=1
                if i==0:
                    usiro=temp
            else:
                usiro=temp
                break
        if (mae+usiro)//2 > mae//2 + usiro//2:
            hasi=1
#    print(henka,"henka")
    count=0
    if k > 1 and n>1:
        count=henka*k + hasi*(k-1)
    if k == 1 and n>1:
        count=henka
    if n==1 and k==1:
        count=0
    if n==1 and k>1:
        count=k//2


    print(count)





if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s=input()
t=s*2
k=int(input())
c,d=1,0
for i in range(1,len(s)):
    if s[i-1]==s[i]:
        c+=1
    else:
        d+=c//2
        c=1
d+=c//2
l,r,p,q=t[0],t[-1],0,0
while s[0]==l:
    s=s[1:]
    p+=1
    if len(s)==0:
        break
if len(s)!=0:
    while s[-1]==r:
        s=s[:-1]
        q+=1
        if len(s)==0:
            break
if t[0]==t[-1]:
    print((k-1)*((p+q)//2)+d*k-(k-1)*(p//2+q//2))
else:
    print(d*k)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
ls = [str for str in S]
if len(set(ls))==1:
  cnt=len(S)*K//2
  print(cnt)
  exit()

if not ls[0]==ls[-1]:
  i=0
  cnt=0
  while i<len(S)-1:
    if ls[i+1]==ls[i]:
      ls[i+1]="0"
      cnt+=1
      i+=1
    else:
      i+=1
    ans=cnt*K
else:
  j=0
  atama=0
  while j<len(S):
    if ls[j+1]==ls[j]:
      j+=1
      atama+=1
    else:
      break
  k=0
  oshiri=0
  while k<len(S):
    if ls[-k-2]==ls[-k-1]:
      k+=1
      oshiri+=1
    else:
      break
  E=ls[atama+1:]+ls[:atama]
  i=0
  cnt=0
  while i<len(S)-1:
    if ls[i+1]==ls[i]:
      ls[i+1]="0"
      cnt+=1
      i+=1
    else:
      i+=1
  ans=cnt*K
  if atama*oshiri%2==1:
    ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

S = input()
N = int(input())

if len(S) == 1:
    print(N-1)
    exit()

if len(S) == 2 and S[0] == S[1]:
    print(N)
    exit()

check = S
check_num = sum(len(list(v))//2 for k, v in groupby(check))
check2 = S * 2
check2_num = sum(len(list(v))//2 for k, v in groupby(check2))
check3 = S * 3
check3_num = sum(len(list(v))//2 for k, v in groupby(check3))

ans = check_num*N + (check2_num-2*check_num)*(N-1)
if check3_num == ans:
    print(ans)
else:
    print(round(N/2)*check_num + N//2*(check2_num-check_num))

Submission status: Wrong Answer

Solution code:
from itertools import groupby
S = input()
K = int(input())

# 単位文字列で置換する
s = [[k, len(list(g))] for k, g in groupby(S)]
s_count = sum(ss[1] // 2 for ss in s)
result = s_count * K

# 最初と最後の文字が同じで、かつ最初か最後の文字列が奇数だった場合の調整
# print(s[0], s[-1])
if s[0][0] == s[-1][0] and (s[0][1] % 2 == 1 and s[-1][1] % 2 == 1):
#    print("調整あり")
    result += K - 1

print(result)

Submission status: Wrong Answer

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

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

zcount=0
ju=0
for i in range(len(S)):
  if S[i]==S[0]:
    zcount+=1
    if i==len(S)-1:
      ju=1
  else:
    break

if ju==0:
  for i in reversed(range(len(S))):
    if S[i]==S[0]:
      zcount+=1
    else:
      break
  
if S[0]==S[1]:
  S[0]="#"
for i in range(1,len(S)):
  if S[i-1]==S[i]:
    S[i]="#"

ans=S.count("#")
if ju==1 and len(S)%2==1:
  print((len(S)*K)//2)
  exit()
  
if S[0]=="#" and zcount%2==1 and ju==0:
  ans-=1
  if S[-2]!=S[0]:
    ans+=1

if zcount==2:
  print(ans*K+(K-1))
  exit()
  
print(ans*K)

Submission status: Wrong Answer

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

SL=list(S)
seq=0
for i in range(len(SL)-1):
  if SL[i]==SL[i+1]:
    SL[i+1]=SL[i+1].upper()
    seq+=1

if K==1 or SL[0]!=SL[-1]:
  print(seq*K)
else:
  SL2=list(S)
  SL2[0]="#"
  seq2=1
  for i in range(1,len(SL2)-1):
    if SL2[i]==SL2[i+1]:
      SL2[i+1]=SL2[i+1].upper()
      seq2+=1
  
  if K%2==0:
    print((seq+seq2)*(K//2))
  else:
    print(seq*((K+1)//2)+seq2*(K//2))

Submission status: Wrong Answer

Solution code:
s=list(input())
ss=s*2
k=int(input())
cnt1,cnt2=0,0
for i in range(len(ss)-1):
    if ss[i]==ss[i+1] and i<=len(s)-1:
        cnt1+=1
        ss[i+1]='.'
    elif ss[i]==ss[i+1] and i>len(s)-1:
        cnt2+=1
        ss[i+1]='.'
if k%2==0:
    print((cnt1*(k//2))+cnt2*((k//2)))
else:
    print((cnt1*(k//2))+cnt2*((k//2)+1))

Submission status: Wrong Answer

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

l = list(s)

count = 0
new_l = l.copy()

for i, c in enumerate(s[1:]):

    if c == new_l[i]:
        new_l[i + 1] = 0
        count += 1

result = count * k

if new_l[0] == new_l[-1]:
    result = +k - 1
print(result)

Submission status: Wrong Answer

Solution code:
S = input()
k = input()
flag=False
cnt=0
for i in range(len(S)):
  if(flag):
    flag=False
    continue;
  if(i<len(S)-1):
    if(S[i] == S[i+1]): 
      flag=True
      cnt +=1
  if(i==len(S)-1):
    if(S[i] == S[0]): 
      cnt +=1
print(cnt*int(k))

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
L = len(S)
a = S[0]
i = 0
C = []
if L == 1:
    C = [0]
while i < L-1:
    count = 1
    b,c = S[i],S[i+1]
    i+= 1
    while b == c:
        count += 1
        if i == L-1:
            break
        b,c = S[i],S[i+1]
        i += 1
    C.append(count)
if a != S[L-1]:
    num = 0
    for co in C:
        num += co//2
    ans = int(num*K)
else:
    num1 = 0
    for co in C:
        num1 += co//2
    num2 = (C[len(C)-1]+1)//2
    for co in C[:len(C)-1]:
        num2 += co//2
    ans = int(num1+num2*(K-1))
if L == 1:
    ans = K//2
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
strings = ""
for i in range(k):
    strings += s
print(strings)
count = 0
for i in range(len(strings) - 2):
    tmp_str = strings[i:i+3]
    if tmp_str[0] == tmp_str[1]:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = input().rstrip()
        K = int(input())

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

        changes = 0
        start = 0
        end = len(S)
        cnt = 2

        if S[0] == S[-1] and len(S) == 2:
            print(K)
            exit()

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

            for i in range(1, len(S) - 1)[::-1]:
                if S[i] != S[0]:
                    end = i + 1
                    break
                cnt += 1

            changes += cnt // 2

        before = S[start]
        length = 1

        for i in range(start + 1, end):
            if S[i] == before:
                length += 1
            else:
                changes += length // 2
                length = 1
                before = S[i]

        changes += length // 2

        print(changes * K)


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Wrong Answer

Solution code:
#coding: utf-8
strings = str(input())
k = int(input())
s = strings + strings
count = 0

for i in range(len(s)-1):
	# print('strj'+str(j))
	if s[i] == s[i+1]:
		# print(str('s[i]=') + s[i] + str(' s[i+1]=') + s[i+1])
		count += 1
		# s[i] = str(i)
		s = s[:i+1] + str('A') + s[i+2:]
		# print(s)

# print(count)
ans = count*k//2

# if k % 2 == 0:
# 	count = count * k // 2
# else:
# 	print(count*k//2)
# 	print(count//2)
# 	count = count * k // 2 - (count // 2)

print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    s = input()
    k = int(input())
    c = 1
    ls = len(s)
    if len(set(s)) == 1 and ls % 2 == 1:
        if k % 2 == 0:
            ans = ls * (k // 2)
        else:
            ans = ls * (k // 2) + ls // 2
        print(ans)
    else:
        ans = 0
        for i in range(len(s) - 1):
            if s[i] == s[i + 1]:
                c += 1
            else:
                ans += c // 2
                c = 1
        ans += c // 2
        print(ans * k)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

for i in range(1, N):
    if S[i - 1] == S[i]:
        cnt += 1
        S[i] = "-1"
ans += cnt
if T[0] == T[-1] and S[N - 1] != "-1":
    cnt2 = 0
    for i in range(N):
        if T[i] == T[i - 1]:
            cnt2 += 1
            T[i] = "-1"
    ans += cnt2 * (K - 1)
else:
    ans += cnt * (K - 1)
print(ans)

Submission status: Wrong Answer

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

S2 = S * 2

singleCnt = 0
doubleCnt = 0
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    S[i+1] = "1" # かぶらない文字に変換
    singleCnt += 1
if S[0] != S[-1]:
  ans = singleCnt * K
  
elif S[0] == S[-1]:
  for i in range(len(S2)-1):
    if S2[i] == S2[i+1]:
      S2[i+1] = "1" # かぶらない文字に変換
      doubleCnt += 1
  if S2[0] != S2[-1]:
    ans = doubleCnt * K // 2 + singleCnt
  else:
    ans = (doubleCnt - singleCnt) * (K - 1) + singleCnt

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
s = input()
k = int(input())
ret = 0
t = 0
for i in range(len(s)-1):
    if s[i] != s[i + 1]:
        break
    if i == len(s)-2:
        print(len(s) * k // 2)
        sys.exit()

if k > 0:
    for j in range(1, 100):
        if j >= len(s):
            break
        for i in range(len(s)-j):
            for u in range(j):
                if s[i + u] != s[i + u + 1]:
                    break
                if u == j-1:
                    if j % 2==1:
                        t += 1
                    else:
                        t -= 1
    ret += t * k
    if len(s) > 2:
        if s[0] == s[-1] and s[-2] != s[-1]:
            ret += (k - 1)

if len(s) == 1:
    ret += k // 2

print(ret)

Submission status: Wrong Answer

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

def counter_func(string,x):
  try:
    if string[x] == string[x+1]:
      return 1
    else:
      return 0
  except:
    return 0
  
counter = []
count = 0
j = 0
while j < length:
  if counter_func(s,j) == 1:
    count += 1
  else:
    counter.append(count)
    count = 0
  j += 1
if s[-1] == s[0] and k > 1:
  counter[-1] += 1
sum = 0
if len(counter) != 1:
  for i in range(len(counter)):
    if counter[i] != 0:
      sum += int((counter[i]+1)/2)*k
else:
  sum = int((length*k)/2)
print(sum)

Submission status: Wrong Answer

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

n = len(s)
cnt = [0]

for i in range(0,n-1):
    if s[i] == s[i+1]:
        cnt[-1] += 1
    else:
        if cnt[-1] != 0:
            cnt.append(0)

ren = 0
for i in cnt:
    ren += int((i+1) // 2)

b=0
if s[0] == s[-1]:
    if (cnt[-1] % 2) == 0:
        b += k-1

ans = ren * k + b

print(ans)

Submission status: Wrong Answer

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

if len(s) == 1:
    print(k // 2)
else: 
    if s[0] == s[-1]:
        # head
        h = 1
        for i in range(1,len(s)):
            if s[0] == s[i]:
                h += 1
            else:
                break
        # tail
        t = 1
        for i in range(len(s)-2, -1, -1):
            if s[-1] == s[i]:
                t += 1
            else:
                break
        if h == len(s):
            # s only consists of the same letter
            z = (h * k) // 2
            k = 1
        else:
            z = (h + t) // 2
        #print(999,h,t,z)
    else:
        h = t = 0
    #print(s,k,h,t)
    if (h + t) < len(s):
        m = s[h]
        n = 1
        for i in range(h+1, len(s)-t):
            if m == s[i]:
                n += 1
                if (n & 2):
                    z += 1
            else:
                m = s[i]
                n = 1
    print(z * k)

Submission status: Wrong Answer

Solution code:
import itertools

S = input()
K = int(input())
totalx = 0
seq = [len(list(g)) for k, g in itertools.groupby(S)]
for i in range(len(seq)):
    if seq[i]%2==0:
        x = seq[i]
    else:
        x = seq[i]-1
    totalx+=int(x/2)
print(totalx*K)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if s.count(s[0])==len(s):
        print(len(s)*k//2)
        exit()
    if len(s) <= j:
        break
    if s[j] == s[j - 1]:
        if j == 0:
            n += 1
            if len(s) == 2:
                k += 1
            elif s[j - 1] == s[j - 2] or s[j] == s[j + 1]:
                n -= 1
            j += 1
        else:
            if len(s) > 2:
                m += 1
                j += 1
    j += 1
print(m * k + n * (k - 1))

Submission status: Wrong Answer

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

pre_str = ''
count = 1
ret = 0
for a in list(S):
    if pre_str == a:
        count += 1
    else:
        ret += int(count / 2)
        count = 1
        pre_str = a
ret += int(count / 2)
print(ret*K)

Submission status: Wrong Answer

Solution code:
st = input()
s = [i for i in st]
k = int(input())
l = len(s)
c=0
i=0
while i<l-1:
    if i+1 <=l-1 and s[i]==s[i+1]:
        s[i+1]='#'
        c+=1
        i+=1
    else:
        i+=1

# print(c)
c*=k
if k>1:
    a = s[0]
    if a==s[-1]:
        c+=k-1
if l==1:
    if k%2==0:
        c=k//2
    else:
        c = (k-1)//2
print(c)

Submission status: Wrong Answer

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

count = 0

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        count += 1
        S = S[:i+1] + "#" + S[i+2:]

print(count*K)

Submission status: Wrong Answer

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

counter = 0
tmp = s[0]
counter_list = []

s_dict = dict()
for i,one in enumerate(s):
    s_dict[one] = i
    
if len(s_dict) == 1:
    print((len(s)*k)//2)
else:
    for one in s[1:]:
        if tmp == one:
            counter += 1
        else:
            counter_list.append((counter+1)//2)
            counter = 0
            tmp = one
    counter_list.append((counter+1)//2)

    sum_counter = sum(counter_list)
    if s[0] == s[-1]:
        if (counter+counter_list[0]+2) % 2 == 0:
            print(sum_counter*k)
        else:
            #print(sum_counter*k + k -1)
            print(sum_counter*k)
    else:
        print(sum_counter*k)

Submission status: Wrong Answer

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

n = len(s)
cnt = 1
arr = []

# 配列全体のループ
for i in range(n):
    try:
        if s[i] == s[i+1]: cnt += 1
        else: arr.append(cnt) ; cnt = 1
    except: arr.append(cnt)

if len(arr) == 1 : pass
elif s[0] == s[n-1] : arr[0],arr[len(arr)-1] = 0,arr[0]+arr[len(arr)-1]

ans = 0
for i in range(len(arr)):
    ans += arr[i]//2
ans *= k
if arr[0]==0 and arr[len(arr)-1]%2==0 : ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = raw_input()
k = raw_input()
c = 0
i = 0
out = 0
while( i < len(s)-1 ):
  if s[i] == s[i+1]:
    c += 1
    i += 1
  elif i == len(s)-2 and s[0] == s[len(s)-1]:
    out = out + 1
  i += 1
out = out + int(k)*c
print(out)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	s = input()
	k = int(input())
	s_ = [[s[0],1]]
	ct = 0
	for i in s[1:-1]:
		if(s_[-1][0] == i):
			s_[-1][1] += 1
		else:
			s_.append([i,1])
	for i in s_:
		if(i[1] > 1):
			ct += math.ceil((i[1] - 1)/2)
	ct *= k
	if((len(s) - 1) % 2 == 1 and len(s_ ) == 1):
		print((len(s) - 1) * k // 2)
	elif(s[0] == s[-2] and s_[0][1] == s_[-1][1]):
		print(ct + k - 1)
	else:
		print(ct)


def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
a = '0'
cnt = 0
flag = 1
out = 0

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        s[i+1] = a
        cnt += 1

if s[0] == s[len(s)-1]:
    cnt += 1
    flag = -1

out = cnt * k

if flag == -1:
    out -= 1

print(out)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
S=input()
K=int(input())
d=defaultdict(int)
first_last=0
memo=[0]*len(S)
count=0
for i in range(len(S)):
  if i>=1:
    if (S[i]==S[i-1])and(memo[i-1]==0):
      count+=1
      memo[i]=1
if (S[0]==S[-1]) and (memo[-1]==0):
  count+=1
  first_last+=1

if first_last==1:
  print(count*K-1)
else:
  print(count*K)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

s = input()
k = int(input())
a = [sum(1 for _ in g) for _, g in groupby(s)]
x, y = a[0], a[-1] if len(a) > 1 else 0
b = (x + y) // 2 if s[0] == s[-1] else x // 2 + y // 2
print(x // 2 + y // 2 + sum(x // 2 for x in a[1:-1]) * k + b * (k - 1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def resolve():
    s = input()
    k = int(input())
    c = 1
    ls = len(s)
    if len(set(s)) == 1 and ls % 2 == 1:
        if k % 2 == 0:
            ans = ls * k // 2
        else:
            ans = ls * (k // 2) + ls // 2
        print(ans)
    else:
        ans = 0
        for i in range(len(s) - 1):
            if s[i] == s[i + 1]:
                c += 1
            else:
                ans += c // 2
                c = 1
        ans += c // 2
        print(ans * k)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-

s = input()
k = int(input())
flag = 1
lenth = 1
ans = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        lenth += 1
    else :
        flag = 0
    if flag == 0:
       ans += lenth//2
       lenth = 1
       flag = 1
ans += lenth//2
lenth = 1
flag = 1

ji = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        lenth += 1
    else :
        flag = 0
    if flag == 0:
       # print(lenth)
       if lenth%2 == 1:
            ji += 1
       break
if lenth%2 == 1 and flag ==1:
    ji += 1
lenth = 1
flag = 1
for i in range(len(s)-1):

    if s[len(s)-i-1] == s[len(s)-1-(i+1)]:
        lenth += 1
    else :
        flag = 0
    if flag == 0:
       # print(lenth)
       if lenth%2 == 1:
            ji += 1
       break
if lenth%2 == 1 and flag == 1:
    ji += 1
ans = ans*k
# print(ans, ji)
if ji == 2 and s[0] == s[len(s)-1]:
    ans = ans+k-1
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
total=0
count=0
flag=0
ss=0
if len(S)==1:
    print(K//2)
    exit(0)
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        count+=1
    else:
        if flag==0:
            ss=count+1
        flag=1
        count+=1
        total+=count//2
        count=0
    #print(count)

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


count+=1
if S[len(S)-1]==S[0]:
    count+=1
total+=count//2
if (count+ss-1)%2==0:
    print(total*K-1)
else:
    if ss%2==0:
        print(total*K-K)
    else:
        print(total * K )

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

T = S

if len(T) == 1:
    print(0)
    exit()

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

count *= K

if T[0] == T[-1]:
    if T[0] != T[1]:
        count += (K-1)

print(count)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

N=len(S)
t=S[0]
cnt=0
arr=[]
for s in S[1:N]:
    if t==s:
        cnt+=1
    else:
        if cnt!=0:
            arr.append((cnt+1)//2)
        cnt=0
    t=s
arr.append((cnt+1)//2)
if N>=5 and S[0]==S[-1] and S[0]!=S[1] and S[-1]!=S[-2]:
    print((sum(arr)+1)*K)
else:
    print((sum(arr))*K)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
cnt = 0
i = 0
c0 = 0
c1 = 0
key = 0
endkey = 0
while i < len(s) - 1:
    if s[i] == s[i + 1]:
        start = i
        end = i
        for j in range(i + 1, len(s)):
            end = j
            if s[j] != s[i]:
                break

        if end == len(s) - 1: #もし最後の一文字が連続に含まれるとき
            if (end - start) % 2 == 0 and s[-1] == s[0]: #最後の一文字が連続でかつ最初の文字と同じでかつ奇数の時
                end += 1
                endkey = 1
            end += 1
        cnt += (end - start) // 2 * k

        if start == 0 and end == len(s) and len(s) % 2 == 1:
            key = 1
            cnt += (end - start) * k // 2
            if k % 2 == 1:
                cnt += (end - start) // 2
        i = end - 1
        # print(start, end)
    i += 1

if len(s) == 1:
    cnt += k // 2
if endkey:
    cnt -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
def read():
    S = str(input().strip())
    K = int(input().strip())
    return S, K

def rle_encode(S):
    S1 = S + '@'
    rle = list()
    head = 0
    for i in range(0, len(S1)):
        if S1[i] != S1[head]:
            rle.append((S1[head], i-head))
            head = i
    return rle

def solve(S, K):
    count = 0
    rle = rle_encode(S)
    if len(rle) == 1:
        return rle[0][1] * K // 2
    else:
        for c, n in rle:
            count += n // 2
        count *= K
        if rle[-1][0] == S[0] and rle[-1][1] % 2 == 1:
            count += (K-1)
    return count

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Wrong Answer

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

count = 0

if len(S)%2 == 1:
    for i in range( len(S)//2 ):
        if S[2*i+1] == S[2*i] or S[2*i+1] == S[2*i+2]:
            count +=1
else:
    for i in range( len(S)//2 ):
        if S[2*i+1] == S[2*i]:
            count +=1
        
print(count*K)

Submission status: Wrong Answer

Solution code:
s=list(input())
k=int(input())
if len(s)==1:
    print(k//2)
    exit()
from collections import Counter
l=Counter(s)
if len(l)==1:
    print(k*len(s)//2)
    exit()
ans=0
f=1
for i in range(len(s)-1):
    if s[i]==s[i+1] and f:
        ans+=1
        f=0
    else:
        f=1
if len(s)>=3 and s[0]==s[1] and s[1]==s[2] and s[0]==s[-1] and f==1:
    print(ans*k+k-1)
    exit()
if s[0]==s[1] and s[0]==s[-1] and f==1:
    print(ans*k)
    exit()
if s[-1]!=s[-2] and s[0]==s[-1]:
    print(ans*k+k-1)
    exit()
if s[0]==s[-1] and f==1:
    print(ans*k+k-1)
    exit()


print(ans*k)

Submission status: Wrong Answer

Solution code:
#coding: utf-8

S=list(input())
K=int(input())
n=len(S)*K

if len(S)==1:	
	print(n//2 if n%2==0 else (n-1)//2)
	exit()

c = 0


for i in range(1,len(S)):
	if S[i]==S[i-1]:
		c+=K
		S[i] = "?"

if S[0] == S[-1]:
	c+=K
	S[0] = "!"

		
print(c)