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=int(input())
ans=0
flg=0
if len(s) == 1:
  print(n//2)
else:
  for i in range(1,len(s)):
    if flg == 0 and s[i] == s[i-1]:
      flg = 1
    elif flg != 0 and s[i] == s[i-1]:
      flg += 1
    elif flg != 0:
      ans += -(-flg//2)
      flg = 0
  ans += -(-flg//2)
  ans *= n
  if flg != 0 and flg % 2 == 0 and s[0] == s[-1]:
    ans += n//2
  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = str(input())
k = int(input())
flag = [0 for _ in range(len(s))]
count = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        if not flag[i]:
            flag[i+1] = 1
            count += 1
if 2 < len(s):
    if s[0] == s[-1] and s[-1] != s[-2]:
        count += 1
    
print(k*count)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
 
ans = 0
#２つ並べて一般性を確かめる
S2 = S*2

for i in range(1,len(S2)):
    if S2[i-1]== S2[i]:
        S2[i] = '@'
        #2回目以降はk-1回任意の@へ直す
        if i>=len(S2)//2:
            ans+= K-1
        else:
            ans+=1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if len(set(s)) == 1:
    print((len(s)*k)//2)
else:
    t = [1]
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            t[-1] += 1
        else:
            t.append(1)
    a = 0
    for i in t:
        a += (i//2)*k
        if s[0] == s[-1]:
            if t[0] % 2 == t[-1] % 2 == 1:
                a += k-1
    print(a)

Submission status: Wrong Answer

Solution code:
s = str(input())
k = int(input())
flag = [0 for _ in range(len(s))]
count = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        if not flag[i]:
            flag[i+1] = 1
            count += 1
print(k*count)

Submission status: Wrong Answer

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

S = S + S
ans_odd = ans_even = 0
for i in range(1, N):
  pre_s = S[i-1]
  s = S[i]
  if s == pre_s:
    ans_odd += 1
    S[i] = '#'

for i in range(N, 2*N):
  pre_s = S[i-1]
  s = S[i]
  if s == pre_s:
    ans_even += 1
    S[i] = '#'

k_even = K // 2
k_odd = K - k_even
print(k_odd*ans_odd + k_even*ans_even)

Submission status: Wrong Answer

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

cnt = 0
t_cnt = 1
tmp = ''
for i in range(len(s)):
    if tmp==s[i]:
        t_cnt += 1
    else:
        cnt += t_cnt//2
        tmp = s[i]
        t_cnt = 1
cnt += t_cnt//2

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

bottom_cnt = 0
char = s[-1]
for i in range(1, len(s)+1):
    if char == s[-i]:
        bottom_cnt += 1
    else:
        break
        
if len(set(s))==1:
    print(len(s)*k//2)
else:
    if s[0]!=s[-1]:
        print(cnt*k)
    else:
        print(cnt*k-top_cnt//2+bottom_cnt//2+k-1)

Submission status: Wrong Answer

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

if len(set(S)) == 1:
  print(len(S)*K // 2)
  quit()

ans = 0
for i in range(1, len(S)):
  pre_s = S[i-1]
  s = S[i]
  if s == pre_s:
    S[i] = '#'
    ans += 1

if S[1]=='#' and len(S)>=3 and S[0]!=S[2] and S[0]==S[-1]:
  S[0], S[1] = S[1], S[0]

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

print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(1, len(S)):
  pre_s = S[i-1]
  s = S[i]
  if s == pre_s:
    S[i] = '#'
    ans += 1

if S[1]=='#' and len(S)>=3 and S[0]!=S[2] and S[0]==S[-1]:
  S[0], S[1] = S[1], S[0]

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

print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(1, len(S)):
  pre_s = S[i-1]
  s = S[i]
  if s == pre_s:
    S[i] = '#'
    ans += 1

if S[1] == '#' and len(S) >= 3 and S[0] != S[2]:
  S[0], S[1] = S[1], S[0]

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

print(ans)

Submission status: Wrong Answer

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

start = S1[0]
end = S1[-1]
now = S1[0]
a1 = 0
flag = False
for s in S1[1:]:
    if flag:
        flag = False
        now = s
        continue
    else:
        if s == now:
            a1 += 1
            flag = True
        now = s
S2 = S1 + S1

start = S2[0]
end = S2[-1]
now = S2[0]
a2 = 0
flag = False
for s in S2[1:]:
    if flag:
        flag = False
        now = s
        continue
    else:
        if s == now:
            a2 += 1
            flag = True
        now = s
b = a2 - 2 * a1

if len(S1) == 1:
    print(len(S1) * K//2)
else:
    print(a1 * K + b * (K-1))

Submission status: Wrong Answer

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

start = S1[0]
end = S1[-1]
now = S1[0]
a1 = 0
flag = False
for s in S1[1:]:
    if flag:
        flag = False
        now = s
        continue
    else:
        if s == now:
            a1 += 1
            flag = True
        now = s
S2 = S1 + S1

start = S2[0]
end = S2[-1]
now = S2[0]
a2 = 0
flag = False
for s in S2[1:]:
    if flag:
        flag = False
        now = s
        continue
    else:
        if s == now:
            a2 += 1
            flag = True
        now = s
b = a2 - 2 * a1

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

Submission status: Wrong Answer

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

start = S[0]
end = S[-1]
now = S[0]
a = 0
flag = False
for s in S[1:]:
    if flag:
        flag = False
        now = s
        continue
    else:
        if s == now:
            a += 1
            flag = True
        now = s

b = 0
if (not flag) and (start == end):
    b = 1

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

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
s = list(s)
S = []
S.extend(s)
S.extend(s)

num = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        S[i+1] = 'A'
        num += 1
k = 0
if S[0] == S[-1]:
    S[-1] == 'A'
    num += 1
    k = 1


n = 0
if K % 2 == 1:
    k = 0
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            s[i+1] = 'A'
            n += 1
        if s[0] == S[-1]:
            n += 1



result = num * (K//2) + n - k

print(result)

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
s = list(s)
S = []
S.extend(s)
S.extend(s)

num = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        S[i+1] = 'A'
        num += 1

if S[0] == S[-1]:
    S[-1] == 'A'
    num += 1


n = 0
if K % 2 == 1:
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            s[i+1] = 'A'
            n += 1
    if s[0] == s[-1]:
        n += 1


result = num * (K//2) + n

print(result)

Submission status: Wrong Answer

Solution code:
s = input()
K = int(input())
s = list(s)
S = []
S.extend(s)
S.extend(s)

num = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        S[i+1] = 'A'
        num += 1

if S[0] == S[-1]:
    S[-1] == 'A'
    num += 1


n = 0
if K % 2 == 1:
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            s[i+1] = 'A'
            n += 1
    if s[0] == S[-1]:
        n += 1


result = num * (K//2) + n

print(result)

Submission status: Wrong Answer

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

num = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        S[i+1] = 'A'
        num += 1

if S[0] == S[-1]:
    num += 1

result = num * K
print(result)

Submission status: Wrong Answer

Solution code:
s = list(input())
t = s[:]
k = int(input())
if len(s)==1:
  print(int(k//2))
  exit()
cou = 0
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    cou += 1
    s[i+1] = '-1'

if s[0]!=s[-1]:
  print(cou*k)
else:
  cou *= k
  cou += k-1
  if t[-2]!=t[-1] and t[-1]==t[0]:
    print(cou-1)
  else:
    print(cou)

Submission status: Wrong Answer

Solution code:
s = list(input())
t = s[:]
k = int(input())
if len(s)==1:
  print(int(k//2))
  exit()
cou = 0
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    cou += 1
    s[i+1] = '-1'

if s[0]!=s[-1]:
  print(cou*k)
else:
  if t[-2]!=t[-1] and t[-1]==t[0]:
    print(cou*k)
  else:
    print((cou+1)*k-1)

Submission status: Wrong Answer

Solution code:
s = list(input())
t = s[:]
k = int(input())
if len(s)==1:
  print(int(k//2))
  exit()
cou = 0
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    cou += 1
    s[i+1] = '-1'

if s[0]!=s[-1]:
  print(cou*k)
else:
  if  t[1]==t[-1] or t[0]==t[-2]:
    print((cou+1)*k-1)
  else:
    print((cou+1)*k-1)

Submission status: Wrong Answer

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

num_s = len(list(s))
count = 0
temp_count = 1
count_1 = 0
count_2 = 0

if s[0] != s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      count += temp_count//2
      temp_count = 1
  ans = count*k
  
elif s[0] == s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      if sign == 1:
        count_1 = temp_count
        sign = 0
      elif sign == 0:
        count += temp_count//2
     
      temp_count = 1

  count_2 = temp_count
  
  ans = count*k + ((count_1 + count_2)//2)*(k-1) + (count_1 //2) + (count_2//2)

  if sign == 1:
    ans = (k*num_s)//2
    
if num_s == 1:
  ans = k//2
  
print(ans)

Submission status: Wrong Answer

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

num_s = len(list(s))
count = 0
temp_count = 1
count_1 = 0
count_2 = 0

if s[0] != s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      count += temp_count//2
      temp_count = 1
  ans = count*k
  
elif s[0] == s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      if sign == 1:
        count_1 = temp_count
        sign = 0
      elif sign == 0:
        count += temp_count//2
     
      temp_count = 1

  count_2 = temp_count
  
  ans = count*k + ((count_1 + count_2)//2)*(k-1) + (count_1 //2) + (count_2//2)

  if sign == 1:
    ans = (k//2)*((2*num_s)//2)
    if k%2 == 1:
      ans += num_s//2
    
if num_s == 1:
  ans = k//2
  
print(ans)

Submission status: Wrong Answer

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

num_s = len(list(s))
count = 0
temp_count = 1
count_1 = 0
count_2 = 0

if s[0] != s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      count += temp_count//2
      temp_count = 1
  ans = count*k
  
elif s[0] == s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      if sign == 1:
        count_1 = temp_count
        sign = 0
      elif sign == 0:
        count += temp_count//2
     
      temp_count = 1

  count_2 = temp_count
  
  ans = count*k + ((count_1 + count_2)//2)*(k-1) + (count_1 //2) + (count_2//2)

  if sign == 1:
    ans = (k//2)*2*(num_s//2)
    if k%2 == 1:
      ans += num_s//2
    
if num_s == 1:
  ans = k//2
  
print(ans)

Submission status: Wrong Answer

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

num_s = len(list(s))
count = 0
temp_count = 1
count_1 = 0
count_2 = 0

if s[0] != s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      count += temp_count//2
      temp_count = 1
  ans = count*k
  
elif s[0] == s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      if sign == 1:
        count_1 += temp_count
        sign = 0
      elif sign == 0:
        count += temp_count//2
     
      temp_count = 1

  count_2 += temp_count
  
  ans = count*k + (count_1 + count_2)*(k-1)//2 + (count_1 //2) + (count_2//2)

  if sign == 1:
    ans = (k//2)*2*(num_s//2)
    if k%2 == 1:
      ans += num_s//2
    
if num_s == 1:
  ans = k//2
  
print(ans)

Submission status: Wrong Answer

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

num_s = len(list(s))
count = 0
temp_count = 1
count_1 = 0
count_2 = 0

if s[0] != s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      count += temp_count//2
      temp_count = 1
  ans = count*k
  
elif s[0] == s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      if sign == 1:
        count_1 += temp_count
        sign = 0
      elif sign == 0:
        count += temp_count//2
     
    temp_count = 1

  count_2 += temp_count
  
  ans = count*k + (count_1 + count_2)*(k-1)//2 + (count_1 //2) + (count_2//2)

  if sign == 1:
    ans = (k//2)*2*(num_s//2)
    if k%2 == 1:
      ans += num_s//2
    
if num_s == 1:
  ans = k//2
  
print(ans)

Submission status: Wrong Answer

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

num_s = len(list(s))
count = 0
temp_count = 1
count_1 = 0
count_2 = 0

if s[0] != s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      count += temp_count//2
      temp_count = 1
  ans = count*k
  
elif s[0] == s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      if sign == 1:
        count_1 += temp_count
        sign = 0
        
      count += temp_count//2
      temp_count = 1

  count_2 += temp_count
  
  ans = count*k + (count_1 + count_2)*(k-1)//2 + (count_1 //2) + (count_2//2)

  if sign == 1:
    ans = (k//2)*2*(num_s//2)
    if k%2 == 1:
      ans += num_s//2
    
if num_s == 1:
  ans = k//2
  
print(ans)

Submission status: Wrong Answer

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

num_s = len(list(s))
count = 0
temp_count = 1
count_1 = 0
count_2 = 0

if s[0] != s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      count += temp_count//2
      temp_count = 1
  ans = count*k
  
elif s[0] == s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      if sign == 1:
        count_1 += temp_count
        sign = 0
        
      count += temp_count//2
      temp_count = 1

  count_2 += temp_count
  
  ans = count*k + (count_1 + count_2)*(k-1)//2 + (count_1 //2) + (count_2//2)

  if count_2 == num_s:
    ans = (k//2)*2*(num_s//2)
    if k%2 == 1:
      ans += num_s//2
    
if num_s == 1:
  ans = k//2
  
print(ans)

Submission status: Wrong Answer

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

num_s = len(list(s))
count = 0
temp_count = 1
count_1 = 0
count_2 = 0

if s[0] != s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      count += temp_count//2
      temp_count = 1
  ans = count*k
  
elif s[0] == s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      if s[0] == s[i-1]:
        count_1 += temp_count
        
      count += temp_count//2
      temp_count = 1

  count_2 += temp_count
  
  ans = count*k + (count_1 + count_2)*(k-1)//2 + (count_1 //2) + (count_2//2)

  if count_2 == num_s:
    ans = (k//2)*2*(num_s//2)
    if k%2 == 1:
      ans += num_s//2
    
if num_s == 1:
  ans = k//2
  
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    S = input()
    K = int(input())
    
    ans = 0
    c = 1
    ps = S[0]
    for s in S[1:]:
        if ps == s:
            c += 1
        else:
            if c != 1:
                ans += c//2
            c = 1
        ps = s
        
    if c != 1:
        ans += c // 2
    
    return ans * K

print(solve())

Submission status: Wrong Answer

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

num_s = len(list(s))
count = 0
temp_count = 1
count_1 = 0
count_2 = 0

if s[0] != s[num_s-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      count += temp_count//2
      temp_count = 1
  ans = count*k
  
elif s[0] == s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      if s[0] == s[i-1]:
        count_1 += temp_count
        
      count += temp_count//2
      temp_count = 1

  count_2 += temp_count
  
  ans = count*k + (count_1 + count_2)*(k-1)//2 + (count_1 //2) + (count_2//2)

  if count_2 == num_s:
    asn = 2*num_s//2 + num_s//2
    
if num_s == 1:
  ans = k//2
  
print(ans)

Submission status: Wrong Answer

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

num_s = len(list(s))
count = 0
temp_count = 1
count_1 = 0
count_2 = 0

if s[0] != s[num_s-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      count += temp_count
      temp_count = 0
      
  ans = (count//2)*k
elif s[0] == s[num_s-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      if s[0] == s[i-1]:
        count_1 += temp_count
      count += temp_count
      temp_count = 1
      
  if temp_count != 0:
    count_2 += temp_count
  
  ans = (count//2)*k + (k-1)*(count_1 + count_2)//2 + count_1//2 + count_2//2

  if count_2 == num_s:
    asn = 2*num_s//2 + num_s//2
  
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
pre = S[0]
cnt = 0
flag = False
for s in S[1:]:
    if pre == s and not flag:
        cnt += 1
        flag = True
    else:
        flag = False
    pre = s
print(cnt*K)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
n=len(s)
ans=0
tmp=0
x=s[0]
ss=[]
for i in range(n):
  if x==s[i]:
    tmp+=1
  else:
    ss.append(tmp)
    tmp=1
    x=s[i]
if tmp>0:
  ss.append(tmp)
if len(ss)==1:
  print(n*k//2)
else:
  if not s[0]==s[-1]:
    ans+=(-ss[0]//2-ss[-1]//2+(ss[0]+ss[-1])//2)*(k-1)
  for i in ss:
    ans+=i//2*k
  print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
n=len(s)
ans=0
tmp=0
x=s[0]
ss=[]
for i in range(n):
  if x==s[i]:
    tmp+=1
  else:
    ss.append(tmp)
    tmp=1
    x=s[i]
if tmp>0:
  ss.append(tmp)
if len(ss)==1:
  print(k)
else:
  if not s[0]==s[-1]:
    ans+=(-ss[0]//2-ss[-1]//2+(ss[0]+ss[-1])//2)*(k-1)
  for i in ss:
    ans+=i//2*k
  print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ans=0
tmp=0
for i in range(len(s)):
  if k==1 and i==0:
    continue
  if s[i]==s[i-1] and i<len(s)-1:
    tmp+=1
  else:
    ans+=((tmp+1)//2 if tmp>0 else 0)
    tmp=0
print(ans*k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = list(input())
t = s[:]
k = int(input())
if len(s)==1:
  print(int(k//2))
  exit()
cou = 0
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    cou += 1
    s[i+1] = '-1'
if s[0]!=s[-1]:
  print(cou*k)
else:
  if  t[1]==t[-1] or t[0]==t[-2]:
    print(cou*k)
  else:
    print((cou+1)*k-1)

Submission status: Wrong Answer

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

def f(S):
    res = 0
    count = 1
    length = len(S)
    for i in range(1,length):
        if S[i] == S[i-1]:
            count += 1
        else:
            res += count // 2
            count = 1
    res += count // 2
    return res

res1 = f(s)
res2 = f(s+s)

print(res1 + (res2-res1) * (k-1))

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
N = len(S)
#最初の1回
ans = 0
prev = S[0]
endchange = False
for i in range(1,N):
    if S[i] == prev:
        ans += 1
        prev = 0
        if i == N:
            endchange = True
    else:
        prev = S[i]

if all([s == S[0] for s in S]):
    print((N*K)//2)

elif K==1 or S[0] != S[-1]:
    print(ans * K)
else:
    front = 1
    while 1:
        if S[front] == S[0]:
            front += 1
        else:break
    back = -1
    while 1:
        if S[back] == S[0]:
            back -= 1
        else:break
    back = -1-back
    print((ans + (front+back)//2 - front//2 - back//2) * K)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
N = len(S)
#最初の1回
ans = 0
prev = S[0]
for i in range(1,N):
    if S[i] == prev:
        ans += 1
        prev = 0
    else:
        prev = S[i]

if K == 1:
    print(ans)
else:
    if S[0] != S[-1]:
        print(ans * K)
    else:
        ans2 = 0
        prev = 1
        for i in range(1,N):
            if S[i] == prev:
                ans += 1
                prev = 0
            else:
                prev = S[i]
        print(ans + (1+ans2) * (K-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
s = input()
k = int(input())
data = []
start = s[0]
seq = 1
if len(set(list(s))) == 1:
    print(len(s)*k//2)
    sys.exit()
for i in s[1:]:
    if start == i:
        seq += 1
    else:
        data.append(seq)
        start = i
        seq = 1
else:
    data.append(seq)
#print(data)
if s[0] != s[-1]:
    ans = 0
    for i in data:
        ans += i//2
    else:
        print(ans*k)
else:
    pati = data[0] + data[-1]
    ans = pati*(k-1)
    for i in range(1,len(data)-1):
        ans += i//2*k
    else:
        print(ans+data[0]//2+data[-1]//2)

Submission status: Wrong Answer

Solution code:
import sys
s = input()
k = int(input())
data = []
start = s[0]
seq = 1
if len(set(list(s))) == 1:
    print(len(s)*k//2)
    sys.exit()
for i in s[1:]:
    if start == i:
        seq += 1
    else:
        data.append(seq)
        start = i
        seq = 1
if s[0] != s[-1]:
    ans = 0
    for i in data:
        ans += i//2
    else:
        print(ans*k)
else:
    pati = data[0] + data[-1]
    ans = pati*(k-1)
    for i in range(1,len(data)-1):
        ans += i//2*k
    else:
        print(ans+data[0]//2+data[-1]//2)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

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

A = []
cnt = 1
C = []
for i in range(1,len(S)):
    if S[i-1] == S[i]:
        cnt += 1
    else:
        C.append([S[i-1], cnt])
        cnt = 1
C.append([S[i], cnt])

ans = 0
S2 = []
for c in C:
    ans += (c[1])//2
    if c[1] == 1:
        S2.append(False)
    else:
        for i in range(c[1]):
            if i % 2 == 1:
                S2.append(True)
            else:
                S2.append(False)

ans *= K

ans2 = 0
if S[0] == S[-1]:
    if S2[-1] == False and S2[0] == False:
        ans2 = K //2
    elif S2[-1] == False:
        ans2 = K-1



print(ans + ans2)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

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

A = []
cnt = 1
C = []
for i in range(1,len(S)):
    if S[i-1] == S[i]:
        cnt += 1
    else:
        C.append([S[i-1], cnt])
        cnt = 1
C.append([S[i], cnt])

ans = 0
S2 = []
for c in C:
    ans += (c[1])//2
    if c[1] == 1:
        S2.append(False)
    else:
        for i in range(c[1]):
            if i % 2 == 1:
                S2.append(True)
            else:
                S2.append(False)

ans *= K

ans2 = 0
if S[0] == S[-1]:
    if S2[-1] == False and S2[0] == False:
        ans2 = K //2
#    elif S2[-1] == False:
#        ans2 = K-1



print(ans + ans2)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
import re
 
s = input()
k = int(input())
#  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
c = collections.Counter(s)

def nchars(s, n):
    """文字列 s に、同じ文字が n 個以上連続している部分文字列を見つける
    """
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  # カンマを取ると n 個ちょうどになる
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

ans = 0

chains = list(nchars(s, 2))

if len(c) == 1:
    print(len(s) * k // 2)
else:
    for r in chains:
        ans += len(r) // 2

    print(ans * k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
import re
 
s = input()
k = int(input())
#  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

def nchars(s, n):
    """文字列 s に、同じ文字が n 個以上連続している部分文字列を見つける
    """
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  # カンマを取ると n 個ちょうどになる
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

ans = 0
for r in list(nchars(s, 2)):
    ans += len(r) // 2

print(ans * k)

Submission status: Wrong Answer

Solution code:
import sys
sys.stdin.readline

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

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

Submission status: Wrong Answer

Solution code:
import sys
sys.stdin.readline

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

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

Submission status: Wrong Answer

Solution code:
import sys
sys.stdin.readline

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

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

Submission status: Wrong Answer

Solution code:
import sys
sys.stdin.readline

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

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

Submission status: Wrong Answer

Solution code:
import sys
sys.stdin.readline

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

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