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:
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
            if i==len(s)-2:
                cnt.append(c)
        else:
            cnt.append(c)
            c=1
    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 = 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(int(ans))

Submission status: Runtime Error

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

# if not(1 <= len(S) and len(S) <= 100):
#     exit()
# if not (S.isalpha() and S.islower()):
#     exit()
# if not float(K).is_integer():
#     exit()
# if not (1 <= int(K) and int(K) <= 10 ** 9):
#     exit()



L = []
tmp = []
pre = ""
for s in S:
    if len(tmp) == 0:
        pre = s
        tmp.append(s)
    elif pre == s:
        tmp.append(s)
    else:
        L.append(tmp)
        pre = s
        tmp = [s]
L.append(tmp)

count = 0
for l in L:
    count += int(len(l) / 2)

count *= int(K)
if len(L) == 1:
    print(count)
    exit()
if L[0][0] == L[len(L) - 1][0]:
    if len(L[0]) % 2 == 1 and len(L[len(L)]) % 2 == 1:
        count = count + 1 * int(K) - 1
print(count)

Submission status: Runtime Error

Solution code:
slist=list(input())
T=input()

i = 0
j = 1
newlist=[]

while i < len(slist)-1:
    if slist[i] == slist[i+1]:
      while True:
        if i == len(slist)-1:
          
          newlist.append(j)
          break
        elif slist[i] == slist[i+1]:
          j = j+1
          i = i+1
        else:
          newlist.append(j)
          i = i+1
          j = 1
          break
    else:
      newlist.append(1)
      i = i+1


if len(newlist)==1:
  print(newlist[0]*int(T)//2)
  
elif slist[0] == slist[-1]:
  start = newlist[0]
  end = newlist[-1]
  del newlist[0]
  del newlist[-1]
  newlist = [i for i in newlist if i >= 2]
  newlist = list(map(lambda x: x // 2 , newlist))
  alpha = (start + end)//2
  ans = sum(newlist)*int(T) + alpha*(int(T)-1) + start//2 + end//2
  print(ans)
  
else:
  del newlist[0]
  del newlist[-1]
  newlist = [i for i in newlist if i >= 2]
  newlist = list(map(lambda x: x // 2 , newlist))
  ans = sum(newlist)*int(T)
  print(ans)

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:]+s[0]:
    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())
cnt = 0
flag = 0
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    cnt += 1
    if i-1 >=0 and s[i-1] == s[i] and flag == 0:
      cnt -= 1
      flag = 1
    else:
      flag = 0
  else:
    flag = 0
tmp = 0
if len(s)%2 and (s[0] == s[1] == s[-1] or s[0] == s[-2] == s[-1]):
  tmp = k//2
print(cnt*k + tmp)

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] and s[-1]==s[-2] and s[-1]==s[-3] and s[-1]==s[-4] and s[0]==s[1]and s[0]==s[2]:
            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()
K = input()

if not(1 <= len(S) and len(S) <= 100):
    exit()
if not (S.isalpha() and S.islower()):
    exit()
if not float(K).is_integer():
    exit()
if not (1 <= int(K) and int(K) <= 10 ** 9):
    exit()



L = []
tmp = []
pre = ""
for s in S:
    if len(tmp) == 0:
        pre = s
        tmp.append(s)
    elif pre == s:
        tmp.append(s)
    else:
        L.append(tmp)
        pre = s
        tmp = [s]
L.append(tmp)

count = 0
for l in L:
    count += int(len(l) / 2)

count *= int(K)
if len(L) == 1:
    print(count)
    exit()
if L[0][0] == L[len(L) - 1][0]:
    if len(L[0]) % 2 == 1 and len(L[len(L)]) % 2 == 1:
        count = count + 1 * int(K) - 1
print(count)

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] and s[-1]==s[-2] and s[-1]==s[-3] and s[0]==s[1]:
            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:
sss

Submission status: Runtime Error

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

res = 0
cnt = 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]:
            cnt += 1

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

if len(S)%2 == 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())
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] and s[-1]==s[-2] and s[0]==s[1]:
            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 = 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 = [::-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]
    
    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)
    else :
        print(len(cnt_list)*K)

