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:
s = input()
k = int(input())
def unit(s):
    """sの両端を外した状態でいくつ変えるか
    """
    count = 0
    prev = s[0]
    for c in s[1:]:
        if c==prev:
            count += 1
            prev = None
        else:
            prev = c
    return count
if len(s)==2:
    if s[0]==s[1]:
        print(k)
    else:
        print(0)
elif k==1:
    print(unit(s))
elif len(s)==1:
    print(k//2)
elif not s:
    print(0)
elif s[0]!=s[-1]:
    print(k * unit(s))
else:
    s0 = unit(s[1:-1])
    s1 = unit(s[1:])
    s2 = unit(s[:-1])
    s3 = unit(s)
    import numpy as np
    a = np.zeros((k+1,2), dtype=int)
    a[1,0] = s3
    a[1,1] = s1
    for n in range(2,k+1):
        a[n, 0] = min(a[n-1,1]+s3, a[n-1,0]+s2) + 1
        a[n, 1] = min(a[n-1,1]+s0, a[n-1,0]+s1) + 1
    print(a[k,0])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = str(input())
N = int(input())
S = S*N
S_list=list(S)
count = 0
for i in range(len(S_list)-1):
    if i < len(S_list)-2 and S_list[i] == S_list[i+1] and S_list[i+1] == S_list[i+2]:
        count += 1
        S_list[i+1] = "1"
    elif S_list[i] == S_list[i+1]:
        count += 1
    elif S_list[i] == S_list[i+1] and i == len(S_list)-2:
        count_last+=1
print(count*N)

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-1] != S[i] and S[0] == S[1]) or  (S[i-1] != S[i] and S[0] != S[1] and S[i] == S[0]) :
            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:
from itertools import groupby

s = input()
k = int(input())
a, b = [], []
count1, count2 = 0, 0

for key, group in groupby(s):
  a.append(list(group))

