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 = list(input())
S.append('end')
K = int(input())
length = []
tl = 1
x = 0
ans = 0
J = True
same = 1
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    same += 1
if same == len(S):
  J = False
if S[0] != S[len(S)-1] and J
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      tl += 1
    else:
      length.append(tl)
      tl = 1
  for i in range(len(length)):
    x += length[i]//2
  ans += x*K
  print(ans)
elif not J:
  ans = len(S)*K//2
  print(ans)
else:
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      tl += 1
    else:
      length.append(tl)
      tl = 1
  ans += ((length[0]+length[len(length)])*(K-1)//2) + length[0]//2 + length[length]//2
  length[0] = 0
  length[len(length)] = 0
  for i in range(len(length)):
    x += length[i]//2
  ans += x*K
  print(ans)

Submission status: Runtime Error

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

for i in range(1, n + 1):
  if s[i - 1] == s[i % n]:
    s[i] = "."
    c   += 1

print(c * k)

Submission status: Runtime Error

Solution code:
s=input()#与えれる文字列
n=int(input())#文字列sを繰り返す回数
l=len(s)
c=0
for i in range(l):
  if s[i-1] == s[i]:
    c+=1
    i+=1
if s[0]==s[-1]:
  if s[-1]==s[-2]:
    c-=1
    
print(int(c)*n)

Submission status: Runtime Error

Solution code:
S=list(input())
K=int(input())
#基本は文字列一単位内でひっくり返す×単位数ですが、文字列が一つの場合と文字列の両端が同じ場合を考慮してね。
P=0
if len(S)==1:
	P=K//2
else:
	for G in range(1,len(S):
		B=S[G-1]
		if S[G] in B:
			S[G]='O'
			P+=1
		else:
			continue
	P=P*K
	if S[0]==S[len(S)-1]:
		P+=K-1
print(P)
S=list(input())
K=int(input())
P=0
if len(S)==1:
	P=K//2
else:
	for G in range(1,len(S)):
		B=S[G-1]
		if S[G] in B:
			S[G]='O'
			P+=1
		else:
			continue
	P=P*K
	if S[0]==S[len(S)-1]:
		P+=K-1
print(P)

Submission status: Runtime Error

Solution code:
S=list(input())
K=int(input())
#基本は文字列一単位内でひっくり返す×単位数ですが、文字列が一つの場合と文字列の両端が同じ場合を考慮してね。
P=0
if len(S)==1:
	P=K//2
else:
	for G in range(1,len(S):
		B=S[G-1]
		if S[G] in B:
			S[G]='O'
			P+=1
		else:
			continue
	P=P*K
	if S[0]==S[len(S)-1]:
		P+=K-1
print(P)

Submission status: Runtime Error

Solution code:
import sys
S = input() 
K = int(input()) 
l = len(S)
ren = [0]*l
cnt = 0

for i in range(1,l):
  if S[i] == S[i-1]:
    cnt += 1
  elif S[i] != S[i-1]:
    ren[cnt] +=1
    cnt = 0
  if i == l-1:
    ren[cnt] +=1
    
ren = [K*i for i in ren]
   
if ren[l-1]:
  print((l*K)//2)
  sys.exit()

if S[0]==S[-1]:
  start = 0
  while S[start]==S[start+1]:
    start += 1
  end = 0
  while S[-1-end]==S[-2-end]:
    end += 1
  ren[start+end+1] += K-1
  ren[start] -= K-1
  ren[end] -= K-1


ans = 0

for i in range(1,l):
  if i%2 ==0:
    ans += (i//2)*ren[i]
  else:
    ans += ((i+1)//2)*ren[i]
      
print(ans)

Submission status: Runtime Error

Solution code:
li = list(input())
K = int(input())
li_s = li*K
a = 0
for j in range(len(li_s)-1):
  if li_s[j] == li_s[j+1]:
    li_s[j+1] = "1"
    a += 1
print(a)

Submission status: Runtime Error

Solution code:
li = list(input())
K = int(input())
li_s = li*K
a = 0
for j in range(len(li_s)-1):
  if li_s[j] == li_s[j+1]:
    li_s[j+1] = "pp"
    a += 1
print(a)

Submission status: Runtime Error

Solution code:
li = list(input())
K = int(input())
for i in range(K):
  li += li
a = 0
for j in range(len(li)-1):
  if li[j] = li[j+1]:
    li[j+1] = "pp"
    a += 1
print(a)

Submission status: Runtime Error

Solution code:
S = str(input())
K = int(input())
n = len(S)
s = [ ]
for i in range(n):
    s.append(S[i])
s.append(S[0])
t = 0
for i in range(n):
    if s[i] == s[i+1]:
        s[i+1] = A
        t = t + 1
if s[n] == s[0]:
    T = t*K
else:
    if K == 1
    T = (t*K) - 1
print(T)

Submission status: Runtime Error

Solution code:
S = str(input())
K = int(input())
s = [ ]
for i in range(K):
    s.append(S[i])
s.append(S[0])
t = 0
for i in range(K):
    if s[i] == s[i+1]:
        s[i+1] = s_i
        t = t + 1
if s[K] == s[0]:
    T = (t*K) - 1
else:
    T = t*K
print(T)

Submission status: Runtime Error

Solution code:
s =list(str(input()))
t = int(input())
s = s*t
n = 0
for i in range(1, len(s)):
    if s[i - 1] == s[i]:
        s[i] = 'ppp'
        n += 1
print(n)

Submission status: Runtime Error

Solution code:
s =list(str(input()))
t = int(input())
s = s*t
print(s)
n = 0
for i in range(1, len(s)):
    if s[i - 1] == s[i]:
        s[i] = 'ppp'
        n += 1
print(n)

Submission status: Runtime Error

Solution code:
#import math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x):#約数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x):#素因数分解配列
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    #x,y = map(int,input().split())           x=1,y=2
    #a = input().split()                      a=['1','2','3',...,'n']
    #a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    #li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    #複数行の「1 2 3 4」型の入力を一配列に
    #x = sorted([list(map(int, input().split())) for _ in range(n)])
    #ソート x.sort(key=lambda y:y[1])
    # print("Yes")  print("No")  x=[[0 for _ in range(n)] for _ in range(n)]
    s=list(input())
    k=int(input())
    index=cnt=key=0
    while index<len(s)-1:
        if s[index]==s[index+1]:
            cnt+=1
            index+=2
        else:
            index+=1
    if s[0]==s[len(s)-1]:
        if s[0]==s[1] or s[len(s)-2]==s[len(s)-1]:
            key=0
        else:
            key=1
    print(cnt*k+key*(k-1))



main()

Submission status: Runtime Error

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

ss = s + s

if len(set(s)==1):
    print(int((len(s)*k)/2))
else:
    a=0
    prev = "?"
    for v in s:
        if v==prev:
            a += 1
            prev = "?"
        else:
            prev = v

    b=0
    prev = "?"
    for v in ss:
        if v==prev:
            b += 1
            prev = "?"
        else:
            prev = v

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

Submission status: Runtime Error

Solution code:
s=list(input())
k=int(input())
A,B,C=0,0,0
test=s*3
for i in range(len(s)*3-1):
    if test[i]==test[i+1]:
        test[i+1]="A"
A=test[:len(s)].count("A")
B=test[len(s):len(s)*2].count("A")
C=test[len(s)*2:len(s)*3].count("A")

flag=0
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        flag=1
        break
if flag==0:print((s*k+1)//2)
if k==1:print(A)
elif k==2:print(A+B)
else:
    print(A+B*(k-2)+C)

Submission status: Runtime Error

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

#for i in range(K)
#	temp = temp

temp = S*K
count = 0;
flag = 0;
#ある文字が前文字と同一であった場合にカウントアップ

for i in range(len(temp)):
  if i >= 1:
    if (temp[i] == temp[i-1]) & (flag == 0):
      count += 1
      flag = 1
    else:
      flag = 0

#print(temp)
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S=input()
K=input()
continuing_sentence=0
for i,s in enumerate(S):
  if s==S[i+1]:
    continuing_sentence+=1
  if i==len(S)-2:
    break
if S[0]==S[-1]:
  continuing_sentence+=1*len(S)-1
print(continuing_sentence)

Submission status: Runtime Error

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

if len(set(S)) == 1:
    print((len(S) * K) // 2)
    sys.exit()

if S[-1] == S[0]:
    letter = S[0]
    i = 1
    left_count = 1
    while letter == S[i]:
        left_count += 1
        i += 1
    right_count = 1
    i = len(S) - 2
    while letter == S[i]:
        right_count += 1
        i -= 1

    if left_count % 2 == 1 and right_count % 2 == 1:
        ans = K - 1
    else:
        ans = 0

tmp_count = 1
tmp_ans = 0
for s in range(1, len(S)):
    tmp = S[s]
    if tmp == S[s - 1]:
        tmp_count += 1
        if s == len(S) - 1:
            tmp_ans += tmp_count // 2
    else:
        tmp_ans += tmp_count // 2
        tmp_count = 1
print(tmp_ans * K + ans)

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
z = int(input())
if n == len(set(s)):
  print(0)
else:
  if s[0] == s[-1]:
    elen = 2
    i = 0
    j = 0
    start=0
    end=0
    while i<n and s[i] == s[i+1]:
      i+=1
      j+=1
      elen+=1
    start=elen
    i = n-1
    while i>0 and s[i]==s[i-1]:
      i-=1
      elen+=1
    end=elen-start
    ans = 0
    j+=1
    while j<n and j<i:
      k=j+1
      while s[k] == s[j] and k<i:
        k+=1
      print(int(int(k-j)/2))
      ans += int(int(k-j)/2)
      j = k
    print(elen, ans)
    print(int(int(elen*(z-1)/2) + int(ans*z) + int(start/2) + int(end/2))

Submission status: Runtime Error

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

S = s*K
cnt = 0
flag = False

for i in range(len(S)-1):
    if flag:
        flag = False

    else:
        if S[i] == S[i+1]:
            cnt += 1
            flag = True

print(cnt)

Submission status: Runtime Error

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

S = S*K
cnt = 0
flag = False

for i in range(len(S)-1):
    if flag:
        flag = False

    else:
        if S[i] == S[i+1]:
            cnt += 1
            flag = True

print(cnt)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
s = s*k
s = list(s)
count = 0
for i in range(1,len(s)):
  if(s[i] == s[i-1]):
    count = count + 1;
    s[i] ='&';
    
print(count)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
s = s*k
count = 0
for i in range(1,len(s)):
  if(s[i] == s[i-1]):
    count = count + 1;
    s[i] ='&';
    
print(count)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
s = s*k
count = 0
for i in range(1,len(s)):
  if(s[i] == s[i-1]):
    count = count + 1;
  	s[i] ='&;
    
print(count)

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
s = s*k
count = 0
for i in range(1,len(s)):
  if(s[i] == s[i-1]):
    count = count + 1;
  	s[i] ='&;

Submission status: Runtime Error

Solution code:
import java.util.Scanner;

public class Main{
    public static void main(final String[] args){
        final Scanner scanner = new Scanner(System.in);
        final String line = scanner.nextLine();
        final long k = scanner.nextLong();
      
        if(all(line)){
            System.out.println(line.length()*k/2);
            return;
        }
      
        long cost = 0;
        for(int i = 0; i < line.length()-1; i++){
            if(line.charAt(i) != line.charAt(i+1)){
                continue;
            }
            cost++;
            i++;
        }
        cost *= k;
        if(line.charAt(0) == line.charAt(line.length()-1)){
            final char begin = line.charAt(0);
            int a;
            for(a = 1; a < line.length() && line.charAt(a) == begin; a++);
            int b;
            for(b = 1; b < line.length() && line.charAt(line.length() - 1- b) == end; b++);
            cost += (k-1)*((a+b)/2 - a/2 - b/2);
        }
        System.out.println(cost);
    }
    private static boolean all(final String string){
        final char c = string.charAt(0);
        for(int i = 1; i < string.length(); i++){
            if(string.charAt(i) != c){
                return fasle;
            }
        }
        return true;
    }
}

Submission status: Runtime Error

Solution code:

if __name__ == '__main__':

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

	leng = len(S)
	cnt = 0

	i = 0
	while i < leng - 1:
		if S[i] == S[i+1]:
			cnt += 1
			i += 2
		else:
			i += 1

	ans = K*cnt

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

	if S.count(S[0]) == leng and leng % 2 == 1:
		ans += 1

	print(ans)

Submission status: Runtime Error

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

count = 0
l = len(S)
check = True
i = 0
while i < l - 1:
    if S[i] == S[i + 1]:
        count += 1
        i += 2
        if i + 1 == l:
            check = False
    else:
        i += 1

ff = 1
while S[ff] == S[0] and ff < l:
    ff += 1
ll = 1
while S[-ll] == S[-1] and ll < l:
    ll += 1

if S[0] == S[-1]:
    if not check:
        print(count * K)
    else:
        print(count + (K - 1) * (ff + ll) // 2)
else:
    print(count * K)

Submission status: Runtime Error

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

count = 0
l = len(S)
check = True
i = 0
while i < l - 1:
    if S[i] == S[i + 1]:
        count += 1
        i += 2
        if i + 1 == l:
            check = False
    else:
        i += 1

ff = 1
while S[ff] == S[0]:
    ff += 1
ll = 1
while S[-ll] == S[-1]:
    ll += 1

if S[0] == S[-1]:
    if not check:
        print(count * K)
    else:
        print(count + (K - 1) * (ff + ll) // 2)
else:
    print(count * K)

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
t=s*2
c=0
for i in range(len(t)-1):
	if t[i]==t[i+1]:		
      c+=1
if c%2==1:
	r=((c+1)/2)*k-1
else:
	r=c/2*k
print(int(r))

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
ans = 0
space = 0
while (i < len(s)):
  if s[i] == s[i + 1]:
	ans += 1
    i += 2
  else:
    i += 1
if s[-1] == s[0]:
  space = 1
final_ans = (ans * k) + (space * (k - 1))
print(final_ans)

Submission status: Runtime Error

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

li = []

count = 1
tmp = s[0]

for i in range(1,len(s)):
    if s[i] == tmp:
        count += 1
    else:
        li.append((s[i-1],count))
        count = 1
    tmp = s[i]
if count != 1:
    li.append((s[-1],count))
    
if len(li) == 1:
    print(li[0][1] * k // 2)
elif li[0][0] == li[-1][0] and k >= 2:
    li2 = [(li[0][0],li[0][1]+li[-1][1])]
    for i in range(1,len(li)-1):
        li2.append(li[i])
    ans = 0
    for i in li2:
        ans += i[1] // 2
    ans *= k - 1
    for i in li:
        ans += i[1] // 2
    print(ans)
else:
    ans = 0
    for i in li:
        ans += i[1] // 2
    ans *= k
    print(ans)

Submission status: Runtime Error

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

T = S * K

Submission status: Runtime Error

Solution code:
s = input()
k = int(input())
cnt = 0
f = 0
for i in range(1,len(s)):
    if f == 1:
        f = 0
        continue
    elif s[i-1] == s[i]:
        cnt += 1
        f = 1
a = int(s[-2]==s[-1])
print(cnt*k-a)

Submission status: Runtime Error

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

print(S * K)

X = []
b = S[0]
cnt = 1
for i in range(1, len(S)):
    s = S[i]
    if b == s:
        cnt += 1
    else:
        X.append([b, cnt])
        cnt = 1
        b = s
X.append([b, cnt])

result = 0
for x in X:
    result += x[1] // 2

result = result * K
if X[0][0] == X[-1][0]:
    result += 1
print(result)

Submission status: Runtime Error

Solution code:
s = input()
l = ["Sunny", "Cloudy", "Rainy"]
print(l[(l.index(s) + 1) % 3])

Submission status: Runtime Error

Solution code:
x,y = map(int,input().split())
print(max(x+y,x-y,x*y))

Submission status: Runtime Error

Solution code:
S=list(input())
K=int(input())
l=[1]
for i in range(len(S)-1):
    if S[i]==S[i+1]:l[-1]+=1;
    else:l.append(1)
if len(l)==1:ans = len(S)*K/2;
else:
    l2=[i/2 for i in l]
    if S[0]==S[-1]:
        ht=l(l[0]+l[-1])//2
        ans=ls2.pop(0)
        ans+=l2.pop(-1)
        ans+=sum(l2)*K
        ans+=ht*(K-1)
    else:
        ans=sum(ls)*K
print(ans)

Submission status: Runtime Error

Solution code:
S=input()
K=int(input())
if len(set(S)) == 1:
    print(K/2)
    
s=list(S*2)
c=0
for i in range(len(s)-2):
    t=set(s[i:i+2])
    if len(t)==1:
        s[i+1]=""
        c+=1
if S[0]!=S[-1]:
    print(c*K)
else:
    i,h,t=0,0,0
    while S[i]==S[i+1]:
        h+=1
        i+=1
    i=0
    while S[-i]==S[-i-1]:
        t+=1
        i+=1
    print(c*K-(h/2+t/2-(h+t)/2)**(K-1))

Submission status: Runtime Error

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

count=0

for i in range(len(S)-2):
    if i>=1:  
      if  S[i]==S[i+1]:
        count+=K
if S[0]==S[len(S)-1]:
  count+=K-1
elif S[0]!=S[len(S)-1] and (S[0]==S[1] or S[len(S)-2]==S[len(S-1)]):
  count+=K
print(count)

Submission status: Runtime Error

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

count=0

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

Submission status: Runtime Error

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

count=0

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

Submission status: Runtime Error

Solution code:
from math import floor

word = input()
num = int(input())
length=len(word)

char_before= ''
sum=0
subsum =0
count= 0
stack=[]

for index in range(length):
    char_now=word[index]
    if index == 0 :
        char_before = char_now
        char_first=char_now
        count = 1
        continue
    
    if char_before == char_now :
        count = count + 1
    else:
        char_before = char_now
        stack.append(count)
        count = 1
    
    if index == length-1:
        char_last=char_now
        stack.append(count)
        
for i in stack:
    subsum= subsum + floor(i/2)
    
if (stack[0]%2)==1 and (stack[-1]%2)==1 and char_last==char_first and len(stack)>=2:
    sum =(subsum+1)*num -1
elif len(stack)==1:
    sum = floor(length*num/2)
else:
    sum =(subsum)*num

print(sum)

Submission status: Runtime Error

Solution code:
from math import floor

word = input()
num = int(input())
length=len(word)
charlist_size=num*length

string_generator=(word[i] for i in range(length))

char_before= ''
sum=0
subsum =0
count= 0
stack=[]

for index in range(length):
    char_now=next(string_generator)
    if index == 0 :
        char_before = char_now
        char_first=char_now
        count = 1
        continue
    
    if char_before == char_now :
        count = count + 1
    else:
        char_before = char_now
        stack.append(count)
        count = 1
    
    if index == length-1:
        char_last=char_now
        stack.append(count)
        
for i in stack:
    subsum= subsum + floor(i/2)
    
if (stack[0]%2)==1 and (stack[-1]%2)==1 and char_last==char_first and len(stack)>=2:
    sum =(subsum+1)*num -1
elif len(stack)==1:
    sum = floor(length*num/2)
else:
    sum =(subsum)*num

print(sum)

Submission status: Runtime Error

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

#s文字列／k繰り返し回数

i=0
c=0

s2=0
s1=0

x=1

while x<=k:
  s1=i+1
  s2=i+2
  if s1 > len(s)-1 and x!=k:
    s1-=len(s)
  if s2 > len(s)-1 and x!=k:
    s2-=len(s)
#  print(i,s1,s2)
  if s1<len(s) and s2<len(s) and s[i]==s[s1] and s[i]==s[s2]:
    c+=1
    i+=3
#    print("3")
    if i > len(s)-1:
      i=i-len(s)
      x+=1
    continue
  if s1<len(s) and s[i]==s[s1]:
    c+=1
    i+=2
#    print("2")
    if i > len(s)-1:
      i=i-len(s)
      x+=1
    continue
  i+=1
  if i > len(s)-1:
    i=i-len(s)
    x+=1
print(c)

Submission status: Runtime Error

Solution code:
from math import floor

word = input()
num = int(input())
length=len(word)
charlist_size=num*length

string_generator=(word[i] for i in range(length))

char_before= ''
sum=0
subsum =0
count= 0
stack=[]

for index in range(length):
    char_now=next(string_generator)
    if index == 0 :
        char_before = char_now
        char_first=char_now
        count = 1
        continue
    
    if char_before == char_now :
        count = count + 1
    else:
        char_before = char_now
        stack.append(count)
        count = 1
    
    if index == length-1:
        char_last=char_now
        stack.append(count)
        
for i in stack:
    subsum= subsum + floor(i/2)
    
if (stack[0]%2)==1 and (stack[-1]%2)==1 and char_last==char_first:
    sum =(subsum+1)*num -1
else:
    sum =(subsum)*num

print(sum)

Submission status: Runtime Error

Solution code:
from math import floor

word = input()
num = int(input())
string = word*num
charlist_size=num*len(word)


char_before= ''
sum=0
count= 0

for index in range(charlist_size):
    if index == 0 :
        char_before = string[index]
        count = 1
        continue
    
    if char_before == string[index] :
        count = count + 1
    else:
        char_before = string[index]
        sum = sum+ floor(count/2)
        count = 1
    
    if index == charlist_size-1:
        sum = sum+ floor(count/2)
    
print(sum)

Submission status: Runtime Error

Solution code:
import sys
string = input()
K = int(input())

if len(set(string)) == 1:
    print((K * len(string)) // 2)
    sys.exit()


f = string[0]
l = string[-1]
if f == l:
    first = 1
    for i in range(1, len(string)):
        if string[i] == f:
            first += 1
        else:
            break
    last = 1
    for i in range(len(string) - 2, 0, -1):
        if string[i] == l:
            last += 1
        else:
            break
ans = 0
final = 0
if (first + last) % 2 == 0 and first % 2 and last % 2:
    final = K - 1

string = string + '_'

count = 1
for n in range(1, len(string)):
    if string[n - 1] == string[n]:
        count += 1
    elif string[n - 1] != string[n] or n == len(string) - 1:
        if count >= 2:
            ans += (count // 2)
            #print(f'n: {n}')
            #print(count)
            #print(ans)
        count = 1
print(ans * K + final)

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
ls=len(s)
t=""
for i in range(1):
    t+=s[0:ls]

lt=0
ex=0
if ls ==1:
    if k%2==0:
        ex=k//2
    else:
        k-=1
        ex=k//2
elif ls==2:
    if s[0]==s[1]:
        ex=k
    else:
        ex=0
else:
        
    for i in range(ls*1):
        try:
            t[lt+1]
        except IndexError:
            lt+=1
        else:
            if t[lt]==t[lt+1]:
                ex+=1
                try:
                    t[lt+2]
                except IndexError:
                    lt+=1
                else:
                    if t[lt+1]==t[lt+2]:
                        
                        lt+=2
                    else:
                        
                        lt+=1
            else:
                lt+=1
if s[0]==s[ls-1]:
    left=0
    for i in range(ls):
        if s[i]!=s[i+1]:
            break
        else:
            left+=1
    right =0
    for i in range(ls-1,-1,-1):
        if s[i]!=s[i-1]:
            break
        else:
            right+=1
    if left%2!=0 or right%2!=0:
        ex*=k
    else:
        ex+=1
        ex*=k
        ex-=1
else:
    ex*=k
print(ex)

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
ls=len(s)
t=""
for i in range(1):
    t+=s[0:ls]

lt=0
ex=0
if ls ==1:
    if k%2==0:
        ex=k//2
    else:
        k-=1
        ex=k//2
elif ls==2:
    if s[0]==s[1]:
        ex=k
    else:
        ex=0
else:
        
    for i in range(ls*1):
        try:
            t[lt+1]
        except IndexError:
            lt+=1
        else:
            if t[lt]==t[lt+1]:
                ex+=1
                try:
                    t[lt+2]
                except IndexError:
                    lt+=1
                else:
                    if t[lt+1]==t[lt+2]:
                        
                        lt+=2
                    else:
                        
                        lt+=1
            else:
                lt+=1
    if s[0]==s[ls-1]:
        left=0
        for i in range(ls):
            if s[i]!=s[i+1]:
                break
            else:
                left+=1
        right =0
        for i in range(ls-1,-1,-1):
            if s[i]!=s[i-1]:
                break
            else:
                right+=1
        if left%2!=0 and right%2!=0:
            print("gu gu")
            ex*=k
        else:
            print("3")
            ex+=1
            ex*=k
            ex-=1
print(ex)

Submission status: Runtime Error

Solution code:
s=input()
k=int(input())
ls=len(s)
t=""
for i in range(1):
    t+=s[0:ls]

lt=0
ex=0
for i in range(ls*1):
    try:
        t[lt+1]
    except IndexError:
        lt+=1
    else:
        if t[lt]==t[lt+1]:
            ex+=1
            try:
                t[lt+2]
            except IndexError:
                lt+=1
            else:
                if t[lt+1]==t[lt+2]:
                    
                    lt+=2
                else:
                    
                    lt+=1
        else:
            lt+=1
if s[0]==s[ls-1]:

    if s[0]==s[1]or s[ls-1]==s[ls-2]:
        ex*=k
    else:
        ex+=1
        ex*=k
        ex-=1

else:
    ex*=k
print(ex)

Submission status: Runtime Error

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

c = [0] * len(s)
for i in range(len(s)):
    if i == len(s) - 1:
        if k == 1:
            continue
        if s[i] == s[0]:
            c[i] = 1
    elif s[i] == s[i+1]:
        c[i] = 1

# print(c)
ans = 0
f = 0
for i in range(len(s)):
    if c[i] == 1 and f == 0:
        ans += 1
        f = 1
    elif f == 1:
        f = 0

if c[-1] + c[-2] == 1 and k > 2 :
    print(ans*k-1)
else:
    print(ans*k)

Submission status: Runtime Error

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

c = [0] * len(s)
for i in range(len(s)):
    if i == len(s) - 1:
        if k == 1:
            continue
        if s[i] == s[0]:
            c[i] = 1
    elif s[i] == s[i+1]:
        c[i] = 1

print(c)
ans = 0
f = 0
for i in range(len(s)):
    if c[i] == 1 and f == 0:
        ans += 1
        f = 1
    elif f == 1:
        f = 0

if c[-1] + c[-2] == 1:
    print(ans*k-1)
else:
    print(ans*k)

Submission status: Runtime Error

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

c = [0] * len(s)
for i in range(len(s)):
    if i == len(s) - 1:
        if k == 1:
            continue
        if s[i] == s[0]:
            c[i] = 1
    elif s[i] == s[i+1]:
        c[i] = 1

print(c)
ans = 0
f = 0
for i in range(len(s)):
    if c[i] == 1 and f == 0:
        ans += 1
        f = 1
    elif f == 1:
        f = 0

if c[-1] + c[-2] = 1:
    print(ans*k-1)
else:
    print(ans*k)

Submission status: Runtime Error

Solution code:

def func():
    if len(S) == 1:
        return int(K/2)
    
    cnt = 1
    pre_s = S[0]
    tup_list = []
    for s in S[1:]:
        if pre_s == s:
            cnt += 1
        else:
            tup_list.append([pre_s, cnt])
            cnt = 1
        pre_s = s
    else:
        tup_list.append([pre_s, cnt])

    if len(tup_list) == 1:
        return int(cnt* K/2)
    
    if tup_list[0][0] == tup_list[-1][0]:
        pre_tup = tup_list.pop()[1]
        tup_list[0][1] += pre_tup
    res = -1 if pre_tup % 2 == 1 else 0
    for _,cnt in tup_list:
        res += int(cnt/2) * K
    return max(0,res) 

S = input()
K = int(input())
print(func())

Submission status: Runtime Error

Solution code:
s = list(input())
k = int(input())
S = s
cnt = 0
cnt_2 = 0
flow = 0
flow_2 = 0


for i in range(len(s)):
    if s[flow] == s[flow+1]:
        cnt += 1
        flow += 2
    else:
        flow += 1

    if flow >= len(s):
        break
# --------------------------

for i in range(len(s)):
    S.append(s[i])

for i in range(len(S)):
    if S[flow_2] == S[flow_2+1]:
        cnt_2 += 1
        flow_2 += 2
    else:
        flow_2 += 1

    if flow_2 >= len(S):
        break

if k == 1:
    print(cnt)
else:
    print(cnt + (cnt_2 - cnt) * (k-1))

Submission status: Runtime Error

Solution code:
s = list(input())
k = int(input())
S = s
cnt = 0
cnt_2 = 0
flow = 0
flow_2 = 0


for i in range(len(s)):
    if s[flow] == s[flow+1]:
        cnt += 1
        flow += 2
    else:
        flow += 1

    if flow >= len(s)-2:
        break
# --------------------------

for i in range(len(s)):
    S.append(s[i])

for i in range(len(S)):
    if S[flow_2] == S[flow_2+1]:
        cnt_2 += 1
        flow_2 += 2
    else:
        flow_2 += 1

    if flow_2 >= len(S)-2:
        break

if k == 1:
    print(cnt)
else:
    print(cnt + (cnt_2 - cnt) * (k-1))

Submission status: Runtime Error

Solution code:
s = list(input())
k = int(input())
S = s
cnt = 0
cnt_2 = 0
flow = 0
flow_2 = 0


for i in range(len(s)):
    if s[flow] == s[flow+1]:
        cnt += 1
        flow += 2
    else:
        flow += 1

    if flow >= len(s)-1:
        break
# --------------------------

for i in range(len(s)):
    S.append(s[i])

for i in range(len(S)):
    if S[flow_2] == S[flow_2+1]:
        cnt_2 += 1
        flow_2 += 2
    else:
        flow_2 += 1

    if flow_2 >= len(S)-1:
        break

if k == 1:
    print(cnt)
else:
    print(cnt + (cnt_2 - cnt) * (k-1))

Submission status: Runtime Error

Solution code:


def connect(s,k):
    
    s=s*k
    leng = len(s)
    if leng==1:
        return k//2
    if leng==2:
        if s[0] != s[1]:
            return 0
        else:
            return k
    start=s[0]
    temp=0
    counts=0
    lhs_count = 0
    for i in range(0,leng):
        if s[i]!=start:
            if start==s[0]:
                lhs_count =counts
            start=s[i]
            temp += counts//2
            counts=0   
            
        counts+=1
        
    start=s[i]
    temp += counts//2
    
    if s[0]==s[-1] and counts%2==1:
        temp+=1
    return temp


s=input()
k=int(input())
print(connect(s,k))

Submission status: Runtime Error

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

a = 1
data = []
for i in range(n-1):
    if s[i] == s[i+1]:
        a += 1
    else:
        data.append(a)
        a = 1
data.append(a)

ans = 0

if s[0] != s[-1]:
    for d in data:
        ans += d//2
    ans *= k
elif len(data) == 1:
    ans = n*k//2
else:
    for i in range(1,n-1):
        ans += data[i]//2
    ans *= k
    ans += data[0]//2 + data[-1]//2 + (data[0] + data[-1])//2 * (k-1)

print(ans)