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:
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(){
  string s;
  cin >> s;
  ll k;
  cin >> k;
  ll cnt1=0;
  ll cnt2=0;
  ll cnt=0;
  int n=s.size();
  for(int i=0;i<n;++i){
    if(s[0]==s[i]) cnt++;
  }
  if(n==cnt){
    cout << (n*k)/2 << endl;
    return 0;
  }

  string t=s+s;
  for(int i=0;i<n;++i){
    if(s[i]==s[i+1]){
      s[i+1]='#';
      cnt1++;
    }
  }

  for(int i=0;i<2*n;++i){
    if(t[i]==t[i+1]){
      t[i+1]='#';
      cnt2++;
    }
  }
  //cout << cnt2 << endl;
  cout << cnt1+(cnt2-cnt1)*(k-1) << endl;
  return 0;

}

Submission status: Runtime Error

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

prev = ''
cnt = 0
for s in S:
    if s == prev:
        cnt += 1
        prev = ''
    else:
        prev = s

b = 0
if K > 2 and S[0] == S[-1]:
    mae = 1
    while S[mae] == S[0]:
        mae += 1
    if mae % 2 == 1 and mae != len(S):
        usiro = 1
        i = len(S) - 2
        while S[i] == S[-1]:
            usiro += 1
            i -= 1
        if usiro % 2 == 1:
            b = K // 2