Submission status: Runtime Error

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

def func(s, k):
    ans = 0
    n = len(s)
    s_list = list(s)
    for i in range(n - 1):
        if s_list[i] == s_list[i + 1]:
            ans += 1
            s_list[i + 1] = str(i + 1)
    ans *= k
    if s_list[0] == s_list[n - 1]:
        ans += k - 1
    return ans

ans1 = func(s, k)
s_inv = ''.join(list(reversed(s)))
ans2 = func(s_inv, k)

if len(s) % 2 == 1:
    check = True
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            pass
        else:
            check = False
            break
if check:
    ans3 = len(s) * k // 2
else:
    ans3 = ans1

print(min(ans1, ans2, ans3))

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)
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:
  anss[0] += anss[len(anss)-1]
  anss.remove(anss[len(anss)-1])
  anss[0].append(s[len(s)-1])
elif s[0] == s[len(s)-1] and k > 1:
  anss[0].append(s[len(s)-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)
if len(anss) == 1 and len(anss[0]) % 2 == 1:
  print(math.floor(len(list(s*k))/2))
else:
  print(pans*k)

Submission status: Runtime Error

Solution code:
list = []
t = 0
s = 0
a = [input() for i in range(2)]
n = int(a[1])
sum = a[0] * n
for i in sum:
  list.append(i)
  if list[t] == sum[t -1]:
    s += 1
  t += 1
if len(a[0])%2 == 1:
  print(round(s / 2) + 1)
else:
  print(round(s / 2))

Submission status: Runtime Error

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

if s[0]==s[1] and s[0]==s[len(t)-1] and s[len(t)-1]==s[len(t)-2]:
    t=t[0]+"@"+t[2:]
    t=t[0:len(t)-1]+"@"
    c+=2
elif s[0]!=s[1] and s[0]==s[len(t)-1] and s[len(t)-1]==s[len(t)-2]:
    t=t[0:len(t)-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]:
    t="@"+t[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]:
    t=t[0:len(t)-1]+"@"
    a=True
    c+=1
for j in range(len(t)-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(t)-1):
  if t[i]==t[i+1]:
    c+=1
c=(c/2)*k
print(c)

Submission status: Runtime Error

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


taihi = n
l = []
for i in range(101):
    l.append(i)

flg = 0
if len(n) % 2 == 1 and k % 2 == 0:
    n = n*2
    flg = 1
elif len(n) % 2 == 1 and k % 2 ==1 and len(n) > 1:
    n = n*2
    flg = 2


hoge = []
for i in n:
    hoge.append(i)

if flg == 2:
    hoge2 = []
    for i in taihi:
        hoge2.append(i)
    count2 = 0
    for i in range(len(hoge2) -1):
        if hoge2[i] == hoge[i+1]:
            hoge2[i+1] = l[i]
            count2 +=1
    #print(count2)



count = 0

if len(hoge) > 1 and hoge[0] == hoge[-1] and hoge[-1] == hoge[-2]:
    hoge[-2] = 'A'
    count += 1
elif hoge[0] == hoge[-1]:
    hoge[-1] = 'B'
    count += 1

for i in range(len(hoge) -1):
    if hoge[i] == hoge[i+1]:
        hoge[i+1] = l[i]
        count +=1


if flg == 0:
    ans = count * k
elif flg == 1:
    ans = count * (k/2)
    ans = int(ans)
elif flg == 2:
    ans =  count * ((k-1)/2) + count2
    ans = int(ans)

if len(hoge) == 1:
    ans = k // 2

#print(hoge)
#print(count)
print(ans)

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(k-2):
	ans+=q[i+1]//2
ans*=k
ans+=q[0]//2
ans+=(q[0]+q[1])//2*(k-1)
ans+=q[-1]//2
print(ans)

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)
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:
  anss[0] += anss[len(anss)-1]
  anss.remove(anss[len(anss)-1])
  anss[0].append(s[len(s)-1])
elif s[0] == s[len(s)-1]:
  anss[0].append(s[len(s)-1])
