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())

n = len(s)
s2 = s + s

renzoku = False
taisho = 0
aida = False
for i in range(2*n-1):
    if s2[i] == s2[i+1]:
        if not renzoku:
            renzoku = True
            start_i = i
            count = 0
        count += 1

    elif renzoku:
        renzoku = False
        end_i = i
        count += 1
        #print(start_i, end_i)
        if count % 2 == 1:
            indexs = list(range(start_i+1, end_i, 2))
            taisho += len(indexs)
            #print(indexs)
            if (n-1 in indexs) or (n in indexs):
                aida = True
        elif count % 2 == 0:
            indexs1 = list(range(start_i, end_i, 2))
            indexs2 = list(range(start_i+1, end_i, 2))
            taisho += len(indexs1)
            #print(indexs1)
            all_indexs = indexs1 + indexs2
            if (n-1 in all_indexs) or (n in all_indexs):
                aida = True

if renzoku:
    renzoku = False
    end_i = 2*n - 1
    count += 1
    if count % 2 == 1:
        indexs = list(range(start_i+1, end_i, 2))
        taisho += len(indexs)
        #print(indexs)
        if (n-1 in indexs) or (n in indexs):
            aida = True
    elif count % 2 == 0:
        indexs1 = list(range(start_i, end_i, 2))
        indexs2 = list(range(start_i+1, end_i, 2))
        taisho += len(indexs1)
        #print(indexs1)
        all_indexs = indexs1 + indexs2
        if (n-1 in all_indexs) or (n in all_indexs):
            aida = True


#if not aida:
if True:
    assert taisho % 2 == 0
    hitotsu = taisho // 2
    out = hitotsu * k
#else:

print(out)

Submission status: Runtime Error

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

cnt,ans=0,0
for i in range(1,len(S)):
  if S[i-1]==S[i]:
    cnt+=1
  else:
    cnt+=1
    ans+=cnt//2
    cnt=0
ans+=cnt//2
if S[0]==S[-1] and S[-1]!=S[-2]:
  print(ans*k+k-1)
else:
  print(ans*k)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if len(s) <= j:
        break
    if s[j] == s[j - 1]:
        if j == 0:
            n += 1
            if len(s) == 2:
                k += 1
            elif s[j - 1] == s[j - 2] or s[j] == s[j + 1]:
                n -= 1
            j += 1
        else:
            if len(s) > 2:
                m += 1
                j += 1
    j += 1
print(m * k + n * (k - 1))

Submission status: Runtime Error

Solution code:
s = list(input())
k = int(input())
count = 0
x = 0
if s[0] != s[-1]:
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            s.pop(i + 1)
            s.insert(i + 1, "")
            count += 1
    count = count * k
else:
    if s[-2] == s[-1]:
        x = 1
    s.append(s[0])
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            s.pop(i + 1)
            s.insert(i + 1, "")
            count += 1
    count = count * k - 1
    if x == 1:
        count += 1
print(int(count))

Submission status: Runtime Error

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

l = []
cnt = 1
for i in range(1, n + 1):
    if s[i - 1] != s[i]:
        l.append(cnt)
        cnt = 1
    else:
        cnt += 1
