Problem:


Score : 300 points

Problem Statement

Given is a string S. Let T be the concatenation of K copies of S.
We can repeatedly perform the following operation: choose a character in T and replace it with a different character.
Find the minimum number of operations required to satisfy the following condition: any two adjacent characters in T are different.

Constraints

1 \leq |S| \leq 100

S consists of lowercase English letters.

1 \leq K \leq 10^9

K is an integer.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the minimum number of operations required.

Sample Input 1

issii
2

Sample Output 1

4

T is issiiissii.  For example, we can rewrite it into ispiqisyhi, and now any two adjacent characters are different.

Sample Input 2

qq
81

Sample Output 2

81

Sample Input 3

cooooooooonteeeeeeeeeest
999993333

Sample Output 3

8999939997



Sample input:
issii
2


Sample output:
4

Submission status: Wrong Answer

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

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

pre_s = ''
flag1 = 0
flag2 = 0
flag = True

pre_s = S[0]
flag1 = 1
for s in S[1:]:
    if pre_s == s:
        flag1 += 1
    else:
        break

pre_s = S[-1]
flag2 = 1
for i, s in enumerate(S[::-1]):
    if i == 0:
        continue
    if pre_s == s:
        flag2 += 1
    else:
        break

if flag1 + flag2 % 2 == 0:
    flag = False

pre_s = ''
rep_count = 0
    

for s in S:
    if pre_s == s:
        rep_count += 1
        pre_s = s.upper()
    else:
        pre_s = s

rep_count *= K
if S[0] == pre_s and flag:
    rep_count += K - 1


print(rep_count)

Submission status: Wrong Answer

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

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

pre_s = ''
flag1 = 0
flag2 = 0
flag = True

pre_s = S[0]
flag1 = 1
for s in S[1:]:
    if pre_s == s:
        flag1 += 1
    else:
        break

pre_s = S[-1]
flag2 = 1
for i, s in enumerate(S[::-1]):
    if i == 0:
        continue
    if pre_s == s:
        flag2 += 1
    else:
        break

if flag1 % 2 == 0 and flag2 % 2 == 0:
    flag = False

pre_s = ''
rep_count = 0
    

for s in S:
    if pre_s == s:
        rep_count += 1
        pre_s = s.upper()
    else:
        pre_s = s

rep_count *= K
if S[0] == pre_s and flag:
    rep_count += K - 1


print(rep_count)

Submission status: Wrong Answer

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

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

pre_s = ''
rep_count = 0
flag = True

pre_s = S[0]
rep_count = 1
for s in S[1:]:
    if pre_s == s:
        rep_count += 1
    else:
        break
pre_s = S[-1]
for i, s in enumerate(S[::-1]):
    if i == 0:
        continue
    if pre_s == s:
        rep_count += 1
    else:
        break

if rep_count % 2 == 0:
    flag = False

pre_s = ''
rep_count = 0
    

for s in S:
    if pre_s == s:
        rep_count += 1
        pre_s = s.upper()
    else:
        pre_s = s

rep_count *= K
if S[0] == pre_s and flag:
    rep_count += K - 1


print(rep_count)

Submission status: Wrong Answer

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

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

pre_s = ''
rep_count = 0
flag = True

pre_s = S[0]
rep_count = 1
for s in S[1:]:
    if pre_s == s:
        rep_count += 1
    else:
        break
if rep_count % 2 == 0:
    flag = False

pre_s = ''
rep_count = 0
    

for s in S:
    if pre_s == s:
        rep_count += 1
        pre_s = s.upper()
    else:
        pre_s = s

rep_count *= K
if S[0] == pre_s and flag:
    rep_count += K - 1


print(rep_count)

Submission status: Wrong Answer

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


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

# --------------------------

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

for i in range(1, len(S)):
    if S[i-1] == S[i]:
        cnt_2 += 1
        S[i] = "A"

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