elif s[len(s)-2] == s[len(s)-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)
if len(anss) == 1 and len(anss[0]) % 2 == 1:
  print(math.floor(len(list(s*k))/2))
else:
  print(pans*k)

Submission status: Runtime Error

Solution code:
from itertools import groupby
S,k= [input() for i in range(2)]
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]
for k in strs_2:
    if k >=2:
        a = k//2
        c +=a
print(c)

Submission status: Runtime Error

Solution code:
S = list(input())
#取得文字列
K = int(input())
#繰り返し回数
T = S*K
#SをK回繰り返して出来る文字列

count = 0
befStr = ""

for i in range(1,len(T)):
  befStr = T[i - 1]
  if befStr == T[i]:
    count += 1
    T[i] = ""
    
  
print(count)

Submission status: Runtime Error

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

#print(link_S)
#S = S.append(S[len(S)-1])
i = 0
sum = 1
total_sum = 0
sum_ketu = 0
while(1):
    if i == len(S)-1:
        if (S[i] == S[0] and S[0] != S[1]) or (S[i] == S[0] and S[i-1] != S[i]):
            if sum % 2 == 1:
                sum += 1
                sum_ketu = -1
        break
    if S[i] == S[i+1]:
     #   print("i is", i)
     #   print("S[i] is", S[i], "S[i+1] is", S[i+1])
        sum += 1
     #   print(sum)
        i += 1
    else:
        total_sum += sum // 2
        sum = 1
        i += 1
        
total_sum += sum // 2
#print(sum_ketu)
#print(total_sum)
print(total_sum * K + sum_ketu)

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<string>
using namespace std;
 
long long int opn(string s, int n){
    if(s.size()==1){
        return n/2;
    }
  int opcnt =0;
  for(int i=0;i<s.size();i++){
    int repcnt=1;
    if(s[i+1]==s[i]){
        while(i<s.size() && s[i+1]==s[i]){
            repcnt++;
		    i++;
        }
        opcnt += repcnt/2;
        i--;
    }
  }
  return 1LL * opcnt * n;
}
 
int main(){
  string s;
  int n;
  cin>>s>>n;
  cout<<opn(s,n);
  return 0;
}

Submission status: Runtime Error

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

if k == 1:
    cnt1 = 0
    cnt2 = 0
    for i in range(n):
        if i == 0:
            if s[i] == s[i+1]:
                cnt1 += 1
        elif i == n-1:
            if i%2 == 0:
                if s[i] == s[i-1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1]:
                    cnt2 += 1
        else:
            if i%2 == 0:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt2 += 1
    print(min(cnt1, cnt2))
elif k == 2:
    s += s
    cnt1 = 0
    cnt2 = 0
    for i in range(1, 2*n-1):
        if i % 2 == 0:
            if s[i] == s[i-1] or s[i] == s[i+1]:
                cnt1 += 1
        else:
            if s[i] == s[i-1] or s[i] == s[i+1]:
                cnt2 += 1
    print(min(cnt1, cnt2))
else:
    s *= 3
    s1 = ''
    s2 = ''
    for i in range(3*n):
        if i < 3*n - 1 and i > 0:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i-1] or s[i] == s[i + 1]:
                    s1 += '0'
                else:
                    s1 += s[i]
            else:
                s1 += s[i]
                if s[i] == s[i-1] or s[i] == s[i + 1]:
                    s2 += '0'
                else:
                    s2 += s[i]
        elif i == 3*n - 1:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i-1]:
                    s1 += '0'
                else:
                    s1 += s[i]
            else:
                s1 += s[i]
                if s[i] == s[i-1]:
                    s2 += '0'
                else:
                    s2 += s[i]
        else:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i + 1]:
                    s1 += '0'
                else:
                    s1 += s[i]
                    
    s1_arr = [s1[:n].count('0'), s1[n:2*n].count('0'), s1[2*n:].count('0')]
    s2_arr = [s2[:n].count('0'), s2[n:2*n].count('0'), s2[2*n:].count('0')]
    print(min(s1_arr[0] + s1_arr[1]*(k-2) + s1_arr[2], s2_arr[0] + s2_arr[1]*(k-2) + s2_arr[2]))