m = sum(map(lambda li: li // 2, l))
if s[0] == s[-2]:
    if len(l) == 1:
        ans = k * n // 2
    elif l[0] % 2 == l[-1] % 2 == 1:
        ans = k * m + k - 1
    else:
        ans = k * m
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin


def change(S, K): 
    c = 0 
    for i in range(1, len(S)):
        if S[i-1] == S[1]:
            c += 1

    if S[-1] == S[0] and S[-1] != S[-2]:
        c += 1

    return K * c 


if __name__ == "__main__":                                                                                                                                                               
    S = stdin.readline().strip()
    K = int(stdin.readline())

    print(change(S, K))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
s=list(input())
k=int(input())
cnt=1
cnt2=0
tmp=0
flg=0
for i in range(len(s)):
    if tmp==s[i]:
        cnt+=1
    else:
        cnt2+=cnt//2
        cnt=1
    tmp=s[i]
cnt2+=cnt//2
if s[0]==s[-1]:
    m=0
    cnt3=0
    while s[m]==s[0]:
        cnt3+=1
        m+=1
        if m==len(s)-1:
            cnt+=3
            break
    n=1
    cnt4=0
    while s[-n]==s[0]:
        cnt4+=1
        n+=1
        if n==len(s):
            cnt4+=1
            break
    if cnt3%2==1 and cnt4%2==1:
        flg=1

if flg==1:
    ans=cnt2*k+k-1
else:
    ans=cnt2*k
print(ans)

Submission status: Runtime Error

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

if s[0]==s[-1] and s[-1]!="A":
    count +=1
    re +=s[-1]
    s[-1]="A"

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

Submission status: Runtime Error

Solution code:
import math

S = input()
K = int(input())
#print(S)
cnt = 1
ans = 0
for i in range(1,len(S)):
    if S[i] == S[i-1]:
        cnt += 1
    else:
        ans += cnt //2 
        cnt = 1
ans += cnt //2 
#print("ans", ans)    
ans *= K
#print("ans*K",ans)
if S[0] == S[-1]:
    cntf = 1
    cnte = 1
    for i in range(1,len(S)):
        #print(S[i], S[i-1] )
        if S[i] == S[i-1]:
            cntf += 1
        else:
            break
    #print("---------------")
    for i in range(1,len(S)):
        #print(S[-i], S[-i+1] )
        if S[-i-1] == S[-i]:
            cnte += 1
        else:
            break
    #print(cnte, cntf)
    if cnte % 2 ==1 and cntf % 2 ==1:
        #print("bbbb")
        ans += (K-1)  

if cnte == len(S):
    ans = len(S) * K // 2
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
def main():
    input = sys.stdin.readline
    S = input().strip()
    K = input()

    len_S = len(S)
    char_S = []
    cnts_S = []
    char_S.append(S[0])
    cnt = 0
    for i in range(len_S - 1):
        if cnt == 0:
            if S[i] == S[i+1]:
                cnt += 1
                if i + 1 == len_S - 1:
                    cnts_S.append(cnt)
            else:
                char_S.append(S[i+1])
                cnts_S.append(cnt)
                cnt = 0
        elif cnt == 1:
            char_S.append(S[i+1])
            cnts_S.append(cnt)
            cnt = 0

    cnts_repeat = np.count_nonzero(cnts_S)

    ans = np.zeros(1, dtype="int64")
    ans[0] = cnts_repeat
    ans[0] *= np.int64(K)
    if S[-1] == S[0]:
        if cnts_S[-1] == 0:
            ans[0] += np.int64(K) - 1
        if cnts_S[0] == 1:
            ans[0] += np.int64(K) - 1
    print(ans[0])

if __name__ == '__main__':
    main()

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 = str(input())
k = input()
if s[0] != s[-1] or k==1:
    print(a(s) * k)
else:
    new_s = s * 2
    org_count = a(s)
    new_count = a(new_s)
    diff = 2 * org_count - new_count
    print(org_count * k - diff * (k - 1))

Submission status: Runtime Error

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

cnt = 0
tmp = 1
for i in range(1, len(S)):
    if S[i - 1] == S[i]:
       tmp += 1
    elif tmp >= 2:
        cnt += tmp // 2
        tmp = 1
    else:
        tmp = 1

if tmp >= 2:
    cnt += 1

tmp1 = cnt
if S[0] == S[-1]:
    if S[-2] != S[-1]:
        cnt += 1

print((cnt * (K - 1) + tmp1))

Submission status: Runtime Error

Solution code:
S = input()
K = int(input())
L = len(S)
a = S[0]
i = 0
C = []
while i < L-1:
    count = 1
    b,c = S[i],S[i+1]
    i+= 1
    while b == c:
        count += 1
        if i == L-1:
            C.append(count)
            break
        b,c = S[i],S[i+1]
        i += 1
    if i == L-1:
        break
    C.append(count)
if a != S[L-1]:
    num = 0
    for co in C:
        num += co//2
    print(int(num*K))
else:
    num1 = 0
    for co in C:
        num1 += co//2
    num2 = (C[len(C)-1]+1)//2
    for co in C[:len(C)-1]:
        num2 += co//2
    print(int(num1+num2*(K-1)))

Submission status: Runtime Error

Solution code:
def main():
    S = input()
    K = int(input())
    ans = 0

    if S[0] is S[-1]:
        length = len(S)
    else:
        length = len(S) - 1

    i = 0
    while i < length:
        if S[i] is S[i + 1]:
            ans += 1
            i += 1
        i += 1

    print(ans * K)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
l = len(s)
s = s * 3
dp = [0,0]
check = []
for i in range(3*l-1):
  if s[i+1] != s[i]:
    dp.append(dp[-1])
  else:
    dp.append(dp[-2]+1)
  if (i+2) % l == 0:
    check.append(dp[-1])
if k % 2 == 0:
  ans = check[1] + (k-2) // 2 * (check[2]-check[0])
else:
  ans = check[0] + (k-1) // 2 * (check[2]-check[0])
print(ans)

Submission status: Runtime Error

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

cnt,ans=0,0
for i in range(1,len(S)):
  if S[i-1]==S[i]:
    cnt+=1
  else:
    cnt+=1
    ans+=cnt//2
    cnt=0
ans+=cnt//2
if S[0]==S[-1] and S[-1]==S[-2]:
  print(ans*k+k)
else:
  print(ans*k)

Submission status: Runtime Error

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

l = len(S)
pair = []
current = S[0]
seq = 1
for i in range(1, l):
    if(i == l-1):
        if(S[i]==current):
            seq += 1
        if(seq != 1):
            pair.append(seq)
    elif(S[i] == current):
        seq += 1
    else:
        if(seq != 1):
            pair.append(seq)
        seq = 1
        current = S[i]

ans = 0
#print(pair)
if(S[0] != S[l-1]):
    for i in range(len(pair)):
        ans += K * (pair[i]//2)
else:
    if(len(pair) == 1):
        ans += ((pair[0]+1)//2)*(K-1) + (pair[0]//2)
    else:
        for i in range(len(pair)-1):
            ans += K * i
        ans += ((pair[i+1]+1)//2)*(K-1) + (pair[i+1]//2)

print(ans)

Submission status: Runtime Error

Solution code:
S = input()
K = int(input())
cnt = 0
for i in range(len(S)):
    if (S[i]==S[i+1])&(S[i]!=S[i-1]):
        cnt += K
print(cnt)

Submission status: Runtime Error

Solution code:
K = int(stdin.readline().rstrip())
ans_odd = 0
ans_even = 0
changed_odd = [False] * len(S)
changed_even = [False] * len(S)

if len(S) == 1:
    print(K // 2)
    exit()

for i in range(1, len(S)):
    if S[i] == S[i - 1] and not changed_odd[i - 1]:
        ans_odd += 1
        changed_odd[i] = True

if S[0] == S[len(S) - 1] and not changed_odd[len(S) - 1]:
    ans_odd += 1
    changed_even[0] = True

for i in range(1, len(S)):
    if S[i] == S[i - 1] and not changed_even[i - 1]:
        ans_even += 1
        changed_even[i] = True

if K % 2 == 0:
    print((ans_odd + ans_even) * (K // 2))
else:
    print((ans_odd + ans_even) * (K // 2) + ans_even)

Submission status: Runtime Error

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

l = len(S)
pair = []
current = S[0]
seq = 1
for i in range(1, l):
    if(i == l-1):
        if(S[i]==current):
            seq += 1
        if(seq != 1):
            pair.append(seq)
    elif(S[i] == current):
        seq += 1
    else:
        if(seq != 1):
            pair.append(seq)
        seq = 1
        current = S[i]

ans = 0
print(pair)
if(S[0] != S[l-1]):
    for i in range(len(pair)):
        ans += K * (pair[i]//2)
else:
    if(len(pair) == 1):
        ans += ((pair[0]+1)//2)*(K-1) + (pair[0]//2)
    else:
        for i in range(len(pair)-1):
            ans += K * i
        ans += ((pair[i+1]+1)//2)*(K-1) + (pair[i+1]//2)

print(ans)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
flag = False
dif = [[True], [False]]
ans = 0
for i in range(len(s) - 1):
    for j in range(2):
        if s[i] == s[i + 1]:
            if dif[j][-1]:
                dif[j].append(False)
            else:
                dif[j].append(True)
        else:
            dif[j].append(False)
if (not dif[1][-1]) and s[0] == s[1]:
    flag = True
if flag:
    print(dif[1].count(True)*(k//2)+dif[0].count(True)*(k-k//2))
else:
    print(dif[1].count(True)*k)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if len(s) <= j:
        break
    if s[j] == s[j - 1]:
        if j == 0:
            n += 1
            if len(s) == 2:
                k += 1
            elif s[j - 1] == s[j - 2]:
                n -= 1
            j += 1
        else:
            if len(s) > 2:
                m += 1
                j += 1
    j += 1
print(m * k + n * (k - 1))

Submission status: Runtime Error

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

prev = ""
count = 0
flag = 0
for i in s:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count += 1
        flag = 1
    prev = i

count2 = 0
if s[0] == s[-1] and s[-1] != s[-2]:
    count2 = 1
ret = count*k + count2*(k-1)

print(ret)

Submission status: Runtime Error

Solution code:
S = input()
K = int(input())
L = len(S)
a = S[0]
modi = 0
i = 0
C = []
while i < L-1:
    count = 1
    b,c = S[i],S[i+1]
    i+= 1
    while b == c:
        count += 1
        if i == L-1:
            C.append(count)
            break
        b,c = S[i],S[i+1]
        i += 1
    if i == L-1:
        break
    C.append(count)
if a != S[L-1]:
    num = 0
    for co in C:
        num += co//2
    print(int(num*K))
else:
    num1 = 0
    for co in C:
        num1 += co//2
    num2 = (C[len(C)-1]+1)//2
    for co in C[:len(C)-1]:
        num2 += co//2
        print(co,co//2)
    print(int(num1+num2*(K-1)))

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
flag = False
dif = [[True], [False]]
ans = 0
for i in range(len(s) - 1):
    for j in range(2):
        if s[i] == s[i + 1]:
            if dif[j][-1]:
                dif[j].append(False)
            else:
                dif[j].append(True)
        else:
            dif[j].append(False)
if (not dif[1][-1]) and s[0] == s[1]:
    flag = True
if flag:
    print(dif[1].count(True)*(k//2)+dif[0].count(True)*(k-k//2))

Submission status: Runtime Error

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


a = S[0]
c = 0
S2 = copy.deepcopy(S)
for i in range(1,len(S)):
    if S[i] == S[i-1]:
        S[i] = '1'
        c += 1
if S[0] == S[-1]:
    c3 = 0
    S3 = copy.deepcopy(S)
    for i in range(2,len(S)+1):
        if S3[i] == S3[i-1]:
            S3[i] = '1'
            c3 += 1
    print(c + c3*(K-1))
else:
    print(c*K)

Submission status: Runtime Error

Solution code:
 def hoge():
    input_values = input()
    input_values = [item.strip() for item in input_values.split(' ')]
    print(input_values)
    string = input_values[0]
    string = string + string[0] + '0'
    num = int(input_values[1])
    count = 0
    total_count = 0
    for i in range(len(string) - 1):
        if string[i] == string[i+1]:
            count += 1
        else:
            if count != 0:
                total_count += (count + 1) // 2
                count = 0
                
    return total_count * num
  
hoge()

Submission status: Runtime Error

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

ans = 0
i=0
while i<len(S)-1:
    renzoku=1
    x=i
    while S[x] == S[i+1]:
        i=i+1
        renzoku+=1
    if renzoku >1:
        ans+=renzoku//2
    i+=1
    
print(ans*K)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
def main():
    input = sys.stdin.readline
    S = input().strip()
    K = input()

    len_S = len(S)
    char_S = []
    cnts_S = []
    char_S.append(S[0])
    cnt = 0
    for i in range(len_S - 1):
        if cnt == 0:
            if S[i] == S[i+1]:
                cnt += 1
                if i + 1 == len_S - 1:
                    cnts_S.append(cnt)
            else:
                char_S.append(S[i+1])
                cnts_S.append(cnt)
                cnt = 0
        elif cnt == 1:
            char_S.append(S[i+1])
            cnts_S.append(cnt)
            cnt = 0

    cnts_repeat = np.count_nonzero(cnts_S)

    ans = np.zeros(1, dtype="int64")
    ans[0] = cnts_repeat
    ans[0] *= np.int64(K)
    if S[-1] == S[0]:
        if cnts_S[-1] == 0:
            ans[0] += K - 1
    print(ans[0])

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
l=list(input())
k=int(input())
n=len(s)
if n==1:
    if k%2==0:
        print(k//2)
    else:
        print((k-1)//2)
    exit()
al=[]
su=[]
f=1
for i in range(n-1):
    if l[i]!=l[i+1]:
        al.append(l[i])
        su.append(f)
        f=1
    else:
        f+=1
if l[-2]==l[-1]:
    al.append(l[-1])
    su.append(f)
else:
    al.append(l[-1])
    su.append(1)
    
if len(al)==1:
    j=su[0]*k
    if j%2==0:
        print(j//2)
    else:
        print((j-1)//2)
    exit()

if al[0]!=al[-1]:
    ans=0
    for i in su:
        if i%2==0:
            ans+=i//2
        else:
            ans+=(i-1)//2
    print(k*ans)
else:
    ans=0
    if su[0]%2==0:
        ans+=su[0]//2
    else:
        ans+=(su[0]-1)//2
    tmp=0
    for i in range(len(al)-2):
        if su[i+1]%2==0:
            tmp+=su[i+1]//2
        else:
            tmp+=(su[i+1]-1)//2
    ans+=tmp*k
    j=su[0]+su[-1]
    if j%2==0:
        ans+=(j//2)*(k-1)
    else:
        ans+=((j-1)//2)*(k-1)
    if su[-1]%2==0:
        ans+=su[-1]//2
    else:
        ans+=(su[-1]-1)//2
    print(ans)

Submission status: Runtime Error

Solution code:
def main():
    s = input()
    k = int(input())
    s = list(s*k)
    cnt = 0
    for i in range(0, len(s), 2):
        target = s[i:i+3]
        if (len(target) == 3):
            if (target[0] == target[1] == target[2]):
                cnt += 1
                s[i+1] = '0'
            if (target[0] != target[1] == target[2]):
                cnt += 1
                s[i+2] = '0'
            if (target[0] == target[1] != target[2]):
                cnt += 1
        else:
            if (len(target) == 2):
                if (target[0] == target[1]):
                    cnt += 1
    print(cnt, end='')


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
 def hoge():
    input_values = input()
    input_values = [item.strip() for item in input_values.split('\n')]
    string = input_values[0]
    string = string + string[0] + '0'
    num = int(input_values[1])
    count = 0
    total_count = 0
    for i in range(len(string) - 1):
        if string[i] == string[i+1]:
            count += 1
        else:
            if count != 0:
                total_count += (count + 1) // 2
                count = 0
                
    return total_count * num
  
hoge()

Submission status: Runtime Error

Solution code:
S = list(input())
K = int(input())
R = []
hoge = 1
for i in range(1,len(S)):
    if S[i] == S[i-1]:
        hoge += 1
    else:
        R.append(S)
        hoge = 1
R.append(hoge)
ans = 0
if len(R) == 1:
    print((R[0]*K)//2)
    exit()
if S[0] == S[-1]:
    ans += (K-1)*((R[0]+R[-1])//2) + R[0]//2 + R[-1]//2
    R[0],R[-1] = 0,0
for i in R:
    ans += (i//2)*K 
print(ans)

Submission status: Runtime Error

Solution code:
import sys
s=input()
k=int(input())
a,i=0,0
if len(s)==1:
    print(k//2)
    sys.exit()
if s[0]==s[-1]:
    s=s*k
    while True:
        if s[i]==s[i+1]:
            a+=1
            i+=1
        i+=1
        if i>=len(s)-1:
            print(a)
            sys.exit()
while True:
    if s[i]==s[i+1]:
        a+=1
        i+=1
    i+=1
    if i>=len(s)-1:
        break
print(a*k)

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 = str(input())
k = int(input())
if s[0] != s[-1] or k==1:
    print(a(s) * k)
else:
    new_s = s * 2
    org_count = a(s)
    new_count = a(new_s)
    diff = 2 * org_count - new_count
    print(org_count * k - diff * (k - 1))

Submission status: Runtime Error

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

l = len(S)

pair = []
current = S[0]
seq = 1
for i in range(1, l):
    if(i == l-1):
        if(S[i]==current):
            seq += 1
        if(seq != 1):
            pair.append(seq)
    elif(S[i] == current):
        seq += 1
    else:
        pair.append(seq)
        seq = 1
        current = S[i]

ans = 0
#print(pair)
if(S[0] != S[l-1]):
    for i in range(len(pair)):
        ans += K * (pair[i]//2)
else:
    if(len(pair) == 1):
        ans += ((pair[0]+1)//2)*(K-1) + (pair[0]//2)
    else:
        for i in range(len(pair)-1):
            ans += K * i
        ans += ((pair[i+1]+1)//2)*(K-1) + (pair[i+1]//2)

print(ans)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
n = len(s)
s1 = s[0]
cnt1 = 0
s2 = s[0]
cnt2 = 0
for i in range(1,n):
    if i%2 == 1:
        s1 += s[i]
        continue
    elif s[i-1] == s[i] or s[i] == s[i + 1]:
        s1 += '0'
        cnt1 += 1
    else:
        s1 += s[i]

for i in range(1,n):
    if i%2 == 0:
        s2 += s[i]
        continue
    elif s[i-1] == s[i] or (i < n-1 and s[i] == s[i + 1]):
        s2 += '0'
        cnt2 += 1
    else:
        s2 += s[i]
s1 += s1
s2 += s2
jdg = [True,True]
for i in range(1,2*n):
    if s1[i] == s1[i-1]:
        jdg[0] = False
    if s2[i] == s2[i-1]:
        jdg[1] = False
if jdg[0] and jdg[1]:
    print(min(cnt1,cnt2)*k)
elif jdg[0]:
    print(cnt1*k)
else:
    print(cnt2*k)

Submission status: Runtime Error

Solution code:
t=str(input())
k=int(input())
L = len(t)
tmp = t[0]
n = 0 #change
flag = 0
for i in range(1,L):
  if flag==1:
    flag=0
  elif t[i]==tmp:# and flag==0:
    n+=1
    flag=1  
  tmp=t[i]
ans=k*n

if t[0]==t[-1] and t[-2]!=t[-1]:
  ans+=k-1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

def main():
    s = list(input().rstrip())
    k = int(input())

    c = 0

    if s[0] == s[-1]:
        if s[0] == s[1]:
            s[0] = '2'
        else:
            s[-1] = '2'

        c += 1

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

    print(c*k)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

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

if len(S) == 1:
    print(K//2)
    sys.exit()
if len(S) == 2:
    if S[0] == S[1]:
        print(K)
    else:
        print('0')
    sys.exit()

olds = S[0]
l = 1
c = 0
first = 1
for i in range(1,len(S)):

    if olds == S[i]:
        l += 1
    else:
        if first:
            firstL = l
            first = 0
        c += l//2
        l = 1
    olds = S[i]
    
    if i == len(S)-1:
        lastL = l
        c += l//2

if S[0] == S[-1] and firstL%2 == 1 and lastL%2 == 1:
    print((c+1)*K-1)
else:
    print(c*K)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
def main():
    input = sys.stdin.readline
    S = input().strip()
    K = np.int64(input())
    
    len_S = len(S)
    char_S = []
    cnts_S = []
    char_S.append(S[0])
    cnt = 0
    for i in range(len_S - 1):
        if cnt == 0:
            if S[i] == S[i+1]:
                cnt += 1
                if i + 1 == len_S - 1:
                    cnts_S.append(cnt)
            else:
                char_S.append(S[i+1])
                cnts_S.append(cnt)
                cnt = 0
        elif cnt == 1:
            char_S.append(S[i+1])
            cnts_S.append(cnt)
            cnt = 0

    cnts_repeat = np.count_nonzero(cnts_S)

    ans = np.zeros(1, dtype="int64")
    ans[0] = cnts_repeat
    ans[0] *= K
    if S[-1] == S[0]:
        if cnts_S[-1] == 0:
            ans[0] += K - 1
    print(ans[0])
    #print(char_S)
    #print(cnts_S)
    #print(np.count_nonzero(cnts_S))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
s=input()
k=int(input())
a,i=0,0
if s[0]==s[-1]:
    s=s*k
    while True:
        if s[i]==s[i+1]:
            a+=1
            i+=1
        i+=1
        if i>=len(s)-1:
            print(a)
            sys.exit()
if len(s)==1:
    print(k//2)
    sys.exit()
while True:
    if s[i]==s[i+1]:
        a+=1
        i+=1
    i+=1
    if i>=len(s)-1:
        break
print(a*k)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=list(input())
k=int(input())
an1=0
an2=0
skip=0

for i in range(len(s)-1):
    if skip==1:
        skip=0
        continue
    
    if s[i]==s[i+1]:
        an1+=1
        skip=1

if s[0]==s[-1]:
    if s[0]!=s[-2]:
        an2=k-1

print(an1*k+an2)

Submission status: Runtime Error

Solution code:
 def hoge():
    string = input()
    string = string + string[0] + '0'
    num = int(input())
    count = 0
    total_count = 0
    for i in range(len(string) - 1):
        if string[i] == string[i+1]:
            count += 1
        else:
            if count != 0:
                total_count += (count + 1) // 2
                count = 0
                
    return total_count * num
 
hoge()

Submission status: Runtime Error

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

N = len(S)
first = S[0]
last = S[-1]
now = 1
ing = 0
a = []
cnt = 1
flag = 0
while now < N:
    if S[now] == S[now-1]:
        ing = 1
        cnt += 1
        now += 1
        continue
    else:
        if ing ==1:
            a.append(cnt)
            cnt = 1
            now +=1
            ing = 0
        else:
            now +=1
            cnt = 1
            ing = 0
if ing ==1:
    a.append(cnt)

output = 0
for j in range(len(a)):
    output += a[j]//2

if first==last:
    if S[0]==S[1]:
        if S[-1]==S[-2]:
            X =a[0]
            Y =a[-1]
        else:
            X = a[0]
            Y = 1
    else:
        if S[-1]==S[-2]:
            X = 1
            Y =a[-1]
        else:
            X = 1
            Y = 1

    if (X==1)and(Y==1):
        output += 1
        flag = 1
    elif X==1:
        if Y%2==1:
            output+=1
            flag = 1
    elif Y==1:
        if X%2==1:
            output+=1
            flag = 1
    else:
        if (X%2==1)and(Y%2==1):
            output += 1
            flag = 1

output = output * K - flag

print(output)

Submission status: Runtime Error

Solution code:
a = list(input())
b - int(input())
c = len(a)
print(c)

Submission status: Runtime Error

Solution code:
def d_c(s):
  count = 0
  x = ''
  for i in range(len(s)):
    if x == s[0]:
      count += 1
      x = ''
    else:
      x = s[0]
    s = s[1:]
  return count

s = input()
k = int(input())
if s[0]==s[-1]:
  print(d_c(s*k))
else:
  print(d_c(s)*k)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

count = 0

if len(s) == 1:
    print(int(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
S = list(input())
K = int(input())


a = S[0]
c = 0
S2 = copy.copy(S)
for i in range(1,len(S)):
    if S[i] == S[i-1]:
        S[i] = '1'
        c += 1
if S[0] == S[-1]:
    c3 = 0
    S3 = copy.copy(S)
    for i in range(2,len(S)+1):
        if S3[i] == S3[i-1]:
            S3[i] = '1'
            c3 += 1
    print(c + c3*(K-1))
else:
    print(c*K)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
def main():
    input = sys.stdin.readline
    S = input().strip()
    K = np.int64(input())
    
    len_S = len(S)
    char_S = []
    cnts_S = []
    char_S.append(S[0])
    cnt = 0
    for i in range(len_S - 1):
        if cnt == 0:
            if S[i] == S[i+1]:
                cnt += 1
                if i + 1 == len_S - 1:
                    cnts_S.append(cnt)
            else:
                char_S.append(S[i+1])
                cnts_S.append(cnt)
                cnt = 0
        elif cnt == 1:
            char_S.append(S[i+1])
            cnts_S.append(cnt)
            cnt = 0

    cnts_repeat = np.count_nonzero(cnts_S)

    ans = np.int64(cnts_repeat * K)
    if S[-1] == S[0]:
        if cnts_S[-1] == 0:
            ans = np.int64(ans + K - 1)
    print(ans)
    #print(char_S)
    #print(cnts_S)
    #print(np.count_nonzero(cnts_S))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
#AGC39 A

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
k = I()
n = len(s)
res = 0
i = 0
flg,flg2 = False,False
if s[i] == s[-1]:
    flg = True
while i < n:
    tmp = s[i]
    i += 1
    cnt = 1
    while i < n and tmp == s[i]:
        cnt += 1
        i += 1
    res += cnt//2
if s[-1] != s[-2]:
    flg2 = True 
print((res+(flg and flg2))*k)

Submission status: Runtime Error

Solution code:
S = input()
K = int(input())
cnt = 0
for i in range(len(S)-1):
    if (S[i]==S[i+1])&&(S[i-1]!=S[i]):
        cnt += K
print(cnt)

Submission status: Runtime Error

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

olds = S[0]
l = 1
c = 0
first = 1
for i in range(1,len(S)):

    if olds == S[i]:
        l += 1
    else:
        if first:
            firstL = l
            first = 0
        c += l//2
        l = 1
    olds = S[i]
    
    if i == len(S)-1:
        lastL = l
        c += l//2

if S[0] == S[-1] and firstL%2 == 1 and lastL%2 == 1:
    print((c+1)*K-1)
else:
    print(c*K)

Submission status: Runtime Error

Solution code:
from itertools import groupby

s = input()
k = int(input())
a = [sum(1 for _ in g) for _, g in groupby(s)]
if s[0] == s[-1]:
    a[0] += a.pop()
print(sum(x // 2 for x in a) * k)