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()
N = len(s)
K = int(input())
if s[0] != s[-1]:
    count = 1
    ans = 0
    now = s[0]
    for i in range(1,len(s)):
        if now == s[i]:
            count += 1
        else:
            now = s[i]
            ans += count//2
            count = 1
    if count != 1:
        ans += count//2
    print(ans*K)
else:
    ans = 0
    fcount = 1
    bcount = 1
    now = s[0]
    start = N-1
    for i in range(1,N):
        if s[i] == now:
            fcount += 1
        else:
            start = i
            break
    if start == N-1:
        print(K*(fcount//2))
    else:
        now = s[-1]
        end= 0
        for i in range(N-2,-1,-1):
            if s[i] == now:
                bcount += 1
            else:
                end = i
                break   
        ans = fcount//2 + bcount//2 + ((fcount+bcount)//2)*(K-1)
        now = s[start]
        count = 1
        mcount = 0
        for i in range(start+1,end+1):
            if s[i] == now:
                count += 1
            else:
                mcount += count//2
                count = 1
                now = s[i]
        if count != 1:
            mcount += count//2
        print(ans + mcount*K)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
if s[0] != s[len(s)-1]:
  count = 0
  cur = '*'
  for i in range(len(s)):
    if cur == s[i]:
      count += 1
      cur = '*'
    else:
      cur = s[i]
  print(count*k)
else:
  flag = True
  for i in range(len(s)-1):
    if s[i] != s[i+1]:
      flag = False
      break
  if flag:
    print(len(s)*k//2)
  else:
    ans = 0
    t = s[0]
    mae = 0
    ushiro = len(s)-1
    for i in range(len(s)-2,-1,-1):
      if s[i] == t:
        ushiro = i
      else:
        break
    for j in range(1,len(s)):
      if s[j] == t:
        mae = j
      else:
        break
    count = 0
    cur = s[mae]
    for i in range(mae+1,ushiro):
      if cur == s[i]:
        count += 1
        cur = '*'
      else:
        cur = s[i]
    ans = count*k
    ans += (len(s)-ushiro+mae+1)*(k-1)//2+(mae+1)//2+(len(s)-ushiro)//2
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
if s[0] != s[len(s)-1]:
  count = 0
  cur = '*'
  for i in range(len(s)):
    if cur == s[i]:
      count += 1
      cur = '*'
    else:
      cur = s[i]
  print(count*k)
else:
  flag = True
  for i in range(len(s)-1):
    if s[i] != s[i+1]:
      flag = False
      break
  if flag:
    print(len(s)*k//2)
  else:
    ans = 0
    t = s[0]
    mae = 0
    ushiro = len(s)-1
    for i in range(len(s)-2,-1,-1):
      if s[i] == t:
        ushiro = i
      else:
        break
    for j in range(1,len(s)):
      if s[j] == t:
        mae = j
      else:
        break
    count = 0
    cur = '*'
    for i in range(mae+1,ushiro):
      if cur == s[i]:
        count += 1
        cur = '*'
      else:
        cur = s[i]
    ans = count*k
    ans += (len(s)-ushiro+mae+1)*(k-1)//2+(mae+1)//2+(len(s)-ushiro)//2
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
if s[0] != s[len(s)-1]:
  count = 0
  cur = '*'
  for i in range(1,len(s)):
    if cur == s[i]:
      count += 1
      cur = '*'
    else:
      cur = s[i]
  print(count*k)
else:
  flag = True
  for i in range(len(s)-1):
    if s[i] != s[i+1]:
      flag = False
      break
  if flag:
    print(len(s)*k//2)
  else:
    ans = 0
    t = s[0]
    mae = 0
    ushiro = len(s)-1
    for i in range(len(s)-2,-1,-1):
      if s[i] == t:
        ushiro = i
      else:
        break
    for j in range(1,len(s)):
      if s[j] == t:
        mae = j
      else:
        break
    count = 0
    cur = '*'
    for i in range(mae+1,ushiro):
      if cur == s[i]:
        count += 1
        cur = '*'
      else:
        cur = s[i]
    ans = count*k
    ans += (len(s)-ushiro+mae+1)*(k-1)//2+(mae+1)//2+(len(s)-ushiro)//2
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def calc(N):
    return sum(int(x) for x in str(N))


def main():
    # sys.stdin = open("sample.txt")
    S = Scanner.string()
    K = Scanner.int()
    if len(Counter(S)) == 1:
        print(len(S) * K // 2)
        return
    ans = 0
    if S[0] == S[-1]:
        c1 = 1
        for i in range(1, len(S)):
            if S[i] == S[0]:
                c1 += 1
            else:
                break
        c2 = 1
        for j in reversed(range(len(S)-1)):
            if S[j] == S[-1]:
                c2 += 1
            else:
                break
        ans = c1 // 2
        ans += c2 // 2
        ans += (c1 + c2) // 2 * (K-1)
        c3 = 0
        c = ""
        for k in range(i, j + 1):
            if S[k] == c:
                c3 += 1
            else:
                ans += c3 // 2 * K
                c = S[k]
                c3 = 1
        ans += c3 // 2 * K
        print(ans)
        return
    else:
        c = "0"
        cnt = 0
        for i in range(len(S)):
            if c == S[i]:
                cnt += 1
            else:
                ans += cnt // 2
                c = S[i]
                cnt = 1
        print(ans * K)
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

if len(s) == 1:
    print(math.floor(k/2))
    exit()
if len(s) == 2:
    if s[0] == s[1]:
        print(k)
        exit()
    else:
        print(0)
        exit()
ans=0
last=s[0]
length=1
change=0
for i in range(1,len(s)):
    if s[i] == last:
        length+=1
    else:
        change += math.floor(length/2)
        length=1
    last=s[i]

change += math.floor(length/2)
ans=change*k
if s[0] != s[-1]:
    print(ans)
    exit()
l_length=1
last=s[0]
for i in range(1,len(s)):
    if s[i] == last:
        l_length+=1
    else:
        break
r_length=1
last=s[-1]
for i in range(len(s)-2,-1,-1):
    if s[i] == last:
        r_length+=1
    else:
        break

if l_length%2==1 and r_length%2==1:
    print(ans+k-1)
    exit()

print(ans)

Submission status: Wrong Answer

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

if len(s) == 1:
    print(math.floor(k/2))
    exit()
if len(s) == 2:
    if s[0] == s[1]:
        print(k)
        exit()
    else:
        print(0)
        exit()
ans=0
last=s[0]
length=1
change=0
for i in range(1,len(s)):
    if s[i] == last:
        length+=1
    else:
        change += math.floor(length/2)
        length=1
    last=s[i]

change += math.floor(length/2)
ans=change*k
if s[0] != s[-1]:
    print(ans)
    exit()

l_length=1
last=s[0]
for i in range(1,len(s)):
    if s[i] == last:
        length+=1
    else:
        break
r_length=1
last=s[-1]
for i in range(len(s)-2,-1,-1):
    if s[i] == last:
        r_length+=1
    else:
        break

if l_length%2==1 and r_length%2==1:
    print(ans+k-1)
    exit()

print(ans)

Submission status: Wrong Answer

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

if len(s) == 1:
    print(math.floor(k/2))
    exit()
if len(s) == 2:
    if s[0] == s[1]:
        print(k)
        exit()
    else:
        print(0)
        exit()

ans=0
last=s[0]
length=1
change=0
for i in range(1,len(s)):
    if s[i] == last:
        length+=1
    else:
        change += math.floor(length/2)
        length=1
    last=s[i]

change += math.floor(length/2)

ans=change*k
if s[0] != s[-1]:
    print(ans)
    exit()

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

print(ans)

Submission status: Wrong Answer

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

if len(s) == 1:
    print(math.floor(k/2))
    exit()
if len(s) == 2:
    if s[0] == s[1]:
        print(k)
        exit()
    else:
        print(0)

ans=0
last=s[0]
length=1
change=0
for i in range(1,len(s)):
    if s[i] == last:
        length+=1
    else:
        change += math.floor(length/2)
        length=1
    last=s[i]

change += math.floor(length/2)

ans=change*k
if s[0] != s[-1]:
    print(ans)
    exit()

if s[0] != s[1] or s[-1] != s[-2]:
    print(ans+k-1)
    exit()

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = list(sr())
K = ir()

base = 0
cur = ''
T = S.copy()
for i in range(len(T)):
    if T[i] == cur:
        T[i] = '_'
        base += 1
    cur = T[i]

if len(set(S)) == 1:
    answer = len(S) * K // 2
elif S[0] != S[-1]:
    answer = base * K
else:
    #Sの先頭と末尾が同じ
    T = S.copy()
    head = 1; tail = 1
    for i in range(1, len(T)):
        if T[i] == T[0]:
            head += 1
        else:
            break
    for i in range(-2, -len(T)-1, -1):
        if T[i] == T[-1]:
            tail += 1
        else:
            break
    
    answer = base * K + (head//2 + tail//2 - (head+tail)//2) * (K-1)

print(answer)
# 24

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def calc(N):
    return sum(int(x) for x in str(N))


def main():
    # sys.stdin = open("sample.txt")
    S = Scanner.string()
    K = Scanner.int()
    N = len(S)
    if N == 1:
        print(K-1)
        return
    cnt = 0
    i = 0
    while i < N-1:
        if S[i-1] == S[i]:
            cnt += 1
            i += 1
        i += 1
    ans = cnt * K
    if S[0] == S[N - 1]:
        if not(S[0] == S[1] or S[N-2] == S[N-1]):
            ans += K-1
    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Feb  2 18:37:08 2020

@author: H_Hoshgi

"""

def count_change(input_list):
    string_list = input_list[:]
    counter = 0
    for i in range(len(string_list)-1):
        if string_list[i] == string_list[i+1]:
            counter += 1
            string_list[i+1] = "_"
        else:
            pass
    counter = counter*K
    if (string_list[0] == string_list[-1]):
        counter += K-1
    else:
        pass
    return counter

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

if len(S) == 1:
    S = S*K
    K = 1
else:
    pass

S_list = [i for i in S]
S_list_inverse = S_list[::-1]

#print(S_list)
#print(S_list_inverse)
#min(count_change(S_list),count_change(S_list_inverse))
#print(S_list)
#print(S_list_inverse)
print(min(count_change(S_list),count_change(S_list_inverse)))

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
check = 0
ans = 0
St = []
for s in S:
    if s != check:
        check = s
        St.append(s)
    else:
        check = 0
        ans += 1
        St.append(0)
ans *= K
if St[0] == St[-1]:
    ans += K - 1
if len(S) == 1:
    ans = K // 2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
check = 0
ans = 0
St = []
for s in S:
    if s != check:
        check = s
        St.append(s)
    else:
        check = 0
        ans += 1
        St.append(0)
ans *= K
if St[0] == St[-1]:
    ans += K - 1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Feb  2 18:37:08 2020

@author: H_Hoshgi

"""

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

if len(S) == 1:
    S = S*K
    K = 1
else:
    pass

S_list = [i for i in S]

counter = 0

for i in range(len(S_list)-1):
    if S_list[i] == S_list[i+1]:
        counter += 1
        S_list[i+1] = "_"
    else:
        pass
counter = counter*K
if (S_list[0] == S_list[-1]):
    counter += K-1
else:
    pass

print(counter)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Feb  2 18:37:08 2020

@author: H_Hoshigi
"""

row_S = input()
S = [i for i in row_S]
K = int(input())

counter = 0

if len(S) == 1:
    pass
else:
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            counter += 1
            S[i+1] = "_"
        else:
            pass
    counter = counter*K
    if (S[0] == S[-1]):
        counter += K-1
    else:
        pass

print(counter)

Submission status: Wrong Answer

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

ans = 0
flag = False
before = ""
for i in range(len(s)):
    if s[i] == before:
        if flag:
            flag = False
        else:
            flag = True
            ans += 1
    else:
        flag = False
    before = s[i]

n = len(s)
if len(set(list(s))) == 1:
    print(len(s) * k // 2)
    exit()
elif s[0] == s[-1]:
    a = 0
    b = 0
    for i in range(len(s)):
        if s[i] == s[i+1]:
            a += 1
        else:
            break
    for i in range(len(s)):
        if s[n-1-i] == s[n-2-i]:
            b += 1
        else:
            break
    if a % 2 == 1 and b % 2 == 1:
        print(ans*k + (k-1))
    else:
        print(ans*k)
else:
    print(ans * k)

Submission status: Wrong Answer

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

ans = 0
flag = False
before = ""
for i in range(len(s)):
    if s[i] == before:
        if flag:
            flag = False
        else:
            flag = True
            ans += 1
    else:
        flag = False
    before = s[i]

n = len(s)
if len(set(list(s))) == 1:
    print(len(s) * k // 2)
    exit()
elif s[0] == s[-1]:
    a = 0
    b = 0
    for i in range(len(s)):
        if s[i] == s[i+1]:
            a += 1
        else:
            break
    for i in range(len(s)):
        if s[n-1-i] == s[n-2-i]:
            b += 1
        else:
            break
    if a % 2 == 1 and b % 2 == 1:
        print(ans*k - (k-1))
    else:
        print(ans*k)
else:
    print(ans * k)

Submission status: Wrong Answer

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

ans = 0
flag = False
before = ""
for i in range(len(s)):
    if s[i] == before:
        if flag:
            flag = False
        else:
            flag = True
            ans += 1
    else:
        flag = False
    before = s[i]

if len(set(list(s))) == 1:
    print(len(s) * k // 2)
    exit()


print(ans * k)

Submission status: Wrong Answer

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

ans = 0
flag = False
before = ""
for i in range(len(s)):
    if s[i] == before:
        if flag:
            flag = False
        else:
            flag = True
            ans += 1
    else:
        flag = False
    before = s[i]

if len(set(list(s))) == 1:
    print(len(s) * k // 2)


print(ans * k)

Submission status: Wrong Answer

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

ans = 0
flag = False
before = ""
for i in range(len(s)):
    if s[i] == before:
        if flag:
            flag = False
        else:
            flag = True
            ans += 1
    else:
        flag = False
    before = s[i]

if set(list(s)) == 1:
    print(len(s) * k // 2)


print(ans * k)

Submission status: Wrong Answer

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

ans = 0
flag = False
before = ""
for i in range(len(s)):
    if s[i] == before:
        if flag:
            flag = False
        else:
            flag = True
            ans += 1
    else:
        flag = False
    before = s[i]


print(ans * k)

Submission status: Wrong Answer

Solution code:
s = input()
k = s
d = list(k*2)
e = list(s[-1] + s)
n = int(input())
endans = 0
for i in range(1,len(e)-1):
    if e[i] == e[i+1]:
        e[i+1] = "0"
        endans += 1
dans = 0
for i in range(len(d)-1):
    if d[i] == d[i+1]:
        d[i+1] = "0"
        dans += 1
if n % 2 == 0:
    ans = dans * n // 2
else:
    ans = dans * (n-1)//2 + endans
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if len(set(s)) == 1:
    ans = len(s) * k //2
else:
    if s[0] != s[-1]:
        i = 0
        cnt = 0
        while i < len(s) - 1:
            if s[i] == s[i+1]:
                cnt += 1
                i += 2
            else:
                i += 1
        ans = cnt * k
    else:
        i = 0
        cnt = 0
        while i < len(s) - 1:
            if s[i] == s[i+1]:
                cnt += 1
                i += 2
            else:
                i += 1
        tmp = cnt * k

        # # s_head == s_tail
        # s_head = s[0]
        # s_tail = s[-1]
        # a, b = 0, 0
        # for val in s:
        #     if val == s_head:
        #         a += 1
        #     else:
        #         break
        # for val in s[::-1]:
        #     if val == s_tail:
        #         b += 1
        #     else:
        #         break
        
        cnt_s = 0
        i = 0
        while i < len(s) - 1:
            if s[i] == s[i+1]:
                cnt_s += 1
                i += 2
            else:
                i += 1
        
        s_2 = s * 2
        cnt_s_2 = 0
        i = 0
        while i < len(s_2) - 1:
            if s_2[i] == s_2[i+1]:
                cnt_s_2 += 1
                i += 2
            else:
                i += 1

        diff = cnt_s_2 - 2 * cnt_s
        ans = tmp - diff * (k-1)

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
t = s * 2

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


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

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

print(ret)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
c = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        c += 1
        s[i + 1] = '?'

if len(set(s)) == 1:
    print(len(s) * (k // 2))
elif s[0] != s[1]:
    print(c * k)
else:
    print(c * k + (k - 1))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
c = 0
s *= 2
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        c += 1
        s[i+1] = '?'

if k % 2 == 0:
    print(c * (k // 2))
else:
    print(c * (k // 2) + c // 2)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
c = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        c += 1
        s[i+1] = '?'

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

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

if c == len(s):
    print(c * k // 2)

elif s[0] != s[-1]:
    print(ans * k)
else:
    a = 0
    for i in range(len(s)-1):
        if s[0] == s[i]:
            a +=1
        else:
            break

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

    print(c * k - (a // 2 + b // 2 - (a+b) // 2) * (k - 1))

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 == len(s):
    print(c * k // 2)

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

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

    print(c * k - (a // 2 + b // 2 - (a+b) // 2) * (k - 1))

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 == len(s):
    print(c * k // 2)

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

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

    print(c * k - (a // 2 + b // 2 - (a+b) // 2) * (k - 1))

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 == len(s):
    print(c * k // 2)
elif s[0] != s[-1]:
    print(c * k)
else:
    a = 0
    for i in range(len(s)-1):
        if s[0] == s[i]:
            a +=1
        else:
            break

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

    print(c * k - (a // 2 + b // 2 - (a+b) // 2) * (k - 1))

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 == len(s):
    print(c * (k // 2))
elif c == 2:
    ans += 1
    print(ans * k)
else:
    ans += c // 2
    print(ans * k)

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 == len(s):
    print(c * k // 2)
elif c == 2:
    ans += 1
    print(ans * k)
else:
    ans += c // 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()

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

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

diff = cnt_even - cnt_odd * 2
print(cnt_odd * K - diff * (K - 1))

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
if len(set(S)) == 1:
    print(len(S) * K // 2)
    exit()

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

cnt_even = 0
S *= 2
i = 0
while i + 1 < len(S):
    if S[i] == S[i + 1]:
        cnt_even += 1
        i += 2
    else:
        i += 1
if K % 2 == 0:
    print(cnt_even * (K // 2))
else:
    print(cnt_even * (K // 2) + cnt_odd)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
if len(S) == 1:
    print(K // 2)
    exit()

i = 0
cnt_odd = 0
while i + 1 < len(S):
    if S[i] == S[i + 1]:
        cnt_odd += 1
        i += 2
    else:
        i += 1
if K == 1:
    print(cnt_odd)
    exit()

cnt_even = 0
S *= 2
i = 0
while i + 1 < len(S):
    if S[i] == S[i + 1]:
        cnt_even += 1
        i += 2
    else:
        i += 1
if K % 2 == 0:
    print(cnt_even * (K // 2))
else:
    print(cnt_even * (K // 2) + cnt_odd)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
if S == 1:
    print(K // 2)
    exit()
    
i = 0
cnt_odd = 0
while i + 1 < len(S):
    if S[i] == S[i + 1]:
        cnt_odd += 1
        i += 2
    else:
        i += 1
if K == 1:
    print(cnt_odd)
    exit()

cnt_even = 0
S *= 2
i = 0
while i + 1 < len(S):
    if S[i] == S[i + 1]:
        cnt_even += 1
        i += 2
    else:
        i += 1
if K % 2 == 0:
    print(cnt_even * (K // 2))
else:
    print(cnt_even * (K // 2) + cnt_odd)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
i = 0
cnt_odd = 0
while i + 1 < len(S):
    if S[i] == S[i + 1]:
        cnt_odd += 1
        i += 2
    else:
        i += 1
if K == 1:
    print(cnt_odd)
    exit()
    
cnt_even = 0
S *= 2
i = 0
while i + 1 < len(S):
    if S[i] == S[i + 1]:
        cnt_even += 1
        i += 2
    else:
        i += 1
if K % 2 == 0:
    print(cnt_even * (K // 2))
else:
    print(cnt_even * (K // 2) + cnt_odd)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
i = 0
cnt_odd = 0
while i + 1 < len(S):
    if S[i] == S[i+1]:
       cnt_odd += 1
       i += 2
    else:
        i += 1
cnt_even = 0
S *= 2
i = 0
while i + 1 < len(S):
    if S[i] == S[i+1]:
       cnt_even += 1
       i += 2
    else:
        i += 1
if K % 2 == 0:
    print(cnt_even * (K // 2))
else:
    print(cnt_even * (K // 2) + cnt_odd)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
i = 0
cnt = 0
while i + 1 < len(S):
    if S[i] == S[i+1]:
       cnt += 1
       i += 2
    else:
        i += 1
print(cnt * K)

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)


if __name__ == '__main__':
    main()