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 two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))



S=one_str()
K=one_int()

before = S[0]
count=1
ranrength = []
for i in S[1:]:
    if before==i:
        count+=1
    else:
        ranrength.append(count)
        count=1
    before=i

ranrength.append(count)

output_count=0
for r in ranrength:
    if r>1:
        output_count += r//2
output_count *= K

if S[0]==S[-1]:
    head=ranrength[0]
    tail=ranrength[-1]
    
    if head>1 and head%2==1 and tail>1 and tail%2==1:
        output_count += 1
print(output_count)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

l=[(k, list(v)) for k, v in groupby(S)]
n=sum([len(v)//2 for k, v in l if len(v) > 1])*K
if l[0][0]==l[-1][0]:
    if len(l[0][1])%2 !=0 and len(l[-1][1])%2 !=0:
        n = n + K - 1
if n > len(S)*K//2:
    n = len(S)*K - n
print(n)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

l=[(k, list(v)) for k, v in groupby(S)]
n=sum([len(v)//2 for k, v in l if len(v) > 1])*K
if l[0][0]==l[-1][0] and len(l[-1][1])%2 != 0 and len(l[0][1])%2 != 0:
    n = n + K - 1
print(n)

Submission status: Wrong Answer

Solution code:
import numpy as np
#A = list(map(int,input().split()))
S = list(input())
K = int(input())

S1 = S + ['0']
S2 = S + S + ['0']

cur=S1[0]
cnt=0
Sl1 = list()
for s in S1:
    if cur==s:
        cnt+=1
    else:
        Sl1 += [cnt]
        cur = s
        cnt = 1

cur=S2[0]
cnt=0
Sl2 = list()
for s in S2:
    if cur==s:
        cnt+=1
    else:
        Sl2 += [cnt]
        cur = s
        cnt = 1

Sl1 = np.array(Sl1,dtype='int64')
Sl2 = np.array(Sl2,dtype='int64')

if 2*len(Sl1)==len(Sl2):
    N = int(K*np.sum(Sl1[::]//2))
else:
    if len(Sl1)>1 :
        N = int(Sl1[0]//2 + Sl1[-1]//2 + K*np.sum(Sl1[1:-1]//2) + (K-1)*((Sl1[0]+Sl1[-1])//2))
    else:
        N = int(K*(Sl1//2))


print(N)

Submission status: Wrong Answer

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

a=""
b=""
ans=0
i=0

s=list(s)

if s[0] == s[len(s)-1]:
  if s[len(s)-2] != s[len(s)-1] :
  	ans += k-1

for l in range(len(s)-1):
  a = s[i]
  b = s[i+1]
  if a==b :
     ans+=k
  i += 1

print(ans)

Submission status: Wrong Answer

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

    ans=cnt=key=0
    for i in range(n-1):
        if key==0 and s[i]==s[i+1]:
            cnt+=1
            key=1
        elif key==1 and s[i]==s[i+1]:
            key=0
        else:
            key=0
    ans=cnt*k
    a=b=1
    for i in range(n-1):
        if s[i]==s[i+1]:
            a+=1
        else:
            break
    for i in range(n-1):
        if s[n-1-i]==s[n-2-i]:
            b+=1
        else:
            break
    if a!=n and s[0]==s[n-1]:
        ans+=(((a+b)//2)-(a//2)-(b//2))*(k-1)
    if a==n and n%2==1:
        ans+=(k-1)
    print(ans)
main()

Submission status: Wrong Answer

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

    ans=cnt=key=0
    for i in range(n-1):
        if key==0 and s[i]==s[i+1]:
            cnt+=1
            key=1
        elif key==1 and s[i]==s[i+1]:
            key=0
        else:
            key=0
    ans=cnt*k
    a=b=1
    for i in range(n-1):
        if s[i]==s[i+1]:
            a+=1
        else:
            break
    for i in range(n-1):
        if s[n-1-i]==s[n-2-i]:
            b+=1
        else:
            break
    if a!=n and s[0]==s[n-1]:
        ans+=(((a+b)//2)-(a//2)-(b//2))*(k-1)
    if a==n and n%2==1:
        ans+=1
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
S = list(input())
S.append('end')
K = int(input())
length = []
tl = 1
x = 0
ans = 0
if S[0] != S[len(S)-1]:
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      tl += 1
    else:
      length.append(tl)
      tl = 1
  for i in range(len(length)):
    x += length[i]//2
  ans += x*K
  print(ans)
else:
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      tl += 1
    else:
      length.append(tl)
      tl = 1
  ans += ((length[0]+length[len(length)])*(K-1)//2) + length[0]//2 + length[length]//2
  length[0] = 0
  length[len(length)] = 0
  for i in range(len(length)):
    x += length[i]//2
  ans += x*K
  print(ans)

Submission status: Wrong Answer

Solution code:
import copy
s = list(input())
k = int(input())
t = copy.deepcopy(s)
transCount = 0
#大体の奴
if s[0] == s[-1]:
    for i in range(len(t) - 2):
        if t[i] == t[i + 1]:
            transCount += 1
            t[i + 1] = '.'
    transCount *= k - 1
    transCount += k - 1
else:
    for i in range(len(t) - 1):
        if t[i] == t[i + 1]:
            transCount += 1
            t[i + 1] = '.'
    transCount *= k - 1
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        transCount += 1
        s[i + 1] = '.'
print(transCount)

Submission status: Wrong Answer

Solution code:
s = list(input()) * 2
k = int(input())
n = len(s)
c = 0

for i in range(1, n):
  if s[i - 1] == s[i]:
    s[i] = "."
    c   += 1

print(c // 2 * k)

Submission status: Wrong Answer

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

for i in range(1, n + 1):
  if s[i - 1] == s[i % n]:
    s[i % n] = "."
    c       += 1

print(c * k)

Submission status: Wrong Answer

Solution code:
import sys

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

def count_min_operation(s):
	i = 0
	j = 0
	count = 0
	length = len(s)
	while j < length-1:
		c = 1
		for j in range(i+1,length):
			if s[i] == s[j]:
				c += 1
			else:
				count += c // 2
				i = j
				break
		if j == length-1:
			count += c // 2

	return count

for i in range(len(s)-1):
	if s[i] == s[i+1]:
		continue
	else:
		s1 = count_min_operation(s)
		s2 = count_min_operation(s+s)
		update = s2 - s1
		print(s1 + update * (k-1))
		sys.exit()

print(k * len(s) // 2)

Submission status: Wrong Answer

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

def count_min_operation(s):
	i = 0
	j = 0
	count = 0
	length = len(s)
	while j < length-1:
		c = 1
		for j in range(i+1,length):
			if s[i] == s[j]:
				c += 1
			else:
				count += c // 2
				i = j
				break
		if j == length-1:
			count += c // 2

	return count

s1 = count_min_operation(s)
s2 = count_min_operation(s+s)

update = s2 - s1

print(s1 + update * (k-1))

Submission status: Wrong Answer

Solution code:
S=list(input())
K=int(input())
#基本は文字列一単位内でひっくり返す×単位数ですが、文字列の文字の種類一つの場合（一つ・複数）と文字列の両端が同じ場合を考慮してね。
if S.count(S[0])==len(S):
	P=(len(S)*K)//2
else:
	P=0
	for G in range(1,len(S)):
		B=S[G-1]
		if S[G] in B:
			S[G]='O'
			P+=1
		else:
			continue
	P=S.count('O')
	P=P*K
	if S[0]==S[len(S)-1]:
		P+=K-1
print(P)

Submission status: Wrong Answer

Solution code:
S=list(input())
K=int(input())
#基本は文字列一単位内でひっくり返す×単位数ですが、文字列が一つの場合と文字列の両端が同じ場合を考慮してね。
P=0
if len(S)==1:
	P=K//2
else:
	for G in range(1,len(S)):
		B=S[G-1]
		if S[G] in B:
			S[G]='O'
			P+=1
		else:
			continue
	P=S.count("O")
	P=P*K
	if S[0]==S[len(S)-1]:
		P+=K-1
print(P)

Submission status: Wrong Answer

Solution code:
S=list(input())
K=int(input())
#基本は文字列一単位内でひっくり返す×単位数ですが、文字列が一つの場合と文字列の両端が同じ場合を考慮してね。
P=0
if len(S)==1:
	P=K//2
else:
	for G in range(1,len(S)):
		B=S[G-1]
		if S[G] in B:
			S[G]='O'
			P+=1
		else:
			continue
	P=P*K
	if S[0]==S[len(S)-1]:
		P+=K-1
print(P)

Submission status: Wrong Answer

Solution code:
S=list(input())
K=int(input())
T=int(len(S))
P=0
for G in range(1,T):
	B=S[G-1]
	if S[G] in B:
		S[G]='O'
		P+=1
	else:
		continue
P=P*K
if S[0]==S[len(S)-1]:
	P+=K-1
print(P)

Submission status: Wrong Answer

Solution code:
import sys
S = input() 
K = int(input()) 
l = len(S)
ren = [0]*l
cnt = 0
first = 1

for i in range(1,l):
  if S[i] == S[i-1]:
    cnt += 1
  elif S[i] != S[i-1]:
    ren[cnt] +=1
    cnt = 0
    if first:
      start = cnt
      first = 0
  if i == l-1:
    ren[cnt] +=1
    end = cnt
    
ren = [K*i for i in ren]

if ren[l-1] or l ==1:
  print((l*K)//2)
  sys.exit()

if S[0]==S[-1]:
  ren[start+end+1] += K-1
  ren[start] -= K-1
  ren[end] -= K-1

ans = 0

for i in range(1,l):
  if i%2 ==0:
    ans += (i//2)*ren[i]
  else:
    ans += ((i+1)//2)*ren[i]
      
print(ans)

Submission status: Wrong Answer

Solution code:
s =list(str(input()))
t = int(input())
n = 0
m = 1
for i in range(1, len(s)):
    if s[i - 1] == s[i]:
        s[i] = 'ppp'
        n += 1

if s[0] != s[len(s) - 1]:
    print(n*t)
else:
    s.pop(0)
    for i in range(1, len(s)):
        if s[i - 1] == s[i]:
            s[i] = 'ppp'
            m += 1
    print(n + m * (t - 1))

Submission status: Wrong Answer

Solution code:
import sys
s_ = input()
k = int(input())

s = s_+"1"
#print(s)
RLE = []

cha = s[0]
cnt = 1

for i in range(1,len(s)):
    if s[i-1] == s[i]:
        cnt += 1
    else:
        RLE.append(cnt)
        cnt = 1
        cha = s[i]
#print(RLE)
ans = 0
if len(RLE)==1:
    print(RLE[0]*k//2)
    sys.exit()
if s[0]!= s[-2]:
    for c in RLE:
        ans += c//2
    print(ans)
    ans *= k
    print(ans)
else:
    RLE[-1]+= RLE[0]
    for c in RLE[1:]:
        ans += c//2
    
    ans *= k
    ans -= RLE[-1]//2
    ans += RLE[0]//2
    ans += (RLE[-1]-RLE[0])//2
    print(ans)

Submission status: Wrong Answer

Solution code:
S = str(input())
K = int(input())
n = len(S)
s = [ ]
for i in range(n):
    s.append(S[i])
s.append(S[0])
t = 0
for i in range(n):
    if s[i] == s[i+1]:
        s[i+1] = 'A'
        t = t + 1
if s[n] == s[0]:
    T = t*K
else:
    T = (t*K) - 1
print(T)

Submission status: Wrong Answer

Solution code:
S = str(input())
K = int(input())
n = len(S)
s = [ ]
for i in range(n):
    s.append(S[i])
s.append(S[0])
t = 0
for i in range(n):
    if s[i] == s[i+1]:
        s[i+1] = str(i)
        t = t + 1
if s[n] == s[0]:
    T = t*K
else:
    T = (t*K) - 1
print(T)

Submission status: Wrong Answer

Solution code:
s = [i for i in input()]
k = int(input())

cnt = 0

def run_length(seq):
    cnt = 1
    result = []
    for i in range(len(seq) - 1):
        if seq[i] == seq[i + 1]:
            cnt += 1
        else:
            result.append([seq[i], cnt])
            cnt = 1
    
    result.append([seq[-1], cnt])
    return result

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

if cnt == (len(s) - 1):
    print(k)
else:
    cnt = 0
    run = run_length(s)

    check = False
    if run[0][0] == run[-1][0]:
        if run[-1][1] == 1:
            check = True
        cnt += 1
        run[-1][1] -= 1
    
    for r in run:
        cnt += r[1]//2

    print(cnt * k - 1 if check else cnt * k )

Submission status: Wrong Answer

Solution code:
import sys
s = list(input())
k = int(input())
cnt = 0
i = 1
while i < len(s)-1:
  if s[i] == s[i-1]:
    i = i + 1
    cnt = cnt + 1
  i =i+ 1
if s[-1] == s[0]:
  cnt += 1
  print(cnt * k - 1)
  sys.exit()
print(cnt * k)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
cnt = 0
i = 1
while i < len(s)-1:
  if s[i] == s[i-1]:
    i = i + 1
    cnt = cnt + 1
  i =i+ 1
if s[-1] == s[0]:
  cnt += 1
print(cnt * k)

Submission status: Wrong Answer

Solution code:
s =list(str(input()))
n = 0
for i in range(1, len(s)):
    if s[i - 1] == s[i]:
        s[i] = 'ppp'
        n += 1
print(n)

Submission status: Wrong Answer

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

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

ans = 0
ss = 0
ll = len(l)
#文字列が1つの文字列で構成されていないとき
if (ll != 1) :
    #最初と最後の文字が同じとき
    if (s[0] == s[ls-1]):
        ans -= (l[0] // 2 + l[ll-1] // 2 - (l[0] + l[ll-1]) // 2) * (k-1)

    for i in range(ll):
        ss += l[i] // 2
    print(ans+ss*k)
else :
    print(l[0] // 2 * k)

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] = "0"

cnt *= K

if(S[0] == S[len(S)-1]):
    cnt += K-1

print(cnt)

Submission status: Wrong Answer

Solution code:
#agc39
from collections import Counter

S = str(input()) #max:100
K = int(input()) #10**9

S = list(S)

ans = 0


        
if K==1: #繰り返しが無ければ冒頭・末尾は考えなくてOK
    for i in range(len(S)-1):
        if S[i]==S[i+1]:
            ans +=1
            S[i+1] = "?"
        
    print(ans)
else:
    if S[0]!=S[-1]:
        for i in range(len(S)-1):
            if S[i]==S[i+1]:
                ans +=1
                S[i+1] = "?"

        print(ans*K)
        
    elif len(S)%2==1 and len(Counter(S))==1:
        for i in range(len(S)-1):
            if S[i]==S[i+1]:
                ans +=1
                S[i+1] = "?"
                
        print(ans*K + K-2)
        
    else:
        for i in range(len(S)-1):
            if S[i]==S[i+1]:
                ans +=1
                S[i+1] = "?"
        
        if S[0]!=S[-1]:
            print(ans*K)
        else:
            print(ans*K + K - 1)

Submission status: Wrong Answer

Solution code:
import itertools as it 

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

groups = [(k, len(list(g))) for k, g in it.groupby(s)]

# print(groups)

if s[0] != s[-1]:
    answer = sum([x[1] // 2 for x in groups])
    print(answer * k)

elif len(set(s)) == 1:
    answer = (len(s) * k) // 2
    print(answer)

elif s[0] == s[-1]:
    answer = sum([x[1] // 2 for x in groups[1:-1]]) * k + (groups[0][1] + groups[-1][1]) // 2
    answer += (k - 1) * (groups[0][1] + groups[-1][1]) // 2
    print(answer)

Submission status: Wrong Answer

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

if len(set(list(S))) == 1:
    print(len(S) * K // 2)
else:
    l = []
    left = 0
    right = 1
    while right < s:
        if S[left] == S[right]:
            right += 1
            if right == s:
                l.append(right - left)
        else:
            if right - left > 1:
                l.append(right - left)
                left = right
                right += 1
            else:
                left = right
                right += 1

    l = [i // 2 for i in l]
    if S[0] == S[-1] and S[0] != S[1] and S[-1] != S[-2]:
        print(sum(l) * K + K - 1)
    else:
        print(sum(l) * K)

Submission status: Wrong Answer

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

if len(set(list(S))) == 1:
    print(len(S) * K // 2)
else:
    l = []
    left = 0
    right = 1
    while right < s:
        if S[left] == S[right]:
            right += 1
            if right == s:
                l.append(right - left)
        else:
            if right - left > 1:
                l.append(right - left)
                left = right
                right += 1
            else:
                left = right
                right += 1

    l = [i // 2 for i in l]

    print(sum(l) * K)

Submission status: Wrong Answer

Solution code:
S = input()
s = len(S)
K = int(input())
answer = 0
l = []
left = 0
right = 1
while right < s:
    if S[left] == S[right]:
        right += 1
        if right == s:
            l.append(right - left)
    else:
        if right - left > 1:
            l.append(right - left)
            left = right
            right += 1
        else:
            left = right
            right += 1

l = [i // 2 for i in l]

print(sum(l) * K)

Submission status: Wrong Answer

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

ss = s + s

a=0
prev = "?"
for v in s:
    if v==prev:
        a += 1
        prev = "?"
    else:
        prev = v
    
b=0
prev = "?"
for v in ss:
    if v==prev:
        b += 1
        prev = "?"
    else:
        prev = v

print(a+(b-a)*(k-1))

Submission status: Wrong Answer

Solution code:
s=list(input())
k=int(input())
test=s*3
for i in range(len(s)*3-1):
    if test[i]==test[i+1]:
        test[i+1]="A"
A=test[:len(s)].count("A")
B=test[len(s):len(s)*2].count("A")
C=test[len(s)*2:len(s)*3].count("A")

if s.count(s[0])==len(s):
    print((len(s)*k)//2)
else:
    if k==1:print(A)
    elif k==2:print(A+B)
    else:print(A+B*(k-2)+A)

Submission status: Wrong Answer

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

def g(arr):
  if len(arr) == 0:
    return [], []
  elements = []
  nums = []
  n = 1
  prev = arr[0]
  for c in arr[1:]:
    if c == prev:
      n += 1
    else:
      elements.append(prev)
      nums.append(n)
      prev = c
      n = 1
  elements.append(prev)
  nums.append(n)
  return elements, nums

sl = g(s)
c = 0
for i in sl[1]:
  c += i//2
if len(s) == 1:
  print(k//2)
elif s[0] == s[-1] and sl[1][0]%2==1 and sl[1][-1]%2==1:
  print(c*k+k-1)
else:
  print(c*k)

Submission status: Wrong Answer

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

def g(arr):
  if len(arr) == 0:
    return [], []
  elements = []
  nums = []
  n = 1
  prev = arr[0]
  for c in arr[1:]:
    if c == prev:
      n += 1
    else:
      elements.append(prev)
      nums.append(n)
      prev = c
      n = 1
  elements.append(prev)
  nums.append(n)
  return elements, nums

sl = g(s)
c = 0
for i in sl[1]:
  c += i//2
if len(s) == 1:
  print(k)
elif s[0] == s[-1] and sl[1][0]%2==1 and sl[1][-1]%2==1:
  print(c*k+k-1)
else:
  print(c*k)

Submission status: Wrong Answer

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

def g(arr):
  if len(arr) == 0:
    return [], []
  elements = []
  nums = []
  n = 1
  prev = arr[0]
  for c in arr[1:]:
    if c == prev:
      n += 1
    else:
      elements.append(prev)
      nums.append(n)
      prev = c
      n = 1
  elements.append(prev)
  nums.append(n)
  return elements, nums

sl = g(s)
c = 0
for i in sl[1]:
  c += i//2
if s[0] == s[-1] and sl[1][0]%2==1 and sl[1][-1]%2==1:
  print(c*k+k-1)
else:
  print(c*k)

Submission status: Wrong Answer

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

def connection_list(s):
  res = [0 for i in range(len(s))]
  prev = ''
  cnt = 0
  start = 0
  connected = 0
  for i in range(len(s)):
    if s[i] == prev:
      cnt += 1
    else:
      res[start] = cnt
      cnt = 0
      start = i
      prev = s[i]
  if cnt > 0:
    res[-1] = cnt
  if s[0] == s[-1]:
    connected = res[-1] + res[0] + 1
  return res, connected

def calc_ceil(n):
  return math.ceil(n/2)
cl, cn = connection_list(s)
if cl[-1] == len(cl) - 1:
  res = calc_ceil(len(cl) * k - 1)
else:
  cl = list(map(calc_ceil, cl))
  if cn > 0:
    res = sum(cl[1:-1]) * (k - 1) + cl[0] + cl[-1] + calc_ceil(cn) * (k - 1)
  else:
    res = sum(cl) * k
print(res)

Submission status: Wrong Answer

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

def connection_list(s):
  res = [0 for i in range(len(s))]
  prev = ''
  cnt = 0
  for i in range(len(s)):
    if s[i] == prev:
      cnt += 1
    else:
      res[i-1] = cnt
      cnt = 0
    prev = s[i]
  res[-1] = cnt
  if s[0] == s[-1]:
    res[0] = res[-1] + 1
  return res

def calc_ceil(n):
  return math.ceil(n/2)
cl = connection_list(s)
if cl[0] == len(cl):
  res = calc_ceil(cl[0] * k - 1)
else:
  cl = list(map(calc_ceil, cl))
  if cl[0] > 0:
    res = sum(cl[1:]) + (k - 1) * sum(cl[:-1])
  else:
    res = sum(cl[1:]) * k
print(res)

Submission status: Wrong Answer

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

def connection_list(s):
  res = [0 for i in range(len(s))]
  prev = ''
  cnt = 0
  for i in range(len(s)):
    if s[i] == prev:
      cnt += 1
    else:
      res[i-1] = cnt
      cnt = 0
    prev = s[i]
  res[-1] = cnt
  if s[0] == s[-1]:
    res[0] = res[-1] + 1
  return res

def calc_ceil(n):
  return math.ceil(n/2)
cl = connection_list(s)
cl = list(map(calc_ceil, cl))
if cl[0] > 0:
  res = sum(cl[1:]) + (k - 1) * sum(cl[:-1])
else:
  res = sum(cl[1:]) * k
print(res)

Submission status: Wrong Answer

Solution code:
s=list(input())
k=int(input())
A,B,C=0,0,0
test=s*3
for i in range(len(s)*3-1):
    if test[i]==test[i+1]:
        test[i+1]="A"
A=test[:len(s)].count("A")
B=test[len(s):len(s)*2].count("A")
C=test[len(s)*2:len(s)*3].count("A")

if k==1:print(A)
elif k==2:print(A+B)
else:
    print(A+B*(k-2)+C)

Submission status: Wrong Answer

Solution code:
import math
s = input()
K = int(input().strip())

out = ','
cnt1=0
cnt2=0
for c in range(0,len(s)):
    if out[-1]==s[c]:
        cnt1+=1
        out+=','
    else:
        out+=s[c]

for c in range(0,len(s)):
    if out[-1]==s[c]:
        cnt2+=1
        out+=','
    else:
        out+=s[c]
# print(out)
print((K-1)*cnt2+cnt1)

Submission status: Wrong Answer

Solution code:
import math
s = input()
K = int(input().strip())

out = ','
cnt=0
if s[0]==s[-1]:
    num=2
else:
    num=1
for i in range(num):
    for c in range(0,len(s)):
        if out[-1]==s[c]:
            cnt+=1
            out+=','
        else:
            out+=s[c]
# print(out)
print(math.ceil(cnt*K/num))

Submission status: Wrong Answer

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

out = ','
cnt=0
if s[0]==s[-1]:
    num=2
else:
    num=1
for i in range(num):
    for c in range(0,len(s)):
        if out[-1]==s[c]:
            cnt+=1
            out+=','
        else:
            out+=s[c]
# print(out)
print(cnt*K//num)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
S=list(input())
K=int(input())
N=len(S)

count=0
cool=True
for i in range(N-1):
    if S[i+1]==S[i] and cool:
        count+=1
        cool=False
    else:
        cool=True

print(count*K)

Submission status: Wrong Answer

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

#for i in range(K)
#	temp = temp

#temp = S*K
count = 0;
flag = 0;
#ある文字が前文字と同一であった場合にカウントアップ

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

count = count * K
if (S[0] == S[i]) & (flag == 0):
  count += K-1
  flag = 1


#print(temp)
print(count)

Submission status: Wrong Answer

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

#for i in range(K)
#	temp = temp

#temp = S*K
count = 0;
flag = 0;
#ある文字が前文字と同一であった場合にカウントアップ

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

count = count * K
if (S[0] == S[i]) & (flag == 0):
  count += K-1


#print(temp)
print(count)

Submission status: Wrong Answer

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

tmp=S+S
tmp+='Q'
cnt=1
cw=0
for i in range(len(tmp)-1):
    if tmp[i]==tmp[i+1]:
        cnt+=1
    else:
        cw+=cnt//2
        cnt=1
ans=0

cnr=1
cv=0
D=S+"Q"
for i in range(0,len(D)-1):
    if D[i]==D[i+1]:
        cnr+=1
    else:
        cv+=cnr//2
        cnr=1
b=2
for i in reversed(range(0,len(S)-1)):
    if S[i]==S[i+1]:
        b+=1

if S[0]==S[len(S)-1]:
    if b>2 and b%2==0:
        cv+=1

if K%2==0:
    ans+=cw*(K//2)
    print(ans)
else:
    ans+=cw*(K//2)+cv
    print(ans)

Submission status: Wrong Answer

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

tmp=S+S
tmp+='Q'
cnt=1
cw=0
for i in range(len(tmp)-1):
    if tmp[i]==tmp[i+1]:
        cnt+=1
    else:
        cw+=cnt//2
        cnt=1
ans=0

cnr=1
cv=0
D=S+"Q"
for i in range(0,len(D)-1):
    if D[i]==D[i+1]:
        cnr+=1
    else:
        cv+=cnr//2
        cnr=1
b=2
for i in reversed(range(0,len(S)-1)):
    if S[i]==S[i+1]:
        b+=1

if S[0]==S[len(S)-1]:
    if b%2==0:
        cv+=1

if K%2==0:
    ans+=cw*(K//2)
    print(ans)
else:
    ans+=cw*(K//2)+cv
    print(ans)

Submission status: Wrong Answer

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

tmp=S+S
tmp+='Q'
cnt=1
cw=0
for i in range(len(tmp)-1):
    if tmp[i]==tmp[i+1]:
        cnt+=1
    else:
        cw+=cnt//2
        cnt=1
ans=0

cnr=1
cv=0
D=S+"Q"
for i in range(0,len(D)-1):
    if D[i]==D[i+1]:
        cnr+=1
    else:
        cv+=cnr//2
        cnr=1
b=1
for i in reversed(range(0,len(S)-1)):
    if S[i]==S[i+1]:
        b+=1

if S[0]==S[len(S)-1]:
    if b%2==0:
        cv+=1

if K%2==0:
    ans+=cw*(K//2)
    print(ans)
else:
    ans+=cw*(K//2)+cv
    print(ans)

Submission status: Wrong Answer

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

tmp=S+S
tmp+='Q'
cnt=1
cw=0
for i in range(len(tmp)-1):
    if tmp[i]==tmp[i+1]:
        cnt+=1
    else:
        cw+=cnt//2
        cnt=1
ans=0

cnr=1
cv=0
D=S+"Q"
for i in range(0,len(D)-1):
    if D[i]==D[i+1]:
        cnr+=1
    else:
        cv+=cnr//2
        cnr=1
if S[0]==S[len(S)-1]:
    if S[len(S)-1]!=S[len(S)-2]:
        cv+=1

if K%2==0:
    ans+=cw*(K//2)
    print(ans)
else:
    ans+=cw*(K//2)+cv
    print(ans)

Submission status: Wrong Answer

Solution code:
s = list(map(str, input().strip()))
k = int(input())

pre = 0
cnt = 1
ans = 0
for i in s:
    if i == pre:
        cnt += 1
    else:
        ans += cnt // 2
        cnt = 1
    pre = i

ans += cnt//2

pcnt = cnt
dcnt = 0
for i in s:
    if i == pre:
        cnt += 1
    else:
        dcnt = cnt - pcnt
        break

if len(s) == 1:
    ans = k//2
elif dcnt % 2 and pcnt % 2:
    ans = ans * k + k - 1
else:
    ans *= k

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(map(str, input().strip()))
k = int(input())

pre = 0
cnt = 1
ans = 0
for i in s:
    if i == pre:
        cnt += 1
    else:
        ans += cnt // 2
        cnt = 1
    pre = i
pcnt = cnt
dcnt = 0
for i in s:
    if i == pre:
        cnt += 1
    else:
        dcnt = cnt - pcnt
        break
if dcnt % 2 and pcnt % 2:
    ans += pcnt//2
    ans = ans * k + k - 1
else:
    ans += pcnt//2
    ans *= k

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(map(str, input().strip()))
k = int(input())

pre = 0
cnt = 1
ans = 0
for i in s:
    if i == pre:
        cnt += 1
    else:
        ans += cnt // 2
        cnt = 1
    pre = i
pcnt = cnt
dcnt = 0
for i in s:
    if i == pre:
        cnt += 1
    else:
        dcnt = cnt - pcnt
        break
if dcnt % 2 and pcnt % 2:
    ans = ans * k + k - 1
else:
    ans += pcnt//2
    ans *= k

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(map(str, input().strip()))
k = int(input())

pre = 0
cnt = 1
ans = 0
for i in s:
    if i == pre:
        cnt += 1
    else:
        ans += cnt // 2
        cnt = 1
    pre = i
pcnt = cnt
for i in s:
    if i == pre:
        cnt += 1
    else:
        ans += cnt // 2 - (cnt - pcnt) // 2
        cnt = 0
        break

if cnt:
    ans += cnt//4

print(ans * k)

Submission status: Wrong Answer

Solution code:
s = list(map(str, input().strip()))
k = int(input())

pre = 0
cnt = 1
ans = 0
for i in s:
    if i == pre:
        cnt += 1
    else:
        ans += cnt // 2
        cnt = 1
    pre = i
pcnt = cnt
for i in s:
    if i == pre:
        cnt += 1
    else:
        ans += cnt // 2 - (cnt - pcnt) // 2
        break

print(ans * k)

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
a = 1
ans = 0
e = 0
l_s = []
for i in range(1,len(s)):
    if s[i] == s[i-1]:
        a += 1
    else:
        l_s.append(a)
        a = 1
l_s.append(a)
if len(l_s) == 1:
    print((l_s[0]*K)//2)
    exit()
if s[0] == s[-1]:
    f = l_s[0]
    l = l_s [-1]
    l_s[-1] += l_s[0]
    del l_s[0]
    e = 1
for i in l_s:
    ans += i//2
if e == 1:
    M = ans*K - l_s[-1]
    M += f//2
    M += l//2
else:
    M = ans*K
print(M)

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
a = 1
ans = 0
l_s = []
for i in range(1,len(s)):
    if s[i] == s[i-1]:
        a += 1
    else:
        l_s.append(a)
        a = 1
l_s.append(a)
if len(l_s) == 1:
    print((l_s[0]*K)//2)
    exit()
if s[0] == s[-1]:
    l_s[-1] += l_s[0]
    del l_s[0]
for i in l_s:
    ans += i//2
print(ans*K)

Submission status: Wrong Answer

Solution code:
from itertools import groupby as gb
s=input()
k=int(input())
if len(s)==1:print(k//2);exit()
elif len(s)==2 and len(set(list(s)))==1:print(k);exit()
ji=[len(list(b))//2 for a,b in gb(s)]
l=k*sum(ji)
if s[0]==s[-1]:
  ji=[len(list(b)) for a,b in gb(s)]
  if ji[0]%2 and ji[-1]%2:l+=k-1
print(l)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
cnt = 1
lst = []
ans = 0
head, tail = S[0], S[-1]
prev = head
for s in S[1:-1]:
	if (prev == s):
		cnt += 1
	else:
		lst.append(cnt)
		prev = s
		cnt = 1
if (prev == tail):
	lst.append(cnt+1)
else:
	lst.extend([cnt, 1])
if (head != tail):
	for c in lst:
		ans += c // 2
	print(ans * K)	
else:
	if (len(lst) == 1):
		ans += (lst[0] * K) // 2
		print(ans)
	else:
		for c in lst[1:-1]:
			ans += c // 2
		ans *= K
		ans += lst[0]//2 + ((lst[0]+lst[-1])//2)*(K-1) + lst[-1]//2
		print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
cnt = 1
lst = []
ans = 0
head, tail = S[0], S[-1]
prev = head
for s in S[1:-1]:
	if (prev == s):
		cnt += 1
	else:
		lst.append(cnt)
		prev = s
		cnt = 1
if (prev == tail):
	lst.append(cnt+1)
else:
	lst.extend([cnt, 1])
if (head != tail):
	for c in filter(lambda x: x>1, lst):
		ans += c // 2
	print(ans * K)	
else:
	if (len(lst) == 1):
		ans += (lst[0] * K) // 2
		print(ans)
	else:
		for c in filter(lambda x: x>1, lst[1:-1]):
			ans += c // 2
		ans *= K
		ans += lst[0]//2 + ((lst[0]+lst[-1])//2)*(K-1) + lst[-1]//2
		print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
cnt = 1
lst = []
ans = 0
head, tail = S[0], S[-1]
prev = head
for s in S[1:-1]:
	if (prev == s):
		cnt += 1
	else:
		lst.append(cnt)
		prev = s
		cnt = 1
lst.append(cnt+(prev == tail))
if (head != tail):
	for c in filter(lambda x: x>1, lst):
		ans += c // 2
	print(ans * K)	
else:
	if (len(lst) == 1):
		ans += (lst[0] * K) // 2
		print(ans)
	else:
		for c in filter(lambda x: x>1, lst[1:-1]):
			ans += c // 2
		ans *= K
		ans += lst[0]//2 + ((lst[0]+lst[-1])//2)*(K-1) + lst[-1]//2
		print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
cnt = 1
lst = []
ans = 0
head, tail = S[0], S[-1]
prev = head
for s in S[1:-1]:
	if (prev == s):
		cnt += 1
	else:
		lst.append(cnt)
		prev = s
		cnt = 1
if (prev == tail):
	lst.append(cnt+1)
if (head != tail):
	for c in lst:
		ans += c // 2
	print(ans * K)	
else:
	if (len(lst) == 1):
		ans += (lst[0] * K) // 2
		print(ans)
	else:
		for c in lst:
			ans += c // 2
		ans *= K
		ans -= (lst[0]//2 - (lst[0]+lst[-1])//2 + lst[-1]//2)*(K-1)
		print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
cnt = 1
lst = []
ans = 0
head, tail = S[0], S[-1]
prev = head
for s in S[1:-1]:
	if (prev == s):
		cnt += 1
	else:
		lst.append(cnt)
		prev = s
		cnt = 1
if (prev == tail):
	lst.append(cnt+1)
if (head != tail):
	for c in filter(lambda x: x>1, lst):
		ans += c // 2
	print(ans * K)	
else:
	if (len(lst) == 1):
		ans += (lst[0] * K) // 2
		print(ans)
	else:
		for c in filter(lambda x: x>1, lst[1:-1]):
			ans += c // 2
		ans *= K
		ans += lst[0]//2 + ((lst[0]+lst[-1])//2)*(K-1) + lst[-1]//2
		print(ans)