Submission status: Runtime Error

Solution code:
S=list(str(input()))
s=set(S)
K=int(input())
num=0
i=0
lst=[]
def dp(i,lst):
  if i==len(S)-1:
    return lst
  if S[i]!=S[i+1]:
    return dp(i+1,lst)
  j=i+1
  while j<=len(S)-1  and S[i]==S[j]:
    j+=1
  lst.append(list(S[i:j]))
  return dp(j-1,lst)
if len(s)>=2:
  L=dp(i,lst)
  for i in range(len(L)):
    num+=(len(L[i])//2)
  if L[-1][-1]==S[0] and len(L[-1])%2==1:
    print(num+(K-1)*(num+1))
  else:
    print(num*K)
else:
  print((len(S)*K)//2)

Submission status: Runtime Error

Solution code:
s0=str(input())
k=int(input())
t=str()
cnt=0

for i in range(k):
  t=str(t)+str(s0)

for i in range(k*len(t)):
  if t[i] != t[i+1]:
    t=t.replace(t[i+1],'h')
    cnt+=1
  else:
    break
print(cnt)

Submission status: Runtime Error

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

if k == 1:
    cnt1 = 0
    cnt2 = 0
    for i in range(n):
        if i == 0:
            if s[i] == s[i+1]:
                cnt1 += 1
        elif i == n-1:
            if i%2 == 0:
                if s[i] == s[i-1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1]:
                    cnt2 += 1
        else:
            if i%2 == 0:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt2 += 1
    print(min(cnt1, cnt2))
elif k == 2:
    s *= 2
    cnt1 = 0
    cnt2 = 0
    for i in range(2*n):
        if i == 0:
            if s[i] == s[i+1]:
                cnt1 += 1
        elif i == 2*n-1:
            if i%2 == 0:
                if s[i] == s[i-1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1]:
                    cnt2 += 1
        else:
            if i%2 == 0:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt2 += 1
    print(min(cnt1, cnt2))
else:
    s *= 3
    s1 = ''
    s2 = ''
    for i in range(3*n):
        if i < 3*n - 1 and i > 0:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i-1] or s[i] == s[i + 1]:
                    s1 += '0'
                else:
                    s1 += s[i]
            else:
                s1 += s[i]
                if s[i] == s[i-1] or s[i] == s[i + 1]:
                    s2 += '0'
                else:
                    s2 += s[i]
        elif i == 3*n - 1:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i-1]:
                    s1 += '0'
                else:
                    s1 += s[i]
            else:
                s1 += s[i]
                if s[i] == s[i-1]:
                    s2 += '0'
                else:
                    s2 += s[i]
        else:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i + 1]:
                    s1 += '0'
                else:
                    s1 += s[i]
                    
    s1_arr = [s1[:n].count('0'), s1[n:2*n].count('0'), s1[2*n:].count('0')]
    s2_arr = [s2[:n].count('0'), s2[n:2*n].count('0'), s2[2*n:].count('0')]
    print(min(s1_arr[0] + s1_arr[1]*(k-2) + s1_arr[2], s2_arr[0] + s2_arr[1]*(k-2) + s2_arr[2]))

Submission status: Runtime Error

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

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

check = [0 for _ in range(len(S))]

if K >= 2:
    if S[0] == S[-1]:
        if S[-2] == S[-1]:
            pass
        else:
            check[0] = 1


for i in range(1, len(S)):
    if S[i - 1] == S[i]:
        if check[i - 1] == 0:
            check[i] = 1

print(sum(check) * K)

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]:
    cnt += 1
b = 0
while b < len(t) - 1:
    if t[b] == t[b + 1]:
        t[b + 1] = '?'
    b += 1
aa = cnt*(k-1)+t.count("?")*k
print(aa)

Submission status: Runtime Error

Solution code:
S = input()
K = int(input())
N = len(S)
cnt = 0
flg1 = False
flg2 = False
flg3 = False
flg4 = False
flg5 = False
for i in range(N-1):
    if S[i] != S[i+1]:
        flg3 = True
        break