if len(a) == 1:
  print(len(s*k) // 2)
  
else:
  for key, group in groupby(s*2):
    b.append(list(group))  

  for i in a:
    count1 += len(i) // 2

  for i in b:
    count2 += len(i) // 2

  c = count2 - count1

  print(count1 + c*(k-1))

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 (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
if len(S) == 1:
    ans = K//2
 
print(ans)

Submission status: Runtime Error

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

word_list = []

a = s[0]
b = 1
for i, v in enumerate(s[1:],1):
    if a != v:
        word_list.append((a,b))
        a = v
        b = 1
    else:
        b += 1
    if i == ls-1:
        word_list.append((a,b))

ans = 0
if len(word_list) == 1:
    ans = (word_list[0][1] * k) // 2
else:
    if word_list[-1][0] != word_list[0][0]:
        for i in word_list:
            ans += (i[1])//2
        ans *= k
    else:
        head, *body, tail = word_list

        for i in body:
            ans += (i[1])//2
        ans *= k
        ans += head[1] // 2
        ans += tail[1] // 2
        headtail = (head[1]+tail[1]) //2 *(k-1)
        ans += headtail
print(ans)

Submission status: Runtime Error

Solution code:
S = str(input())
K = int(input())
ans = int(0)
count = int(0)
count_first = int(0)
onelen = int(0)
if S[0]==S[-1]:
    count_first += 1
#if count_first == 0:
for i in range(1,len(S)):
    if S[i] == S[i - 1] and i != len(S) - 1:
        count += 1
    elif S[i] == S[i - 1] and i == len(S) - 1:
        count += 1
        if count != len(S)-1:
            onelen += (count + 1) // 2
        else:
            ans = ((count+1) * K) // 2
            print(ans)
            exit()
    else:
        onelen += (count + 1) // 2
        count = 0
if ans == 0:
    ans = onelen * K
#    if S[0] == S[-1]:
#        ans -= 2

#else:
if count_first==1:
    i = int(0)
    while S[i] == S[i + 1]:
        count_first += 1
        i += 1
    i = int(-1)
    while S[i] == S[i - 1]:
        count_first += 1
        i -= 1
    if count_first % 2 == 1:
        ans += K-1

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[j]:
            n+=1
        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 * (k - 1))

Submission status: Runtime Error

Solution code:

def a(s):
    count = 0
    for i in range(len(s) - 2):
        if s[i] == s[i + 1]:
            s = s[:i + 1] + 'A' + s[i + 2:]
            count += 1
    if s[-1] == s[-2]:
        count += 1
    return count


s = input()
k = int(input())
if s[0] != s[-1] or k == 1:
    print(a(s) * k)
elif k == 2:
    new_s = s * 2
    print(a(new_s))
elif len(s) == s.count(s[0]):
    new_s = s * 2
    count_2 = a(new_s)
    print(count_2 * (k // 2) + a(s) * (k % 2))
else:
    new_s = s * 2
    count_2 = a(new_s)
    count_3 = a(new_s + s)
    diff = count_3 - count_2
    print(count_3 + (k-3) * diff)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
def unit(s):
    """sの両端を外した状態でいくつ変えるか
    """
    count = 0
    prev = s[0]
    for c in s[1:]:
        if c==prev:
            count += 1
            prev = None
        else:
            prev = c
    return count
if len(s)==2:
    if s[0]==s[1]:
        print(k)
    else:
        print(0)
elif k==1:
    print(unit(s))
elif len(s)==1:
    print(k//2)
elif not s:
    print(0)
elif s[0]!=s[-1]:
    print(k * unit(s))
#     if k==1:
#         print(unit(s))
#     else:
#         result = s2 + s0 * (k-2) + s1
#         print(result)
else:
    s0 = unit(s[1:-1])
    s1 = unit(s[1:])
    s2 = unit(s[:-1])
    s3 = unit(s)
    import numpy as np
    a = np.zeros((k+1,2), dtype=int)
    a[1,0] = s3
    a[1,1] = s1
    for n in range(2,k+1):
        a[n, 0] = min(a[n-1,1]+s3, a[n-1,0]+s2) + 1
        a[n, 1] = min(a[n-1,1]+s0, a[n-1,0]+s1) + 1
    print(a[k,0])
#     result = min(s1*(k-1)+s3, s2*(k-1)+s3)
#     if k%2==0:
#         result2 = min(s3*(k/2)+s0*(k/2-1)+s1, s2+s3*(k/2)+s0*(k/2-1))
#     else:
#         result2 = min(s3*(k//2+1)+s0*(k//2), s2+(s3*(k//2)+s0*(k//2-1))+s1)
#     print(min(result, result) + (k-1))

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 s[i+1] == s[i+2] and flag == 0 :
      flag = 1
      cnt -= 1
    else:
      flag = 0
print(cnt*k)

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


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


def LF(): return list(map(float, input().split()))


def LI_(): return list(map(lambda x: int(x)-1, input().split()))


def II(): return int(input())


def IF(): return float(input())


def LS(): return list(map(list, input().split()))


def S(): return list(input().rstrip())


def IR(n): return [II() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def FR(n): return [IF() for _ in range(n)]


def LFR(n): return [LI() for _ in range(n)]


def LIR_(n): return [LI_() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]


mod = 1000000007
inf = float('INF')


def A():
    S = input()
    
    K = II()
    

    i = 0
    ans = 0
    A = 1
    while(A > 0):
        count = 0
        while(S[i] == S[i+1]):
            count += 1
            i += 1
        if(S[i] != S[i+1]):
            i += 1
        if count > 0:
            ans += (count+1)//2

        if S[-1] == S[i]:
            A = -1
    if K>=2 and S[-2] == S[0] and S[-3] != S[-2] and S[0] != S[1]:
        ans+=1
        print((ans*K)-1)
    else:
        print(ans*K)


    

    return

# B


def B():
    N, K = map(int, input().split())
    h = LI()
    count = 0

    for i in h:
        if i >= K:
            count += 1
        else:
            continue
    print(count)
    return

# C


def C():
    N = II()
    A = LI()
    J = [0] * N
    for i, n in enumerate(A):
        J[n-1] = i+1
    for s in J:
        print(s, end=" ")

    return

# D


def D():
    A, B = map(int, input().split())
    g = gcd(A, B)
    # go = g
    # myset = set([1])
    sq = int(sqrt(g)) + 2
    ans = 1

    for i in range(2, sq):
        if g % i == 0:
            ans += 1
        while g % i == 0:
            g /= i

            # myset.add(i)
        if g == 1:
            break
        if i == sq - 1:
            # myset.add(go)
            ans += 1

    print(ans)

    return

# E


def E():
    N, M = LI()
    bit_max = 1 << N
    dp = [[inf for i in range(bit_max)] for j in range(M+1)]
    dp[0][0] = 0

    for i in range(M):
        a, b = LI()

        c = LI()
        bit = 0

        for d in c:
            bit |= 1 << (d-1)

        for w in range(bit_max):

            t = w | bit
            cost = dp[i][w] + a

            dp[i+1][t] = min(dp[i+1][t], cost)

            dp[i+1][w] = min(dp[i][w], dp[i+1][w])

    print(-1) if dp[-1][-1] == inf else print(dp[-1][-1])

    return

# F


def F():
    N, M = LI()

    value = [0] * M
    power = [0] * M
    for i in range(M):
        a, b = LI()
        value[i] = a
        c = LI()
        L = ['0'] * N
        for k in c:
            L[k - 1] = '1'
        bint = ''.join(L)
        power[i] = int(bint, 2)
    bint = ''.join(list(['1'] * N))
    dp = [inf] * (int(bint, 2)+1)
    t = 0
    cost = 0

    dp[0] = 0
    for s in range(int(bint, 2) + 1):
        for i in range(M):
            t = s | power[i]
            cost = dp[s] + value[i]
            dp[t] = min(dp[t], cost)
    print(-1) if(dp[-1] == inf) else print(dp[-1])

    return

    # you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")


def solution(S):
    # write your code in Python 3.6
    import math

    vowels = "AIUEO"
    count = 0
    consonants = 0
    newC = []
    newV = []

    for i in S[:-1]:
        if i in vowels:
            count += 1
            newV.append(i)
        else:
            consonants += 1
            newC.append(i)

    if consonants < count or consonants - 2 > count:
        return 0

    a = math.factorial(len(set(newC))) * math.factorial(len(set(newV)))
    return a

    pass


# Solve
if __name__ == '__main__':
    A()

Submission status: Runtime Error

Solution code:
import sys
s = input()
k = int(input())
ret = 0
t = 0

s = s*k

for j in range(1, len(s)):
    for i in range(len(s)-j):
        for u in range(j):
            if s[i + u] != s[i + u + 1]:
                break
            if u == j-1:
                if j % 2==1:
                    t += 1
                else:
                    t -= 1


print(t)

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 (count+1)%2==1 and a[0]%2 == 1 and S[0]== S[1]:
    
    ans+=K-1
if S[0]!= S[1] and (count+1)%2 ==1:
    ans+=K-1
if len(S) == 1:
    ans = K//2
 
print(ans)

Submission status: Runtime Error

Solution code:
S=input()
K=int(input())
A=[]
D=1
for i in range(len(S)-2):
  if S[i]==S[i+1]:
    D+=1
  else:
    A.append(D)
    D=1
A.append(D)
B=[i for i in A if not i==1]
C=[(i//2) for i in B]
count=(sum(C)*K)

if S[0]==S[-1]:
  count+= (K-1)
if S[-1]==S[-2]:
  count+=1
  
print(count)

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
if S[-2] != S2[-2]:
    if S[-1] == S2[-1]:
        count -= 1
count *= K

print(count)

Submission status: Runtime Error

Solution code:
k = int(input())
t = s * k
cnt = 0
loop = 0
t = [i for i in t]
b = 0
while b < len(t) - 1:
    if t[b] == t[b + 1]:
        t[b + 1] = '?'
    b += 1
print(t.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-1] != S[i] and S[0] == S[1]):
            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:
def a(s):
    count = 0
    for i in range(len(s) - 2):
        if s[i] == s[i + 1]:
            s = s[:i + 1] + 'A' + s[i + 2:]
            count += 1
    if s[-1] == s[-2]:
        count += 1
    return count


s = input()
k = int(input())
if s[0] != s[-1] or k == 1:
    print(a(s) * k)
elif k == 2:
    new_s = s * 2
    print(a(new_s))
elif len(s) % 2 == 1 and len(s) == s.count(s[0]):
    new_s = s * 2
    count_2 = a(new_s)
    print(count_2 * (k // 2) + a(s) * (k % 2))
else:
    new_s = s * 2
    count_2 = a(new_s)
    count_3 = a(new_s + s)
    diff = count_3 - count_2
    print(count_3 + (k-3) * diff)

Submission status: Runtime Error

Solution code:
S = list(input())
K = int(input())
S2 = S[:]

if len(S) == 1:
    print(K//2)
    exit()
cons = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cons += 1
        S[i+1] = '_'
if K == 1:
    print(cons)
    exit()
if S[0] != S[-1]:
    print(cons * K)
    exit()

# 最初から何文字連続するか
# この時最後の連続する文字はすでに奇数でかつ最初の文字と一緒
cons2 = 1
j = 0
while True:
    if S2[j] == S2[j+1]:
        cons2 += 1
        j += 1
    else:
        break
if cons2 % 2 == 0:
    minus = 0
else:
    minus = 1
print(cons * K + minus * (K-1) )

Submission status: Runtime Error

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

if s[0]==s[-1]:
    word=s[-1]
    s[-1]="A"
    count +=1

print((count*k)-1 if (s[-1]=="A")and(s[-2]!=word) else count*k)

Submission status: Runtime Error

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

count = 0

if S[0] == S[-1] and S[0] == S[1] and len(S) > 2:
    S[0] = "#"
    change = True
    count += 1

else:
    change = False

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        S[i+1] = "#"
        count += 1

if change:
    print(count*K - 1*K//2)
else:
    print(count*K)

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 S[-1] == S[-2]:
  if S[-2] == S[-3]:
    count = count * K + count - 1
  else:
    count = count * K
    
else:
  count = count * K
  
print(count)

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
S=''
#for i in range(k):
#	S+=s
#print(s)
S = list(s)
#last_word=s[-1]
count1=0
l_s=len(S)
code_list = 'abcdefghijklmnopqrstuvwxyz'
for i in range(1,l_s):
  #print(S,count)
  if S[i]==S[i-1] and i<l_s-1:
    for j in code_list:
      if j != S[i+1] and j !=S[i-1]:
        S[i]=j
        count1+=1
        break
  elif S[i]==S[i-1]:
    for j in code_list:
      if j != S[i-1] and j !=S[0]:
        S[i]=j
        count1+=1
        break
last=S[-1]
S=list(s)
count2=0
for i in range(0,l_s):
  #print(S,count)
  if i==0 and S[0]==last:
    for j in code_list:
      if j != S[i+1] and j !=last:
        S[i]=j
        count2+=1
        break
  elif S[i]==S[i-1] and i<l_s-1:
    for j in code_list:
      if j != S[i+1] and j !=S[i-1]:
        S[i]=j
        count2+=1
        break
  elif S[i]==S[i-1]:
    for j in code_list:
      if j != S[i-1] and j !=S[0]:
        S[i]=j
        count2+=1
        break
count3=0
S=list(s)
for i in range(0,l_s):
  #print(S,count)
  if i==0 and S[0]==last:
    for j in code_list:
      if j != S[i+1] and j !=last:
        S[i]=j
        count3+=1
        break
  elif S[i]==S[i-1] and i<l_s-1:
    for j in code_list:
      if j != S[i+1] and j !=S[i-1]:
        S[i]=j
        count3+=1
        break
  elif S[i]==S[i-1]:
    for j in code_list:
      if j != S[i-1] and j !=S[0]:
        S[i]=j
        count3+=1
        break
print(count1+count2*(k-2)+count3)

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

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

Submission status: Runtime Error

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

j = j*k

counter = 0
ans_L = []

s = [i for i in j]
s.append("0")
renzoku = 1

for val in range(0,len(s)-1):
    tmp = s[val+1]
    if s[val] == tmp:
        renzoku += 1
    elif renzoku > 1 and s[val] != tmp:
        ans_L.append(renzoku//2)
        renzoku = 1
print(sum(ans_L))

Submission status: Runtime Error

Solution code:
import re
input1 = input()
input2 = int(input())

replace_cnt = 0
for m in re.finditer(r'(.)\1+', input1):
    replace_cnt += int(len(m[0])/2)
print(replace_cnt*input2)

Submission status: Runtime Error

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

str_list = list(T)
str_list.append('0')
replace_times = 0

for i in range(0, len(T) - 1):
  if i == len(T) - 1:
    break
  elif str_list[i] == str_list[i+1] == str_list[i+2]:
    str_list[i+1] = str(i)
    replace_times += 1
    continue
  elif str_list[i] == str_list[i+1]:
    str_list[i+1] = str(i)
    replace_times += 1
print(replace_times)

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())
t=s*k
t=list(t)

ans=0
for num,moji in enumerate(t):
    if t[num]==t[num-1]:
        t[num]="a"
        ans+=1
        #print(t)
print(ans)

Submission status: Runtime Error

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

cnt = 0
i = 0

while i < len(T):
    if T[i] == T[i+1]:
        cnt += 1
        i += 2

    else:
        i += 1

print(cnt)

Submission status: Runtime Error

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

S = list(input())
K = int(input())
N = len(S)
ans = 0
last_same = False
if N==1:
    print(K//2)
    exit()
for i in range(1,N):
    if S[i]!=S[i-1]:
        break
else:
    print(N*K//2)
    exit()
pre = S[0]
p = False
for i in range(1,N):
    if p:
        pre = S[i]
        p = False
        continue
    s = S[i]
    if pre==s:
        ans += 1
        p = True
        if i==N-1:
            last_same = True
        elif i==N-2:
            if S[-1]==S[-2]:
                last_3_same = True
    pre = s

l_same = False
if not last_same:
    if not S[0]==S[1]:
        if S[0]==S[-1]:
            ans += 1
            l_same = True
    elif S[1]==S[2]:
        if last_3_same:
            ans += 1
            l_same = True

ANS = ans*K
if l_same:
    ANS -= 1
print(ANS)

Submission status: Runtime Error

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

count = 0
xi = 0

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

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

    print(int(count * k + xi * (k - 1)))

Submission status: Runtime Error

Solution code:
s = list(map(str,input()))
k = int(input())
cnt =0
bool =True
x=-1
ck=0
while bool:
    if s[x]==s[x+1]:
        #print('+A')
        #print(x)
        cnt+=1
        x+=2
        if x==-1:
            x-=1
            ck=1
        if x==len(s)-1 or x==len(s)-2:
            #print('fiA')
            break
    else:
        x+=1
        if x==len(s)-1 or x==len(s)-2:
            #print('fiB')
            break
#print(cnt)
print(cnt*k)

Submission status: Runtime Error

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

for i in range(k):
  t=t+s0
for j in range(k*len(t)):
  if t[i] == t[i+1]:
    t=t.replace(t[j+1],'a')
    cnt+=1

print(cnt)

Submission status: Runtime Error

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

t = s * k

# print(t)
list_o = list(set(list(t)))
# print(list_o)

# list_s = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
# list_s = ['a', 'b', 'c']
count = 0
for i in range(len(t)-2):
    # print(t[i:i+3])
    test_s = t[i:i+3]
    if test_s[0] == test_s[1] == test_s[2]:
        # print('おなじだよ')
        num = i + 1
        # print('num', num)
        # print('t', t)
        t = t[:num] + '0' + t[num+1:]
        count += 1
        # print('t+', t)

for i in range(len(t)-1):
    # print(t[i:i+3])
    test_s = t[i:i+3]
    
    re_s = '0'
    if test_s[0] == test_s[1]:
        if re_s == test_s[0]:
            re_s = '1'
        try:
            if re_s == test_s[2]:
                re_s = '2'
        except Exception as e:
            re_s = '2'
        
        # print('おなじだよ')
        num = i + 1
        # print('num', num)
        # print('t', t)
        
        t = t[:num] + re_s + t[num+1:]
        count += 1
        # print('t+', t)

print(count)

Submission status: Runtime Error

Solution code:
    s = list(input())
    k = int(input())
     
    count = 0
    xi = 0
     
	if len(s) == 1:
    	print(int(k//2))
	elif map_all(s) == True:
    	print(int((len(s)*k)//2))
	else:
        for i in range(len(s)-1):
            if s[i] == s[i+1]:
                count += 1
                p = i % 10
                s[i+1] = str(p)
     
        if s[0] == s[-1]:
            xi= 1
            p = i % 10
            s[-1] = str(p)
     
        print(int(count*k+xi*(k-1)))

Submission status: Runtime Error

Solution code:
import copy
def main():
    S = input()
    K = int(input())
    a = list(S)
    b = copy.copy(a)
    cnt = 0
    if len(set(a))==1 and len(a) != 1:
        cnt = (len(a)*K)//2
        print(cnt)
    elif len(a) ==1:
        cnt += K//2
        print(cnt)
    else:
        cnt_2 = 0
        for i in range(len(a)-1):
            if a[i+1] == a[i]:
                a[i+1] = str(i)
                cnt += 1
        cnt *= K
        if a[0] == a[-1] and len(a) > 1:
            cnt += K-1
        for j in range(len(b)-1):
            if b[j+1] == b[j]:
                b[j] = str(j)
                cnt_2 += 1
        cnt_2 *= K
        if b[0] == b[-1] and len(b) > 1:
            cnt_2 += K-1

        print(min(cnt,cnt_3))

    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

prev_c = S[0]
num_changes = 0
for c in S[1:]:
    if c == prev_c:
        num_changes += 1
        prev_c = 'replaced'
    else:
        prev_c = c

total_changes = 0
if S[0] == prev_c and S[1] == S[0] and len(S) % 2 == 1:
    num_changes2 = 0
    for c in S:
        if c == prev_c:
            num_changes2 += 1
            prev_c = 'replaced'
        else:
            prev_c = c
    total_changes = num_changes * int(K/2 + 1) + num_changes2 * int(K/2)
elif S[0] == prev_c:
    num_changes2 = 0
    for c in S:
        if c == prev_c:
            num_changes2 += 1
            prev_c = 'replaced'
        else:
            prev_c = c
    total_changes = num_changes + num_changes2 * (K-1)
else:
    total_changes = num_changes * K

print(total_changes)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
n = 0
j = s[0]
l = 1
p = 0
for i in range(1,len(s)):
  if s[i] == j:
    l += 1
  else:
    n += l//2
    l = 1
    j = s[i]
n += l//2
if s[0] == s[-1] and s[0] != s[1] and s[0] != s[-2]:
  p = k-1
print(n*k+p)

Submission status: Runtime Error

Solution code:
# 時間かかりすぎ
s = list(input())
k = int(input())
t = s * k

count = 0
for i in range(1, len(t)):
    if t[i-1] == t[i]:
        count += 1
        t[i] = '-'
print(count)

Submission status: Runtime Error

Solution code:
buf=''
cnt = 1
total = 0
cnts = []


for s in S:
    #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)

if S[0]==S[-1]:
    if (cnts[1]+cnts[-1]) % 2 == 0:
        print(total*K+K-1)
else:
    print(total*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]:
    ind += 1
for i in range(99-ind-1):
  anss.remove([])
if s[0] == s[len(s)-1] and s[len(s)-2] == s[len(s)-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
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:
s = input()
k = int(input())
c = 1
i = 1
l = []
c2 = 0
while i < len(s):
    if i == len(s)-1:
        if s[i] == s[i-1]:
            c = c+1
            l.append(c)
            i = i+1
        else:
            l.append(c)
            l.append(1)
            i = i+1
    elif s[i] == s[i-1]:
        c = c + 1
        i = i + 1
    else:
        l.append(c)
        c = 1
        i = i+1
if len(l) == 1:
    print((len(s)*k)//2)
elif s[0] == s[len(s)-1]:
    for i in range(1,len(l)-1):
        c2 = c2 + l[i]//2
    print(c2*k+((l[0]+l[len(l)-1])//2)*(k-1)+l[0]//2+l[len(l)-1]//2)
else:
    for i in range(0,len(l)):
        c2 = c2 + l[i]//2
    print(c2*k)

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]:
            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:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

S = str(input())
n = len(S)
K = I()

for i in range(1,n):
    if S[i]!=S[i-1]:
        break
    else:
        if i==n-1:
            print(K*n//2)
            exit()

ren = 1
num = 0
for i in range(1,n):
    if S[i]==S[i-1]:
        ren += 1
    else:
        if i!=n-1:
            num += ren//2
            ren = 1

last = ren

if S[0]==S[-1]:
    num2 = 0
    for i in range(n):
        if S[i]==S[-1]:
            ren += 1
        else:
            now = i
            break
    num2 += ren//2
    ren = 1
    for i in range(now,n):
        if S[i]==S[i-1]:
            ren += 1
        else:
            if i!=n-1:
                num2 += ren//2
                ren = 1
    num3 = 0
    ren = 1
    for i in range(n-1-last+2,n):
        if S[i]==S[i-1]:
            ren += 1
        else:
            num3 += ren//2
            ren = 1
    num3 += ren//2
    print(num+num2*(K-1)+num3)
else:
    num += ren//2
    print(num*K)