if K % 2 == 0:
    res = cnt * (K // 2) + (b - 1)
else:
    res = cnt * (K // 2) + cnt // 2 + b
print(res)

Submission status: Runtime Error

Solution code:
s=input()
n=int(input())
ans=0
same=False
cnt=0
for i in range(len(s)):
    if i>0 and s[i-1]==s[i]:
        cnt+=1
    else:
        ans+=(cnt+1)//2
        cnt=0

ans+=(cnt+1)//2

if s[0]==s[-1] and s[-1]!=s[-2]:
    ans+=1
    same=True

print(ans*n if same==False else ans*n-1)

Submission status: Runtime Error

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

if S[0] != S[-1]:
    ans = 0
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            S = S[:i] + '*' + S[i + 2:]
            ans += 1
    print(ans * K)
else:
    # S -> s_1 s_2 ... s_k + A + t_l t_l-1 ... t_1 (s_i = t_j)と分解
    k, l = 0, len(S) - 1
    while k < len(S) and S[k] == S[-1]:
        k += 1
    while l > -1 and S[l] == S[0]:
        l -= 1

    # 連結に関係ない部分のカウント
    A = S[k:l + 1]
    ans = 0
    for i in range(len(A) - 1):
        if A[i + 1] == A[i]:
            A = A[:i + 1] + '*' + A[i + 2:]
            ans += 1
    ans *= K

    # 連結に関係ある部分のカウント
    if l == -1 and k == len(S):
        # 全部同じ
        print((len(S) * K) // 2)
    else:
        ans += (len(S) - l + k - 1) // 2 * (K - 1)
        ans += (len(S) - l) // 2 + (k - 1) // 2
        print(ans)

Submission status: Runtime Error

Solution code:
def cal(S):
    tmp, a, cnt = S[0], 1, 0
    flag = True
    for s in S[1:]:
        if S[0]!=s: flag=False
        if flag: a+=1
        if tmp[-1]==s:
            s = '*'
            ans += 1
        tmp += s
    return a, cnt


S = input().replace('\n', '')
k = int(input())
ans = 0
if len(list(set(S)))==1:
    ans = len(S)*k//2
else:
    a, cnt = cal(S)
    b, _ = cal(S[::-1])
    ans = cnt*k
    if S[0]==S[-1]:
        ans -= ((a//2)+(b//2)-((a+b)//2))*(k-1)
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    S=list(input())
    K=int(input())
    S=S*K

    cnt=0
    gr=groupby(S)
    for key,group in gr:
        if len(list(group))>=2:
            cnt+=1
    print(cnt)

resolve()

Submission status: Runtime Error

Solution code:
s=input()

n=int(input())

ss = s+s[0]

ss=list(ss)

ss.reverse()

if ss[0] == ss[1] and ss[1] != ss[2]:
    sa = 1
else:
    sa = 0

count = 0

for i in range(1,len(ss)):
    if ss[i] == ss[i-1]:
        ss[i] = '!'
        count += 1
print(count*n-sa)

Submission status: Runtime Error

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

inter = 0
inner = 0

for i in range(len(S) - 1):
    if S[i] == S[i + 1]:
        S[i + 1] = '#' + S[i + 1]
        inner += 1
if S[0] == S[-1]:
    if S[-2] == '#' + S[-1]:
        pass
    else:
        inter += K - 1
# print(S)
# print(inter)
print(inter + inner * K)

Submission status: Runtime Error

Solution code:
S=input()
K=int(input())
L=len(S)
cnt=0
ren=1

if L==1:
  ans= K//2
elif L==2:
  if S[0]==S[1]:
    ans = K
  else:
    ans = 0
else:  #|S|>=3が保証
  if S[0]!=S[-1]:
    for i in range(1,L):  
      if S[i]==S[i-1]:
        ren +=1
        if i==L-1:
          cnt += ren//2  
      else:
        cnt += ren//2
        ren=1
    ans=cnt*K
  else:
    head=0
    tail=0
    i=0
    j=0
    while S[i]==S[0]:
      head += 1
      i +=1
    while S[-1-j]==S[-1]:
      tail += 1
      j += 1
    #print(head,tail)
    if L-head-tail<0:
      ans=K*L//2
    elif L-head-tail==0:
      ans= K*( (head//2)+(tail//2) )
    else:  
      for k in range(head,L-tail):  
        #print("k=",k,"S[k]=",S[k])
        if S[k]==S[k-1]:
          ren +=1
          if k==L-tail-1:
            cnt += ren//2  
        else:
          cnt += ren//2
          ren=1
      #print("cnt",cnt)   
      
    ans=K*cnt + (K-1)*(head+tail)//2 + head//2 + tail//2
    
print(ans)

Submission status: Runtime Error

Solution code:
S=input()
K=int(input())
L=len(S)
cnt=0
ren=1

if L==1:
  ans= K//2
elif L==2:
  if S[0]==S[1]:
    ans = K
  else:
    ans = 0
else:  #|S|>=3が保証
  if S[0]!=S[-1]:
    for i in range(1,L):  
      if S[i]==S[i-1]:
        ren +=1
        if i==L-1:
          cnt += ren//2  
      else:
        cnt += ren//2
        ren=1
    ans=cnt*K
  else:
    head=0
    tail=0
    i=0
    j=0
    while S[i]==S[0]:
      head += 1
      i +=1
    while S[-1-j]==S[-1]:
      tail += 1
      j += 1
    #print(head,tail)
    if L-head-tail<=0:
      ans=K*L//2
    else:  
      for k in range(head,L-tail):  
        #print("k=",k,"S[k]=",S[k])
        if S[k]==S[k-1]:
          ren +=1
          if k==L-tail-1:
            cnt += ren//2  
        else:
          cnt += ren//2
          ren=1
      #print("cnt",cnt)   
      
    ans=K*cnt + (K-1)*(head+tail)//2 + head//2 + tail//2
    
print(ans)

Submission status: Runtime Error

Solution code:
S=input()
K=int(input())
L=len(S)
cnt=0
ren=1

if L==1:
  ans= K//2
elif L==2:
  if S[0]==S[1]:
    ans = K
  else:
    ans = 0
else:  #|S|>=3が保証
  if S[0]!=S[-1]:
    for i in range(1,L):  
      if S[i]==S[i-1]:
        ren +=1
        if i==L-1:
          cnt += ren//2  
      else:
        cnt += ren//2
        ren=1
    ans=cnt*K
  else:
    head=0
    tail=0
    i=0
    j=0
    while S[i]==S[0]:
      head += 1
      i +=1
    while S[-1-j]==S[-1]:
      tail += 1
      j += 1
    #print(head,tail)
    elif L-head-tail<=0:
      ans=K*L//2
    else:  
      for k in range(head,L-tail):  
        #print("k=",k,"S[k]=",S[k])
        if S[k]==S[k-1]:
          ren +=1
          if k==L-tail-1:
            cnt += ren//2  
        else:
          cnt += ren//2
          ren=1
      #print("cnt",cnt)   
      
    ans=K*cnt + (K-1)*(head+tail)//2 + head//2 + tail//2
    
print(ans)

Submission status: Runtime Error

Solution code:
S=input()
K=int(input())
L=len(S)
cnt=0
ren=1

if L==1:
  ans= K//2
elif L==2:
  if S[0]==S[1]:
    ans = K
  else:
    ans = 0
else:  #|S|>=3が保証
  if S[0]!=S[-1]:
    for i in range(1,L):  
      if S[i]==S[i-1]:
        ren +=1
        if i==L-1:
          cnt += ren//2  
      else:
        cnt += ren//2
        ren=1
    ans=cnt*K
  else:
    head=0
    tail=0
    i=0
    j=0
    while S[i]==S[0]:
      head += 1
      i +=1
    while S[-1-j]==S[-1]:
      tail += 1
      j += 1
    #print(head,tail)
    if L-head-tail==0:
      print(K*L//2)
    elif L-head-tail<0:
      ans=K*L//2
    else:  
      for k in range(head,L-tail):  
        #print("k=",k,"S[k]=",S[k])
        if S[k]==S[k-1]:
          ren +=1
          if k==L-tail-1:
            cnt += ren//2  
        else:
          cnt += ren//2
          ren=1
      #print("cnt",cnt)   
      
    ans=K*cnt + (K-1)*(head+tail)//2 + head//2 + tail//2
    
print(ans)

Submission status: Runtime Error

Solution code:
import sys
S=input()
k=int(input())
ans=0
flag=0
if S[0]==S[-1]:
    left=1
    for i in range(len(S)-1):
        if S[i+1]==S[0]:
            left+=1
        else:
            break
    if left==len(S):
        print(left*k//2)
        sys.exit()
    right=1
    for i in range(len(S)-1):
        if S[-i-2]==S[0]:
            right+=1
        else:
            break
    
now=""
for i in range(left,len(S)-right):
    if flag==1:
        flag=0
        now=S[i]
        continue
    if now==S[i]:
        ans+=1
        flag=1
    now=S[i]
ans*=k

if S[0]==S[-1]:
    ans+=(left+right)//2*(k-1)
    ans+=left//2+right//2
print(ans)

Submission status: Runtime Error

Solution code:
import sys
S=input()
k=int(input())
ans=0
flag=0
if S[0]==S[-1]:
    now=S[0]
    left=1
    for i in range(len(S)-1):
        if S[i+1]==now:
            left+=1
        else:
            break
    if left==len(S):
        print(left*k//2)
        sys.exit()
    now=S[-1]
    right=1
    for i in range(len(S)-1):
        if S[-i-2]==now:
            right+=1
        else:
            break
    
now=""
for i in range(left,len(S)-right):
    if flag==1:
        flag=0
        continue
    if now==S[i]:
        ans+=1
        flag=1
    now=S[i]
ans*=k

if S[0]==S[-1]:
    ans+=(left+right)//2*(k-1)
    ans+=left//2+right//2
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
K = int(input())
cot = 0
before = ""
seq = []

if len(S) == 1:
    ans = len(K)//2
else:
    for i in range(len(S)):
        c = S[i]
        if cot == 0:
            cot += 1
            before =c
        else:
            if c == before:
                cot += 1
            else:
                before = c
                seq.append(cot)
                cot = 1

    seq.append(cot)
    ans = 0
    for temp in seq:
        ans +=temp//2
    ans *= K
    if S[0] == S[-1]:
        ans += (seq[0] + seq[-1]) * (K - 1) //2 - (seq[0] //2 + seq[-1]//2 )* (K - 1)
print(ans)

Submission status: Runtime Error

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    K = int(input())
    last = ""
    a = 0
    if len(S) == 1:
        print(K // 2)
        return
    for s in S:
        if s == last:
            a += 1
            last = ""
        else:
            last = s
    b = 0
    if S[0] == S[-1]:
        if S[0:2] == S[-2:] and len(S) > 2:
            k = 0
            while True:
                if S[k] == S[len(S) - k - 1]:
                    k += 1
                else:
                    break
            b = k % 2
        else:
            if S[1] == S[0] or S[-2] == S[0]:
                b = 0
            else:
                b = 1

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


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    K = int(input())
    last = ""
    a = 0
    for s in S:
        if s == last:
            a += 1
            last = ""
        else:
            last = s
    b = 0
    if S[0] == S[-1]:
        if S[-2] == S[0] or S[1] == S[0]:
            b = 0
        else:
            b = 1

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


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def resolve():
    '''
    code here
    '''
    line = input()
    K = int(input())


    base_cnt = 0
    prev = line[0]
    
    if len(line) >=2:
        for item in line[1:]:
            if item == prev:
                base_cnt += 1
                prev = -1
            else:
                prev = item
        
        if line[-1] == line[-2]:
            is_tail_double = True

    res = base_cnt * K
    # print(base_cnt, res)

    if line[0] == line[-1]:
        if not is_tail_double:
            res = base_cnt + (base_cnt + 1) * (K-1)

    if len(line) == 1:
        res = K //2
    
    print(res)

if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from itertools import groupby

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

t = s * k
cont = [sum(1 for _ in it) for k, it in groupby(t)]

res = 0
for c in cont:
    if c != 1:
        res += c // 2

print(res)

Submission status: Runtime Error

Solution code:
import math
s = list(input())
ss = s[:]
k = int(input())
cnt = 0

if len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2)
else:
    cnt = 0
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt += 1
            s[i + 1] = '*'
    cnt *= k
    if s[0] == s[-1]:
        a = 0
        for i in range(len(s) - 1):
            if ss[i] == ss[i + 1]:
                a += 1
        b = 0
        for j in range(len(s), 0, -1):
            if ss[j] == ss[j - 1]:
                b += 1
        cnt -= (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2))
print(cnt)

Submission status: Runtime Error

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
#template
#issueから始める
s = list(input())
K = int(input())
n = len(s)
count =0
counta = 0
if s[0] == s[-1]:
    if s[-1] != s[-2]:
        counta = K-1
for i in range(n-1):
    if s[i] == s[i+1]:
        count +=1
        s[i+1] = '?'
print(count*K+counta)

Submission status: Runtime Error

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

S = list(input())
K = iin()
s = copy.deepcopy(S)
last_update = False
count1 = 0
for si in range(1, len(s)):
    if s[si-1] == s[si]:
        s[si] = '?'
        count1 += 1
        if si == len(s)-1:
            last_update = True
count2 = 0
last_update2 = False
if not last_update and S[0] == S[-1]:
    count2 = 1
    S2 = list('?')
    S2.extend(S[1:])
    for i in range(1, len(S2)):
        if S2[i-1] == S[i]:
            S2[i] = '?'
            count2 += 1
            if i == len(S2)-1:
                last_update2 = True
if count2 == 0 or K == 1:
    print(K*count1)
else:
    if last_update2:
        count12 = count1+count2
        ans = count12*(K//2)
        if K % 2 == 1: ans+= count1
        else ans -= 1
        print(ans)
    else:
        print(count1 + count2*(K-1))

Submission status: Runtime Error

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

S = list(input())
K = iin()
s = copy.deepcopy(S)
last_update = False
count1 = 0
for si in range(1, len(s)):
    if s[si-1] == s[si]:
        s[si] = '?'
        count1 += 1
        if si == len(s)-1:
            last_update = True
count2 = 0
if not last_update and S[0] == S[-1]:
    S2 = list['?'].extend(S[1:])
    for i in range(1, len(S2)):
        if S2[i-1] == S[i]:
            S2[i] = '?'
            count2 += 1
if count2 == 0:
    print(K*count1)
else:
    print(count1+count2*(K-1))

Submission status: Runtime Error

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

t = 0

if k >= 2:
    for i in range(len(s) - 1):
        if s[i] == s[i+1]:
            t += 1
            s[i+1] = '?'
    if s[-2] == s[-1] == s[0]:
        t += 1
    print(t * k)
else:
    for i in range(len(s) - 1):
        if s[i] == s[i+1]:
            t += 1
            s[i+1] = '?'
    print(t)

Submission status: Runtime Error

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

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

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

flagtail = 0
old_s = ""
cnt = 0
for s_ in S:
	if s_ == old_s:
		cnt +=1
		old_s = ""
	else:
		old_s = s_

ans = cnt * K

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

print(ans)

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
nagasa=len(s)
cnt=1
ans=0
if nagasa==1:
    print(k//2)
elif nagasa==2:
    if s[0]==s[1]:
        print(k)
    else:
        print(0)
else:
    for i in range(nagasa-1):
        if s[i+1]==s[i]:
            cnt+=1
        else:
            ans+=(cnt//2)*k
            cnt=1
    if s[-1]==s[-2]:
        ans+=(cnt//2)*k
        cnt=0
    if s[-1]==s[0]:
        t=0
        tcnt1=1
        while t<nagasa-2:
            if s[t]==s[t+1]:
                tcnt+=1
                t+=1
            else:
                break
        t=1
        tcnt2=1
        while t<nagasa-2:
            if s[-t]==s[-t-1]:
                tcnt2+=1
                t+=1
            else:
                break
        ans-=(k-1)*(tcnt1//2)
        ans-=(k-1)*(tcnt2//2)
        ans+=(k-1)*((tcnt1+tcnt2)//2)
    print(ans)

Submission status: Runtime Error

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

cnt = 0
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    s[i+1] = "1"
    cnt += 1
print(cnt*n)

Submission status: Runtime Error

Solution code:
S = list(input())
s = len(S)
K = int(input())
A = []
j = 1

for i in range(0,s-1,1):
  if S[i] == S[i+1]:
    j += 1
  else:
    A.append(j)
    j = 1
A.append(j)

a = len(A)

b = 0
for i in range(0,a,1):
  b += A[i]//2
  
x = b*K

if S[s-1] == S[0] and A[a-1] % 2 == 1 and A[1] % 2 == 1:
  x += K-1

print(x)

Submission status: Runtime Error

Solution code:
S = list(input())
s = len(S)
K = int(input())
A = []
j = 1

for i in range(0,s-1,1):
  if S[i] == S[i+1]:
    j += 1
  else:
    A.append(j)
    j = 1
A.append(j)

a = len(A)

b = 0
for i in range(0,a,1):
  b += A[i]//2
  
x = b*K

if S[s-1] == S[0] and A[a-1] % 2 == 1 and A[1] % 2 == 1:
  x += K-1

print(b)
print(x)

Submission status: Runtime Error

Solution code:
S = list(input())
s = len(S)
K = int(input())
A = []
j = 1

for i in range(0,s-1,1):
  if S[i] == S[i+1]:
    j += 1
  else:
    A.append(j)
    j = 1
A.append(j)

a = len(A)

b = 0
for i in range(a):
  b += i//2
  
x = b*K

if S[s-1] == S[0] and A[a-1] % 2 == 1 and A[1] % 2 == 1:
  x += K-1
  
print(x)

Submission status: Runtime Error

Solution code:
def main():
    S = input()
    K = int(input())
    ans = 0
    L = len(S)
    if L == 1:
        ans = K//2
        print(ans)
        exit()
    cnt = 1
    for i in range(L):
        if S[i] == S[i+1] and i+1 < L:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K
    if S[0] == S[-1]:
        t = S[0]
        i = 0
        a = 0
        b = 0
        while S[i] == t and i < L:
            a += 1
            i += 1
            if i >= L:break
        i = L-1
        while S[i] == t and i >= 0:
            b += 1
            i -= 1
            if i < 0:break
        tmp = a//2+b//2-(a+b)//2
        tmp *= (K-1)
        ans -= tmp
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    S = input()
    K = int(input())
    ans = 0
    L = len(S)
    if L == 1:
        ans = K//2
        print(ans)
        exit()
    cnt = 1
    for i in range(L-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K
    if S[0] == S[-1]:
        t = S[0]
        i = 0
        a = 0
        b = 0
        while S[i] == t and i < L:
            a += 1
            i += 1
        i = L-1
        while S[i] == t and i >= 0:
            b += 1
            i -= 1
        tmp = a//2+b//2-(a+b)//2
        tmp *= (K-1)
        ans -= tmp
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    S = input()
    K = int(input())
    ans = 0
    L = len(S)
    if L == 1:
        ans = K//2
        print(ans)
        exit()
    cnt = 1
    for i in range(L-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K
    if S[0] == S[-1]:
        t = S[0]
        i = 0
        a = 0
        b = 0
        while S[i] == t:
            a += 1
            i += 1
        i = L-1
        while S[i] == t:
            b += 1
            i -= 1
        tmp = a//2+b//2-(a+b)//2
        tmp *= (K-1)
        ans -= tmp
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
k = INT()
ans = 0
i = 0
while i < len(s):
    tmp = 1
    for j in range(i + 1, len(s)):
        if s[i] == s[j]:
            tmp += 1
        else:
            i = j - 1
            break
    tmp //= 2
    ans += tmp
    i += 1
ans *= k
if s[0] == s[-1] and s[-1] != s[-2]:
    ans += k - 1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

cnt = 0
serial = 1
for i in range(len(S)):
  if S[i] == S[(i+1)%len(S)]:
    serial += 1
  else:
    cnt += int(serial/2)
    serial = 1
  #print(serial)
cnt += int(serial/2)
      
#print(cnt)
if S[0]==S[-1] and S[-1]!=S[-2]:
  ans = cnt*K-1
  
else:
  ans = cnt*K

print(ans)

Submission status: Runtime Error

Solution code:
def main():
    S = input()
    K = int(input())
    l = []
    t = 1
    m = S[0]
    if len(S) == 2:
        if S[0] == S[1]:
            print(K)
            return
        else:
            print(0)
            return
    if len(S) == 3:
        if S[0] == S[1] == S[2]:
            print(3*K//2)
            return
        elif S[0] == S[1] or S[1] == S[2]:
            print(K)
            return
        elif S[0] == S[2]:
            print(K-1)
            return
        else:
            print(0)
            return
    for v in S[1:]:
        if v == m:
            t += 1
        elif t != 1:
            l.append(t)
            t = 1
        m = v
    if t != 1:
        l.append(t)
    ls = 0
    if S[0] == S[-1]:
        if len(l) == 1:
            print(len(l)*K//2)
            return
        if S[0] == S[1] == S[-2]:
            ls = l[-1] + l[0]
            l = l[1:-1]
        elif S[-1] == S[-2]:
            ls = l[-1] + 1
            l = l[:-1]
        elif S[0] == S[1]:
            ls = l[0] + 1
            l = l[1:]
        else:
            ls = 2
    r = 0
    for i in l:
        if i % 2 == 0:
            r += i // 2
        else:
            r += (i - 1)//2
    r *= K
    if ls % 2 == 0:
        r += (K-1) * (ls // 2)
    else:
        r += (K-1) * ((ls - 1) // 2)
    if ls > 2 and ls % 2 == 0:
        r += ls  // 2
    elif ls > 2:
        r += (ls - 1) // 2
    print(r)
main()

Submission status: Runtime Error

Solution code:
def main():
    S = input()
    K = int(input())
    l = []
    t = 1
    m = S[0]
    if len(S) == 2:
        if S[0] == S[1]:
            print(K)
            return
        else:
            print(0)
            return
    if len(S) == 3:
        if S[0] == S[1] == S[2]:
            print(3*K//2)
            return
        elif S[0] == S[1] or S[1] == S[2]:
            print(K)
            return
        elif S[0] == S[2]:
            print(K-1)
            return
        else:
            print(0)
            return
    for v in S[1:]:
        if v == m:
            t += 1
        elif t != 1:
            l.append(t)
            t = 1
        m = v
    if t != 1:
        l.append(t)
    ls = 0
    if S[0] == S[-1]:
        if S[0] == S[1] == S[-2]:
            ls = l[-1] + l[0]
            l = l[1:-1]
        elif S[-1] == S[-2]:
            ls = l[-1] + 1
            l = l[:-1]
        elif S[0] == S[1]:
            ls = l[0] + 1
            l = l[1:]
        else:
            ls = 2
    r = 0
    for i in l:
        if i % 2 == 0:
            r += i // 2
        else:
            r += (i - 1)//2
    r *= K
    if ls % 2 == 0:
        r += (K-1) * (ls // 2)
    else:
        r += (K-1) * ((ls - 1) // 2)
    if ls > 2 and ls % 2 == 0:
        r += ls  // 2
    elif ls > 2:
        r += (ls - 1) // 2
    print(r)
main()

Submission status: Runtime Error

Solution code:
S = str(input())
K = int(input())
SS = []
for i in range(len(S)):
  SS.append(S[i])
for i in range(len(S)-1):
  if SS[i] == SS[i+1]:
    SS[i+1] = "1"

if S[0] == S[-1] and S[-1] != S[-2]:
  print(SS.count("1")*K-1)
else:
  print(SS.count("1")*K)

Submission status: Runtime Error

Solution code:
# Author: cr4zjh0bp
# Created: Sat Mar 14 20:41:10 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

from collections import Counter

s = ns()
n = len(s)
s = s + "$"
k = ni()

c = []
cnt = 1
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        cnt += 1
    elif cnt > 1:
        c.append(cnt)
        cnt = 1

if len(c) == 1 and c[0] == n:
    print(n * k // 2)
elif s[0] != s[-2]:
    print(sum([x // 2 for x in c[:]]) * k)
else:
    a, b = 1, 1
    if s[0] == s[1]:
        a = c[0]
    if s[-2] == s[-3]:
        b = c[-1]
    print(sum([x // 2 for x in c[:]]) * k - (a // 2 + b // 2 - (a + b) // 2) * (k - 1))