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:
def main():
    def f(s):
        n = len(s)

        ret = 0
        i = 0
        while i < n - 1:
            if s[i] == s[i + 1]:
                ret += 1
                i += 2
                continue
            i += 1

        return ret

    s = input()
    k = int(input())

    if k == 1:
        print(f(s))
        return

    d = f(s * 3) - f(s * 2)
    ret = f(s * 1) + d * (k - 1)

    print(ret)

    for x in range(1, 14):
        print(f(s * x), x)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = 0
c = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        c +=1
    elif s[i] != s[i+1]:
        if c == 2:
            ans += 1
        else:
            ans += c // 2
        c = 1
        
if c == 2:
    ans += 1
else:
    ans += c // 2     

print(ans * 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(500000)

S = readline().decode("utf-8").rstrip()
K = int(readline())

last = " "

cnt = 0
for s in S[:-1]:
    if last == s:
        cnt += 1
        last = " "
    else:
        last = s
ans = 0
if last == S[-1]:
    if S[0] == S[-1]:
        cnt += 1
    else:
        ans = K - 1
else:
    if S[0] == S[-1]:
        ans = K - 1

ans += cnt * K
        
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(500000)

S = readline().decode("utf-8").rstrip()
K = int(readline())

last = " "
new = ""
cnt = 0
for s in S:
    if last == s:
        cnt += 1
        last = " "
    else:
        last = s
    new += last
ans = cnt * K
if new[0] == new[-1]:
  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(500000)

S = readline().decode("utf-8").rstrip()
K = int(readline())

last = ""
cnt = 0
for s in S:
    if last == s:
        cnt += 1
        last = ""
    else:
        last = s
        
print(cnt * K)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
cnt=1
s=0
e=s+1
sum=0
while True:
  if e>len(S)-1:
    break    
  if S[s]==S[e]:
    cnt=cnt+1
    e=e+1
  else:
    s=e
    sum+=cnt//2
    e=s+1
    cnt=1
sum=sum*K
if S[0]==S[-1]:
  sum+=K
print(sum)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
cnt=1
s=0
e=s+1
sum=0
while True:
  if e>=len(S)-1:
    break    
  if S[s]==S[e]:
    cnt=cnt+1
    e=e+1
  else:
    s=e
    sum+=cnt//2
    e=s+1
    cnt=1
sum=sum*K
if S[0]==S[-1]:
  sum+=K
print(sum)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

N = len(S)

if len(set(list(S))) == 1:
    print(N * K // 2)
else:
    G = list(map(lambda g: len(list(g[1])), (groupby(S))))
    cnt = sum(map(lambda g: g // 2, G)) * K

    if S[0] != S[N - 1]:
        print(cnt)
    else:
        a = G[0]
        b = G[-1]
        print(cnt - (a // 2 - b // 2 + (a + b) // 2) * (K - 1))

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

N = len(S)

if len(set(list(S))) == 1:
    print(N * K // 2)
else:
    G = list(map(lambda g: len(list(g[1])) // 2, (groupby(S))))
    cnt = sum(G)

    if S[0] != S[N - 1]:
        print(cnt * K)
    else:
        a = G[0]
        b = G[-1]
        print(cnt * K - (a // 2 - b // 2 + (a + b) // 2) * (K - 1))

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

N = len(S)

if len(set(list(S))) == 1:
    print(N * K // 2)
else:
    G = list(map(lambda g: len(list(g[1])) // 2, (groupby(S))))
    cnt = sum(G)

    if S[0] != S[N - 1]:
        print(cnt * K)
    else:
        a = G[0]
        b = G[-1]
        print(cnt * K - a // 2 - b // 2 + (a + b) // 2)

Submission status: Wrong Answer

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

N = len(S)

cnt = 0
f = 0
for i in range(N):
    if i == N - 1:
        if S[0] == S[i]:
            f = 1
    elif S[i] == S[i + 1]:
        S[i + 1] = '.'
        cnt += 1

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

Submission status: Wrong Answer

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

N = len(S)

cnt = 0
f = 0
for i in range(N - 1):
    if S[i] == S[i + 1]:
        S[i + 1] = '.'
        cnt += 1
    elif i == N - 1 and S[0] == S[i]:
        f = 1

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

Submission status: Wrong Answer

Solution code:
#n = int(input())
#L = list(map(int, input().split()))
#import math
#import sys
#import heapq
#import fractions
#import bisect
#import numpy


a = list(input())
b = int(input())
ans=0
for i in range(1,len(a)-1):
    print(a,ans)
    if i == 1 or i==len(a)-2:
        if a[-1]!=a[0]:
            if a[i-1] == a[i]:
                ans += 1
                a[i] = '1'
    elif a[i-1]==a[i]:
        ans+=1
        a[i]='1'
ans*=b
if a[-1]==a[0]:
    if len(a)>2:
        if a[-1]==a[-2]:
            ans+=b
        else:
            ans+=b-1
    elif len(a)==2 :
        ans += b
    elif len(a)==1 :
        ans += b//2

print(ans)

Submission status: Wrong Answer

Solution code:
#n = int(input())
#L = list(map(int, input().split()))
#import math
#import sys
#import heapq
#import fractions
#import bisect
#import numpy


a = list(input())
b = int(input())
ans=0
for i in range(1,len(a)-2):
    if i == 1 or i==len(a)-3:
        if a[-1]!=a[0]:
            if a[i] == a[i+1]:
                ans += 1
                a[i+1] = '1'
    elif a[i]==a[i+1]:
        ans+=1
        a[i+1]='1'
ans*=b
if a[-1]==a[0] and len(a)>2:
    ans+=b-1
print(ans)

Submission status: Wrong Answer

Solution code:
#n = int(input())
#L = list(map(int, input().split()))
#import math
#import sys
#import heapq
#import fractions
#import bisect
#import numpy


a = list(input())
b = int(input())
ans=0
for i in range(1,len(a)-2):
    print(a)
    if i == 1 or i==len(a)-3:
        if a[-1]!=a[0]:
            if a[i] == a[i+1]:
                ans += 1
                a[i+1] = '1'
    elif a[i]==a[i+1]:
        ans+=1
        a[i+1]='1'
ans*=b
if a[-1]==a[0] and len(a)>2:
    ans+=b-1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
if K > 1: S = S+S[0]

i = 0
n = 0
while i < len(S)-1:
    if S[i] == S[i+1]:
        n += 1
        i += 2
    else:
        i += 1

print(n*K + (-1 if K > 1 else 0))

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
if K > 1: S = S+S[0]

i = 0
n = 0
while i < len(S)-1:
    if S[i] == S[i+1]:
        n += 1
        i += 2
    else:
        i += 1
print(n*K)

Submission status: Wrong Answer

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

first = s[:]
fcnt = 0
for i in range(len(first)-1):
    if first[i] == first[i+1]:
        first[i+1] = "_"
        fcnt += 1

s.insert(0, first[-1])

cnt = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        s[i+1] = "_"
        cnt += 1

print(fcnt + cnt*(k-1))

Submission status: Wrong Answer

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

ans = 0
for i in range(1, len(s)):
    if s[i-1] == s[i]:
        ans += 1
        s[i] = "_"

print(ans*k)

Submission status: Wrong Answer

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

ans = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        s[i+1] = "_"
        ans += 1

if s[0] == s[-1]:
    print(ans*k + k-1)
else:
    print(ans*k)

Submission status: Wrong Answer

Solution code:
def is_all(t):
    for i in range(len(t)-1):
        if t[i]!=t[i+1]:
            return False
    return True

s=input()
n=len(s)
k=int(input())
cor=[0]
ans=0
c=1
if is_all(s):
    print(n*k//2)
    exit()
i=0
while i<n-1:
    if s[i]==s[i+1]:
        cor[0]+=1
        i+=1
    else:
        i+=1
        break
if cor[0]==0:
    cor[0]+=1
while i<n-1:
    if s[i]==s[i+1]:
        cor.append(1)
        while i<n-1:
            if s[i]==s[i+1]:
                cor[-1]+=1
                i+=1
            else:
                break
    i+=1
#print(cor)
if s[0]==s[-1]:
    for i in range(1,len(cor)-1):
        ans+=cor[i]//2
    ans*=k
    ans+=(cor[0]+cor[-1])//2*(k-1)
    print(ans+cor[0]//2+cor[-1]//2)
else:
    for i in range(len(cor)):
        ans+=cor[i]//2
    print(ans*k)

Submission status: Wrong Answer

Solution code:
def is_all(t):
    for i in range(len(t)-1):
        if t[i]!=t[i+1]:
            return False
    return True

s=input()
n=len(s)
k=int(input())
cor=[0]
ans=0
c=1
if is_all(s):
    print(n*k//2)
    exit()
i=0
while i<n-1:
    if s[i]==s[i+1]:
        cor[0]+=1
        i+=1
    else:
        i+=1
        break
if cor[0]==0:
    cor[0]+=1
while i<n-1:
    if s[i]==s[i+1]:
        cor.append(1)
        while i<n-1:
            if s[i]==s[i+1]:
                cor[-1]+=1
                i+=1
            else:
                break
    i+=1
print(cor)
if s[0]==s[-1]:
    for i in range(1,len(cor)-1):
        ans+=cor[i]//2
    ans*=k
    ans+=(cor[0]+cor[-1])//2*(k-1)
    print(ans+cor[0]//2+cor[-1]//2)
else:
    for i in range(len(cor)):
        ans+=cor[i]//2
    print(ans*k)

Submission status: Wrong Answer

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

#
#  文字数一種類
#
if len(set(s)) == 1:
    print((len(s) * k) // 2)
    exit()

#
# 先頭と末尾が異なる
#
if s[0] != s[-1]:
    cnt = 0
    bf_same = False
    tmp = 1
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            tmp += 1
        else:
            if tmp > 1:
                cnt += (tmp // 2) * k
                tmp = 1
    else:
        if tmp > 1:
            cnt += (tmp // 2) * k
        print(cnt)
    exit()

#
# 先頭と末尾が一緒
#

# 先頭のダブリ
tp = 1
tp_idx = -1
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        tp += 1
        tp_idx = i + 1
    else:
        break

# 末尾のダブリ
bt = 1
bt_idx = -1
for i in range(len(s) - 1, 0, -1):
    if s[i] == s[i - 1]:
        bt += 1
        bt_idx = i - 1
    else:
        break

# 連結部分以外のダブリ
cnt = 0
bf_same = False
tmp = 1
for i in range(tp_idx + 1, bt_idx - 1):
    if s[i] == s[i + 1]:
        tmp += 1
    else:
        if tmp > 1:
            cnt += (tmp // 2) * k
            tmp = 1
else:
    if tmp > 1:
        cnt += (tmp // 2) * k

print(tp, bt, cnt)
print(tp // 2 + bt // 2 + ((tp + bt) // 2) * (k - 1))
ans = cnt + tp // 2 + bt // 2 + ((tp + bt) // 2) * (k - 1)
print(ans)

Submission status: Wrong Answer

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

#
#  文字数一種類
#
if len(set(s)) == 1:
    print((len(s) * k) // 2)
    exit()

#
# 先頭と末尾が異なる
#
if s[0] != s[-1]:
    cnt = 0
    bf_same = False
    tmp = 1
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            tmp += 1
        else:
            if tmp > 1:
                cnt += (tmp // 2) * k
                tmp = 1
    else:
        if tmp > 1:
            cnt += (tmp // 2) * k
        print(cnt)
    exit()

#
# 先頭と末尾が一緒
#

# 先頭のダブリ
tp = 1
tp_idx = -1
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        tp += 1
        tp_idx = i + 1
    else:
        break

# 末尾のダブリ
bt = 1
bt_idx = -1
for i in range(len(s) - 1, 1, -1):
    if s[i] == s[i - 1]:
        bt += 1
        bt_idx = i - 1
    else:
        break

# 連結部分以外のダブリ
cnt = 0
bf_same = False
for i in range(tp_idx + 1, bt_idx - 1):
    if s[i] == s[i + 1]:
        if bf_same:
            bf_same = False
        else:
            cnt += 1
            bf_same = True

# print(tp, bt, cnt)
ans = cnt * k + tp // 2 + bt // 2 + (((tp + bt) * (k - 1)) // 2)
print(ans)

Submission status: Wrong Answer

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

ans = 0
cnt = 1

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

ans = ans * k

print(ans)

Submission status: Wrong Answer

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

ans = 0
cnt = 1

for i in range(len(S)):
    if S[i] == S[i-1]:
        cnt += 1
    else:
        ans += cnt//2
        cnt = 1
if cnt != 1:
    ans += cnt//2

print(ans*k)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
flg = 0
ans1 = 0
ans2 = 0
for i in range(1,n):
  if s[i] == s[i-1] and flg == 0:
    flg = 1
    ans1 += 1
  else:
    flg = 0
s = s*2
n *= 2
flg = 0
for i in range(1,n):
  if s[i] == s[i-1] and flg == 0:
    flg = 1
    ans2 += 1
  else:
    flg = 0
k = int(input())
if ans2>ans1*2:
  print((k//2)*ans2+(k%2)*ans1+(k-1)//2)
else:
  print((k//2)*ans2+(k%2)*ans1)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
flg = 0
ans1 = 0
ans2 = 0
for i in range(1,n):
  if s[i] == s[i-1] and flg == 0:
    flg = 1
    ans1 += 1
  else:
    flg = 0
if s[n-1] == s[0] and flg == 0:
  ans2 = 1
k=int(input())
if n == 1:
  print(k//2)
elif len(set(list(s))) == 1:
  print(k*n//2)
else:
  print((ans1+ans2)*(k-1)+ans1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
flg = 0
ans1 = 0
ans2 = 0
for i in range(1,n):
  if s[i] == s[i-1] and flg == 0:
    flg = 1
    ans1 += 1
  else:
    flg = 0
if s[n-1] == s[0] and flg == 0:
  ans2 = 1
else:
  ans = 0
k=int(input())
print((ans1+ans2)*(k-1)+ans1)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
flg = 0
ans1 = 0
ans2 = 0
for i in range(1,n):
  if s[i] == s[i-1] and flg == 0:
    flg = 1
    ans1 += 1
  else:
    flg = 0
s = s*2
n *= 2
flg = 0
for i in range(1,n):
  if s[i] == s[i-1] and flg == 0:
    flg = 1
    ans2 += 1
  else:
    flg = 0
k = int(input())
print((k//2)*ans2+(k%2)*ans1)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
flg = 0
ans1 = 0
ans2 = 0
for i in range(1,n):
  if s[i] == s[i-1]:
    if flg == 0:
      flg = 1
      ans1 += 1
    else:
      flg = 0
s = s*2
n *= 2
flg = 0
for i in range(1,n):
  if s[i] == s[i-1]:
    if flg == 0:
      flg = 1
      ans2 += 1
    else:
      flg = 0
k = int(input())
print((k//2)*ans2+(k%2)*ans1)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

S = input().rstrip()
K = INT()
N = len(S)

C = Counter(S).most_common()
if len(C) == 1:
	print(N*K//2)

else:
	A = []
	for i in range(N-1):
		if S[i] == S[i+1]:
			if len(A)==0 or A[-1]!=i-1:
				A.append(i)
	#print(A)
	ans = len(A)*K
	#print(ans)
	if S[0] == S[-1] and S[-1] != S[-2]:
		ans += (K-1)
	print(ans)

Submission status: Wrong Answer

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

S = input().rstrip()
K = INT()
N = len(S)
S += S*2
#print(S)

A = []
for i in range(N*3):
	if S[i] == S[i-1]:
		if len(A)==0 or A[-1]!=i-1:
			A.append(i)
#print(A)
if S[0]==S[-1] and S[-1]==S[-2] and A[0]==0 and A[-1]==N*3-1:
	A.pop()
#print(A)
print(len(A)*K//3)

Submission status: Wrong Answer

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

if len(s) == 1:
    print(k//2)
if len(s) > 1:
    count = 0
    flag = True
    for i in range(1, len(s)):
        if not flag:
            flag = True
            continue
        if s[i] == s[i-1]:
            count += 1
            flag = False

    count2 = 0
    flag = True
    s = s*2
    for i in range(1, len(s)):
        if not flag:
            flag = True
            continue
        if s[i] == s[i-1]:
            count2 += 1
            flag = False
    # 連結部分の数を加える
    print(count * k + (count2-count*2)*(k-1))

Submission status: Wrong Answer

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

S = input().rstrip()
K = INT()
N = len(S)
S += S*2
#print(S)

A = []
for i in range(N*3):
	if S[i] == S[i-1]:
		if len(A)==0 or A[-1]!=i-1:
			A.append(i)
#print(A)
print(len(A)*K//3)

Submission status: Wrong Answer

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

count = 0
flag = True
for i in range(1, len(s)):
    if not flag:
        flag = True
        continue
    if s[i] == s[i-1]:
        count += 1
        flag = False

count2 = 0
flag = True
s = s*2
for i in range(1, len(s)):
    if not flag:
        flag = True
        continue
    if s[i] == s[i-1]:
        count2 += 1
        flag = False
# 連結部部の数を加える
print(count * k + (count2-count*2)*(k-1))

Submission status: Wrong Answer

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

count = 0
flag = True
for i in range(1, len(s)):
    if not flag:
        flag = True
        continue
    if s[i] == s[i-1]:
        count += 1
        flag = False

count2 = 0
flag = True
s = s*2
for i in range(1, len(s)):
    if not flag:
        flag = True
        continue
    if s[i] == s[i-1]:
        count2 += 1
        flag = False
print(count2*(k//2) + count * (k % 2))

Submission status: Wrong Answer

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

S = input().rstrip()
K = INT()
N = len(S)

A = []
for i in range(N):
	if S[i] == S[i-1]:
		if len(A)==0 or (i!=N-1 and A[-1]!=i-1) or (i==N-1 and (N==3 or A[0]!=0)):
			A.append(i)
#print(A)
print(len(A)*K)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
n=len(s)
cnt1=1
cnt2=1
cnt3=0
t=s+s+s
a1=0
a2=0
a3=0
if k==1 or s[0]!=s[len(s)-1]:
  for i in range(n-1):
    if s[i]==s[i+1]:
      cnt1+=1
    else:
      a1+=cnt1//2
      cnt1=1
  a1+=cnt1//2
  print(k*a1)
else:
  for i in range(3*n-1):
    if i<=n-2:
      if t[i]==t[i+1]:
        cnt1+=1
      else:
        a1+=cnt1//2
        cnt1=1
    elif i<=2*n-2:
      if t[i]==t[i+1]:
        cnt2+=1
      else:
        a2+=cnt2//2
        cnt2=1
    else:
      if t[i]==t[i+1]:
        cnt3+=1
      else:
        a3+=cnt3//2
        cnt3=1
  a1+=cnt1//2
  a2+=cnt2//2
  a3+=cnt3//2
  print(a1+(k-2)*a2+a3)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

def count(s):
    l = []
    c = 0
    for key,value in groupby(s):
        l.append(list(value))
    for i in l:
        c += len(i)//2
    return c
s = list(input())
k =int(input())
if k <= 10**5:
    print(count(s*k))
else:
    print((count(s*3)-count(s*2))*(k-2) + count(s*2))

Submission status: Wrong Answer

Solution code:
from itertools import groupby

def count(s):
    l = []
    c = 0
    for key,value in groupby(s):
        l.append(list(value))
    for i in l:
        c += len(i)//2
    return c
s = list(input())
k =int(input())
if k <= 3:
    print(count(s*k))
else:
    print((count(s*3)-count(s*2))*(k-2) + count(s*2))

Submission status: Wrong Answer

Solution code:
from itertools import groupby

def count(s):
    l = []
    c = 0
    for key,value in groupby(s):
        l.append(list(value))
    for i in l:
        c += len(i)//2
    return c


if __name__=="__main__":
    s = list(input())
    k = int(input())
    c = 0
    l = []
    for key,value in groupby(s):
        l.append(list(value))
    for i in l[1:-1]:
        c += len(i)//2*k
    if len(l) >= 2:
        c += len(l[0])//2 + len(l[-1])//2

    if s[0] == s[-1] and len(l) >= 3:
        c += len(l[0]+l[-1])//2*(k-1)
    if len(l) == 2:
        c += len(l[0])//2*(k-1) + len(l[1])//2*(k-1)
    if len(l) == 1:
        c += len(l[0])*k//2
    print(c)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

def count(s):
    l = []
    c = 0
    for key,value in groupby(s):
        l.append(list(value))
    for i in l:
        c += len(i)//2
    return c


if __name__=="__main__":
    s = list(input())
    k = int(input())
    c = 0
    l = []
    if k <= 10**5:
        c += count(s*k)
    else:
        for key,value in groupby(s):
            l.append(list(value))
        for i in l[1:-1]:
            c += len(i)//2*k
        if len(l) >= 2:
            c += len(l[0])//2 + len(l[-1])//2

        if s[0] == s[-1] and len(l) >= 3:
            c += len(l[0]+l[-1])//2*(k-1)
        if len(l) == 1:
            c += len(l[0])*k//2
    print(c)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

def count(s):
    l = []
    c = 0
    for key,value in groupby(s):
        l.append(list(value))
    for i in l:
        c += len(i)//2
    return c


if __name__=="__main__":
    s = list(input())
    k = int(input())
    c = 0
    l = []
    if k <= 10**4:
        c += count(s*k)
    else:
        for key,value in groupby(s):
            l.append(list(value))
        for i in l[1:-1]:
            c += len(i)//2*k
        if len(l) >= 2:
            c += len(l[0])//2 + len(l[-1])//2

        if s[0] == s[-1] and len(l) >= 3:
            c += len(l[0]+l[-1])//2*(k-1)
        if len(l) == 1:
            c += len(l[0])*k//2
    print(c)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

def count(s):
    l = []
    c = 0
    for key,value in groupby(s):
        l.append(list(value))
    for i in l:
        c += len(i)//2
    return c


if __name__=="__main__":
    s = list(input())
    k = int(input())
    c = 0
    l = []
    if k <= 10**3:
        c += count(s*k)
    else:
        for key,value in groupby(s):
            l.append(list(value))
        for i in l[1:-1]:
            c += len(i)//2*k
        if len(l) >= 2:
            c += len(l[0])//2 + len(l[-1])//2

        if s[0] == s[-1] and len(l) >= 3:
            c += len(l[0]+l[-1])//2*(k-1)
        if len(l) == 1:
            c += len(l[0])*k//2
    print(c)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

if __name__=="__main__":
    s = list(input())
    k = int(input())
    c = 0
    l = []
    for key,value in groupby(s):
        l.append(list(value))
    for i in l[1:-1]:
        c += len(i)//2*k
    if len(l) >= 2:
        c += len(l[0])//2 + len(l[-1])//2

    if s[0] == s[-1] and len(l) >= 3:
        c += len(l[0]+l[-1])//2*(k-1)
    if len(l) == 1:
        c += len(l[0])*k//2
    print(c)

Submission status: Wrong Answer

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

sames = 1
ans = 0
prev = 'prev'

for s in S:
	if prev == s:
		sames+=1
	else:
		if sames > 1:
			ans+=(sames//2)
			sames = 1
	prev = s
	
add = 0
if S[0] == S[len(S)-1]:
	for s in S:
		if s == S[0]:
			add+=1
		else:
			break
	for sr in reversed(S):
		if s == S[len(S)-1]:
			add+=1
		else:
			break

if len(set(list(S))) == 1:
	print(K*len(S)//2)
else:
	print(ans*K + (add//2)*(K-1))

Submission status: Wrong Answer

Solution code:
s=list(input())
k=int(input())
l=[]
p=1
for i in range(len(s)-1):

    if s[i]==s[i+1]:
        p+=1
    else:
        l.append(p)
        p=1
l.append(p)
m=0
if len(l)==1:
    print(l[0]*k//2)

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

    else:
        for i in range(len(l)):
            m+=l[i]//2
        m*=k
        print(m)

Submission status: Wrong Answer

Solution code:
s, k = input(), int(input())
r = 0
f = True
fir = 0
las = 0

for i in range(len(s)):
    if s[i] == s[0]:
        fir += 1
    else:
        break

for i in range(len(s) - 1, -1, -1):
    if s[i] == s[0]:
        las += 1
    else:
        break

i = 1
tmp = 1
while i < len(s):
    if s[i] == s[i - 1]:
        tmp += 1
    else:
        r += tmp // 2
        tmp = 1
    i += 1
r += tmp // 2

if r == len(s)//2:
    print(len(s) * k // 2)
else:
    print(r * k - (k - 1) * (fir // 2 + las // 2 - (fir + las) // 2))

Submission status: Wrong Answer

Solution code:
s, k = input(), int(input())
r = 0
f = True
fir = 0
las = 0

for i in range(len(s)):
    if s[i] == s[0]:
        fir += 1
    else:
        break

for i in range(len(s) - 1, -1, -1):
    if s[i] == s[0]:
        las += 1
    else:
        break

i = 1
tmp = 1
while i < len(s):
    if s[i] == s[i - 1]:
        tmp += 1
    else:
        r += tmp // 2
        tmp = 1
    i += 1
r += tmp // 2

print(r * k - (k - 1) * (fir // 2 + las // 2 - (fir + las) // 2))

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
checked = [0] * len(S)


for i in range(1, len(S)):
    now = S[i]
    if now == S[i - 1] and checked[i - 1] == 0:
        checked[i] = 1
    mae = now
if S[0] == S[-1] and checked[-1] == 0:
    checked[-1] = 1
print(checked.count(1) * K)

Submission status: Wrong Answer

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

s = input()
k = int(input())

ns = []
ns.append(s[0])
c = 0
for i in range(1, len(s)):
    if ns[i - 1] == s[i]:
        c += 1
        ns.append('0')
    else:
        ns.append(s[i])
c *= k
if k > 1:
    if s[0] == ns[-1]:
        c += k - 1
print(c)

Submission status: Wrong Answer

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

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

    else:
        co += (len_count_0 // 2)
        len_count_0 = 1
co += (len_count_0//2)

t = s * 2
count = 0
len_count = 1
for i in range(len(t)-1):
    if t[i] == t[i+1]:
        len_count += 1

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

count_2 += (len_count//2)


if n == 1:
    print(co)
    exit()
elif n == 2:
    print(count)
    exit()
elif n == 3:
    print(count_2)
    exit()
else:
    ans = (count_2 - count) * (n-2) + count
    print(ans)

Submission status: Wrong Answer

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

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

    else:
        co += (len_count_0 // 2)
        len_count_0 = 1
co += (len_count_0//2)

t = s * 2
count = 0
len_count = 1
for i in range(len(t)-1):
    if t[i] == t[i+1]:
        len_count += 1

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

count_2 += (len_count//2)

print(count)
print(count_2)

if n == 1:
    print(co)
    exit()
elif n == 2:
    print(count)
    exit()
elif n == 3:
    print(count_2)
    exit()
else:
    ans = (count_2 - count) * (n-2) + count
    print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
count = 0
if S[0] != S[-1]:
    if len(S) == 2:
        print(K)
    elif len(S) == 1:
        print(K//2)
    else:
        flag = False
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                S[i+1] = '1'
                count += 1
        print(K*count)
else:
    if len(S) == 2:
        print(K)
    elif len(S) == 1:
        print(K//2)
    else:
        if S[0] == S[1] and S[-1] != S[-2]:
            S[0] ='1'
            count += 1
        elif S[0] != S[1] and S[-1] == S[-2]:
            S[-1] = '1'
            count += 1
        elif S[0] == S[1] and S[-1] == S[-2]:
            S[0] = '1'
            count += 1
        elif S[0] != S[1] and S[-1] != S[-2]:
            S[0] = '1'
            count += 1
        
        
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                S[i+1] = '1'
                count += 1
        print(K*count)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
count = 0
if S[0] != S[-1]:
    flag = False
    for i in range(len(S)-1):
        if not flag and S[i] == S[i+1]:
            count += 1
            flag = True
        if flag:
            flag = False
    print(K*count)
else:
    if len(S) == 2:
        print(K)
    else:
        S = S[:-1]+'X'
        count = 1
        flag = False
        for i in range(len(S)-1):
            if not flag and S[i] == S[i+1]:
                count += 1
                flag = True
            if flag:
                flag = False
        print(K*count)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
count = 0
if S[0] != S[-1]:
    flag = False
    for i in range(len(S)-1):
        if not flag and S[i] == S[i+1]:
            count += 1
            flag = True
        if flag:
            flag = False
    print(K*count)
else:
    if len(S) == 2:
        print(K)
    else:
        flag = False
        for i in range(len(S)-1):
            if not flag and S[i] == S[i+1]:
                count += 1
                flag = True
            if flag:
                flag = False
        print(K*count)

Submission status: Wrong Answer

Solution code:
s=list(input())
k=int(input())
len_s=len(s)
a=0
ans_lst=[]
buf=''

if len_s==1:
    print(k//2)
elif len(set(s))==1:
    print(len_s*k//2)
else:
    for i in range(len_s):
        if s[i]!=buf:
            ans_lst.append(a)
            buf=s[i]
            a=1
        else:
            a+=1
    ans_lst.append(a)
    ans=0
    for v in ans_lst:
        ans+=v//2
    print(ans*k)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
len_s=len(s)-1
ans=0
for i in range(len_s):
    if s[i]==s[i+1]:
        ans+=1
print(-(-ans//2)*k)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
len_s=len(s)
lst=[]
ans_lst=[]
ans=0
for i in range(len_s):
    if s[i] not in lst:
        ans_lst.append(len(lst))
        lst=[s[i]]
    else:
        lst.append(s[i])
ans_lst.append(len(lst))
for n in ans_lst:
    ans+=n//2
print(ans*k)