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())

if len(S) == 1:
    print(K//2)
elif len(S) % 2 == 1 and K % 2 == 1 and len(set(S)) == 1:
    print(len(S)*K//2)
else:
    c = 0
    flg = False
    for i in range(len(S)-1):
        if S[i] == S[i+1] and flg is False:
            c += 1
            flg = True
        else:
            flg = False

    if flg is False and S[-1] == S[0]:
        j = 1
    else:
        j = 0

    print(c*K+j*(K-1))
    # print(c, j)

Submission status: Wrong Answer

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

def main():
    S = input()
    K = int(input())

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


    R = []
    lastLetter = None
    cnt = 0

    for c in S:
        if lastLetter == c:
            cnt += 1
        else:
            lastLetter = c
            if cnt > 0:
                R.append(cnt)

            cnt = 1
    
    R.append(cnt)
    S = 1 if len(R) > 1 and S[0] == S[-1] and R[0]%2 == 1 and R[-1]%2 == 1 else 0

    x = sum(r//2 for r in R)*K + (K-1)*S

    print(x)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
#ts=time.time()
#sys.setrecursionlimit(10**6)
#input=sys.stdin.readline
show_flg=False
show_flg=True

b=StoI()
a=b+[b[0]]
k=I()
n=len(a)
p=a[0]
t=0
for i in range(n-1):
    if p==a[i+1]:
        t+=1
        p=-1
    else:
        p=a[i+1]

ans=t*k
if n==2:
    ans=k//2
if len(Counter(b))==1:
    ans=(k*len(b))//2
print(ans)
#show(a,k)

Submission status: Wrong Answer

Solution code:
import sys

S = input()
K = int(input())
N = len(S)
Ans = 0
i = 0

if N == 1:
  KK = K // 2
  Ans = Ans + KK
  print(Ans)
  sys.exit()

while i < N-1:
  if S[i] == S[i+1]:
    Ans = Ans + 1
    i = i + 2
  else:
    i = i + 1

Ans = Ans * K

if S[N-2] != S[N-1] and S[N-1] == S[0]:
  Ans = Ans + K - 1

print(Ans)

Submission status: Wrong Answer

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

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

flag = False
if s[0] == s[-1]:
    flag = True
    #sとの連結部分も考える
    count = 0
    dp = ""
    for i in range(len(s)):
        if dp == s[i]:
            count += 1
            dp = ""
        else:
            dp = s[i]
    ans = count * k

else:
    #sの中だけ考える
    count = 0
    dp = ""
    for i in range(len(s)):
        if dp == s[i]:
            count += 1
            dp = ""
        else:
            dp = s[i]
    ans = count * k

if flag == True:
    try:
        #もし後ろ３つが同じなら
        if set([s[-1],s[-2],s[-3]]) == 1:
            print("3連続")
            ans = ans + (k-1)
    except IndexError:
        pass
else:
    pass

print(ans)

Submission status: Wrong Answer

Solution code:
def li():
    return list(map(input().split()))


if __name__ == "__main__":
    s = input()
    k = int(input())

    count = 0
    first = s[0]
    same_count_start = 0
    before = ""
    for si in s:
        if before == si:
            count += 1
            before = ""
        else:
            before = si
    if si == first:
        same_count_start += 1

    is_corner = before == s[0] and same_count_start % 2 == 1
    corner_count = k - 1 if is_corner else 0
    print(count * k + corner_count)

Submission status: Wrong Answer

Solution code:
def count(st):
    n=len(st)
    tmp=1
    res=[]
    for i in range(n-1):
        if st[i]==st[i+1]:
            tmp+=1
        else:
            res.append(tmp)
            tmp=1
    res.append(tmp)
    return res
S=input()
K=int(input())
T=S*3
N=len(S)
if N==1:
    print(K//2)
    exit()
if K<=2:
    Y=count(S*K)
    ans=0
    for i in Y:
        ans+=i//2
    print(ans)
    exit()
X=[]
if S[0]==S[-1]:
    j=0
    for j in range(1,N):
        if S[j-1]!=S[j]:
            break
    tmp=1
    for i in range(j,j+N-1):
        if T[i]==T[i+1]:
            tmp+=1
        else:
            X.append(tmp)
            tmp=1
    X.append(tmp)
else:
    X=count(S)

cnt=0
for i in X:
    cnt+=i//2
Y=count(T)
cnt2=0
for i in Y:
    cnt2+=i//2
print(cnt*(K-3)+cnt2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import re
import sys

s = input()
k = int(input())
count=0

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

pattern = "a+|b+|c+|d+|e+|f+|g+|h+|i+|j+|k+|l+|m+|n+|o+|p+|q+|r+|s+|t+|u+|v+|w+|x+"
result = re.finditer(pattern, s)
for res in result:
  #print(res.group())
  l = res.end()-res.start()
  if l>1:
    #切り捨て
    count += l//2
    #print(count)

if s[0]==s[-1] and count==0:
  count += k-1
else:
  count *= k
  
print(count)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()
n = len(s)
k = ni()

if n == 1:
    print(k // 2)
else:
    # 2個つなげる
    s2 = s + s

    # 前半、後半の変える場所を記録
    prev = ""
    flag = True
    fst = 0
    lat = 0
    for i, si in enumerate(s2):
        if si == prev:
            if flag:
                if i < n:
                    fst += 1
                else:
                    lat += 1
                flag = False

            else:
                flag = True
        else:
            flag = True

        prev = si

    print(fst + lat * (k-1))

Submission status: Wrong Answer

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

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

if s[0] != s[-1]:
    count = 1
    box = []
    for i in range(len(s)-1):
        if s[i+1] == s[i]:
            count += 1
        else:
            box.append(count)
            count = 1
    if count > 1:
        box.append(count)

    ans = 0
    for b in box:
        ans += b // 2
    print(ans * k)
    exit()

flag = 0
word = s[0]
for si in s:
    if si != word:
        flag = 1

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



count = 1
box = []
for i in range(len(s)-1):
    if s[i+1] == s[i]:
        count += 1
    else:
        box.append(count)
        count = 1
if count > 1:
    box.append(count)

front = box[0] // 2
back = box[-1] // 2

mid = 0
for i in range(len(box)-1):
    if i == 0:
        continue
    mid += box[i] // 2

joint = (box[0] + box[-1]) // 2

print(front + back + mid * k + joint * k-1)

Submission status: Wrong Answer

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

cnt = 0
L = len(S)

if L == 1:
    print(K//2)
    exit()

changed = False
for i in range(L-1):
    if not changed:
        if i == L - 2:
            if S[i] == S[i + 1]:
                cnt += 1
                changed = True
            else:
                if K > 1:
                    if S[i] == S[i + 1]:
                        cnt += 1
                        changed = True
        else:
            if S[i] == S[i+1]:
                cnt += 1
                changed = True
    else:
        changed = False

print(cnt*K)

Submission status: Wrong Answer

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

def count(string):
    total = 0
    i = 1
    while i < len(string):
        if string[i-1] == string[i]:
            total += 1
            if i+1 < len(string) and string[i+1] == string[i]:
                i += 1
        i += 1
    return total

        
if S[0] == S[-1]:
    new = S.strip(S[0])
    res = K * (count(new) + (len(S) - len(new)) // 2)
else:
    res = K * count(S)

print(res)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    a = list(S)
    cnt = 0
    for i in range(len(a)-1):
        if a[i+1] == a[i]:
            a[i+1] = str(i)
            cnt += 1
    cnt *= K
    if a[0] == a[-1] and len(a) > 1:
        cnt += K-1
    else:
        cnt += K//2
    print(cnt)

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

for i in range(len(S)):
  if SR[i]==SR[i+1]:
    cnt+=1

ans = cnt*K
print(ans)

Submission status: Wrong Answer

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

tmp = ""
cnt = 0
ans = 0
for s in S:
    if s == tmp:
        cnt += 1
    else:
        ans += cnt//2
        cnt = 1
    tmp = s
ans *= K
first_cnt = 0
if S[0] == S[-1]:
    for s in S:
        if s == S[0]:
            first_cnt += 1
        else:
            break
    if first_cnt == len(S):
        first_cnt = 0
ans += (cnt+first_cnt)//2 * (K-1)
ans += cnt//2

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 * 2
check_num = sum(len(list(v))//2 for k, v in groupby(check))
if check_num == 1:
    print(N-1)
else:
    print(check_num*N//2)

Submission status: Wrong Answer

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

count = 0
flag = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        s = s[:i+1] + "0" + s[i+2:]
        count += 1

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


if flag == 0:
    print(count * k)
else:
    print(count * k - 1)

Submission status: Wrong Answer

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

S+="*"

count=1
result=0
for x in range(len(S)-1):
    if S[x]==S[x+1]:# and S[x+1]!="*":
        count+=1
    else:
        if count>1:
             result+=int(count/2)
        count=1
    #print(S[x],":",S[x+1])
    #print(count)
    #print(result)
result*=K
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ans=0
tmp=0
before=s[0]
t=0
flag=0
tmp2=0
hoge=0
for i in range(len(s)-1):
    if before==s[i+1]:
        t+=1
    else:
        if flag==0:
            hoge+=t
            flag=1
        else:
            tmp+=-(-t//2)
        if i==len(s)-2:
            hoge+=t
        t=0
        before=s[i+1]
tmp2=tmp-(-t//2)
tmp+=-(-t//2)
if s[0]==s[-1]:
    print(tmp2*(k-1)+tmp)
else:
    print(tmp2*k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

ans = 0
T = list(S)
b = 0

for i, t in enumerate(T[1:-1], start=1):
    if t == T[i - 1] and T[i - 1] != '.':
        b += 1
        T[i] = '.'

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

print(ans + b * K)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
p=s[0]
cnt=1
q=[]
for i in range(len(s)-1):
	if s[i+1]==p:
		cnt+=1
	else:
		q.append(cnt//2)
		cnt=1
		p=s[i+1]
q.append(cnt//2)
import copy
qq=copy.copy(q)
for i in range(len(s)):
	if s[i]==p:
		cnt+=1
	else:
		qq[-1]=(cnt//2)
		cnt=0
		break
if cnt>0:
	print(len(s)*k//2)
	exit()
ans=0
ans+=(k-1)*sum(qq)
ans+=sum(q)
print(ans)

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    s = input()
    k = ii()
    s = list(s)
    sc = deepcopy(s)

    n = len(s)
    cnt = 0
    for i in range(1,n):
        if sc[i] == sc[i-1]:
            sc[i] = '0'
            cnt+=1
    
    if sc[n-1] == sc[n-2] or sc[0] == sc[n-1]:
        flag = True
    else:
        flag = False

    ans = cnt*k+(flag*(k-1))

    cnt = 1
    s[0] = '0'
    for i in range(1,n):
        if s[i] == s[i-1]:
            s[i] = '0'
            cnt+=1
    
    if s[n-1] == s[n-2] or s[0] == s[n-1]:
        flag = True
    else:
        flag = False

    ans2 = cnt*k+(flag*k)
    print(min(ans,ans2))





main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
S = list(input())[: -1]
K = int(input())
if len(S) == 1:
  print(K // 2)
  exit(0)
res = 0
a = 0
i = 0
while i < len(S) - 1:
  if S[i] == S[i + 1]:
    res += 1
    if i == 0:
      a -= 1
    if i == len(S) - 2:
      a -= 1
    i += 1
  i += 1
if S[0] == S[-1]: 
  a += 1
print(res * K + max(a, 0) * (K - 1))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
S = input()
K = int(input())

lenS = len(S)
cntD = 0
cntE = 0
i = 0
if lenS == 1:
    print(K//2)
    exit()
while i < lenS:
    if i == lenS-1:
        if S[i] == S[0]:
            cntE += 1
        i += 1
    else:
        if S[i] == S[i+1]:
            cntD += 1
            i += 2
        else:
            i += 1
print((cntD)*K + cntE*(K-1))

Submission status: Wrong Answer

Solution code:
#A問題
S = list(str(input()))
K = int(input())

if K == 1:
    ans = 0
    old = ""
    for s in S:
        if old == "":
            old = s
        else:
            if old == s:
                ans+=1
                old = ""
            else:
                old = s
    print(ans)
else:
    ans = 0
    old = ""
    T = S+S
    for t in T:
        if old == "":
            old = t
        else:
            if old == t:
                ans+=1
                old = ""
            else:
                old = t
    if K%2 == 0:
        print(ans*(K//2))
    else:
        ans2 = 0
        old = ""
        U = S+S+S
        for u in U:
            if old == "":
                old = u
            else:
                if old == u:
                    ans2+=1
                    old = ""
                else:
                    old = u
        print(ans*((K//2)-1) + ans2)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list
def summarize_list(l):
  sl=l

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res

def main():
  s=S()
  k=I()

  l=summarize_list(s)

  ans=0
  bf=False
  
  if l[0][0]==l[-1][0] and (l[-1][1]+l[0][1])%2==1:
    ans+=min(0,k-1)

  _ans=0
  for x in l:
    _ans+=x[1]//2
  ans+=_ans*k

  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as df
s=input().rstrip()
k=int(input())
if len(s)==1:
    print((k+1)//2)
    exit()
count=0
ans=0
s=[i for i in s]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        s[i]='1'
        count+=1

ans=(count*k)
if s[-1]==s[0]:
    ans+=k-1
print(ans)

Submission status: Wrong Answer

Solution code:
t=str(input())
k=int(input())
L = len(t)
tmp = t[0]
n = 0 #change
flag = 0
for i in range(1,L):
  if flag==1:
    flag=0
  elif t[i]==tmp:# and flag==0:
    n+=1
    flag=1  
  tmp=t[i]
ans=k*n
print(ans)

Submission status: Wrong Answer

Solution code:
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    s = input()
    k = ii()
    s = list(s)
    sc = deepcopy(s)

    n = len(s)
    cnt = 0
    for i in range(1,n):
        if sc[i] == sc[i-1]:
            sc[i] = '0'
            cnt+=1
    
    if sc[n-1] == sc[n-2] or sc[0] == sc[n-1]:
        flag = True
    else:
        flag = False

    ans = cnt*k+(flag*(k-1))

    cnt = 1
    s[0] = '0'
    for i in range(1,n):
        if s[i] == s[i-1]:
            s[i] = '0'
            cnt+=1
    
    if s[n-1] == s[n-2] or s[0] == s[n-1]:
        flag = True
    else:
        flag = False

    ans2 = cnt*k+(flag*k)
    print(min(ans,ans2))

Submission status: Wrong Answer

Solution code:
def count(st):
    n=len(st)
    tmp=1
    res=[]
    for i in range(n-1):
        if st[i]==st[i+1]:
            tmp+=1
        else:
            res.append(tmp)
            tmp=1
    res.append(tmp)
    return res
S=input()
K=int(input())
T=S*3
N=len(S)

if K<=2:
    Y=count(S*K)
    ans=0
    for i in Y:
        ans+=i//2
    print(ans)
    exit()
X=[]
if S[0]==S[-1]:
    j=0
    for j in range(1,N):
        if S[j-1]!=S[j]:
            break
    tmp=1
    for i in range(j,j+N-1):
        if T[i]==T[i+1]:
            tmp+=1
        else:
            X.append(tmp)
            tmp=1
    X.append(tmp)
else:
    X=count(S)

cnt=0
for i in X:
    cnt+=i//2
Y=count(T)
cnt2=0
for i in Y:
    cnt2+=i//2
print(cnt*(K-3)+cnt2)

Submission status: Wrong Answer

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

change = []
tmp = 1
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        tmp += 1
    else:
        change.append(tmp)
        tmp = 1
change.append(tmp)

#print(change)

ret = 0
if len(s) >= 3:

    for i in range(1, len(change) - 1):
        ret += change[i] // 2 * k
    
    if s[0] == s[-1]:
        ret += (change[0] + change[-1]) // 2 * (k - 1) + change[0] // 2 + change[-1] // 2
    else:
        ret += (change[0] // 2 + change[-1] // 2) * k
elif len(s) == 2:
    if s[0] == s[-1]:
        ret = k
    else:
        ret = 0
else:
    ret = k // 2

print(ret)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
flag = False
count = 0
for i in range(len(S)-1):
    if not flag:
        if S[i] == S[i+1]:
            count += 1
            flag = True
    else:
        if i != len(S) - 2:
            flag = False
ans = 0
if flag:
    ans = count * K
elif S[0] == S[-1]:
    ans = count + (count+1) * (K-1)
else:
    ans = count * K
print(ans)

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.readline
#import heapq
#from fractions import gcd
#from collections import defaultdict
#sys.setrecursionlimit(10**9)
#map(int,input().split())

def main():
    s=input()
    k=int(input())
    n=len(s)
    cnt1=0
    tmp1=0
    ss=s*2
    nn=n*2
    for i in range(n-1):
        if s[i]==s[i+1] and tmp1==0:
            cnt1+=1
            tmp1=1
        elif s[i]==s[i+1]:
            tmp1=0
        else:
            tmp1=0
    cnt2=0
    tmp2=0
    for i in range(nn-1):
        if ss[i]==ss[i+1] and tmp2==0:
            cnt2+=1
            tmp2=1
        elif ss[i]==ss[i+1]:
            tmp2=0
        else:
            tmp2=0
    if cnt2==2*cnt1:
        print(cnt1*k)
    else:
        if k%2==0:
            print(cnt2*(k//2))
        else:
            print(cnt2*(k//2)+cnt1)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

S = S + S[0]

cnt= 0
flg = True
for i in range(len(S)-1):
  if S[i] == S[i+1] and flg:
    cnt += 1
    flg = False
  else:
    flg = True
  
print(int(cnt)*int(K))

Submission status: Wrong Answer

Solution code:
s = list(input())
n = len(s)
k = int(input())
if n == 1:
    print(k // 2)
    exit(0)
t = s + s
tmp1 = 0
for i in range(n * 2 - 1):
    if t[i] == t[i + 1]:
        tmp1 += 1
        t[i + 1] = 'X'
tmp2 = 0
for i in range(n - 1):
    if s[i] == s[i + 1]:
        tmp2 += 1
        s[i + 1] = 'X'
tmp3 = tmp1 - tmp2 * 2
print(tmp3 * (k - 1) + tmp2 * k)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
split_s = []
counter = 1
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        split_s.append(counter)
        counter = 1
    else:
        counter += 1
split_s.append(counter)

ans = 0
if len(split_s) == 1:
    print(len(s)*k//2)
elif s[0] != s[-1]:
    # 繋がらないのでそれぞれの変換回数を求める
    for i in range(len(split_s)):
        ans += split_s[i]//2
    print(ans*k)
else:
    # 端がつながるので分割
    for i in range(1, len(split_s)-1):
        ans += split_s[i]//2
    ans += (split_s[-1]+split_s[0])//2
    print(ans*k+split_s[0]//2)

Submission status: Wrong Answer

Solution code:
import re
import sys

s = input()
k = int(input())
count=0

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

pattern = "a+|b+|c+|d+|e+|f+|g+|h+|i+|j+|k+|l+|m+|n+|o+|p+|q+|r+|s+|t+|u+|v+|w+|x+"
result = re.finditer(pattern, s)
for res in result:
  #print(res.group())
  l = res.end()-res.start()
  if l>1:
    #切り捨て
    count += l//2
    #print(count)

if s[0]!=s[-1]:
  count *= k
else:
  count *= k
  
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ans=0
if k<=10**5:
  s=s*k
  cnt=1
  for i in range(1,len(s)):
    if s[i]==s[i-1]:
      cnt+=1
    else:
      ans+=cnt//2
      cnt=1
  ans+=cnt//2
  print(ans)
else:
  if k%2==1:
    cnt=1
    for i in range(1,len(s)):
      if s[i]==s[i-1]:
        cnt+=1
      else:
        ans+=cnt//2
        cnt=1
    ans+=cnt//2
  s=s+s
  cnt=1
  tmp=0
  for i in range(1,len(s)):
    if s[i]==s[i-1]:
      cnt+=1
    else:
      tmp+=cnt//2
      cnt=1
  tmp+=cnt//2
  ans+=tmp*(k//2)
  print(ans)

Submission status: Wrong Answer

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

ans = 0

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

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    S = stdin.readline().rstrip()
    K = int(stdin.readline().rstrip())
    count = 0
    skip = False
    for i, c in enumerate(S[:-1]):
        if skip:
            skip = False
            continue
        nc = S[i + 1]
        if c == nc:
            count += 1
            skip = True
    print(count * K)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


pre = ""
count = 0
first = S[0]
last = S[len(S)-1]

for i in range(len(S)):
    if pre != S[i]:
        pre = S[i]

    elif pre == S[i]:
        count += 1
        pre = ""

    # if i == len(S):
    #     print("DADA")
    #     if pre != "":
    #         count += 1


# print(count)
print(count*int(K))
# print(S)

Submission status: Wrong Answer

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

ans = 0 
target = [s[0]]

for i in range(1,len(s)):
  if target[i - 1] == s [i]:
    target.append("0")
    ans += 1
  else:
    target.append(s[i])
    
if target[0] == target[-1]:
  target[-1] ="0"
  ans += 1
  
print(ans * n)

Submission status: Wrong Answer

Solution code:
import math
S = input()
K = int(input())
buf=''
cnt = 0
for s in S:
    if s == buf:
        cnt += 1
    buf = s
print(math.ceil(cnt/2)*K)

Submission status: Wrong Answer

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

L = []
temp = S[0]
c = 1
for i in range(1, len(S)):
    if S[i] == temp:
        c += 1
    else:
        L.append(c)
        c = 1
        temp = S[i]
    if i == len(S)-1:
        L.append(c)
        
ans = 0

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

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
c=0
b=0
a=0
if len(s)==1:
  print(len(s)//2)
else:
  for i in range(len(s)-1):
    if s[i]==s[i+1]:
      if a==0:
        c+=1
        a=1
      else:
        a=0
    else:
      a=0
  if s[0]==s[-1]:
    if a==0:
      b+=1
  print(c*k+b*(k-1))

Submission status: Wrong Answer

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

ans = 0
def aa(s):
    ansaa=0
    a = 0
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            a += 1
        else:
            if a > 0:
                ansaa += (a+1)//2
                a = 0
    ansaa += (a+1)//2    
    return ansaa
# print(aa(s))
# print(aa(s*2))
print(aa(s) + (aa(s*2) - aa(s))*(k-1))

# l = -1
# r = 0
# if s[0] == s[-1]:
#     ss = s[0]
#     while l >= -n and s[l] == ss:
#         l -= 1
#     while r < n and s[r] == ss:
#         r += 1
#     if l == -n:
#         ans = (n*k)//2
#     else:
#         ans += ((r-l+1)//2)*(k-1)
#         ans += aa(s[r:n-l+1])*k
# else:
#     ans += aa(s)*k

# print(ans)

Submission status: Wrong Answer

Solution code:
import sys
s=input()
k=int(input())
a,i=0,0
b=0
if s[-1]==s[0]:
    b=k-1
if len(s)==1:
    print(k//2)
    sys.exit()
while True:
    if s[i]==s[i+1]:
        a+=1
        i+=1
    i+=1
    if i>=len(s)-1:
        break
print(a*k+b)

Submission status: Wrong Answer

Solution code:
# N, K = map(int, input().split())
S = input()
K = int(input())

if K >= 2:
    S = S + S

pp = '#'
res = 0
for s in S:
    if pp == s:
        res += 1
        pp = '#'
    else:
        pp = s

# print(vC)
if K >= 2:
    print(res * K // 2)
else:
    print(res)

Submission status: Wrong Answer

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

def main():
    S = input()
    K = int(input())

    R = []
    lastLetter = None
    cnt = 0

    for c in S:
        if lastLetter == c:
            cnt += 1
        else:
            lastLetter = c
            if cnt > 0:
                R.append(cnt)

            cnt = 1
    
    R.append(cnt)
    S = 1 if len(R) > 1 and S[0] == S[-1] and R[0]%2 == 1 and R[-1]%2 == 1 else 0

    x = sum(r//2 for r in R)*K + (K-1)*S

    print(x)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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


xx = 0
ss = s + s
i = 0
while i < len(ss) - 1:
    if ss[i] == ss[i + 1]:
        xx += 1
        i += 2
    else:
        i += 1
ans = k // 2 * xx + (x if k % 2 == 1 else 0)


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

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    k = int(input().rstrip('\n'))
    cnt = 0
    t = 0
    cnt_a = 0
    t_a = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            if t == 0:
                t = 2
            else:
                t += 1
        else:
            if t != 0:
                cnt += (t // 2)
            t = 0
    cnt += (t // 2)
    t_a = t
    if t_a >= 1:
        for i in range(1, len(s)):
            if s[i] == s[i-1]:
                t_a += 1
            else:
                cnt_a = t_a // 2
                break
    print(cnt * k + cnt_a * (k - 1) + t // 2)


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
now = ""
ans = 0
if len(S) == 1:
    print(K//2)
else:
    for i in range(len(S)):
        tmp = S[i]
        if tmp == now:
            ans += 1
            now = ""
        elif i == len(S)-1:
            if tmp == S[0]:
                ans += 1
        else:
            now = S[i]    
    print(ans*K)

Submission status: Wrong Answer

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

tmp = ""
cnt = 0
ans = 0
for s in S:
    if s == tmp:
        cnt += 1
    else:
        ans += cnt//2
        cnt = 1
    tmp = s
ans *= K
if S[0] == S[-1]:
    first_cnt = 0
    for s in S:
        if s == S[0]:
            first_cnt += 1
        else:
            break
    if first_cnt == len(S):
        first_cnt = 0
    ans += (cnt+first_cnt)//2 * (K-1)
    ans += cnt//2

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    k = int(input())
    s_ = []
    for i in range(len(s)):
        if not s_:
            s_.append(s[i])
        elif not s_[-1][0] == s[i]:
            s_.append(s[i])
        else:
            s_[-1] += s[i]
    if s_[0][0] == s_[-1][0]:
        if len(s_) > 1:
            s_[0] = s_[0] + s_[-1]
            s_ = s_[:-1]
    ans = 0
    for i in s_:
        ans += len(i)//2
    ans *= k
    print(ans)
    
if __name__ == '__main__':
    main()