Submission status: Wrong Answer

Solution code:

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

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

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

Submission status: Wrong Answer

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

count = 0
for i,letter in enumerate(s):
    if i != 0:
        if prev_letter == letter:
            count += 1
            prev_letter = '0'
        elif i == len(s)-1 and letter == s[0]:
            count += 1
        else:
            prev_letter = letter
    else:
        prev_letter = letter

print(count * k)

Submission status: Wrong Answer

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

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

else:
    cnt = 0
    pre_s = S[0]
    for s in S[1:]:
        if pre_s == s:
            cnt += 1
            pre_s = ''
        else:
            pre_s = s

    S2 = S*2
    cnt2 = 0
    pre_s = S[0]
    for s in S2[1:]:
        if pre_s == s:
            cnt2 += 1
            pre_s = ''
        else:
            pre_s = s

    joint = cnt2 - cnt * 2

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

Submission status: Wrong Answer

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

cnt = 0
pre_s = S[0]
for s in S[1:]:
    if pre_s == s:
        cnt += 1
        pre_s = ''
    else:
        pre_s = s

S2 = S*2
cnt2 = 0
pre_s = S[0]
for s in S2[1:]:
    if pre_s == s:
        cnt2 += 1
        pre_s = ''
    else:
        pre_s = s
        
joint = cnt2 - cnt * 2

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

Submission status: Wrong Answer

Solution code:


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


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

Submission status: Wrong Answer

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

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

pre_s = ''
rep_count = 0
for s in S:
    if pre_s == s:
        rep_count += 1
        pre_s = s.upper()
    else:
        pre_s = s

rep_count *= K
if S[0] == pre_s:
    rep_count += K - 1