if (flg3 == False) and N % 2 == 1:
    print((N*K)//2)
    exit()


if (S[0] == S[N-1]) and K != 1:
    if S[0] != S[1]:
        cnt += 1
        flg1 = True
        flg5 = True
    if (S[1] == S[2]) and (2 < N) and (flg5 == False):
        cnt += 1
        flg1 = True
if (S[N-2] == S[N-1]):
    flg4 = True

for i in range(N-1):
    if flg2:
        flg2 = False
        continue
    if (i == N - 2) and flg1:
        break
    if S[i] == S[i+1]:
        cnt += 1
        flg2 = True
if flg1 and flg4 == False:
    print(cnt*K-1)
else:
    print(cnt*K)

Submission status: Runtime Error

Solution code:
import numpy as np
S = list(input())
K = int(input())

a_li = []
b = len(S)
i = 0
j = 0
S.append(0)
x = 0

while i != b:
    a = 1
    while S[j] == S[j+1]:
        i += 1
        j += 1
        a += 1
    i += 1
    j += 1
    a_li.append(a)

if S[0] == S[-2]:
    if a_li[0] >= 2 and (a_li[0]%2 == 1):
        if a_li[0] >= 2 and (a_li[0]%2 == 1):
            x = K-1

a_array = np.array(a_li)
a_array //= 2
scr = sum(a_array)*K+x
print(scr)

Submission status: Runtime Error

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

count = 0 
f = False
for index, st in enumerate(S):
  try:
    if st == S[index + 1]:
      if f == True:
        f = False
      else:
      	count += 1
      	f = True
      
    else:
      f = False

  except:
    pass
  
if len(S) > 2:
	if S[-1] == S[-2]:
		if S[-2] == S[-3]:
			count = count * K + count - 1
		else:
			count = count * K
    	
	else:
  		count = count * K
        
elif len(S) = 1:
  count = K - 1
else:
  count = count * K 
 
print(count)

Submission status: Runtime Error

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

print(count)

Submission status: Runtime Error

Solution code:
S = input()
K = int(input())
a = []
ans = 0
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] :
        count += 1
    else:
        if count!=0:
            ans += (count+1)//2
            a.append(count+1)
            count = 0
if count !=0:
    ans += (count+1)//2 
ans = ans*K
a.append(0)
if len(S) == 1:
    ans = K//2
    print(ans)
    break
if (count+1)%2==1 and a[0]%2 == 1 and S[0]== S[1] and S[0] == S[len(S)-1]:
    
    ans+=K-1
if S[0]!= S[1] and (count+1)%2 ==1 and  S[0] == S[len(S)-1]:
    ans+=K-1

Submission status: Runtime Error

Solution code:
import numpy as np

S = list(map(str,input().split()))
S = [c for c in S[0]]
K = int(input())

count = 0
S2 = S[1:] + [S[0]]

countflag = True
tmp = 0
for i in range(len(S2)):
    if S[i] == S2[i]:
        if tmp == 1:
            tmp = 0
            countflag = True
            
        if countflag:
            count += 1
        else:
            tmp += 1
        
        countflag = False
    else:
        countflag = True
count *= K
if S[-2] != S2[-2]:
    if S[-1] == S2[-1]:
        count -= 1

print(count)

Submission status: Runtime Error

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

if k == 1:
    cnt1 = 0
    cnt2 = 0
    for i in range(n):
        if i == 0:
            if s[i] == s[i+1]:
                cnt1 += 1
        elif i == n-1:
            if i%2 == 0:
                if s[i] == s[i-1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1]:
                    cnt2 += 1
        else:
            if i%2 == 0:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt2 += 1
    print(min(cnt1, cnt2))
elif k == 2:
    s += s
    cnt1 = 0
    cnt2 = 0
    for i in range(2*n):
        if i == 0:
            if s[i] == s[i+1]:
                cnt1 += 1
        elif i == 2*n-1:
            if i%2 == 0:
                if s[i] == s[i-1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1]:
                    cnt2 += 1
        else:
            if i%2 == 0:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt2 += 1
    print(min(cnt1, cnt2))
