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=str(input())
k=int(input())

if k>=2:
    sl=list(s)
    ss=list(s+s)
    cnt=0
    for i in range(len(ss)-1):
        if ss[i]==ss[i+1]:
            cnt+=1
            ss[i+1]="?"
    cnt2=0
    for i in range(len(s)-1):
        if sl[i]==sl[i+1]:
            cnt2+=1
            sl[i+1]="?"
    print((k//2)*cnt+(k%2)*cnt2)

else:
    cnt=0
    sl=list(s)
    for i in range(len(sl)-1):
        if sl[i]==sl[i+1]:
            cnt+=1
            sl[i+1]="?"
    print(cnt)

Submission status: Wrong Answer

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

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

if s[0] == s[-1] and s[0] != s[1] and s[-1] != s[-2]:
    count = 1
else:
    count = 0

ngo = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        ngo+=1
    else:
        count += ngo//2
        ngo=1
count += ngo//2
print(count*k)

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 - 1

print(ans + b * K)

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

# 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:
def f():
    S = input()
    K = int(input())
    S = list(S)
    if K == 1 and len(S) == 1:
        print(0)
        return
    
    if K == 1 and len(S) != 1:
        ans = 0
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                S[i+1] = '1'
                ans += 1
        print(ans)
        return
    
    if K != 1 and len(S) == 1:
        ans = K // 2
        print(ans)
        return
    
    if K != 1 and len(S) != 1:
        ans = 0
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                S[i+1] = '1'
                ans += 1
                
        if S[0] == S[-1]:
            ans = ans*K + K-1
        else:
            ans = ans*K
        
        print(ans)
        return

f()

Submission status: Wrong Answer

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

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)
print(tmp2*(k-1)+tmp)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
s = list(input())
n = len(s)
k = int(input())
c = 0
d = 0
for i in range(n):
    if s[i] == 'X' or s[i + 1 - n] == 'X':
        continue
    if s[i] == s[i + 1 - n]:
        s[i + 1 - n] = 'X'
        if i == n - 1:
            d += 1
        else:
            c += 1
print(c * k + d * (k - 1))

Submission status: Wrong Answer

Solution code:
k=list(input())
l=k[::]
n=int(input())
for i in range(len(k)):
    if i==0:
        continue
    a,b=k[i-1],k[i]
    if a==b:
        k[i]="0"
l[0]="0"
for i in range(len(l)):
    if i==0:
        continue
    a,b=l[i-1],l[i]
    if a==b:
        l[i]="0"
if k[-1]!=k[0]:
    print(k.count("0")*n)
else:
    print(k.count("0")*(n//2)+l.count("0")*(n-n//2))

Submission status: Wrong Answer

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

last_changed = False
x = 0
for a,b in zip(S,S[1:]):
    if a == b and not last_changed:
        x += 1
        last_changed = True
    else:
        last_changed = False

if last_changed or S[0] != S[-1]:
    print(x*K)
    exit()

last_changed = True
y = 1
for a,b in zip(S,S[1:]):
    if a == b and not last_changed:
        y += 1
        last_changed = True
    else:
        last_changed = False

m = K//2
print(y*m + x*(m+K%2))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
c = 0
b = 0
memo = [0]
for c1, c2 in zip(s[:], s[1:]):
    if not memo[-1] and c1 == c2:
        c += 1
        memo.append(1)
    else:
        memo.append(0)
if not memo[-1] and s[-1] == s[0]:
    b = 1
print(k * c + b * (k - 1))

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.insert(場所,要素)
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
T = stdin.readline().rstrip()
num = int(stdin.readline().rstrip())
ch = ''
count = 0
changed = False
for t in T:
    if (ch == t and not changed):
        count += 1
        changed = True
    elif (changed):
        changed = False
    ch = t
count *= num
if (T[0] == T[len(T) - 1]):
    count += num-1
print(count)

Submission status: Wrong Answer

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

ans = 0
b = None
for c in s:
    if b == c:
        ans += 1
        b = None
    else:
        b = c

if k == 1:
    print(ans)
else:
    if s[-1] != s[0]:
        print(ans * k)
    else:
        odd = ans
        even = 0
        for c in s:
            if b == c:
                even += 1
                b = None
            else:
                b = c
        print(even * (k // 2) + odd * (k - k // 2))

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(change) >= 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(change) == 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().strip()
K = int(input())

cnt = 0
L = len(S)
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()
N = int(input())
c = 0
s = S+S
j = [True]*len(s)
for i in range(0,len(s)-1):
  if s[i]==s[i+1] and j[i]==True:
    #print(i,s[i],s[i+1])
    #print(s)
    j[i+1]=False
    c+=1
print(int(N*(c/2)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
count_single=count_double=0
flag=True
for i in range(1, len(S)):
  if not flag:
    flag=True
    continue
  if S[i-1]==S[i]:
    count_single+=1
    flag=False
SS=S+S
flag=True
for i in range(1, len(SS)):
  if not flag:
    flag=True
    continue
  if SS[i-1]==SS[i]:
    count_double+=1
    flag=False
print(int((K//2)*count_double+(K%2)*count_single))

Submission status: Wrong Answer

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

cont = []
n = 1
t = S[0]
for s in S[1:]:
    if s == t:
        n += 1
    else:
        cont.append(n)
        n = 1
    t = s
else:
    cont.append(n)

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

print(ans)

Submission status: Wrong Answer

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

t1 = 0
t2 = 0
if s[0] == s[-1]:
    for i in range(len(s)):
        if s[i] == s[0]:
            t1 += 1
        else:
            break
    s = s[::-1]
    for i in range(len(s)):
        if s[i] == s[0]:
            t2 += 1
        else:
            break
    if len(set(s)) == 1:
        t = len(s)
    s = s[::-1]
    t = t1 + t2

t = t1 + t2
ss = t//2
ans = 0
tmp = 0

for i in range(t1, len(s)-t2):
    if i == t1:
        tmp = 1
    elif t1 < i < len(s)-t2-1:
        if s[i] == s[i-1]:
            tmp += 1
        else:
            ans += tmp//2
            tmp = 1
    else:
        if s[i] == s[i-1]:
            tmp += 1
            ans += tmp //2
        else:
            tmp = 1

if len(set(s)) == 1:
    anser = len(s) * k //2
    print(anser)
else:
    anser = ss*(k-1) + ans * k + t1//2 + t2//2
    print(anser)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
if k>=3:
    ss=s+s+s
else:
    ss=s*k
flag=[0]*len(ss)
for i in range(1,len(ss)):
    if ss[i-1]==ss[i] and flag[i-1]==0:
        flag[i]=1
        continue
if k>=3:
    count=sum(flag[0:len(s)])+sum(flag[len(s):2*len(s)])*(k-2)+sum(flag[2*len(s):3*len(s)])
else:
    count=sum(flag)
print(count)

Submission status: Wrong Answer

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

if lenS == 1:
  print(0)
  exit()

cnt1 = 0
for key, values in groupby(S):
  len_values = len(list(values)) 
  if len_values >= 2:
    cnt1 += len_values//2

cnt2 = 1 if key == S[0] and len_values%2==1 else 0
    
print(cnt1 + (cnt1+cnt2)*(K-1))

Submission status: Wrong Answer

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

count = 0
flag = 0
S = S + S[0]

for i in range(0, len(S) - 1):
    if S[i] == S[i + 1]:
        if flag == 0:
            count += 1
            flag = 1
        else:
            flag = 0
    else:
        flag = 0

print(count * K)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
S = list(input())[: -1]
K = int(input())
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:
t=""
s=input()

k=int(input())
for i in range(k):
  t+=s
c=0
for j in range(len(t)-1):
  if t[j]==t[j+1]:
    c+=1
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
S_list = [i for i in S]
single_S = 0

for i in range(len(S_list) - 1):
    if S_list[i] == S_list[i + 1]:
        single_S += 1
        S_list[i + 1] = "1"
print(K * single_S)

Submission status: Wrong Answer

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

idx = 0
res = 0
while idx+1 < len(S):
  if S[idx] == S[idx+1]:
    res += 1
    idx += 2
  else:
    idx += 1

res *= K

if len(S) >=3 and S[0] == S[-1] and S[0] != S[1] and S[-2] != S[-1]:
  res += K-1

print(res)

Submission status: Wrong Answer

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

cnt = 0
last = 0
for i, s in enumerate(S):
    if S[(i + 1) % len(S)] == S[(i + 2) % len(S)] == s:
        S[(i + 1) % len(S)] = '_'
        cnt += 1
    elif S[(i + 1) % len(S)] == s:
        S[i] = '_'
        cnt += 1
        if i == len(S) - 1:
            last = 1

print(cnt * K - last)

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-1))
    print(min(ans,ans2))





main()

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
ans_1, ans_2 = 0, 0

# はじめに例外処理
if len(S) == 1:
    print(len(S) // 2)
    exit()

# 前の文字と同じ場合は書き換えてカウント
for si in range(1, len(S)):
    if S[si] == S[si - 1]:
        S = S[: si] + "?" + S[si + 1:]
        ans_1 += 1

# 最後の文字についてカウント
if S[-1] == S[0]:
    ans_2 = K - 1

print(ans_1 * K + ans_2)

Submission status: Wrong Answer

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

cnt = 0
x = [0]*len(s)
for i in range(len(s)):
    if s[i] == s[(i+1)%len(s)]:
        x[(i+1)%len(s)] = 1
        if x[i] == 1:
            x[(i+1)%len(s)] = 0

print(sum(x)*k)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    s=input()
    k=int(input())
    from itertools import groupby
    s=groupby(s)
    S=[]
    for tup in s: S.append((tup[0],len(list(tup[1]))))
    p=0 # s自体で変更する数
    for a,b in S[1:-1]:
        p+=b//2
    q=(S[0][1]+S[-1][1])//2 if S[0][0]==S[-1][0] else 0 # 境界で変更する数
    ans=p*k+q*(k-1)
    ans+=S[0][1]//2+S[-1][1]//2
    print(ans if len(S)!=1 else ans//2)
resolve()

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)

print(ans)

Submission status: Wrong Answer

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

if K > 1:
    S += S[0]
tmp = ''
cnt = 0
for i in range(len(S)):
    if S[i] == tmp:
        cnt += 1
        tmp = 'X'
    else:
        tmp = S[i]
        
print(K*cnt)

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
  ans2=1
  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())
pre_s = ''
cnt = 1
ans = 0
flag = False
for s in S:
    if s == pre_s:
        cnt += 1
    else:
        ans += cnt // 2
        pre_s = s
        cnt = 1
ans += cnt // 2

if S[0] == S[-1]:
    pre_s = S[0]
    cnt = 1
    for s in S[1:]:
        if s == pre_s:
            cnt += 1
        else:
            break
    end_cnt = 1
    for s in reversed(S[:-1]):
        if s == pre_s:
            end_cnt += 1
        else:
            break
    if (end_cnt + cnt) % 2 == 0 and end_cnt % 2 == 1:
        ans += 1
        flag = True
        
if flag:
    print(ans*K-1)
else:
    print(ans*K)

Submission status: Wrong Answer

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

count = 0

if len(s) == 1:
    print(int(k//2))
else:
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            count += 1
            p = i % 10
            s[i+1] = str(p)

    if s[0] == s[-1]:
        count += 1
        p = i % 10
        s[-1] = str(p)

    print(int(count*k))

Submission status: Wrong Answer

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

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

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


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

for i in range(len(ruisekiwa)):
    cnt += ruisekiwa[i]//2

cnt = cnt * K

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

print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
cnt = 0
f = False
for i in range(1, len(s)):
  if f:
    f = False
    continue
  if s[i] == s[i - 1]:
    cnt += 1
    f = True
print(cnt * k)

Submission status: Wrong Answer

Solution code:

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

count = 0
s1 = ''
s2 = ''
for s2 in S:
    if s1 == s2:
        code = ord(s2) + 1
        s2 = chr(code) if code <= ord('z') else 'a'
        count += 1
    
    s1 = s2

ans = count * K
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

i0 = s[0]
count = 0
if len(s) == 1:
    ans = n//2
else:
    for i, name in enumerate(s[1:]):
        if name == i0:
            i0 = "aa"
            count += 1
        else:
            i0 = name
    if s[0] == s[-1]:
        al = n-1
    else:
        al = 0
    ans = count*n + 0

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
cnt = 0
d = 0

for i in range(1, len(s)):
    if s[i] == s[i-1]:
        s[i] = ""
        cnt += 1
    elif i == len(s)-1 and s[i] == s[0]:
        d = k - 1

print(cnt * k + d)

Submission status: Wrong Answer

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

count = 0
flag = 0
S = S + S[0]

for i in range(0, len(S) - 1):
    if S[i] == S[i + 1]:
        if flag == 0:
            count += 1
            flag = 1
        else:
            flag = 0
    else:
        flag = 0

    print(S[i], flag, count)

print(count * K)

Submission status: Wrong Answer

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

n=len(s)
ss=s+s
nn=len(ss)
tmps=1
cnts=0
tmpss=1
cntss=0
for i in range(n-1):
    if s[i]==s[i+1]:
        tmps+=1
    else:
        cnts+=(tmps//2)
        tmps=1
cnts+=(tmps//2)


for i in range(nn-1):
    if ss[i]==ss[i+1]:
        tmpss+=1
    else:
        cntss+=(tmpss//2)
        tmpss=1
cntss+=(tmpss//2)

print((cntss-cnts)*(k-1)+cnts)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
num = [1]
p = S[0]
for i in range(1, len(S)):
    if S[i] == p:
        num[-1] += 1
    else:
        num.append(1)
        p = S[i]
if len(S) == 1:
    print( sum( [num[i]//2 for i in range(len(num))] ) )
elif S[0] != S[-1]:
    print( sum( [num[i]//2 for i in range(len(num))] ) * K )
elif len(num) == 1:
    print(len(S)*K // 2)
else:
    num_s = num[1:-1] + [num[0] + num[-1]]
    ans = sum( [num_s[i]//2 for i in range(len(num_s))] ) * (K-1)
    ans += sum( [num[i]//2 for i in range(len(num))] )
    print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(reversed(S[:]))
K = int(input())
ans = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        ans += K
        S[i+1] = "Z"
if S[0] == S[-1] and S[0] != "Z":
    ans += K-1
l = ans
S = T[:]
ans = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        ans += K
        S[i+1] = "Z"
if S[0] == S[-1] and S[0] != "Z":
    ans += K-1
print(min(l,ans))

Submission status: Wrong Answer

Solution code:
s = list(input().strip())
t = int(input())
ans = 0
change = False
for i in range(1, len(s)):
    if change == True:  # 変更直後は必ず通る
        change = False
        continue
    if s[i] == s[i - 1]:  # 変更する
        ans += 1
        change = True
# 最初と最後が同じ文字かつ、最後を変更していない場合
if change == False and s[0] == s[-1]:
    ans += 1

print(ans*t)

Submission status: Wrong Answer

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

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
print(count*k)

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
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:
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[0] == S[-1] and len(S) > 2:
    ans += K - 1

print(ans + b * K)

Submission status: Wrong Answer

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

count = 0
i=0
join_flag =0
join_n = 0
if len(s)==1:
  count = k//2
else:
  while i<len(s)-1:
    if s[i] == s[i+1]:
      count+=1
      i+=2
    else:
      i+=1
  
  if (s[-1] == s[0]) and (s[-1] != s[-2]):
    join_flag =1
    
if join_flag:
   join_n = join_n*k -1
    
print(count*k + join_n)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
c=0
s=list(s)
if len(s)>1:
  for i in range(1,len(s)):
    if s[i]==s[i-1]:
      s[i]='12'
      c+=1
# print(s)
# print(c)
  print(n*c)
else:
  print(n//2)
'''
c o o o o o o o o o n t e e e e e e e e e e s t

g 12 g 12 g 
'''

Submission status: Wrong Answer

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

li = [0 for i in range(len(s)+1)]
wrd = [i for i in s]
wrd.append(wrd[0])

for i in range(len(s)):
    if wrd[i]==wrd[i+1] and li[i]==0:
        li[i+1] = 1

ans = 0    
for i in range(len(s)+1):
    if li[i] == 1:
        ans += 1

ans *= k

if li[len(s)]==1:
    ans -= 1
    
print(ans)

Submission status: Wrong Answer

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

mycnt = 0
myflag = 0

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

else:
    for i in range(len(S)-1):
        if S[i] == S[i+1] and myflag == 0:
            mycnt += 1
            myflag = 1
        else: myflag = 0
    
    print(mycnt * K)

Submission status: Wrong Answer

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

ops = 0
i = 1

while i < len(s):
    if s[i-1] == s[i]:
        ops += 1
        i += 1
    i += 1

ops *= k

between = False
if i == len(s) and k >= 2 and s[0] == s[-1]:
    between = True

if between:
    ops += k - 1

print(ops)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

line = [x for x in input()]
counter = 0
for i in range(1, len(line)):
    if line[i] == line[i - 1]:
        counter += 1
        line[i] = "."

if len(line) > 1:
    counter2 = 0
    if line[0] == line[-1]:
        counter2 = 1
    
    num = int(input())
    print(num * counter + (num - 1) * counter2)
else:
    num = int(input())
    print(int(num / 2))

Submission status: Wrong Answer

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

def count(string):
    total = 0
    i = 0
    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:
S = input()
K = int(input())
cnt = 0
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        cnt += K
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

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

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

s_2 = s + s

num_first = 0
renzoku = 1
before = 0
for i in range(len(s)):
    now = s[i]
    if now == before:
        renzoku += 1
    else:
        num_first += renzoku // 2
        renzoku = 1
    before = now
num_first += renzoku // 2

num_rest = 0
renzoku = 1
before = 0
for i in range(len(s_2)):
    now = s_2[i]
    if now == before:
        renzoku += 1
    else:
        num_rest += renzoku // 2
        renzoku = 1
    before = now
num_rest += renzoku // 2

num_rest -= num_first

print(num_first + (k-1) * num_rest)

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))
print(check_num*N//2)

Submission status: Wrong Answer

Solution code:
import sys, collections, copy

def solve():
    S = list(input())
    S2 = copy.deepcopy(S)
    K = int(input())
    lens = len(S)
    head_change = 0
    for i in range(1, lens):
        if S[i] == S[i - 1]:
            head_change += 1
            S[i] = "Changed"
    
    inner_change = 0
    S2[0] = "Changed"
    for i in range(1, lens):
        if S2[i] == S2[i-1]:
            inner_change += 1
            S2[i] = "Changed"

    if S[lens-1] != "Changed":
        if S2[lens-1] != "Changed":
            print(head_change + inner_change * (K - 1))
        else:
            print((head_change + inner_change) * (K // 2) + head_change * (K % 2))
    else:
        print(head_change * K)


    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

S += S[0]
tmp = ''
cnt = 0
for i in range(len(S)):
    if S[i] == tmp:
        cnt += 1
        tmp = 'X'
    else:
        tmp = S[i]
        
print(K*cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def Run_length_encoding(S: str):
    """AAABBC -> [(A, 3), (B, 2), (C, 1)]
    """
    ans = []
    curr = S[0]
    counter = 0
    for c in S:
        if c == curr:
            counter += 1
        else:
            ans.append((curr, counter))
            curr = c
            counter = 1
    ans.append((curr, counter))
    return ans


def solve(S: str, K: int):
    rle = Run_length_encoding(S)
    fchr, fcnt = rle[0]
    lchr, lcnt = rle[-1]
    ans = 0
    for c, cnt in rle:
        ans += cnt//2
    ans *= K

    if K > 1 and fchr == lchr:
        ans -= K*(fcnt//2)
        ans -= K*(lcnt//2)
        ans += (K-1)*((fcnt+lcnt)//2)
        ans += fcnt//2
        ans += lcnt//2

    print(ans)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(S, K)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
s=input()
k=int(input())
a,i=0,0
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)

Submission status: Wrong Answer

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

count=0
end=True
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    s[i]=1
    count+=1
    if i==len(s)-1:
      end=False

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

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:], start=1):
    if t == T[i - 1] and T[i - 1] != '.':
        b += 1
        T[i] = '.'

if S[0] == S[-1]:
    if len(S) > 2 and S[-1] != S[-2]:
        ans += K - 1

print(ans + b * K)

Submission status: Wrong Answer

Solution code:
s, k = input(), int(input())
char=[]
prev = "0"
cnt = 0
for i in s:
    if i==prev: cnt+=1
    else: char.append(cnt);cnt=1
    prev = i
char.append(cnt)

if s[0]==s[-1]:
    tmp = char.pop(1)
    char[-1] += tmp

ans = 0
for i in char: ans += i//2
print(ans*k)