print(rep_count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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


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

Submission status: Wrong Answer

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

# S = S * K

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

pre_s = ''
rep_count = 0
for s in S:
    if not pre_s:
        pre_s = s
        continue
    if pre_s == s:
        rep_count += 1
        pre_s = s.upper()
    else:
        pre_s = s

rep_count *= K
if S[0] == pre_s:
    rep_count += K - 1

print(rep_count)

Submission status: Wrong Answer

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

pre_s = ''
rep_count = 0
for s in S:
    if not pre_s:
        pre_s = s
        continue
    if pre_s == s:
        rep_count += 1
        pre_s = s.upper()
    else:
        pre_s = s

rep_count *= K
if S[0] == pre_s:
    rep_count += K - 1

print(rep_count)

Submission status: Wrong Answer

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

# S = S * K

pre_s = ''
rep_count = 0
for s in S:
    if not pre_s:
        pre_s = s
        continue
    if pre_s == s:
        rep_count += 1
        pre_s = s.upper()
    else:
        pre_s = s

rep_count *= K
if S[0] == pre_s.lower():
    rep_count += K - 1

print(rep_count)

Submission status: Wrong Answer

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

# S = S * K

pre_s = ''
rep_count = 0
for s in S:
    if not pre_s:
        pre_s = s
        continue
    if pre_s == s:
        rep_count += 1
        pre_s = s.upper()
    else:
        pre_s = s

rep_count *= K
if S[0] == pre_s:
    rep_count += K - 1

print(rep_count)

Submission status: Wrong Answer

Solution code:
import copy


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


def count(s):
    s = list(s)
    cnt = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s[i] = '*'
            cnt += 1
    return cnt


def main():
    if len(S) == 1:
        return K // 2
        # if K % 2 == 0:
        #     return K // 2
        # else:
        #     return (K - 1) // 2

    else:
        n1 = count(S)
        n2 = count(S + S)
        return (K - 1) * (n2 - n1) + n1
            

if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

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

# S = S * K

pre_s = ''
rep_count = 0
for s in S:
    if not pre_s:
        pre_s = s
        continue
    if pre_s == s:
        rep_count += 1
        pre_s = s.upper()
    else:
        pre_s = s

rep_count *= K

print(rep_count)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
count = 0
a = 1
b = 1
if s[0]!=s[-1]:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
            s[i+1]='*'
    count*=k
elif len(s)==1:
    count = k//2
else:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            a +=1
        else:
            break
    for i in range(len(s)-1):
        if s[-i-1]==s[-i-2]:
            b +=1
        else:
            break
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
            s[i+1]='*'
    count*=k
    count-=((a//2)+(b//2)-((a+b)//2))*(k-1)
print(count)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
count = 0
a = 1
b = 1
if s[0]!=s[-1]:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
            s[i+1]='*'
    count*=k
else:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            a +=1
        else:
            break
    for i in range(len(s)-1):
        if s[-i-1]==s[-i-2]:
            b +=1
        else:
            break
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
            s[i+1]='*'
    count*=k
    count-=((a//2)+(b//2)-((a+b)//2))*(k-1)
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
case1 = True
time1 = 0
now = s[0]
ans1 = 0
count = 1
for i in range(1,n):
    if s[i] != s[0] and time1 == 0:
        case1 = False
        time1 = i+1

    if s[i] != now:
        ans1 += count//2
        count = 1
        now = s[i]
    if s[i] == now:
        count += 1

if case1:
    print(n*k//2)
elif s[0] != s[n-1]:
    print(ans1*k)
else:
    print(ans1*k-(time1//2 + count//2 - (time1 + count)//2)*(k-1))

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
if s[0] != s[-1]:
    c = 0
    t = 0
    now = s[0]
    for i in range(1,n):
        if s[i] != now:
            c += t//2
            t = 1
            now = s[i]
        else:
            t += 1
    print(c*k)
else:
    case = True
    c = 0
    t = 0
    now = s[0]
    time1 = -1
    for i in range(1, n):
        if s[i] != s[0] and time1 == -1:
            time1 = i+1
            case = False

        if s[i] != now:
            c += t // 2
            t = 1
            now = s[i]
        else:
            t += 1
    c += t//2
    if case:
        print(n*k//2)
    else:
        print(c*k + (t//2 + time1//2 - (t+time1)//2)*(k-1))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
count = 0
if k>=10:
    if s[0]==s[-1]:
        if k%2==0:
            l = s*2
            for i in range(len(l)-1):
                if l[i]==l[i+1]:
                    count+=1
                    l[i+1]='*'
            count*=k//2
        else:
            l = s*2
            for i in range(len(l)-1):
                if l[i]==l[i+1]:
                    count+=1
                    l[i+1]='*'
            count*=k//2
            m = list(l[-1])+s
            for i in range(len(m)-1):
                if m[i]==m[i+1]:
                    count+=1
                    m[i+1]='*'
    else:
        for i in range(len(s)-1):
            if s[i]==s[i+1]:
                count+=1
                s[i+1]='*'
        count*=k
else:
    l = s*k
    for i in range(len(l)-1):
        if l[i]==l[i+1]:
            count+=1
            l[i+1]='*'
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
if s[0] != s[-1]:
    c = 0
    t = 0
    now = s[0]
    for i in range(1,n):
        if s[i] != now:
            c += t//2
            t = 1
            now = s[i]
        else:
            t += 1
    print(c*k)
else:
    case = True
    c = 0
    t = 0
    now = s[0]
    time1 = -1
    for i in range(1, n):
        if s[i] != s[0] and time1 == -1:
            time1 = i+1
            case = False

        if s[i] != now:
            c += t // 2
            t = 1
            now = s[i]
        else:
            t += 1
    c += t//2
    if case:
        print(n*k//2)
    else:
        print(c*k + t//2 + time1//2 - (t+time1)//2)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
if s[0] != s[-1]:
    c = 0
    t = 0
    now = s[0]
    for i in range(1,n):
        if s[i] != now:
            c += t//2
            t = 1
            now = s[i]
        else:
            t += 1
    print(c*k)
else:
    case = True
    c = 0
    t = 0
    now = s[0]
    time1 = -1
    for i in range(1, n):
        if s[i] != s[0] and time1 == -1:
            time1 = i+1
            case = False

        if s[i] != now:
            c += t // 2
            t = 1
            now = s[i]
        else:
            t += 1
    c += t//2
    if case:
        print(n*k//2)
    else:
        if t%2 == 1 and time1%2 == 1:
            print(c*k + k-1)
        else:
            print(c*k)

Submission status: Wrong Answer

Solution code:
s = str(input())
K = int(input())
S = s+s[0]
count = 0
result = 0

for i,x in enumerate(S[1:]):
    count += 1
    if x!=S[i]:
        result += count//2
        count=0
count += 1
result += count//2
result = result*K
if len(s)==1:
	print(K//2)
else:
	print(result if count%2==1 else result-1)

Submission status: Wrong Answer

Solution code:
s = str(input())
K = int(input())
S = s+s[0]
count = 0
result = 0

for i,x in enumerate(S[1:]):
    count += 1
    if x!=S[i]:
        result += count//2
        count=0
count += 1
result += K*(count//2)
if len(s)==1:
	print(K//2)
else:
	print(result if count%2==1 else result-1)

Submission status: Wrong Answer

Solution code:
s = str(input())
K = int(input())
S = s+s[0]
count = 0
result = 0
for i,x in enumerate(S[1:]):
    count += 1
    if x!=S[i]:
        result += count//2
        count=0
result += count//2
print(result*K)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
from queue import PriorityQueue
from fractions import gcd
inf, eps, mod = 10 ** 20, 1.0 / 10**10, 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def _cumsum(l): return list(itertools.accumulate(l))

"""
なかのものと端のもの
両端が一緒かどうか
一緒なら、K-1個変える
中を変える/2切り下げ
まず、端が一緒か
"""
S = input()
K = _I()
ans = 0

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

if S[0] == S[-1]:
    if S[-1] == S[-2]:
        if S[-2] != S[-3]:
            ans += 1
    S = S[:-1] + '?'
    ans += K - 1
    # 端は上で変えられた
else:
    pass

# 端変えないので、中だけ
previous = 'HOGE'
for s in S:
    if s == previous:
        ans += K
        previous = 'HOGE'
    else:
        previous = s
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
ans = 0
if len(set(s)) == 1:
    print(len(s)*k//2)
    exit()
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        s[i+1] = "A"
        ans += 1
if s[0] == s[-1]:
    print(ans*k + k - 1)
else:
    print(ans*k)

"""
aaabba
a#ab#a a#ab#a

issii
is#i# is#i#

aaabaaa
a#aba#a #a#ba#a #a#ba#a
"""

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
ans = 0
if len(set(s)) == 1:
    print(len(s)*k//2)
    exit()
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        s[i+1] = "A"
        ans += 1
if s[0] == s[-1]:
    print(ans*k + k - 1)
else:
    print(ans*k)

"""
a#ab#a a#ab#a

is#i# is#i#
"""

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
from queue import PriorityQueue
from fractions import gcd
inf, eps, mod = 10 ** 20, 1.0 / 10**10, 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def _cumsum(l): return list(itertools.accumulate(l))

"""
なかのものと端のもの
両端が一緒かどうか
一緒なら、K-1個変える
中を変える/2切り下げ
まず、端が一緒か
"""
S = input()
K = _I()
ans = 0

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

if K == 1:
    # その中でしか判断しない
    previous = 'HOGE'
    for s in S:
        if s == previous:
            ans += K
            previous = 'HOGE'
        else:
            previous = s
    print(ans)
    exit()

if S[0] == S[-1]:
    if S[-1] == S[-2]:
        ans += 1
    S = S[:-1] + '?'
    ans += K - 1
    # 端は上で変えられた
else:
    pass

# 端変えないので、中だけ
previous = 'HOGE'
for s in S:
    if s == previous:
        ans += K
        previous = 'HOGE'
    else:
        previous = s
print(ans)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
from queue import PriorityQueue
from fractions import gcd
inf, eps, mod = 10 ** 20, 1.0 / 10**10, 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def _cumsum(l): return list(itertools.accumulate(l))

"""
なかのものと端のもの
両端が一緒かどうか
一緒なら、K-1個変える
中を変える/2切り下げ
まず、端が一緒か
"""
S = input()
K = _I()

if len(S) == 1:
    print(math.floor(K//2))
    exit()
ans = 0
if S[0] == S[-1]:
    if S[-1] == S[-2]:
        ans += 1
    S = S[:-1] + '?'
    ans += K - 1
    # 端は上で変えられた
else:
    pass

# 端変えないので、中だけ
previous = 'HOGE'
for s in S:
    if s == previous:
        ans += K
        previous = 'HOGE'
    else:
        previous = s
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
ans = 0
if len(set(s)) == 1:
    print(len(s)*k//2)
    exit()
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        s[i+1] = "A"
        ans += 1
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] = "A"
        ans += 1
if s[0] != s[-1]:
    print(ans*k)
else:
    print(ans*k-1)

Submission status: Wrong Answer

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

def nasu(L):
  ans = 0
  N = len(L)
  t = L[0]
  cnt = 1
  for i in range(1, N):
    if t == L[i]:
      cnt += 1
    else:
      ans += cnt // 2
      cnt = 1
    t = L[i]
  ans += cnt // 2
  return ans 

a = nasu(S)
b = nasu(S + S)

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import math

mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def cnt(s, k):
    s = s * k
    ans = 0
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            s[i+1] = ' '
            ans += 1
    return ans


def main():
    s = [i for i in input()]
    k = int(input())
    if len(s) == 1:
        print(k // 2)
        return 
    if k <= 100:
        ans = cnt(s, k)
        print(ans)
        return
    cnt50 = cnt(s, 50)
    cnt51 = cnt(s, 51)
    dif = cnt51 - cnt50
    print(cnt50 + (k - 50) * dif)

main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import math

mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def cnt(s, k):
    s = s * k
    ans = 0
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            s[i+1] = ' '
            ans += 1
    return ans

def main():
    s = [i for i in input()]
    k = int(input())
    if k <= 100:
        ans = cnt(s, k)
        print(ans)
        return
    cnt50 = cnt(s, 50)
    cnt51 = cnt(s, 51)
    dif = cnt51 - cnt50
    print(cnt50 + (k - 50) * dif)

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
S2=S[:]+S[:]
S3=S[:]+S[:]+S[:]
count=0
for i in range(len(S)-1):
    if(S[i]==S[i+1]):
        S[i+1]="#"
        count+=1
count2=0
for i in range(len(S2)-1):
    if(S2[i]==S2[i+1]):
        S2[i+1]="#"
        count2+=1
count3=0
for i in range(len(S3)-1):
    if(S3[i]==S3[i+1]):
        S3[i+1]="#"
        count3+=1
#print(S)
N=count3-count2
E=count2-N

flag=0
if(S[0]==S[len(S)-1]):
    flag=1

if(flag==0):
    print(count*K)
else:
    if(K==1):
        print(count)
    else:
        print(N*(K-1)+E)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
s = input()
k = int(input())
l = [[k, len(list(g))] for k, g in groupby(s)]
ans = 0
ans2 = 0
for i in range(len(l)):
  if l[i][1] > 1:
    ans += l[i][1] // 2
if len(l) > 1:
  if l[0][0] == l[-1][0]:
    if l[0][1] % 2 == 1 and  l[-1][1] % 2 == 1 :
        ans2 = k - 1
if len(s) == 1:
  print(k // 2)
elif len(l) == 1:
  if l[0][1] % 2 == 1:
    print(((l[0][1] // 2) * k + (k - 1)))
  else:
    print((l[0][1] // 2) * k)
else:
  print(ans * k + ans2)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
s = input()
k = int(input())
l = [[k, len(list(g))] for k, g in groupby(s)]
ans = 0
ans2 = 0
for i in range(len(l)):
  if l[i][1] > 1:
    ans += l[i][1] // 2
if len(l) > 1:
  if l[0][0] == l[-1][0]:
    if l[0][1] % 2 == 1 and  l[-1][1] % 2 == 1 :
        ans2 = k - 1
if len(s) == 1:
  print(k // 2)
elif len(l) == 1:
  if l[0][1] % 2 == 1:
    print(k // 2 * k + k - 1)
  else:
    print(k // 2 * k)
else:
  print(ans * k + ans2)

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]="#"
        count+=1
#print(S)

flag=0
if(S[0]==S[len(S)-1]):
    flag=1

if(flag==0):
    print(count*K)
else:
    if(K==1):
        print(count)
    elif(K%2==0):
        print((2*count+1)*(K//2))
    else:
        print((2*count+1)*(K//2)+count)

Submission status: Wrong Answer

Solution code:
def main():
    s = str(input())
    N = int(input())
    st = []
    moji = s[0]
    a = len(s)
    count = 1
    for i in range(a-1):
        if moji == s[i+1]:
            count += 1
        else:
            st.append(count)
            moji = s[i+1]
            count = 1
    st.append(count)
    ans = 0
    for i in st:
        ans += i//2
    ans *= N
    if len(st) != 1 and s[0] == s[-1]:
        ans += ((st[0]+st[-1])//2-st[0]//2-st[-1]//2)*(N-1)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    s = str(input())
    N = int(input())
    st = []
    moji = s[0]
    a = len(s)
    count = 1
    for i in range(a-1):
        if moji == s[i+1]:
            count += 1
        else:
            st.append(count)
            moji = s[i+1]
            count = 1
    st.append(count)
    ans = 0
    for i in st:
        ans += i//2
    ans *= N
    if s[0] == s[-1] and st[-1]%2 == 1:
        ans += N-1

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

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

li = []
onaji = 1
for i in range(len(S)-1):
  if S[i:i+1] == S[i+1:i+2]:
    onaji += 1
  else:
    li.append(onaji)
    onaji = 1
    
# Sが全て同じ文字の場合
if S[-1:] == S[0:1]:
  if not li:
    li.append(onaji * K)
    print(li[0] // 2)
    sys.exit()   
  else:
    li.append(onaji + li[0])
    first = li.pop(0)
    last = onaji
  
ans = 0
for l in li:
  ans += (l // 2) * K

if S[-1:] == S[0:1] and last % 2 != 0 and first % 2 != 0:
  ans -= 1
  
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

list = []
onaji = 1
for i in range(len(S)-1):
  if S[i:i+1] == S[i+1:i+2]:
    onaji += 1
  else:
    list.append(onaji)
    onaji = 1
    
# Sが全て同じ文字の場合
if S[-1:] == S[0:1]:
  if not list:
    list.append(onaji * K)
    print(list[0] // 2)
    sys.exit()   
  else:
    list.append(onaji + list[0])
    first = list.pop(0)
    last = onaji
  
ans = 0
for l in list:
  ans += (l // 2) * K

if S[-1:] == S[0:1] and last % 2 != 0 and first % 2 != 0:
  ans -= 1
  
print(ans)

Submission status: Wrong Answer

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

if(len(set(S)) == 1):
    print(len(S) // 2 * K)
else:
    ans = 0
    cnt = 1
    a = []
    for i in range(len(S)-1):
        if(S[i] == S[i+1]):
            cnt += 1
        else:
            a.append(cnt)
            cnt = 1
    a.append(cnt)

    for i in a:
        ans += (i//2)*K

    if (S[0] == S[-1]):
        ans -= (a[0]//2 + a[-1]//2  - (a[0] + a[-1])//2)*(K-1)

    print(ans)

Submission status: Wrong Answer

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

if(n == 1):
  print(0)
  exit()

if(len(strs) == 1):
  print(1)
  exit()

res = 0
for k, g in itertools.groupby(strs):
  cnt = len(list(g))
  if(cnt >= 2):
    res += cnt // 2
print(res * n)

Submission status: Wrong Answer

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

if(len(set(S)) == 1):
    print(len(S) // 2 * K)
else:
    m = 0
    ans = 0
    if(S[0] == S[-1]):
        l = 0
        r = 1
        while(S[l] == S[l+1]):
            l += 1
        while(S[-r] == S[-r-1]):
            r += 1
        r -= 1
        m = l//2 + r//2 - (l+r)//2
        m *= K - 1

    for i in range(len(S)-1):
        if(S[i] == S[i+1]):
            ans += 1
            S[i+1] = "3"
    ans *= K
    ans -= m
    print(ans)

Submission status: Wrong Answer

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

if(len(set(S)) == 1):
    print(len(S) // 2 * K)
else:
    m = 0
    ans = 0
    if(S[0] == S[-1]):
        l = 0
        r = 0
        while(S[l] == S[l+1]):
            l += 1
        while(S[-r] == S[-r-1]):
            r += 1
        l += 1
        r += 1
        m = l//2 + r//2 - (l+r)//2
        m *= K - 1

    for i in range(len(S)-1):
        if(S[i] == S[i+1]):
            ans += 1
            S[i+1] = "3"
    ans *= K
    ans -= m
    print(ans)

Submission status: Wrong Answer

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

if(len(set(S)) == 1):
    print(len(S) // 2 * K)
else:
    m = 0
    ans = 0
    if(S[0] == S[-1]):
        l = 0
        r = 0
        while(S[l] == S[l+1]):
            l += 1
        while(S[-r] == S[-r-1]):
            r += 1
        m = l + r - (l+r)//2
        m *= K - 1

    for i in range(len(S)-1):
        if(S[i] == S[i+1]):
            ans += 1
            S[i+1] = "3"
    ans *= K
    ans -= m
    print(ans)

Submission status: Wrong Answer

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

if(len(set(S)) == 1):
    print(len(S) // 2 * K)
else:
    m = 0
    ans = 0
    if(S[0] == S[-1]):
        l = 0
        r = 0
        while(S[l] == S[l+1]):
            l += 1
        while(S[-r] == S[-r-1]):
            r += 1
        m = l + r - (l+r)
        m *= K - 1

    for i in range(len(S)-1):
        if(S[i] == S[i+1]):
            ans += 1
            S[i+1] = "3"
    ans *= K
    ans -= m
    print(ans)

Submission status: Wrong Answer

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

if(len(set(S)) == 1):
    print(len(S) // 2 * K)
else:
    m = 0
    ans = 0
    if(S[0] == S[-1]):
        l = 0
        r = 0
        while(S[l] == S[l+1]):
            l += 1
        while(S[-r] == S[-r-1]):
            r += 1
        m = l//2 + r//2 - (l+r)//2
        m *= K - 1

    for i in range(len(S)-1):
        if(S[i] == S[i+1]):
            ans += 1
            S[i+1] = "3"
    ans *= K
    ans -= m
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
S = list(s)
K = int(input())
cnt1 = 0
cnt2 = 0
if len(set(S)) == 1:
  print(len(S) // 2 * K)
  exit()
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    S[i+1] = "#"
    cnt1 += 1
SS = list(s + s)
for i in range(len(S)*2-1):
  if SS[i] == SS[i+1]:
    SS[i+1] = "#"
    cnt2 += 1
print(cnt1 + (cnt2 - cnt1) * (K - 1))