else:
    s += 2*s
    s1 = ''
    s2 = ''
    for i in range(3*n):
        if i < 3*n - 1 and i > 0:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i-1] or s[i] == s[i + 1]:
                    s1 += '0'
                else:
                    s1 += s[i]
            else:
                s1 += s[i]
                if s[i] == s[i-1] or s[i] == s[i + 1]:
                    s2 += '0'
                else:
                    s2 += s[i]
        elif i == 3*n - 1:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i-1]:
                    s1 += '0'
                else:
                    s1 += s[i]
            else:
                s1 += s[i]
                if s[i] == s[i-1]:
                    s2 += '0'
                else:
                    s2 += s[i]
        else:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i + 1]:
                    s1 += '0'
                else:
                    s1 += s[i]
                    
    s1_arr = [s1[:n].count('0'), s1[n:2*n].count('0'), s1[2*n:].count('0')]
    s2_arr = [s2[:n].count('0'), s2[n:2*n].count('0'), s2[2*n:].count('0')]
    print(min(s1_arr[0] + s1_arr[1]*(k-2) + s1_arr[2], s2_arr[0] + s2_arr[1]*(k-2) + s2_arr[2]))

Submission status: Runtime Error

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

if k == 1:
    cnt1 = 0
    cnt2 = 0
    for i in range(n):
        if i == 0:
            if s[i] == s[i+1]:
                cnt1 += 1
        elif i == 2*n-1:
            if i%2 == 0:
                if s[i] == s[i-1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1]:
                    cnt2 += 1
        else:
            if i%2 == 0:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt2 += 1
    print(min(cnt1, cnt2))
elif k == 2:
    s += s
    cnt1 = 0
    cnt2 = 0
    for i in range(2*n):
        if i == 0:
            if s[i] == s[i+1]:
                cnt1 += 1
        elif i == 2*n-1:
            if i%2 == 0:
                if s[i] == s[i-1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1]:
                    cnt2 += 1
        else:
            if i%2 == 0:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt2 += 1
    print(min(cnt1, cnt2))
else:
    s += 2*s
    s1 = ''
    s2 = ''
    for i in range(3*n):
        if i < 3*n - 1 and i > 0:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i-1] or s[i] == s[i + 1]:
                    s1 += '0'
                else:
                    s1 += s[i]
            else:
                s1 += s[i]
                if s[i] == s[i-1] or s[i] == s[i + 1]:
                    s2 += '0'
                else:
                    s2 += s[i]
        elif i == 3*n - 1:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i-1]:
                    s1 += '0'
                else:
                    s1 += s[i]
            else:
                s1 += s[i]
                if s[i] == s[i-1]:
                    s2 += '0'
                else:
                    s2 += s[i]
        else:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i + 1]:
                    s1 += '0'
                else:
                    s1 += s[i]
                    
    s1_arr = [s1[:n].count('0'), s1[n:2*n].count('0'), s1[2*n:].count('0')]
    s2_arr = [s2[:n].count('0'), s2[n:2*n].count('0'), s2[2*n:].count('0')]
    print(min(s1_arr[0] + s1_arr[1]*(k-2) + s1_arr[2], s2_arr[0] + s2_arr[1]*(k-2) + s2_arr[2]))

Submission status: Runtime Error

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

L = []
LS = []
ans = 0
streak = 1
s = ''

for i in range(len(S)-1):
    if i == 0:
        s = S[0]
        streak = 1
    
    if s == '':
        if S[i+1:i+2] == S[i:i+1]:
            s = S[i:i+1]
            streak += 1
    else:
        if S[i+1:i+2] == s:
            streak += 1
        else:
            L.append(streak)
            LS.append(s)
            s = ''
            streak = 1
    
    if i == len(S)-2:
        if streak >= 2:
            L.append(streak)
            LS.append(s)
        if streak == len(S):
            ans = K*(len(S)//2)
            print(ans)
            exit()

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