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: Wrong Answer

Solution code:
S = input()
K = int(input())
SS = S[::-1]

count = 0
l = len(S)
check = True
ff = 1
while ff < l:
    if S[ff] == S[0]:
        ff += 1
    else:
        break
ll = 1
while ll < l:
    if SS[ll] == SS[0]:
        ll += 1
    else:
        break

if S[0] != SS[0]:
    ff = 0
    ll = 0

if ff == l:
    print(l//2 * K)
    exit()

i = ff

while i < l - ll - 1:
    if S[i] == S[i + 1]:
        count += 1
        i += 2
    else:
        i += 1

# print(count, ff, ll)

print(K * count + (K - 1) * ((ff + ll + 1) // 2))

Submission status: Wrong Answer

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

count = 0
l = len(S)
check = True
i = 0
while i < l:
    if i + 1 == l:
        if not check:
            if S[0] == S[-1]:
                count += 1
                print(count * K - K + 1)
                exit()
        break
    if S[i] == S[i + 1]:
        count += 1
        i += 2
        if i + 1 == l:
            check = False
    else:
        i += 1

#print(count)
print(count * K)

Submission status: Wrong Answer

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

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

#print(count)
if check:
    print(count * K)
else:
    print(count * K - K + 1)

Submission status: Wrong Answer

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

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

#print(count)
print(count * K)

Submission status: Wrong Answer

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

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

print(count)
print(count * K)

Submission status: Wrong Answer

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

tmp = S[0]
count = 1
S_num = list()
for i in range(1,len(S)):
	if S[i] == tmp:
		count += 1
	else:
		tmp = S[i]
		S_num.append(count)
		count = 1
S_num.append(count)

S_num = list(map(lambda x: x//2, S_num))

if len(S_num) == 1:
	print(len(S)*K//2)
else:
	if S[0] != S[-1]:
		print(sum(S_num)*K)
	else:
		a = S_num[0]
		b = S_num[-1]
		print(sum(S_num)*K - a//2 - b//2 + (a+b)//2)

Submission status: Wrong Answer

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: Wrong Answer

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

def one(S):
    c = 0
    r = 1
    pre = ""
    for s in S:
        if pre == s:
            r += 1
        else:
            c += r // 2
            r = 1
        pre = s
    c += r // 2
    return c

def two(S):
    c = 0
    r = 1
    pre = ""
    for s in S*2:
        if pre == s:
            r += 1
        else:
            c += r // 2
            r = 1
        pre = s
    c += r // 2
    return c

o = one(S)
t = two(S)

if len(S) == 1:
    print(K//2)
else:
    print(o*K + (t-o*2)*(K-1))

Submission status: Wrong Answer

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

def one(S):
    c = 0
    r = 1
    pre = ""
    for s in S:
        if pre == s:
            r += 1
        else:
            c += r // 2
            r = 1
        pre = s
    c += r // 2
    return c

def two(S):
    c = 0
    r = 1
    pre = ""
    for s in S*2:
        if pre == s:
            r += 1
        else:
            c += r // 2
            r = 1
        pre = s
    c += r // 2
    return c

o = one(S)
t = two(S)

print(o * K + (t-o*2)*(K-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
d=[]
w=""
cnt=0
for i in s:
    if w!=i:
        w=i
        if cnt:
            d.append(cnt)
        cnt=1
    else:
        cnt+=1
d.append(cnt)
t=len(d)
if t==1:
    print(d[0]*k//2)
else:
    ans=0
    for i in range(t):
        if i==0 and s[0]!=s[-1] and d[0]>1:
            ans+=d[0]//2*k
        elif i==0 and s[0]==s[-1] and d[0]>1:
            ans+=d[0]//2*k
        elif i==t-1 and s[0]==s[-1]:
            ans+=(d[0]+d[-1])//2*(k-1)
            ans+=d[-1]//2
        elif i==t-1 and s[0]!=s[-1]:
            ans+=d[-1]//2*k
        elif d[i]>1:
            ans+=d[i]//2*k
    print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
d=[]
w=""
cnt=0
for i in s:
    if w!=i:
        w=i
        if cnt:
            d.append(cnt)
        cnt=1
    else:
        cnt+=1
d.append(cnt)
t=len(d)
if t==1:
    print(d[0]*k//2)
else:
    ans=0
    for i in range(t):
        if i==0 and s[0]!=s[-1]:
            ans+=(d[0]*k)//2
        elif i==0 and s[0]==s[-1]:
            ans+=d[0]*k//2
        elif i==t-1 and s[0]==s[-1]:
            ans+=(d[0]+d[-1])*(k-1)//2
            ans+=d[-1]//2
        elif i==t-1 and s[0]!=s[-1]:
            ans+=d[-1]*k//2
        else:
            ans+=d[i]//2
    print(ans)

Submission status: Wrong Answer

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

li = []

count = 1
tmp = s[0]

if len(s) == 1:
    print(0)
    exit()

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: Wrong Answer

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

def A(S, K):
	if len(S) == 0: return 0
	if len(S) == 1: return K - 1

	i = 1
	count = 0
	change_end = False

	while i < len(S):
		if S[i] == S[i - 1]:
			count += 1
			if i == len(S) - 1:
				change_end = True
			i += 2

		else:
			i += 1

	if S[-1] == S[0] and not change_end:
		return K * count + (K - 1)
	return K * count

print(A(S, K))

Submission status: Wrong Answer

Solution code:
import sys
s = input()
k = int(input())
t = ''
i = 0
j = 0
count = [0]*len(s)
count1 = 0
start = 0
end = 0
countSum = 0

for i in range(len(s)-1):
	if s[i] == s[i+1]:
		count1 +=1
if count1 == len(s)-1:#すべて同じ場合
	print((len(s)*k//2))
	sys.exit()

for i in range(len(s)-1):#issiiissii
	if s[i] == s[i+1]:
		count[j] +=1
	elif s[i] != s[i+1] and count[0] != 0:
		j += 1
for i in range(j+1):
	countSum += -(-count[i]//2)


if s[0] != s[-1]:#先頭と末尾が異なる場合
	print(countSum*k)

elif s[0] == s[-1]:#先頭と末尾が同じ場合
	for i in range(len(s)):# start
		if s[0] == s[i]: 
			start += 1
		else:
			break
	if start == 1:# 1は消す
		start = 0

	for i in reversed(range(len(s))):#end 
		if s[-1] == s[i]:
			end += 1
		else:
			break
	if end == 1:#1は消す
		end = 0

	print (k*countSum-\
			((k-1)*(-(-start//2))+\
				(-(-end//2))-\
					(-(-start-end)//2)))

Submission status: Wrong Answer

Solution code:
import sys
s = input()
k = int(input())
t = ''
i = 0
j = 0
count = [0]*len(s)
count1 = 0
start = 0
end = 0
countSum = 0

for i in range(len(s)-1):
	if s[i] == s[i+1]:
		count1 +=1
if count1 == len(s)-1:#すべて同じ場合
	print((len(s)*k//2))
	sys.exit()

for i in range(len(s)-1):#issiiissii
	if s[i] == s[i+1]:
		count[j] +=1
	elif s[i] != s[i+1] and count[0] != 0:
		j += 1
for i in range(j+1):
	countSum += -(-count[i]//2)


if s[0] != s[-1]:#先頭と末尾が異なる場合
	print(countSum*k)

elif s[0] == s[-1]:#先頭と末尾が同じ場合
	for i in range(len(s)):# start
		if s[0] == s[i]: 
			start += 1
		else:
			break
	if start == 1:# 1は消す
		start = 0

	for i in reversed(range(len(s))):#end 
		if s[-1] == s[i]:
			end += 1
		else:
			break
	if end == 1:#1は消す
		end = 0

	print (k*countSum-\
			((k-1)*(-(-start//2))+\
				(-(end//2))-\
					(-(-start-end)//2)))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
t=s*10
str1=[]
for i in range(len(t)):
    str1.append(t[i])
ret=True
c=0
while ret:
    ret=False
    for i in range(len(str1)-1):
        if str1[i]==str1[i+1]:
            str1[i+1]='A'
            c+=1
            ret=True
print(int(c/10*k))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
t=s*2
str1=[]
for i in range(len(t)):
    str1.append(t[i])
ret=True
c=0
while ret:
    ret=False
    for i in range(len(str1)-1):
        if str1[i]==str1[i+1]:
            str1[i+1]='A'
            c+=1
            ret=True
print(int(c/2*k))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
t=s*10
str1=[]
for i in range(len(t)):
    str1.append(t[i])

ret=True
c=0
while ret:
    ret=False
    for i in range(len(str1)-1):
        if str1[i]==str1[i+1]:
            str1[i+1]='A'
            c+=1
            ret=True
print(int(c/10)*k)

Submission status: Wrong Answer

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


def count(s):
    n = 0
    while 1 < len(s):
        i = 1
        while i < len(s) and s[i] == s[0]:
            i += 1
        n += i // 2
        s = s[i:]
    return n


if K < 2:
    print(count(S * K))
else:
    a2 = count(S * 2)
    a3 = count(S * 3)
    print(a2 + (a3 - a2) * (K - 2))

Submission status: Wrong Answer

Solution code:
import sys
s = input()
k = int(input())
t = ''
i = 0
j = 0
count = [0]*len(s)
count1 = 0
start = 0
end = 0
countSum = 0

for i in range(len(s)-1):
	if s[i] == s[i+1]:
		count1 +=1
if count1 == len(s)-1:#すべて同じ場合
	print((len(s)*k//2))
	sys.exit()

for i in range(len(s)-1):#issiiissii
	if s[i] == s[i+1]:
		count[j] +=1
	elif s[i] != s[i+1] and count[0] != 0:
		j += 1
for i in range(j+1):
	countSum += -(-count[i]//2)


if s[0] != s[-1]:#先頭と末尾が異なる場合
	print(countSum*k)

elif s[0] == s[-1]:#先頭と末尾が同じ場合
	for i in range(len(s)):# start
		if s[0] == s[i]: 
			start += 1
		else:
			break
	if start == 1:# 1は消す
		start = 0

	for i in reversed(range(len(s))):#end 
		if s[-1] == s[i]:
			end += 1
		else:
			break
	if end == 1:#1は消す
		end = 0

	print (k*countSum-\
			((k-1)*(-(-start//2))+\
				(-(end//2))-\
					(-(-(start+end)//2))))

Submission status: Wrong Answer

Solution code:
import sys
s = input()
k = int(input())
t = ''
i = 0
j = 0
count = [0]*len(s)
count1 = 0
start = 0
end = 0
countSum = 0

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

if count1 == len(s)-1:#すべて同じ場合
	print((len(s)*k//2))
	sys.exit()
for i in range(len(s)-1):#issiiissii
	if s[i] == s[i+1]:
		count[j] +=1
	elif s[i] != s[i+1] and count[0] != 0:
		j += 1
for i in range(j+1):
	countSum += -(-count[i]//2)


if s[0] != s[-1]:#先頭と末尾が異なる場合
	print(countSum*k)

elif s[0] == s[-1]:#先頭と末尾が同じ場合
	for i in range(len(s)):# start
		if s[0] == s[i]: 
			start += 1
		else:
			break
	if start == 1:# 1は消す
		start = 0

	for i in reversed(range(len(s))):#end 
		if s[-1] == s[i]:
			end += 1
		else:
			break
	if end == 1:#1は消す
		end = 0

	print (k*countSum-\
			((k-1)*(start//2)+\
				(end//2)-\
					(start+end)//2))

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
t = ''
i = 0
j = 0
count = [0]*len(s)
start = 0
end = 0
countSum = 0

if count == len(s)-1:#すべて同じ場合
	print((len(s)*k//2))

for i in range(len(s)-1):#issiiissii
	if s[i] == s[i+1]:
		count[j] +=1
	elif s[i] != s[i+1] and count[0] != 0:
		j += 1

for i in range(j+1):
	countSum += -(-count[i]//2)


if s[0] != s[-1]:#先頭と末尾が異なる場合
	print(countSum*k)

elif s[0] == s[-1]:#先頭と末尾が同じ場合
	for i in range(len(s)):# start
		if s[0] == s[i]: 
			start += 1
		else:
			break
	if start == 1:# 1は消す
		start = 0

	for i in reversed(range(len(s))):#end 
		if s[-1] == s[i]:
			end += 1
		else:
			break
	if end == 1:#1は消す
		end = 0

	print (k*countSum-\
			((k-1)*(start//2)+\
				(end//2)-\
					(start+end)//2))

Submission status: Wrong Answer

Solution code:
import random

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

concatedString_list = list(S)


def check(string, index, times):
    if index == len(string) - 1:
        if string[0] == string[len(string) - 1]:
            print((times * K) + (K - 1))
        else:
            print(times * K)
        return string
    if string[index] != string[index + 1]:
        return check(string, index + 1, times)
    else:
        if index + 2 < len(string) - 1:
            string[index + 1] = chr(ord(string[index + 1]
                                        ) + random.randint(1, 10))
            while(string[index + 1] == string[index + 2]):
                string[index + 1] = chr(ord(string[index + 1]
                                            ) + random.randint(1, 10))
        else:
            string[index + 1] = chr(ord(string[index + 1]
                                        ) + random.randint(1, 10))
        return check(string, index + 1, times + 1)


check(concatedString_list, 0, 0)

Submission status: Wrong Answer

Solution code:
import random

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

concatedString_list = list(S)


def check(string, index, times):
    if index == len(string) - 1:
        if string[0] == string[len(string) - 1]:
            print((times * K) + (K - 1))
        else:
            print(times * K)
        return string
    if string[index] != string[index + 1]:
        return check(string, index + 1, times)
    else:
        if index + 2 < len(string) - 1:
            string[index + 1] = chr(ord(string[index + 1]
                                        ) + random.randint(1, 10))
            while(string[index + 1] == string[index + 2]):
                string[index + 1] = chr(ord(string[index + 1]
                                            ) + random.randint(1, 10))
        else:
            string[index + 1] = chr(ord(string[index + 1]
                                        ) + random.randint(1, 10))
        return check(string, index, times + 1)


check(concatedString_list, 0, 0)

Submission status: Wrong Answer

Solution code:
import random

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

concatedString_list = list(S)


def check(string, index, times):
    if index == len(string) - 1:
        if string[0] == string[len(string) - 1]:
            print(times * K + K - 1)
        else:
            print(times * K)
        return string
    if string[index] != string[index + 1]:
        return check(string, index + 1, times)
    else:
        if index + 2 < len(string) - 1:
            string[index + 1] = chr(ord(string[index + 1]
                                        ) + random.randint(1, 5))
            while(string[index + 1] == string[index + 2]):
                string[index + 1] = chr(ord(string[index + 1]
                                            ) + random.randint(1, 5))
        else:
            string[index + 1] = chr(ord(string[index + 1]
                                        ) + random.randint(1, 5))
        return check(string, index, times + 1)


check(concatedString_list, 0, 0)

Submission status: Wrong Answer

Solution code:
import random

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

if K % 2 == 0:
    S = S * 2
    K = int(K / 2)
if K % 3 == 0:
    S = S * 3
    K = int(K / 3)

concatedString_list = list(S)


def check(string, index, times):
    if index == len(string) - 1:
        print(times * K)
        return string
    if string[index] != string[index + 1]:
        return check(string, index + 1, times)
    else:
        if index + 2 < len(string) - 1:
            string[index + 1] = chr(ord(string[index + 1]
                                        ) + random.randint(1, 5))
            while(string[index + 1] == string[index + 2]):
                string[index + 1] = chr(ord(string[index + 1]
                                            ) + random.randint(1, 5))
        else:
            string[index + 1] = chr(ord(string[index + 1]
                                        ) + random.randint(1, 5))
        return check(string, index, times + 1)


check(concatedString_list, 0, 0)

Submission status: Wrong Answer

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

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
if len(X) == 1:
    print(K)
elif X[0][0] == X[-1][0]:
    s = X.pop(0)
    e = X.pop()
    for x in X:
        result += x[1] // 2
    result *= K
    result += s[1] // 2
    result += e[1] // 2
    x = (s[1] + e[1]) // 2
    result += x * (K - 1)
    print(result)
else:
    for x in X:
        result += x[1] // 2
    result *= K
    print(result)

Submission status: Wrong Answer

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

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
if len(X) == 1:
    print(K)
elif X[0][0] == X[-1][0]:
    s = X.pop(0)
    e = X.pop()
    for x in X:
        result += x[1] // 2
    result *= K
    if (s[1] + e[1]) % 2 == 1:
        result += ((s[1] + e[1]) // 2) * K
    else:
        result += ((s[1] + e[1]) // 2) * (K - 1)
    print(result)
else:
    for x in X:
        result += x[1] // 2
    result *= K
    print(result)

Submission status: Wrong Answer

Solution code:
import random

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


def check(string, index, times):
    if index == len(string) - 1:
        print(times * K)
        return string
    if string[index] != string[index + 1]:
        return check(string, index + 1, times)
    else:
        if index + 2 < len(string) - 1:
            string[index + 1] = chr(ord(string[index + 1]
                                        ) + random.randint(1, 5))
            while(string[index + 1] == string[index + 2]):
                string[index + 1] = chr(ord(string[index + 1]
                                            ) + random.randint(1, 5))
        else:
            string[index + 1] = chr(ord(string[index + 1]
                                        ) + random.randint(1, 5))
        return check(string, index, times + 1)


check(concatedString_list, 0, 0)

Submission status: Wrong Answer

Solution code:
import random

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


def check(string, index, times):
    if index == len(string) - 1:
        print(times * K)
        return string
    if string[index] != string[index + 1]:
        return check(string, index + 1, times)
    else:
        string[index + 1] = chr(ord(string[index + 1]) + random.randint(1, 5))
        return check(string, index, times + 1)


check(concatedString_list, 0, 0)

Submission status: Wrong Answer

Solution code:
import string
import random

ascii = string.ascii_lowercase
S = str(input())
K = int(input())
concatedString_list = list(S)


def check(string, index, times):
    if index == len(string) - 1:
        print(times * K)
        return string
    if string[index] != string[index + 1]:
        return check(string, index + 1, times)
    else:
        # swapChar = random.choice(ascii)
        # if swapChar == string[index + 1]:
        #     swapChar = random.choice(ascii)
        string[index + 1] = chr(ord(string[index + 1]) + random.randint(1, 5))
        return check(string, index, times + 1)


check(concatedString_list, 0, 0)

Submission status: Wrong Answer

Solution code:
import string
import random

ascii = string.ascii_lowercase
S = str(input())
K = int(input())
concatedString_list = list(S)


def check(string, index, times):
    if index == len(string) - 1:
        print(times * K)
        return string
    if string[index] != string[index + 1]:
        return check(string, index + 1, times)
    else:
        swapChar = random.choice(ascii)
        if swapChar == string[index + 1]:
            swapChar = random.choice(ascii)
        string[index + 1] = random.choice(ascii)
        return check(string, index, times + 1)


check(concatedString_list, 0, 0)

Submission status: Wrong Answer

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

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 len(X) != 1 and X[0][0] == X[-1][0] and (X[0][1] + X[-1][1]) % 2 == 0:
    result += (X[0][1] + X[-1][1]) // 2
print(result)

Submission status: Wrong Answer

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

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 len(X) != 1 and X[0][0] == X[-1][0] and (X[0][1] + X[-1][1]) % 2 == 0:
    result += 1
print(result)

Submission status: Wrong Answer

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

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: Wrong Answer

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

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

A = 0
result = 0
for x in X:
    result += x // 2

print(result * K)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
t4=s*4
str4=[]
c4=0
for i in range(0,len(t4)):
    str4.append(t4[i])
ret=True
while ret:
    ret=False
    for i in range(0,len(t4)-1):
        if str4[i]==str4[i+1]:
            str4[i+1]="A"
            c4+=1        
            ret=True
print(int(c4//4)*k)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
t3=s*3
t4=s*4
str3=[]
str4=[]
c3=0
c4=0
for i in range(0,len(t3)):
    str3.append(t3[i])
for i in range(0,len(t4)):
    str4.append(t4[i])
ret=True
while ret:
    ret=False
    for i in range(0,len(t3)-1):
        if str3[i]==str3[i+1]:
            str3[i+1]="A"
            c3+=1        
            ret=True
print(int(c3//3)*k)

Submission status: Wrong Answer

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

current_ch = start_ch = s[0]
end_ch = s[-1]

counter = 1
px = 0

for i in s[1:]:
    if i == current_ch:
        counter += 1
    else:
        current_ch = i
        px += round(counter/2.0)
        counter = 1

if current_ch == end_ch:
    px += round(counter/2.0)

print(px * n)

Submission status: Wrong Answer

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[0]+l[-1])//2
        ans=l2.pop(0)
        ans+=l2.pop(-1)
        ans+=sum(l2)*K
        ans+=ht*(K-1)
    else:
        ans=sum(l2)*K
print(int(ans))

Submission status: Wrong Answer

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[0]+l[-1])//2
        ans=l2.pop(0)
        ans+=l2.pop(-1)
        ans+=sum(l2)*K
        ans+=ht*(K-1)
    else:
        ans=sum(l2)*K
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
t = ''
i = 0
count = 0
start = 0
end = 0

for i in range(len(s)-1):
	if s[i] == s[i+1]:
		count +=1
	else:
		-(-count//2)*2

if count == len(s)-1:#すべて同じ場合
	print((len(s)*k//2))

elif s[0] != s[-1]:#先頭と末尾が異なる場合
	print(-(-count//2)*k)

elif s[0] == s[-1]:#先頭と末尾が同じ場合
	for i in range(len(s)):# start
		if s[0] == s[i]: 
			start += 1
		else:
			break
	if start == 1:# 1は消す
		start = 0

	for i in reversed(range(len(s))):#end 
		if s[-1] == s[i]:
			end += 1
		else:
			break
	if end == 1:#1は消す
		end = 0

	print (k*(-(-count//2))-\
			((k-1)*(start//2)+\
				(end//2)-\
					(start+end)//2))

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
if len(set(list(S))) == 1:
    print(int(len(S)*K/2))
    exit()
else:  
    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(int(c*K/2))

    else:
        i,h,t=0,0,0
        while S[0]==S[i]:i+=1;h+=1
        i=1
        while S[-1]==S[-i]:t+=1;i+=1
        
        print(int(c*K/2-(h/2+t/2-(h+t)/2)*(K-1)))

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
s=list(S*2)
c=0
if len(set(list(S))) == 1:
    print(int(len(S)*K/2))
else:
    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]:c+=1
    print(int(c*(K-1)/2))

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
if len(set(list(S))) == 1:
    print(int(len(S)*K/2))
    exit()
else:  
    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(int(c*K/2))

    else:
        i,h,t=0,1,0
        while S[i]==S[i+1]:
            h+=1
            i+=1
        i=0
        while S[-i]==S[-i-1]:
            t+=1
            i+=1
        print(int(((h+t)*(K-1))/2))

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
if len(set(list(S))) == 1:
    print(int(len(S)*K/2))
    exit()
else:  
    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(int(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(int((h+t)*(K-1)))

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
if len(set(list(S))) == 1:
    print(int(len(S)*K/2))
    exit()
else:  
    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: Wrong Answer

Solution code:
S=input()
K=int(input())
if len(set(list(S))) == 1:
    print(len(S)*K/2)
    exit()
else:  
    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: Wrong Answer

Solution code:
S=input()
K=int(input())
if len(set(list(S))) == 1:
    print(K/2)
    exit()
else:  
    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: Wrong Answer

Solution code:
S=input()
K=int(input())
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]:c+=1
print(int(c*K/2))

Submission status: Wrong Answer

Solution code:
l = list(input())+["A"]
order = []
ans = 1
for i in range(len(l)-1):
  if l[i] == l[i + 1]:
    ans += 1
  else:
    order.append(ans)
    ans = 1
if len(order) == 1:
  if order[0]//2*2 == order[0]:
    print(order[0]//2 * int(input()))
  else:
    repeat = int(input())
    print(order[0]//2 * repeat + repeat // 2)
else:
  repeat = order
  if l[0] == l[-1]:
    repeat[-1] = repeat[0] + repeat[-1]
  del repeat[0]
  order = sum([i//2 for i in order])
  repeat = sum([i//2 for i in repeat])
  print((int(input())-1)*repeat + order)

Submission status: Wrong Answer

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

check_str=[[k, len(list(g))] for k, g in itertools.groupby(s)]
c = 0
for i in range(len(check_str)):
	c += check_str[i][1]//2
if c == 0:
	if check_str[0] == check_str[-1]:
		print("%d" % (n-1))
	else:
		print(0)
else:
	print("%d" % (c*n))