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:
import sys
sys.stdin.readline

S = [a for a in input()]
Y = [1 for i in range(len(S))]
K = int(input())
length = len(S) * K
count = 0
sum = 0

if S[0] == S[len(S)-1]:
    for i in range(1, len(S)):
        if S[i] == S[i-1]:
            count += 1
        else:
            Y[i-1] += count
            count = 0
    if count != 0:
        Y[len(S)-1] += count
    start = Y[0]
    fin = Y[len(S)-1]
    for i in range(len(Y)):
        sum += Y[i] // 2
    print(sum*K+ (-int((start + fin)/2) + int(start / 2) + int(fin / 2))*(K-1))
else:
    for i in range(1, len(S)):
        if S[i] == S[i-1]:
            count += 1
        else:
            Y[i-1] += count
            count = 0
    if count != 0:
        Y[len(S)-1] += count
    for i in range(len(Y)):
        sum += Y[i] // 2
    print(sum * K)

Submission status: Wrong Answer

Solution code:
import sys
sys.stdin.readline

S = [a for a in input()]
Y = [1 for i in range(len(S))]
K = int(input())
length = len(S) * K
count = 0
sum = 0

if S[0] == S[len(S)-1]:
    for i in range(1, len(S)):
        if S[i] == S[i-1]:
            count += 1
        else:
            Y[i-1] += count
            count = 0
    if count != 0:
        Y[len(S)-1] += count
    start = Y[0]
    fin = Y[len(S)-1]
    for i in range(len(Y)):
        sum += Y[i] // 2
    print(sum*K+ ((start + fin)//2 - start // 2 - fin // 2)*(K-1))
else:
    for i in range(1, len(S)):
        if S[i] == S[i-1]:
            count += 1
        else:
            Y[i-1] += count
            count = 0
    if count != 0:
        Y[len(S)-1] += count
    for i in range(len(Y)):
        sum += Y[i] // 2
    print(sum * K)

Submission status: Wrong Answer

Solution code:
import sys
sys.stdin.readline

S = [a for a in input()]
Y = [1 for i in range(len(S))]
K = int(input())
length = len(S) * K
count = 0
sum = 0

if S[0] == S[len(S)-1]:
    for i in range(1, len(S)):
        if S[i] == S[i-1]:
            count += 1
        else:
            Y[i-1] += count
            count = 0
    if count != 0:
        Y[len(S)-1] += count
    start = Y[0]
    fin = Y[len(S)-1]
    for i in range(len(Y)):
        sum += Y[i] // 2 + ((start + fin)//2 - start // 2 - fin // 2)
else:
    for i in range(1, len(S)):
        if S[i] == S[i-1]:
            count += 1
        else:
            Y[i-1] += count
            count = 0
    if count != 0:
        Y[len(S)-1] += count
    for i in range(len(Y)):
        sum += Y[i] // 2


print(sum * K)


'''
#Memory Error
Z = S*K


Y = [0 for i in range(length)]


for i in range(1, length):
    if Z[i] == Z[i-1]:
        Y[i] = Y[i-1] + 1
        Z[i] = Y[i]
    else:
        Y[i] = Y[i-1]


print(Y[length-1])
'''

Submission status: Wrong Answer

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

ans = 0
lens = len(s)
# n -> n//2

def tansaku(moji, n, m, k):
	# n以上 m未満を探索する.
	ans = 0
	cnt = 1
	for i in range(n, m-1):
		if moji[i] == moji[i + 1]:
			cnt += 1
		else:
			ans += (cnt // 2) * k
			cnt = 1
	ans += (cnt // 2) * k
	return ans

if lens >= 2:
	if k >= 2:
		zencnts = 0
		atocnts = 0
		if s[lens-1] == s[0]:
			for i in range(lens):
				if s[lens-1-i] == s[lens-1]:
					zencnts += 1
				else:
					break
			for i in range(lens):
				if s[i] == s[0]:
					atocnts += 1
				else:
					break
		news = s[atocnts:] + s[:atocnts]
		news1 = s[atocnts:]
		news2 = s[:atocnts]
		ans += tansaku(news, 0, lens, k-1)
		ans += tansaku(news1, 0, lens-atocnts, 1)
		ans += tansaku(news2, 0, atocnts, 1)
		print(ans)
	else:
		ans += tansaku(s, 0, lens, 1)
		print(ans)
else:
	print(k//2)

Submission status: Wrong Answer

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

ans = 0
lens = len(s)
# n -> n//2

zencnts = 0 #繰り返し含む
atocnts = 0
if lens >= 2:
	if s[lens-1] == s[0]:
		for i in range(lens):
			if s[lens-1-i] == s[lens-1]:
				zencnts += 1
			else:
				break
		for i in range(lens):
			if s[i] == s[0]:
				atocnts += 1
			else:
				break

	news = s[atocnts:] + s[:atocnts]

	cnt = 1

	for i in range(lens-1):
		if news[i] == news[i+1]:
			cnt += 1
		else:
			ans += (cnt // 2) * k
			cnt = 1

	ans += (cnt // 2) * k

	print(ans)
else:
	print(k//2)

Submission status: Wrong Answer

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

ans = 0
lens = len(s)
# n -> n//2

zencnts = 0 #繰り返し含む
atocnts = 0

if s[lens-1] == s[0]:
	for i in range(lens):
		if s[lens-1-i] == s[lens-1]:
			zencnts += 1
		else:
			break
	for i in range(lens):
		if s[i] == s[0]:
			atocnts += 1
		else:
			break

news = s[atocnts:] + s[:atocnts]

cnt = 1

for i in range(lens-1):
	if news[i] == news[i+1]:
		cnt += 1
	else:
		ans += (cnt // 2) * k
		cnt = 1

ans += (cnt // 2) * k

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
S=input()
K=int(input())
S_double = S*2
n = 0
if len(set(list(S)))==1:
    print(len(S)*K//2)
    exit()
while n< len(S_double)-1:
    if S_double[n] ==S_double[n+1]:
        S_double = S_double[:n+2]+' '+S_double[n+3:]
    n += 1
ans = Counter(S_double[:len(S)])[' '] + Counter(S_double[len(S):])[' ']*(K-1)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
S=input()
K=int(input())
S_double = S*2
n = 0
while n< len(S_double)-1:
    if S_double[n] ==S_double[n+1]:
        S_double = S_double[:n+1]+' '+S_double[n+2:]
    n += 1
ans = Counter(S_double[:len(S)])[' '] + Counter(S_double[len(S):])[' ']*(K-1)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
ss = set(s)
# print(ss)
ans = 0
if n == 1:
    print(n//2)
    exit()
if len(ss) == 1:
    print(k*n//2)
    exit()
streaks = []
cnt = 0
now = s[0]
for i in range(n):
    if now == s[i]:
        cnt += 1
    else:
        streaks.append(cnt)
        now = s[i]
        cnt = 1
streaks.append(cnt)
# print(streaks)
m = len(streaks)
if s[0] == s[-1]:
    for i in range(1, m-1):
        ans += streaks[i]//2
    # print(ans)
    ans *= k
    # print(ans)
    ans += (streaks[0] + streaks[m-1])//2*(k-1)
    # print(ans)
    ans += streaks[0]//2 + streaks[m-1]//2
    # print(ans)
else:
    for i in range(m):
        ans += streaks[i]//2
    ans *= k

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
ss = set(s)
# print(ss)
ans = 0
if n == 1:
    print(n//2)
    exit()
if len(ss) == 1:
    print(k*n//2)
    exit()
streaks = []
cnt = 0
now = s[0]
for i in range(n):
    if now == s[i]:
        cnt += 1
    else:
        streaks.append(cnt)
        now = s[i]
        cnt = 1
streaks.append(cnt)
print(streaks)
m = len(streaks)
if s[0] == s[-1]:
    for i in range(1, m-1):
        ans += streaks[i]//2
    # print(ans)
    ans *= k
    # print(ans)
    ans += (streaks[0] + streaks[m-1])//2*(k-1)
    # print(ans)
    ans += streaks[0]//2 + streaks[m-1]//2
    # print(ans)
else:
    for i in range(m):
        ans += streaks[i]//2
    ans *= k

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
l=len(s)
s+='?'
ch = 1
ans=0
j=0

for i in range(l):
    if s[i]==s[i+1]:
        ch+=1
    else:
        ans+=ch//2
        if j==0:
            st=ch
        if s[i+1]=='?':
            gl=ch
        ch=1
        j=1
ans*=k
if st%2==1 and gl%2==1 and s[0]==s[l-1]:
    ans+=k-1

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
s = input()
k = int(input())
l=len(s)
s+=s
s+='?'
ch = 1
ans=0
for i in range(l*2):
    if s[i]==s[i+1]:
        ch+=1
    else:
        ans+=ch//2
        ch=1
ans=ceil(ans/2*k)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
l=len(s)
s+=s
s+='?'
ch = 1
ans=0
for i in range(l*2):
    if s[i]==s[i+1]:
        ch+=1
    else:
        ans+=ch//2
        ch=1
ans=ans//2*k
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
l=len(s)
s+=s[0]
s+='?'
ch = 1
ans=0
for i in range(l+1):
    if s[i]==s[i+1]:
        ch+=1
    else:
        ans+=ch//2
        ch=1
ans*=k
print(ans)

Submission status: Wrong Answer

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

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

if len(S)%2 == 0:
    ans = 0
    tmp = ""
    for s in S:
        if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
    if S[0] == tmp:
        ans += 1
    ans *= K
    print(ans)
    exit()
else:
    ans1 = 0
    tmp = ""
    for s in S:
        if s == tmp:
            ans1 += 1
            tmp = ""
            continue
        else:
            tmp = s
    S = S*2
    ans2 = 0
    tmp = ""
    for s in S:
        if s == tmp:
            ans2 += 1
            tmp = ""
            continue
        else:
            tmp = s
    if S[0] == tmp:
        ans += 1
    d,m = divmod(K,2)
    ans = ans2*d + ans1*m
    print(ans)
    exit()

Submission status: Wrong Answer

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

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

ans = 0
tmp = ""
for s in S:
    if s == tmp:
        ans += 1
        tmp = ""
        continue
    else:
        tmp = s

if S[0] == tmp:
    ans += 1

ans *= K

print(ans)

Submission status: Wrong Answer

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

ans = 0
tmp = ""
for s in S:
    if s == tmp:
        ans += 1
        tmp = ""
        continue
    else:
        tmp = s

if S[0] == tmp:
    ans += 1

ans *= K

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
ans = []
now = s[0]
cou = 0
if len(s) == 1:
    print(k//2)
    exit()

for i in range(len(s)):
    if now == s[i]:
        cou += 1
    elif now != s[i]:
        ans.append(cou)
        cou = 1
        now = s[i]
if cou > 0:
    ans.append(cou)
    
p = 0
for i in ans:
    p += (i//2)*k

if s[0] == s[-1]:
    p -= (ans[0]//2 + ans[-1]//2)*(k-1)
    p += ((ans[0]+ans[-1])//2)*(k-1)

print(p)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
ans = []
now = s[0]
cou = 0
for i in range(len(s)):
    if now == s[i]:
        cou += 1
    elif now != s[i]:
        ans.append(cou)
        cou = 1
        now = s[i]
if cou > 0:
    ans.append(cou)
    
p = 0
for i in ans:
    p += (i//2)*k

if s[0] == s[-1]:
    p -= (ans[0]//2 + ans[-1]//2)*(k-1)
    p += ((ans[0]+ans[-1])//2)*(k-1)

print(p)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
cou = 0
p = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        cou += 1
        s[i+1] = "V"
if s[0] == s[-1]:
    p = 1

print(cou*k + p * (k-1))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = list(readline().rstrip().decode())
k = int(read())
if len(set(s)) == 1:
    print(len(s) * k // 2)
    exit()
ans = 0
for i, (bf, af) in enumerate(zip(s, s[1:])):
    if bf == af:
        ans += 1
        s[i + 1] = '?'
ans *= k
if k > 1 and s[-1] == s[0]:
    ans += k - 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = list(readline().rstrip().decode())
k = int(read())
ans = 0
for i, (bf, af) in enumerate(zip(s, s[1:])):
    if bf == af:
        ans += 1
        s[i + 1] = '?'
memo = 0
if k > 1:
    if s[-1] == s[0]:
        memo += k // 2
print(ans * k + memo)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = list(readline().rstrip().decode())
s += s[0]
k = int(read())
ans = 0
for i, (bf, af) in enumerate(zip(s, s[1:])):
    if bf == af:
        ans += 1
        s[i + 1] = '?'
print(ans * k)

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

import copy

# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    k = ni()

    if len(s)==1:
        print(k//2)
        exit(0)

    def changer(sss):
        ts = sss.copy()
        cnt = 0
        for i in range(1, len(ts)):
            if ts[i] == ts[i - 1]:
                ts[i] = "@"
                cnt += 1

        return cnt

    print(changer(s) + (k - 1) * (changer(s + s) - changer(s)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

import copy

# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    k = ni()

    def changer(sss):
        ts = sss.copy()
        cnt = 0
        for i in range(1, len(ts)):
            if ts[i] == ts[i - 1]:
                ts[i] = "@"
                cnt += 1

        return cnt

    print(changer(s) + (k - 1) * (changer(s + s) - changer(s)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    k = ni()

    if len(s) == 1:
        print(k // 2)
        exit(0)

    cnt = 0
    for i in range(len(s)):
        next = i + 1 if i < len(s) - 1 else 0
        if s[i] == s[next]:
            s[next] = "@"
            cnt += 1

    tmp = 0
    if s[0] == "@" and k == 1:
        tmp = 1

    print(cnt * k - tmp)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    k = ni()

    if len(s)==1:
        print(k//2)
        exit(0)

    cnt = 0
    for i in range(len(s)):
        next = i + 1 if i < len(s) - 1 else 0
        if s[i] == s[next]:
            s[next] = "@"
            cnt+=1
    
    tmp=0
    if s[0]=="@" and k==1:
        tmp=1

    print(cnt*k-1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    k = ni()

    if len(s)==1:
        print(k//2)
        exit(0)
        
    cnt = 0
    for i in range(len(s)):
        next = i + 1 if i < len(s) - 1 else 0
        if s[i] == s[next]:
            s[next] = "@"
            cnt+=1

    print(cnt*k)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    k = ni()

    cnt = 0
    for i in range(len(s)):
        next = i + 1 if i < len(s) - 1 else 0
        if s[i] == s[next]:
            s[next] = "@"
            cnt+=1

    print(cnt*k)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if L == 1:
    print(L*K // 2)
    exit()

def n_changes(s):
    sc = s.copy()
    count = 0
    for i in range(1, len(sc)):
        if sc[i] == sc[i-1]:
            sc[i] = "X"
            count += 1
    return count

N = n_changes(S)
print(n_changes(S) + (K-1) * (n_changes(2*S) - n_changes(S)))

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
L = len(S)
count = 0
changed = [0]*L

i = 0
while i < L-1:
    if S[i] == S[i+1]:
        changed[i] = 1
        i += 2
        count += 1
    else:
        i += 1

if changed[L-1] == changed[L-2] == 0 and S[L-2] == S[L-1]:
    count += 1

if changed[0] == 0 and changed[L-2] == 0 and S[0] == S[L-1]:
    ans = count * K + K -1
else:
    ans = count * K

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
L = len(S)
count = 0
changed = [0]*L

i = 0
while i < L-1:
    if S[i] == S[i+1]:
        changed[i] = 1
        i += 2
        count += 1
    else:
        i += 1

if changed[0] == 0 and changed[L-2] == 0 and S[0] == S[L-1]:
    ans = count * K + K -1
else:
    ans = count * K


print(ans)

Submission status: Wrong Answer

Solution code:
import sys
s = input()
k = int(input())
n = len(s)
if n==1:
    print(k//2)
    sys.exit()
if n==2:
    print(k if s[0]==s[1] else 0)
    sys.exit()
i = 1
change = [0, 0]
same = True
while i<n:
    if s[i-1]==s[i]:
        if i==n-1:
            same = False
        change[0] += 1
        i += 1
    i += 1
if s[0]!=s[-1]:
    same = False
if not same:
    print(change[0]*k)
    sys.exit()
i = 2
change[1] = 1
same = True
while i<n:
    if s[i-1]==s[i]:
        change[1] += 1
        i += 1
        if i==n-1:
            same = False
    i += 1
if same:
    print(change[0]+change[1]*(k-1))
else:
    print(change[0]*((k+1)//2)+change[1]*(k//2))

Submission status: Wrong Answer

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

if all(s[0]==c for c in s) :
  print(len(s)*k // 2)
  exit(0)

replace, skip = 0, False
for i, c in enumerate(s):
  if not skip and c == s[(i+1)%len(s)]:
    replace += 1
    skip = True
  elif skip:
    skip = False
if skip:
  print(replace * k - 1)
else:
  print(replace * k)

Submission status: Wrong Answer

Solution code:
import collections
s = str(input())
k = int(input())

ans = 0
#if s[0] == s[-1]:
#    ans += k

tmp = ''
tmp_num = 0
for i, w in enumerate(s):
    if i == 0:
        tmp = w
        tmp_num += 1
        continue
    
    if tmp == w:
        tmp_num += 1
    
    elif tmp != w:
        ans += (tmp_num // 2) * k
        #print('ans', ans)
        tmp = w
        tmp_num = 1
    
    if i == len(s)-1:
        ans += (tmp_num // 2) * k
        #print('last', ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
s = str(input())
k = int(input())

ans = 0
#if s[0] == s[-1]:
#    ans += k

tmp = ''
tmp_num = 0
for i, w in enumerate(s):
    if i == 0:
        tmp = w
        tmp_num += 1
        continue
    
    if tmp == w:
        tmp_num += 1
        continue
    
    elif tmp != w:
        ans += (tmp_num // 2) * k
        #print('ans')
        #print(ans)
        tmp = w
        tmp_num = 1
    
    if i == len(s)-1:
        ans += (tmp_num // 2) * k

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
s = str(input())
k = int(input())

ans = 0
if s[0] == s[-1]:
    ans += k

tmp = ''
tmp_num = 0
for i, w in enumerate(s[1:-1]):
    if i == 0:
        tmp = w
        tmp_num += 1
        continue
    
    if tmp == w:
        tmp_num += 1
        continue
    
    elif tmp != w:
        ans += (tmp_num // 2) * k
        #print('ans')
        #print(ans)
        tmp = w
        tmp_num = 1

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
s = str(input())
k = int(input())

ans = 0
if s[0] == s[-1]:
    ans += k

#print(s[1:-1])
c = list(collections.Counter(s[1:-1]).values())
#print(c)

tmp = 0
for i in c:
    tmp += i//2

print(ans + tmp*k)

Submission status: Wrong Answer

Solution code:
import sys
s = input()
k = int(input())
n = len(s)
if n==1:
    print(k//2)
    sys.exit()
if n==2:
    print(k if s[0]==s[1] else 0)
    sys.exit()
i = 1
change = [0, 0]
same = True
while i<n:
    if s[i-1]==s[i]:
        if i==n-1:
            same = False
        change[0] += 1
        i += 1
    i += 1
if s[0]!=s[-1]:
    same = False
if not same:
    print(change[0]*k)
    sys.exit()
i = 2
change[1] = 1
same = True
while i<n:
    if s[i-1]==s[i]:
        change[1] += 1
        i += 1
        if i==n-1:
            same = False
    i += 1
if same:
    print(change[0]+change[1]*(k-1))
else:
    print(change[0]*((k+1)//2)+change[1]*(k//2))
print(change)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
n = len(s)
same = True
for i in range(1,len(s)):
    if s[i]!=s[i-1]:
        same = False
if same:
    print(len(s)*k//2)
    exit()

for i in range(1,len(s)):
    if s[i] != s[i-1]:
        before = i-1
        break
for i in range(len(s)-1,-1,-1):
    if s[i] != s[i-1]:
        after = i
        break

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

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
n = len(s)
same = True
for i in range(1,len(s)):
    if s[i]!=s[i-1]:
        same = False
if same:
    print(len(s)*k//2)
    exit()

for i in range(1,len(s)):
    if s[i] != s[i-1]:
        before = i-1
        break
for i in range(len(s)-1,-1,-1):
    if s[i] != s[i-1]:
        after = i
        break

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

Submission status: Wrong Answer

Solution code:
s = input() + '*'
k = int(input())
first, last = s[0], s[-1]
first_flag = 1
a, b  = 0, 0
tmp = s[0]
tmp_cnt = 0
cnt = 0

for i in range(len(s)):
    c = s[i]
    if c == first and first_flag:
        a += 1
    elif c != first:
        first_flag = 0
    
    if c == tmp:
        tmp_cnt += 1
    else:
        if i == len(s) - 1:
            b = tmp_cnt
        cnt += (tmp_cnt // 2)
        tmp_cnt = 1
        tmp = c

if len(set(s[:-2])) == 1:
    print((len(s)-1)*k//2)
    exit()

if first != last:
    ans = cnt * k
else:
    ans = cnt * k - (a//2 + b//2 - (a+b)//2)*(k-1)

print(ans)

Submission status: Wrong Answer

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

n = len(s)

cnt = 0
flg = True
for i in range(1, n):
	if s[i] != s[i - 1]:
		flg = True
	elif s[i] == s[i - 1] and flg:
		cnt += 1
		flg = False
	else:
		flg = True

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

Submission status: Wrong Answer

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

n = len(s)

cnt = 0
flg = True
for i in range(1, n):
	if s[i] != s[i - 1]:
		flg = True
	elif s[i] == s[i - 1] and flg:
		cnt += 1
		flg = False
	else:
		flg = True

if cnt % 2 == 0:
	print(k * (cnt // 2))
else:
	print(k * (cnt // 2) - 1)

Submission status: Wrong Answer

Solution code:
s = input() + '*'
k = int(input())
first, last = s[0], s[-1]
first_flag = 1
a, b  = 0, 0
tmp = s[0]
tmp_cnt = 0
cnt = 0

for i in range(len(s)):
    c = s[i]
    if c == first and first_flag:
        a += 1
    elif c != first:
        first_flag = 0
    
    if c == tmp:
        tmp_cnt += 1
    else:
        if i == len(s) - 1:
            b = tmp_cnt
        cnt += (tmp_cnt // 2)
        tmp_cnt = 1
        tmp = c

if first != last:
    ans = cnt * k
else:
    ans = cnt * k - (a//2 + b//2 - (a+b)//2)*(k-1)

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
cnt = 0
tmp = s[0]
tmp_cnt = 1

for c in s[1:] + '*':
    if c == tmp:
        tmp_cnt += 1
    else:
        cnt += (tmp_cnt // 2)
        tmp_cnt = 1
        tmp = c

if k == 1:
    print(cnt)
    exit()

tmp_cnt = 1
cnt2 = 0
tmp = s[0]
for c in s[1:] + s + '*':
    if c == tmp:
        tmp_cnt += 1
    else:
        cnt2 += (tmp_cnt // 2)
        tmp_cnt = 1
        tmp = c

if k%2 == 0:
    ans = cnt2 * (k//2)
else:
    ans = cnt2 * (k//2) + cnt

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
cnt = 0
tmp = s[0]
tmp_cnt = 1

for c in s[1:] + '*':
    if c == tmp:
        tmp_cnt += 1
    else:
        cnt += (tmp_cnt // 2)
        tmp_cnt = 1
        tmp = c

if k == 1:
    print(cnt)
    exit()

tmp_cnt = 1
cnt2 = 0
tmp = s[0]
for c in s[1:] + s + '*':
    if c == tmp:
        tmp_cnt += 1
    else:
        cnt2 += (tmp_cnt // 2)
        tmp_cnt = 1
        tmp = c

if k%2 == 0:
    ans = cnt2 * (k/2)
else:
    ans = cnt2 * (k//2) + cnt

print(ans)

Submission status: Wrong Answer

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

w = ""
c = 0
cnt = 0
for i in s:
    if w != i:
        #print(w)
        cnt += c//2
        c = 1
        w = i
    else:
        c +=1
cnt += c//2
#print(cnt)

start = 0
start_w = s[0]
for i in s:
    if start_w != i:
        break
    else:
        start +=1

s.reverse()

end = 0
end_w = 0
for i in s:
    if end_w != i:
        break
    else:
        end +=1

same = len(list(set(s)))
#print(same)

if s[0] != s[-1]:
    print(cnt*a)
elif same ==1:
    print(len(s)*a//2)
else:
    print(cnt*a-(a-1)*(start//2+end//2-(start+end)//2))

Submission status: Wrong Answer

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

w = ""
c = 0
cnt = 0
for i in s:
    if w != i:
        #print(w)
        cnt += c//2
        c = 1
        w = i
    else:
        c +=1
cnt += c//2
#print(cnt)

start = 0
start_w = s[0]
for i in s:
    if start_w != i:
        break
    else:
        start +=1

s.reverse()

end = 0
end_w = 0
for i in s:
    if end_w != i:
        break
    else:
        end +=1


if s[0] != s[-1]:
    print(cnt*a)
else:
    print(cnt*a-(a-1)*(start//2+end//2-(start+end)//2))

Submission status: Wrong Answer

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

l = len(s)

ss = s + s
ll = len(ss)

single = 0
cnt = 0

for i in range(1, l):
    if s[i - 1] == s[i]:
        if cnt == 0:
            single += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                single += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0

double = 0
cnt = 0

for i in range(1, ll):
    if ss[i - 1] == ss[i]:
        if cnt == 0:
            double += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                double += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0

if single * 2 == double:
    ans = single * k
else:
    ans = single + (single + 1) * (k - 1)

# print(single, double)
print(ans)

Submission status: Wrong Answer

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

l = len(s)

ss = s + s
ll = len(ss)

single = 0
cnt = 0

for i in range(1, l):
    if s[i - 1] == s[i]:
        if cnt == 0:
            single += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                single += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0

double = 0
cnt = 0

for i in range(1, ll):
    if ss[i - 1] == ss[i]:
        if cnt == 0:
            double += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                double += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0

if single * 2 == double:
    ans = single * k
else:
    if k % 2 == 0:
        ans = double * (k // 2)
    else:
        ans = double * (k // 2) + single
#print(single, double)
print(ans)

Submission status: Wrong Answer

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

l = len(s)

ss = s + s
ll = len(ss)

single = 0
cnt = 0

for i in range(1, l):
    if s[i - 1] == s[i]:
        if cnt == 0:
            single += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                single += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0

double = 0
cnt = 0

for i in range(1, ll):
    if ss[i - 1] == ss[i]:
        if cnt == 0:
            double += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                double += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0

if single * 2 == double:
    ans = single * k
else:
    if k % 2 == 0:
        ans = double * k // 2
    else:
        ans = double * k // 2 + single
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())

k = int(input())

n = len(s)

c = 0
for i in range(n-1):
    if(s[i] == s[i+1]):
        c += 1
        s[i+1] = s[i+1].upper()
c *= k
if(s[0] == s[-1]):
    c += k - 1

print(c)

Submission status: Wrong Answer

Solution code:
s = list(input())
n = int(input())
ans = 0
if s[0] != s[-1]:
    cnt = 1
    tmp = ''
    for i in range(len(s)):
        if i == 0:
            tmp = s[i]
            continue
        if tmp == s[i]:
            cnt += 1
        else:
            ans += cnt // 2
            cnt = 1
            tmp = s[i]
    ans += cnt // 2
    print(ans*n)
else:
    cnt = 1
    tmp = ''
    f = 0
    for i in range(len(s)):
        if i == 0:
            tmp = s[i]
            continue
        if tmp == s[i]:
            cnt += 1
        else:
            if f == 0:
                f = cnt
            ans += cnt // 2
            cnt = 1
            tmp = s[i]
    ans += cnt // 2
    if f == 0:
        print((cnt*n)//2)
    else:
        m = ans - f//2 - cnt//2
        ans = f // 2 + cnt // 2
        # print(m,ans)
        ans += m * n
        ans += (n-1) * (f+cnt) // 2
        print(ans)