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: Runtime Error

Solution code:
import numpy as np
S=input()
K=int(input())
count1=[]
count2=[]
count=0
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        count+=1
        if i==len(S)-2:
            count1.append(count)
            count=0
    elif count!=0 and S[i]!=S[i+1]:
        count1.append(count)
        count=0
Num1=len(count1)       
count1=np.array(count1)


for i in range(len(S)-1):
    if S[len(S)-1]==S[len(S)-i-2]:
        count+=1
        if i==len(S)-2:
            count2.append(count)
            count=0
    elif  S[len(S)-1]!=S[len(S)-i-2]:
        count2.append(count)
        count=0
        break

for i in range(len(S)-1):
    if S[len(S)-1]==S[i]:
        count+=1
        if i==len(S)-2:
            count2.append(count)
            count=0
    elif  S[len(S)-1]!=S[i]:
        count2.append(count)
        count=0
        break
a1=int(np.sum((count1+1)//2))
if count2[1]!=0:
    if count2[0]>=1 and count2[1]==1:
        print(a1*K+((sum(count2)+1)//2-(count1[Num1-1]+1)//2)*(K-1))
    elif count2[0]>=1 and count2[1]>1:
        print(a1*K+((sum(count2)+1)//2-(count1[Num1-1]+1)//2-(count1[0]+1)//2)*(K-1))
    elif count2[0]==0 and count2[1]==1:
        print(np.sum((count1+1)//2)*K+(K-1))
    elif count2[0]==0 and count2[1]>=1:
        print(a1*K+((sum(count2)+1)//2-(count1[0]+1)//2)*(K-1))
else:
    print(int(np.sum((count1+1)//2))*K)

Submission status: Runtime Error

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

tail = s[0]
plus = 0
if tail == s[-1]:
  tmp_cnt1 = 0
  tmp_cnt2 = 0
  for i in s:
    if tail == i:
      tmp_cnt1 += 1
    else:
      break
  for i in s[::-1]:
    if tail == i:
      tmp_cnt2 += 1
    else:
      break
  if (tmp_cnt1 % 2) == 1 and (tmp_cnt2%2)==1:
    plus = 1

cnt=0
if len(s)==1:
  ret = k
else:
  tmp=s[0]
  tmp_cnt=0
  for i in s[1:]:
    if tmp==i:
      tmp_cnt+=1
    else:
      cnt+=(tmp_cnt+1)//2
      tmp_cnt=0
    tmp=i
  cnt+=(tmp_cnt+1)//2
  ret=cnt*k
  if plus == 1:
    ret += k-1
  if tmp_cnt1 == len(s):
    ret = len(s)*k//2
print(ret)

Submission status: Runtime Error

Solution code:
import numpy as np
S=input()
K=int(input())
count1=[]
count2=[]
count=0
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        count+=1
        if i==len(S)-2:
            count1.append(count)
            count=0
    elif count!=0 and S[i]!=S[i+1]:
        count1.append(count)
        count=0
Num1=len(count1)       
count1=np.array(count1)


for i in range(len(S)-1):
    if S[len(S)-1]==S[len(S)-i-2]:
        count+=1
        if i==len(S)-2:
            count2.append(count)
            count=0
    elif  S[len(S)-1]!=S[len(S)-i-2]:
        count2.append(count)
        count=0
        break

for i in range(len(S)-1):
    if S[len(S)-1]==S[i]:
        count+=1
        if i==len(S)-2:
            count2.append(count)
            count=0
    elif  S[len(S)-1]!=S[i]:
        count2.append(count)
        count=0
        break
a1=int(np.sum((count1+1)//2))
if count2[1]!=0:
    if count2[0]>=1 and count2[1]==1:
        print(a*K+((sum(count2)+1)//2-(count1[Num1-1]+1)//2)*(K-1))
    elif count2[0]>=1 and count2[1]>1:
        print(a*K+((sum(count2)+1)//2-(count1[Num1-1]+1)//2-(count1[0]+1)//2)*(K-1))
    elif count2[0]==0 and count2[1]==1:
        print(np.sum((count1+1)//2)*K+(K-1))
    elif count2[0]==0 and count2[1]>=1:
        print(a*K+((sum(count2)+1)//2-(count1[0]+1)//2)*(K-1))
else:
    print(int(np.sum((count1+1)//2))*K)

Submission status: Runtime Error

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


if s[0]==s[1] and s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
    s=s[0]+"@"+s[2:]
    s=s[0:len(s)-1]+"@"
    c+=2
elif s[0]!=s[1] and s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
    s=s[0:len(s)-1]+"@"
    a=True
    c+=1
elif s[0]==s[1] and s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
    s="@"+s[1:]
    a=True
    c+=1
elif s[0]!=s[1] and s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
    s=s[0:len(s)-1]+"@"
    a=True
    c+=1
for j in range(len(s)-2):
  if s[j]==s[j+1] and s[j+1]==s[j+2]:
    s=s[0:j+1]+"@"+s[j+2:]
    c+=1
    j+=1
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    c+=1

print(str(c*k))

Submission status: Runtime Error

Solution code:
def zen(s):
    ans=0
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            ans+=1
        if len(s)-1==ans:
            return True
        else:
            return False

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = input()
K = int(input())
d=[[0 for _ in range(100)] for _ in range(4)]
ans = [0,0,0,0]
l = len(S)
odd_diff = 0
even_diff = 0
if l == 1:
    ans = K // 2
    print(ans)
if l > 1:
    for i in range(4):
        s = S * (i + 1)
        l = len(s)
        for j in range(l-1):
            
            if j == 0 and s[j] == s[j+1]:
                ans[i] += 1
                d[i][0] = 1
            if j > 0 and s[j] == s[j+1] and d[i][j-1] == 0:
                ans[i] += 1
                d[i][j] = 1
    if K <= 4:
        print(ans[K-1])
    elif K > 4 and K % 2 == 0:
        even_diff = ans[3] - ans[1]
        print(ans[1]+(K/2)*even_diff)
    elif K > 4 and K % 2 == 1:
        odd_diff = ans[2] - ans[0]
        print(ans[0]+(K//2)*odd_diff)

Submission status: Runtime Error

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


if s[0]==s[1] and s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
    s=s[0]+"@"+s[2:]
    s=s[0:len(s)-1]+"@"
    c+=2
elif s[0]!=s[1] and s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
    s=s[0:len(s)-1]+"@"
    a=True
    c+=1
elif s[0]==s[1] and s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
    s="@"+s[1:]
    a=True
    c+=1
elif s[0]!=s[1] and s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
    s=s[0:len(s)-1]+"@"
    a=True
    c+=1
for j in range(len(s)-2):
  if s[j]==s[j+1] and s[j+1]==s[j+2]:
    s=s[0:j+1]+"@"+s[j+2:]
    c+=1
    j+=1
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    c+=1

print(c*k)

Submission status: Runtime Error

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

T=S*K
count=0
for i in range(len(T)-1):
  T[i]==T[i+1]
  count+=1
print(count)

Submission status: Runtime Error

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

T=S*K
count=0
for i in range(len(T)-1):
  T[i]==T[i+1]
  count+=1
print(count)

Submission status: Runtime Error

Solution code:
s=input()
c=0
g=0
k=int(input())
a=False


if s[0]==s[1] and s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
    s=s[0]+"@"+s[2:]
    s=s[0:len(s)-1]+"@"
    c+=2
elif s[0]!=s[1] and s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
    s=s[0:len(s)-1]+"@"
    a=True
    c+=1
elif s[0]==s[1] and s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
    s="@"+s[1:]
    a=True
    c+=1
elif s[0]!=s[1] and s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
    s=s[0:len(s)-1]+"@"
    a=True
    c+=1
for j in range(len(s)-2):
  if s[j]==s[j+1] and s[j+1]==s[j+2]:
    s=s[0:j+1]+"@"+s[j+2:]
    c+=1
    j+=1
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    c+=1
c=c*k
print(c)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
t = s
cnt = 0
loop = 0
t = [i for i in t]
if t[::-1][0] == t[0] and t[::-1][1] != t[0] and t[::-1][0] != t[1] :
    cnt += 1
b = 0
while b < len(t) - 1:
    if len(list(set(t[b:]))) == len(t[b:]):
        break
    if t[b] == t[b + 1]:
        t[b + 1] = '?'
    b += 1
aa = cnt*(k-1)+t.count("?")*k
print(t.count("?")*k)

Submission status: Runtime Error

Solution code:
import numpy as np
S=input()
K=int(input())
count1=[]
count2=[]
count=0
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        count+=1
        if i==len(S)-2:
            count1.append(count)
            count=0
    elif count!=0 and S[i]!=S[i+1]:
        count1.append(count)
        count=0
Num1=len(count1)       
count1=np.array(count1)


for i in range(len(S)-1):
    if S[len(S)-1]==S[len(S)-i-2]:
        count+=1
        if i==len(S)-2:
            count2.append(count)
            count=0
    elif  S[len(S)-1]!=S[len(S)-i-2]:
        count2.append(count)
        count=0
        break

for i in range(len(S)-1):
    if S[len(S)-1]==S[i]:
        count+=1
        if i==len(S)-2:
            count2.append(count)
            count=0
    elif  S[len(S)-1]!=S[i]:
        count2.append(count)
        count=0
        break
       
    
if count2[1]!=0:
    if count2[0]>=1 and count2[1]==1:
        print(np.sum((count1+1)//2)*K+((sum(count2)+1)//2-(count1[Num1-1]+1)//2)*(K-1))
    elif count2[0]>=1 and count2[1]>1:
        print(np.sum((count1+1)//2)*K+((sum(count2)+1)//2-(count1[Num1-1]+1)//2-(count1[0]+1)//2)*(K-1))
    elif count2[0]==0 and count2[1]==1:
        print(np.sum((count1+1)//2)*K+(K-1))
    elif count2[0]==0 and count2[1]>=1:
        print(np.sum((count1+1)//2)*K+((sum(count2)+1)//2-(count1[0]+1)//2)*(K-1))
else:
    print(int(np.sum((count1+1)//2))*K)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
t = ''
i = 0
count = 0
first = 0
end =  0
while s[0] ==s[i]:
	first += 1
	i = i + 1

i = len(s)-1
while s[i] ==s[len(s)-1]:
	end += 1
	i = i - 1


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

if i == len(s)-2:
	if s[i] == s[i+1]:
		count +=1
	if s[0] == s[len(s)-1]:
		if (first + end) %2 !=0
			count += 1
print(count*k)

Submission status: Runtime Error

Solution code:
s=input()
c=0
g=0
k=int(input())
a=False


if s[0]==s[1] and s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
    s=s[0]+"@"+s[2:]
    s=s[0:len(s)-1]+"@"
    c+=2
elif s[0]!=s[1] and s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
    s=s[0:len(s)-1]+"@"
    a=True
    c+=1
elif s[0]==s[1] and s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
    s="@"+s[1:]
    a=True
    c+=1
elif s[0]!=s[1] and s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
    s=s[0:len(s)-1]+"@"
    a=True
    c+=1
for j in range(len(s)-2):
  if s[j]==s[j+1] and s[j+1]==s[j+2]:
    s=s[0:j+1]+"@"+s[j+2:]
    c+=1
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    c+=1
c=c*k
print(c)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
t = ''
i = 0
count = 0
first = 0
end =  0
while s[0] ==s[i]:
	first += 1
	i = i + 1

i = 0
while s[i] ==s[len(s)-1]:
	end += 1
	i = i - 1


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

if i == len(s)-2:
	if s[i] == s[i+1]:
		count +=1
	if s[0] == s[len(s)-1]:
		if (first + end) %2 !=0
			count += 1
print(count*k)

Submission status: Runtime Error

Solution code:
import sys

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

s = [v for v in S]

block = []
count = 1

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

z = len(block)
t = 0
d = 0

if not z == 1:
    for j in range(len(block)):
        x = len(block[j])
        if x == 1:
            continue
        else:
            if x%2 == 0:
                t += x//2
            elif x%2 == 1:
                t += x - (x+1)//2
    
    if block[0][0] == block[-1][-1]:
        joint = block[0] + block[-1]
        y = len(joint)
        if y%2 == 1:
            d = 0
        elif y%2 == 0:
            d = 1
else:
    p = len(block[0])
    if p%2 == 0:
        t = p//2
    else:
        t = (p-1)//2
        if K%2 == 1:
            ans = t + p*(K-1)//2                       
            print(ans)
            sys.exit()
        else:
            ans = p + p*(K-2)//2
            print(ans)
            sys.exit()

ans = t*K + d*(K-1)
print(ans)

Submission status: Runtime Error

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

res = 0
cn = 0
for i in range(1, len(S)):
    if S[i-1] == S[i] :
        res += 1          
        if i != len(S)-1 and S[i] == S[i+1]:
            cn += 1

cnt = cn // 2
if cn % 2 == 1:
    cnt += 1
n = res - cnt

if len(S)%2 == 1 and S[0] == S[-1] and S[0] != S[1]  and S[-2] != S[-1]:
    ans = n*K + K - 1
else:
    ans = n*K

print(ans)

Submission status: Runtime Error

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

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

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

    print(change * K)
else:
    ans = 0
    if S[0] == S[1]:
        S[0] = '.'
        ans += K - 1
    if S[-1] == S[-2]:
        S[-1] = '.'
        ans += K - 1
    if ans == 0:
        ans += K - 1

    change = 0
    for i, t in enumerate(T[1:], start=2):
        if t == T[i - 1]:
            change += 1
            T[i] = '.'

    ans += change * K
    print(ans)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
t = ''
i = 0
count = 0
first = 0
end =  0
while s[0] ==s[i]:
	first += 1
	i = i + 1

i = 0
while s[i] ==s[len(s)-1]:
	end += 1
	i = i - 1


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

if i == len(s)-2:
	if s[i] == s[i+1]:
		count +=1
	if s[0] == s[len(s)-1]:
		if (first + end) %2 ==0
			count += 1
print(count*k)

Submission status: Runtime Error

Solution code:
import math
s = input()
k = int(input())
s = list(s)
ind = 0
anss = [[] for i in range(100)]
for i in range(len(s)-1):
  anss[ind].append(s[i])
  if s[i] != s[i+1] and i != len(s)-2:
    ind += 1
  elif i == len(s)-2:
    ind += 1
#print(ind)
#print(anss)
for i in range(100-ind):
  anss.remove([])
#print(anss)
f = 0
pf = 0
if len(anss) == 0:
  anss.append([])
if s[0] == s[len(s)-1] and s[len(s)-2] == s[len(s)-1] and len(anss)>1 and k > 1:
  if len(anss[0]) % 2 == 1:
    pf = 1
  anss[0] += anss[len(anss)-1]
  anss.remove(anss[len(anss)-1])
  anss[0].append(s[len(s)-1])
  if len(anss[0]) % 2 == 0 and pf == 1 and len(anss) > 1:
    f = 1
elif s[0] == s[len(s)-1] and k > 1:
  if len(anss[0]) % 2 == 1:
    pf = 1
  anss[0].append(s[len(s)-1])
  if len(anss[0]) % 2 == 0 and pf == 1 and len(anss) > 1:
    #print(len(anss[0]),pf)
    f = 1
elif s[len(s)-2] == s[len(s)-1] and k > 1:
  anss[len(anss)-1].append(s[len(s)-1])
else:
  anss.append([s[len(s)-1]])
pans = 0
#print(anss)
for i in anss:
  pans += math.floor(len(i) / 2)
#print(f)
if len(anss) == 1 and len(anss[0]) % 2 == 1:
  print(math.floor(len(list(s*k))/2))
elif f == 1:
  print(pans*k-1)
else:
  print(pans*k)

Submission status: Runtime Error

Solution code:
S = input()
K = int(input())
T = list(S * K)
count = 0
for i in range (len(T) - 1) :
    if T[i] == T[i+1] :
        count += 1
        T[i+1] = '$'
print(count)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
t = ''
i = 0
count = 0
first = 0
end =  0
while s[0] ==s[i]:
	first += 1
	i = i + 1

i = 0
while s[i] ==s[len(s)-1]:
	end += 1
	i = i - 1



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

if i == len(s)-2:
	if s[i] == s[i+1]:
		count +=1
	if s[0] == s[len(s)-1]:
		if (first + end) %2 ==0
			count += 1
print(count*k)

Submission status: Runtime Error

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

T=S*K
count=0
for i in range(3,len(T)):
    if T[i]==T[i-1]:
        count=count+1
        if T[i-1]==T[i-2]:
            count=count-1
if T[2]==T[1]:
    count=count+1
            
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

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

def connect_cnt(S):
	cnt_tmp = 1
	cnt = []

	for i in range(len(S) - 1):

		if S[i] == S[i+1]:
			cnt_tmp += 1
		else:
			cnt.append(cnt_tmp)
			cnt_tmp = 1

		if i == len(S)-2:
			cnt.append(cnt_tmp)

	connect_cnt = sum(np.array(cnt) // 2)
	return connect_cnt


if K == 1:
	print(connect_cnt(S))
	exit(0)

if len(S) == 1:
	print(connect_cnt(S*K))
	exit(0)

if S[0] != S[-1]:

	connect_cnt = connect_cnt(S)
	ans = connect_cnt * K
	print(ans)

else:
	print(connect_cnt(S*K))

Submission status: Runtime Error

Solution code:
import math
s = input()
k = int(input())
s = list(s)
ind = 0
anss = [[] for i in range(100)]
for i in range(len(s)-1):
  anss[ind].append(s[i])
  if s[i] != s[i+1] and i != len(s)-2:
    ind += 1
  elif i == len(s)-2:
    ind += 1
#print(ind)
#print(anss)
for i in range(100-ind):
  anss.remove([])
#print(anss)
f = 0
pf = 0
if len(anss) == 0:
  anss.append([])
if s[0] == s[len(s)-1] and s[len(s)-2] == s[len(s)-1] and len(anss)>1 and k > 1:
  if len(anss[0]) % 2 == 1:
    pf = 1
  anss[0] += anss[len(anss)-1]
  anss.remove(anss[len(anss)-1])
  anss[0].append(s[len(s)-1])
  if len(anss[0]) % 2 == 0 and pf == 1:
    f = 1
elif s[0] == s[len(s)-1] and k > 1:
  if len(anss[0]) % 2 == 1:
    pf = 1
  anss[0].append(s[len(s)-1])
  if len(anss[0]) % 2 == 0 and pf == 1:
    #print(len(anss[0]),pf)
    f = 1
elif s[len(s)-2] == s[len(s)-1] and k > 1:
  anss[len(anss)-1].append(s[len(s)-1])
else:
  anss.append([s[len(s)-1]])
pans = 0
#print(anss)
for i in anss:
  pans += math.floor(len(i) / 2)
#print(f)
if len(anss) == 1 and len(anss[0]) % 2 == 1:
  print(math.floor(len(list(s*k))/2))
elif f == 1:
  print(pans*k-1)
else:
  print(pans*k)

Submission status: Runtime Error

Solution code:
import sys

args = sys.argv
S=args[1]
K=int(args[2])
result=0

a=S[0]
renzoku=0
sumInS=0
for s in S:
    if a==s:
        renzoku=renzoku+1
    else:
        sumInS=sumInS+renzoku//2
        renzoku=1
    a=s
sumInS=sumInS+renzoku//2
result = sumInS*K

if S[0]==S[-1]:
    rst=0
    for s in S:
        if s==S[0]:
            rst=rst+1
        else:
            break
    ren=0
    for s in S[::-1]:
        if s==S[-1]:
            ren=ren+1
        else:
            break
    if rst%2==1 and ren%2==1:
        result=result+(K-1)

if renzoku==len(S):
    total=len(S)*K
    result=total//2

print(result)

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
k = ni()

n = 0
m = 0
p = False
for i in range(len(s)):
	if i == 0:
		if s[i] == s[-1] and s[-1] != s[-2]:
			n = 1
	elif not p and s[i] == s[i-1]:
		m += 1
		p = True
	else:
		p = False

print(m*k+n*(k-1))

Submission status: Runtime Error

Solution code:
S, K = [(input(i)) for i in range(2)]
K = int(K)
T = list(S * K)
count = 0
for i in range (len(T) - 1) :
    if T[i] == T[i+1] :
        count += 1
        T[i+1] = '$'
print(count)

Submission status: Runtime Error

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

if len(S) == 1:
    print(K // 2)
else :
    pre = S[0]
    flg = 0
    cnt = 0
    cnt_list =[]
    
    for i in range(1, len(S)):
        cnt += 1
        if flg == 1:
            flg = 0
            pre = S[i]
            continue
        if S[i] == pre:
            cnt_list.append(cnt)
            flg = 1
        pre = S[i]
    
    S = S[::-1]
    pre = S[0]
    flg = 0
    cnt = 0
    cnt_list2 =[]
    
    for i in range(1, len(S)):
        cnt += 1
        if flg == 1:
            flg = 0
            pre = S[i]
            continue
        if S[i] == pre:
            cnt_list2.append(cnt)
            flg = 1
        pre = S[i]

    print(cnt_list, S*K)
    
    if S[0] == S[-1] and (S[-1] == S[-2] and len(S)-1 in cnt_list):
        print(len(cnt_list)*K)
    elif S[0] == S[-1] and (S[0] == S[1] and 0 in cnt_list2):
        print(len(cnt_list2)*K)
    elif S[0] == S[-1]:
        print(len(cnt_list)*K+K-1)
    else :
        print(len(cnt_list)*K)

Submission status: Runtime Error

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)
		cnt=1
		p=s[i+1]
q.append(cnt)
if q[-1]%2==0:
	cnt=True
else:
	cnt=False
ans=0
if cnt==True:
	for i in range(len(q)):
		ans+=q[i]//2
	print(ans*k)
	exit()
if len(q)==1:
	print(len(s)*k//2)
	exit()
for i in range(len(q)-1):
	ans+=q[i+1]//2
ans*=k
ans+=q[0]//2
if s[0]==s[-1]:
	ans+=(q[0]+q[-1])//2*(k-1)
	ans+=q[-1]//2
	print(ans)
	print(2/0)
else:
	ans=0
	for i in range(len(q)):
		ans+=q[i]//2
	print(ans*k)

Submission status: Runtime Error

Solution code:
from itertools import groupby
N = int(input())
S,k= [input() for i in range(N)]
K=int(k)
c=0
strs=S*K
strs_1 = [[k, len(list(g))] for k, g in groupby(strs)]
strs_2 = [x[1] for x in strs_1]
strs_2
for k in strs_2:
    if k >=2:
        a = k//2
        c +=a
print(c)

Submission status: Runtime Error

Solution code:
s=input()
c=0
g=0
k=int(input())
a=False


if s[0]==s[1] and s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
    s=s[0]+"@"+s[2:]
    s=s[0:len(s)-1]+"@"
    c+=2
elif s[0]!=s[1] and s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
    s=s[0:len(s)-1]+"@"
    a=True
    c+=1
elif s[0]==s[1] and s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
    s="@"+s[1:]
    a=True
    c+=1
elif s[0]!=s[1] and s[0]==s[len(t)-1] and s[len(t)-1]!=s[len(t)-2]:
    s=s[0:len(s)-1]+"@"
    a=True
    c+=1
for j in range(len(s)-2):
  if s[j]==s[j+1] and s[j+1]==s[j+2]:
    s=s[0:j+1]+"@"+s[j+2:]
    c+=1
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    c+=1
c=c*k
print(c)

Submission status: Runtime Error

Solution code:
    S = str(input())
    K = int(input())
    # 全部異なる文字だった場合
    if len(set(S)) == len(S):
        result = 0
    # １文字めと最後の文字が異なる場合
    elif S[0] != S[-1]:
        box = []
        mini_count = 0
        mini_str = ''
        for index, s in enumerate(S[:-1]):
            #print(s, S[index+1])
            if s == S[index+1]: # 次の文字と同じだった場合
                mini_count += 1
                mini_str = s
            else:
                if mini_count != 0:
                    #print('#################')
                    box.append(mini_str * (mini_count+1))
                    mini_str = ''
                    mini_count = 0
                   
        all_temp = 0
        for each in box:
            if len(each) % 2 == 0: # 偶数の場合
                temp = len(each) / 2
            else: # 奇数の場合
                temp = len(each) // 2
            all_temp += temp
            
        result = all_temp * K
     
                
    # １文字めと最後の文字が同じ場合
    else:
        box = []
        mini_count = 0
        mini_str = ''
        for index, s in enumerate(S):
            if index+1 != len(S):# 最後の文字でない場合
                if s == S[index+1]: # 次の文字と同じだった場合
                    mini_count += 1
                    mini_str = s
                else:
                    if mini_count != 0:
                        box.append(mini_str * (mini_count+1))
                        mini_str = ''
                        mini_count = 0
            else: # 最後の文字の場合
                if mini_count != 0:
                    box.append(mini_str * (mini_count+1))
                    mini_str = ''
                    mini_count = 0
                
                   
        all_temp = 0
        for each in box:
            if len(each) % 2 == 0: # 偶数の場合
                temp = len(each) / 2
            else: # 奇数の場合
                temp = len(each) // 2
            all_temp += temp
            
        if S[0] in box[-1] or S[0] in box[0]:
            result = (all_temp * K)
        else:
            result = (all_temp * K) + (K - 1)
        
    print(int(result))

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
t=s*k
t=list(t)
ans=0
for num,moji in enumerate(t):
    if num==len(t)-1:
        break
    if t[num]==t[num+1]:
        t[num+1]="a"
        ans+=1
        print(t)
print(ans)

Submission status: Runtime Error

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

s = [v for v in S]

block = []
count = 1

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

z = len(block)
t = 0
d = 0

if not z == 1:
    for j in range(len(block)):
        x = len(block[j])
        if x == 1:
            continue
        else:
            if x%2 == 0:
                t += x/2
            elif x%2 == 1:
                t += x - (x+1)/2
    
    if block[0][0] == block[-1][-1]:
        joint = block[0] + block[-1]
        y = len(joint)
        if y%2 == 1:
            d = 0
        if y%2 == 0:
            d = 1
else:
    p = len(block[0])
    if p%2 == 0:
        t = p/2
    else:
        t = (p-1)/2
        if K%2 == 1:
            ans = t + p*(K-1)/2                       
            print(ans)
            exit()
        else:
            ans = p + p*(K-2)/2
            print(ans)
            exit()

ans = t*K + d*(K-1)
print(ans)

Submission status: Runtime Error

Solution code:
s=input()
c=0
g=0
k=int(input())
a=False


if s[0]==s[1] and s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
    s=s[0]+"@"+s[2:]
    s=s[0:len(s)-1]+"@"
    c+=2
elif s[0]!=s[1] and s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
    s=s[0:len(s)-1]+"@"
    a=True
    c+=1
elif s[0]==s[1] and s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
    s="@"+s[1:]
    a=True
    c+=1
elif s[0]!=s[1] and s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
    s=s[0:len(s)-1]+"@"
    a=True
    c+=1
for j in range(len(s)-2):
  if s[j]==s[j+1] and s[j+1]==s[j+2]:
    t=t[0:j+1]+"@"+t[j+2:]
    c+=1
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    c+=1
c=c*k
print(c)

Submission status: Runtime Error

Solution code:
S, K = [(input()) for i in range(2)]
K = int(K)
T = list(S * K)
count = 0
for i in range (len(T) - 1) :
    if T[i] == T[i+1] :
        count += 1
        T[i+1] = '$'
print(count)

Submission status: Runtime Error

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

SK = S*K
buf=''
cnt = 1
total = 0
cnts = []
for s in SK:
    #print(buf,s,cnt)
    if s == buf:
        cnt += 1       
    else:
        cnts.append(cnt)
        total += int(cnt/2)
        cnt = 1        
    buf = s
cnts.append(cnt)    
total += int(cnt/2)

print(total)

Submission status: Runtime Error

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

import re

def nchars(s, n):
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

if S[0]!=S[-1]:
  S_l = list(nchars(S,2))
  answer = 0
  for s in S_l:
    answer += len(s)//2
  print(answer*K)

else:
  if (S[0]!=S[1])&(S[-1]!=S[-2]):
    answer = 0
    S_lr=0
    S_l = list(nchars(S,2))
    for s in S_l:
      S_lr += len(s)//2

    answer = S_lr + (1+S_lr)*(K-1)
    print(answer)
  
  elif (S[0]!=S[1])&(S[-1]==S[-2]):
    answer = 0
    S_lr=0
    S_l = list(nchars(S,2))
    for s in S_l:
      S_lr += len(s)//2
    
    a=len(S_l[-1])
    answer = S_lr + ((a+1)//2 + (S_lr-a//2))*(K-1)
    print(answer)
  
  elif (S[0]==S[1])&(S[-1]!=S[-2]):
    answer = 0
    S_lr=0
    S_l = list(nchars(S,2))
    for s in S_l:
      S_lr += len(s)//2
    
    a=len(S_l[0])
    answer = S_lr + ((a+1)//2 + (S_lr-a//2))*(K-1)
    print(answer)
    
  else:
    answer = 0
    S_lr=0
    S_l = list(nchars(S,2))
    for s in S_l:
      S_lr += len(s)//2
    
    a=len(S_l[0])
    b=len(S_l[-1])
    answer = S_lr + ((a+b)//2 + (S_lr-a//2-b//2))*(K-1)
    print(answer)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=input()
c=0
g=0
k=int(input())
a=False


if s[0]==s[1] and s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
    s=s[0]+"@"+s[2:]
    s=s[0:len(s)-1]+"@"
    c+=2
elif s[0]!=s[1] and s[0]==s[len(s)-1] and s[len(s)-1]==s[len(s)-2]:
    s=s[0:len(s)-1]+"@"
    a=True
    c+=1
elif s[0]==s[1] and s[0]==s[len(s)-1] and s[len(s)-1]!=s[len(s)-2]:
    s="@"+s[1:]
    a=True
    c+=1
elif s[0]!=s[1] and s[0]==s[len(t)-1] and s[len(t)-1]!=s[len(t)-2]:
    s=s[0:len(s)-1]+"@"
    a=True
    c+=1
for j in range(len(s)-2):
  if s[j]==s[j+1] and s[j+1]==s[j+2]:
    t=t[0:j+1]+"@"+t[j+2:]
    c+=1
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    c+=1
c=c*k
print(c)

Submission status: Runtime Error

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

tail = s[0]
if tail == s[-1]:
  tmp_cnt1 = 0
  tmp_cnt2 = 0
  for i in s:
    if tail == i:
      tmp_cnt1 += 1
    else:
      for i in s.reverse():
        if tail == i:
          tmp_cnt2 += 1
        else:
          break
      break
  if (tmp_cnt1 + tmp_cnt2) % 2 == 1:
    tail = ''

cnt=0
if len(s)==1:
  ret = k
else:
  tmp=s[0]
  tmp_cnt=0
  for i in s[1:]+tail:
    if tmp==i:
      tmp_cnt+=1
    else:
      cnt+=(tmp_cnt+1)//2
      tmp_cnt=0
    tmp=i
  cnt+=(tmp_cnt+1)//2
  ret=cnt*k
print(ret)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if s.count(s[0]) == len(s):
        print(len(s) * k // 2)
        exit()
    if len(s) <= j + 1:
        if s[0] == s[-1] == s[-2]== s[-3]== s[-4]== s[-5]== s[-6] \
                and s[0] == s[1] == s[2]== s[3]== s[4]== s[5]:
            print(s[10000000000000000000000000])
        break
    if s[j] == s[j + 1]:
        if j == len(s) - 1:
            n += 1
        else:
            m += 1
        j += 1
    j += 1
print(m * k + n)