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 = list(input().strip())
t = int(input())
ans = 0
change = False
last = False
# 長さ1の時は回数割る2切り捨てだけ変える必要
if len(s) == 1:
    print(t // 2)
    exit()
for i in range(1, len(s)):
    if change == True:  # 変更直後は必ず通る
        change = False
        continue
    if s[i] == s[i - 1]:  # 変更する
        ans += 1
        change = True
# 最初と最後が同じ文字かつ、最後を変更していない場合
if change == False and s[0] == s[-1]:
    ans += 1
    last = True
# 最後の一回は最後の文字を変更する必要ない
if last == True:
    print(ans * t - 1)
else:
    print(ans*t)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = str(input())
K = int(input())
N = len(S)

count1 = 0
x = "A"
con = 1
#仮に1回でもダメなやつ
for i in range(N):
  if x == S[i]:
    con += 1 
  else:
    x = S[i]
    if con != 1:
      count1 += con //2
    con = 1
  #print(count1, i)
if con != 1:
  count1 += con //2
  
if con == N:
  print(N * K // 2)
  quit()
#print(count1)
count2 = 0
if S[0] == S[-1]:
  if S[0] != S[1]:
    if S[-1] != S[-2]:
      count2 = 1
print(count1 * K + count2 * (K - 1))

Submission status: Wrong Answer

Solution code:
import numpy as np

S = raw_input()
K = int(raw_input())

S_twice = S + S

A = np.full(len(S),0)
A_twice = np.full(len(S),0)

count = 0
for i in range(0, len(S)-1):
    if S[i] == S[i-1]:
        count = count + 1
    else:
        A[count] = A[count] + 1
        count = 0

count = 0
for i in range(0, len(S_twice)-1):
    if S_twice[i] == S_twice[i-1]:
        count = count + 1
    else:
        A_twice[count] = A_twice[count] + 1
        count = 0

if count > len(S):
    print len(S)*K/2
    exit()

A_k = A + (K-1)*(A_twice-A)

ans = 0

print A_k

for i in range(A_k.shape[0]):
    ans = ans + (i+1)/2*A_k[i]

print ans

Submission status: Wrong Answer

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

len_s=len(s)
ans=0

#print(s[len_s-2])
for i in range(len_s-1):
	if s[i]==s[i+1]:
		ans=ans+1
		s=list(s)
		s[i+1]="0"
		s="".join(s)

ans=ans*k

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

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)
K = int(input())
T = S.copy()
S += S
ans = 0
cnt = 0

for i in range(1, N):
    if S[i - 1] == S[i]:
        cnt += 1
        S[i] = "-1"
ans += cnt
if T[0] == T[-1] and S[N - 1] != "-1":
    cnt2 = 1
    T[0] = "-1"
    for i in range(1, N):
        if T[i] == T[i - 1]:
            cnt2 += 1
            T[i] = "-1"
    ans += cnt2 * (K - 1)
else:
    ans += cnt * (K - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
s = raw_input()
t = raw_input()
c = 0
i = 0
while( i < len(s)-1 ):
  if s[i] == s[i+1]:
    c += 1
    i += 1
  i += 1
print(int(t)*c)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
brob = 0
temp = 1
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        temp += 1
    else:
        brob += temp // 2
        temp = 1
        
brob += temp // 2

if K == 1:
    print(brob)

else:
    if len(S) == 1:
        print(K // 2)
    
    elif S[-1] != S[0]:
        print(brob * K)

    elif S[-2] == S[0] or S[1] == S[-1]:
        print(brob * K)

    else:
        print(brob * K + K - 1)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def change(S, K):
    c = 0 
                                                                                                                                                                                         
    if len(S) == 1:
        return K/2

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

    if S[-1] == S[0] and S[-1] != S[-2]:
        c += 1 

    return K * c 


if __name__ == "__main__":
    S = stdin.readline().strip()
    K = int(stdin.readline())

    print(change(S, K))

Submission status: Wrong Answer

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

cnt = 0
S2 = list(S)
for i in range(1, len(S2)):
    if S2[i-1] == S2[i]:
        S2[i] = "A"
        cnt += 1

cnt = cnt * K

if S2[0] == S2[-1]:
    cnt += K-1

print(cnt)

Submission status: Wrong Answer

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

if k>=2:
    sl=list(s)
    ss=list(s+s)
    cnt=0
    for i in range(len(ss)-1):
        if ss[i]==ss[i+1]:
            cnt+=1
            ss[i+1]="?"
    cnt2=0
    for i in range(len(sl)-1):
        if sl[i]==sl[i+1]:
            cnt2+=1
            sl[i+1]="?"
    if s[0]==s[-1] and ss[-1]!="?":
        print((k//2)*cnt+(k%2)*cnt2+1)
    else:
        print((k//2)*cnt+(k%2)*cnt2)

else:
    cnt=0
    sl=list(s)
    for i in range(len(sl)-1):
        if sl[i]==sl[i+1]:
            cnt+=1
            sl[i+1]="?"
    print(cnt)

Submission status: Wrong Answer

Solution code:
ls=list(input())
n=int(input())

ls.append(ls[0])

count=0
dounat=False
for i in range(len(ls)-1):
    a,b=ls[i],ls[i+1]
    if a==b:
        if i == len(ls)-2:
            ls[i]='!'
            dounat=True
        else:
            ls[i+1]='?'
        count+=1
ans = count * n
if dounat:
    ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
def solve(text, count):
    chars = [ch for ch in text]

    if len(text) == 1:
        return count // 2

    change = 0

    for i, ch in enumerate(chars):
        if i == 0:
            continue
        if chars[i - 1] == chars[i] and chars[i - 1] != '!':
            chars[i] = '!'  # Any char fine since we can choose any
            change += count
            continue

    # chars[0] comes after chars[-1], so compare and add change
    # but this happens not at first
    if chars[0] == chars[-1] and chars[-1] != '!':
        chars[0] = '!'
        change += count - 1

    return change


if __name__ == "__main__":
    s = input()
    k = int(input())
    print(solve(s, k))

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

s = list(input())
ss = deepcopy(s)
k = int(input())
cnt = 0

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

ans = cnt * k

if ss[-1] != "0" and s[-1] == s[0]:
    l = 1
    for idx, c in enumerate(s):
        if c != s[0]:
            l = idx
            break
    if l % 2:
        ans += k - 1

print(ans)

Submission status: Wrong Answer

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

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

is_same = False
b = ''
count = 0
tail = False
for c in s:
  if c == b and not is_same:
    count += 1
    is_same = True
  else:
    is_same = False
  b = c
else:
  if s[0] == s[-1] and not is_same:
    tail = True
ans = count * k
if tail:
  ans += k-1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ans=0
if k%2==1:
  cnt=1
  for i in range(1,len(s)):
    if s[i]==s[i-1]:
      cnt+=1
    else:
      ans+=cnt//2
      cnt=1
  ans+=cnt//2
t=s+s
cnt=1
tmp=0
for i in range(1,len(t)):
  if t[i]==t[i-1]:
    cnt+=1
  else:
    tmp+=cnt//2
    cnt=1
tmp+=cnt//2
ans+=tmp*(k//2)
flag=True
if cnt>=2:
  flag=False
if flag==True:
  cnt1=1
  for i in range(1,len(s)):
    if s[i]==s[i-1]:
      cnt1+=1
    else:
      break
  cnt2=1
  for i in range(1,len(s)):
    if s[-i]==s[-(i+1)]:
      cnt2+=1
    else:
      break
  if s[0]==s[-1]:
    ans+=((k-1)//2)*(cnt1+cnt2)//2
print(ans)

Submission status: Wrong Answer

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

count = 0
flag = 0

if len(S) == 1:
    print(K // 2)
else:
    S = S + S[0]
    for i in range(0, len(S) - 1):
        if S[i] == S[i + 1]:
            if flag == 0:
                count += 1
                flag = 1
            else:
                flag = 0
        else:
            flag = 0

    if flag == 1:
        print(count * K - 1)
    else:
        print(count * K)

Submission status: Wrong Answer

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

if len(s) == 1:
    print(k//2)
else:
    changedLast = False

    result = 0

    i = 1
    while i < len(s):
        if s[i] == s[i-1]:
            result += k
            if i == len(s)-1:
                changedLast = True
        i += 1

    if not changedLast and s[0] == s[-1]:
        result += k-1
    print(result)

Submission status: Wrong Answer

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

result = 0
lastchanged = False
for i, x in enumerate(S):
    if i > 0 and not lastchanged and x == S[i-1]:
        result += 1
        lastchanged = True
    else:
        lastchanged = False

if not lastchanged and len(S) > 1 and S[0] == S[-1]:
    result += 1
    result *= K
    result -= 1
else:
    result *= K

print(result)

Submission status: Wrong Answer

Solution code:
import math
S=list(input())
K=int(input())
count = 0
ans = 0
flag = False
firstCount = 0
firstChart = ""
for i in range(1,len(S)):
  if S[i-1] == S[i]:
    count += 1
  else:
    if flag == False:
      firstCount = 0
      firstChart = S[i-1]
    flag = True
    ans += math.ceil(count/2)*K
    count = 0

ans += math.ceil(count/2)
    
if flag:
  if firstChart == S[len(S)-1]:
    ans += math.ceil((firstCount + count)/2)*(K-1)
else:
  ans += math.ceil(count/2)*(K-1) 
if len(S) == 1:
  if K == 1:
    print("0")
  else:
    print(math.ceil(K/2))
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

s = input()
n = int(input())
ans = 0
comp_k = []
comp_s = []
for k,v in groupby(s):
  comp_k += [k]
  comp_s += [len(list(v))]

if len(comp_s) == 1:
  print(comp_s[0] * n // 2)
  quit()
  
if comp_k[0] == comp_k[-1]:
  ans += comp_s[0]//2 + comp_s[-1]//2
  comp_s[0] += comp_s.pop()
  ans -= comp_s[0]//2

for i in range(len(comp_s)):
  ans += comp_s[i] // 2
ans *= n

print(ans)

Submission status: Wrong Answer

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

counter = 0
tmp = s[0]
counter_list = []

s_dict = dict()
for i,one in enumerate(s):
    s_dict[one] = i
    
if len(s_dict) == 1:
    print((len(s)*k-1)//2)
else:
    for one in s[1:]:
        if tmp == one:
            counter += 1
        else:
            counter_list.append((counter+1)//2)
            counter = 0
            tmp = one
    counter_list.append((counter+1)//2)

    sum_counter = sum(counter_list)
    if s[0] == s[-1]:
        if counter % 2 != 0:
            print(sum_counter*k)
        else:
            print(sum_counter*k + k -1)
    else:
        print(sum_counter*k)

Submission status: Wrong Answer

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

result = 0

# S内の重複
dup_c = 0
c_list = ['XXXXX']
for s in S:
    if c_list[0] == s:
        dup_c += 1
        c_list = ['XXXXX']
    else:
        c_list[0] = s
result = dup_c * K

# 間の重複
if len(S) > 1:
    if S[0] == S[len(S)-1]:
        if S[1] != S[0] and S[len(S)-2] != S[0]:
            result += K - 1
else:
    result += K//2

print(result)

Submission status: Wrong Answer

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

def count(string):
    total = 0
    i = 1
    while i < len(string):
        if string[i-1] == string[i]:
            total += 1
            if i+1 < len(string) and string[i+1] == string[i]:
                i += 1
        i += 1
    return total

if len(set(S)) == 1:
    res = (K * len(S)) // 2      
elif S[0] == S[-1]:
    new = S.strip(S[0])
    start = len(S) - len(S.lstrip(S[0]))
    end = len(S) - len(S.rstrip(S[0]))
    res = count(S[0] * start) + count(S[0] * end) + K * count(new) + (K - 1) * (start + end) // 2
else:
    res = K * count(S)

print(res)

Submission status: Wrong Answer

Solution code:
import math
import copy 
S = list(input())
K = int(input())
S1 = copy.copy(S)
S.extend(S)

x = S[0]
c1 = 0
c2 = 0
for i in range(len(S)-1):
    if x == S[i+1]:
        c1 += 1
    else:
        c2 += math.ceil(c1/2)
        c1 = 0
    x = S[i+1]

c2 += math.ceil(c1/2)
b = c2

S.extend(S1)

x = S[0]
c1 = 0
c2 = 0
for i in range(len(S)-1):
    if x == S[i+1]:
        c1 += 1
    else:
        c2 += math.ceil(c1/2)
        c1 = 0
    x = S[i+1]

c2 += math.ceil(c1/2)
c = c2
print((K//2)*b+K%2*(c-b))

Submission status: Wrong Answer

Solution code:
st = input()
s = [i for i in st]
k = int(input())
l = len(s)
c=0
i=0
while i<l-1:
    if i+1 <=l-1 and s[i]==s[i+1]:
        s[i+1]='|'
        c+=1
        i+=1
    else:
        i+=1

# print(c)
c*=k
if k>1:
    a = s[0]
    if a==s[-1]:
        c+=k-1
if l==1:
    if k%2==0:
        c=k//2
    else:
        c = (k-1)//2
print(c)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
print(k*9)
ans=0
f=0
for i in range(k):
	for j in range(len(s)):
		if i==0 and j==0:
			sf=s[j]
			continue
		elif f==1:
			sf=s[j]
			f=0
			continue
		elif sf==s[j]:
			ans+=1
			f=1
		sf=s[j]
		if j==len(s)-1:
			sf=s[0]
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
S = str(input())
K = int(input())

if len(S) == 1:
    print(K // 2)
else:
    before_s = ""
    dup_list = []
    dup_num = 0
    for s in S:
        if s == before_s:
            dup_num += 1
            if dup_num == 1:
                dup_list.append(dup_num)
            else:
                dup_list[-1] = dup_num
        else:
            before_s = s
            dup_num = 0
    ans = 0
    for dnum in dup_list:
        ans += (dnum + 1) // 2
    ans *= K
    print(dup_num)
    if S[0] == S[-1]:
        if S[-1] != S[-2] or dup_num % 2 == 0: # 最後の文字が連続する同じ文字だった場合、連続数が奇数なら変換数増
            ans += K - 1
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
c = 0
i = 0
if s[0]*len(s) == s:
    s_ = s + s
    while i<len(s_)-1:
        if s_[i] == s_[i+1]:
            c += 1
            i += 2
        else:
            i += 1
    if k%2 == 0:
        print(c*k//2)
    else:
        c = c*(k//2)
        i = 0
        while i<len(s)-1:
            if s[i] == s[i+1]:
                c += 1
                i += 2
            else:
                i += 1
        print(c)
else:   
        
    while i<len(s)-1:
        if s[i] == s[i+1]:
            c += 1
            i += 2
        else:
            i += 1
    if s[0] == s[-1] and i==len(s)-1:
        c += 1
        print(k*c-1)
    else:
        print(k*c)

Submission status: Wrong Answer

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

if len(s) == 1:
  print(k // 2)
else:
  cnt = 0
  p = 1
  while p < len(s):
    if s[p-1] == s[p]:
      cnt += 1
      p += 1
    p += 1
      
  cnt2 = 0
  p2 = 1
  s2 = s + s
  while p2 < len(s2):
    if s2[p2-1] == s2[p2]:
      cnt2 += 1
      p2 += 1
    p2 += 1

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

Submission status: Wrong Answer

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

for i in range(len(S)):
    if S[i]==S[i-1]:
        if i%2==0:
            S[i]="?"
        else:
            S[i]="!"
        count+=1
if S[-1]==S[0]:
    print(count*K-2)
else:
    print(count*K)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
c = 0
i = 0
while i < len(s)-1:
    if s[i]==s[i+1]:
        c+=1
        i+=1
    i+=1
if s[len(s)-1]==s[0]:
    if s[len(s)-1]!=s[len(s)-2]:
        c+=1
print(c*k)

Submission status: Wrong Answer

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

S.extend(S)

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

if K%2 ==0:
	count = count*K/2
else:
	count = count*(K-1)/2 + count//2

if S[0] == S[-1] and K>=2:
	if S[-1] == S[0]:
		count += K//2

print(int(count))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list
def summarize_list(l):
  sl=l

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res

def main():
  s=S()
  k=I()

  if len(s)==1:
    return k//2

  l=summarize_list(s)

  ans=0
  bf=False
  
  if l[0][0]==l[-1][0] and l[0][1]==1 and l[-1][1]==1:
    bf=True

  _ans=0
  for x in l:
    _ans+=x[1]//2
  ans+=_ans*k

  if bf:
    ans+=k-1

  return ans

# main()
print(main())

Submission status: Wrong Answer

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

ans = 0
rep = 1
for i in range(0, len(s) - 1):
    current = s[i]
    next = s[i+1]
    if current == next:
        rep += 1
    else:
        if rep > 1:
            ans += rep // 2
            rep = 1

if rep > 1:
    ans += rep // 2

start_eq_end = 0
if len(s) > 2 and s[0] == s[-1]:
    if rep % 2 != 0:
        start_eq_end = k - 1


print(ans * k + start_eq_end)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
ans = 0
if len(S) == 1:
  print(K//2);exit()
elif len(S) == 2:
  if S[0] ==  S[1]:
    print(K);exit()
  else:
    print(0);exit()
else:
  for i in range(0,len(S)-2,1):
    s = S[i:i+3]
    if s[0] == s[1] and s[1] == s[2]:
      ans += 1
      S[i+1] = "0"
    elif s[0] == s[1]:
      ans += 1
      S[i+1] = "0"
    elif s[1] == s[2]:
      ans += 1
      S[i+2] = "0"
if S[0] == S[-1]:
  print(ans*K+K-1)
else:
  print(ans*K)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
pre_character = ''
S_list=list(S)
def get_abc(s1,s2):
    if s1 == 'a':
        if s2 == 'b':
            return 'c'
        else:
            return 'b'
    elif s1 == 'b':
        if s2 == 'a':
            return 'c'
        else:
            return 'a'
    else:
        if s2 == 'a':
            return 'b'
        else:
            return 'a'
        
s_len = len(S)
count = 0
for i in range(s_len):
    if pre_character == S_list[i]:
        count += 1
        if (s_len - 1) != i:
            S_list[i] = get_abc(pre_character,S_list[i+1])
        else:
            S_list[i] = get_abc(pre_character,S_list[0])
    pre_character = S_list[i]
if S_list[0] == S_list[-1]:
    pre_character = S_list[-1]
    second_count = 0
    for i in range(s_len):
        if pre_character == S_list[i]:
            second_count += 1
            if (s_len - 1) != i:
                S_list[i] = get_abc(pre_character,S_list[i+1])
            else:
                S_list[i] = get_abc(pre_character,S_list[0])
        pre_character = S_list[i]
    print(count + (second_count*(K-1)))
else:
    print(count*K)

Submission status: Wrong Answer

Solution code:
S = str(input())
K = int(input())
N = len(S)

count1 = 0
x = "A"
con = 1
#仮に1回でもダメなやつ
for i in range(N):
  if x == S[i]:
    con += 1 
  else:
    x = S[i]
    if con != 1:
      count1 += con //2
    con = 1
  #print(count1, i)
if con != 1:
  count1 += con //2
  
if con == N:
  print(N * K // 2)
  quit()
#print(count1)
count2 = 0
if S[0] == S[-1]:
  if S[0] != S[1]:
    if S[-1] != S[-2]:
      count2 = 1
print(count1 * K + count2)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
ans = 0
i= 1

while i < len(S)-1:
    if S[i-1] == S[i]:
        ans += 1
        i += 1
    i+=1
if K != 1:
    if S[0] == S[len(S)-1]: ans += 1

ans *= K

if len(S) == 1:
    ans = -(-K//2)

print(ans)

Submission status: Wrong Answer

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



if len(s)==1:
    if k<=2:
        ans = 0
    else:
        ans = k//2
elif len(s)==2:
    if s[0]==s[1]:
        ans = k
    else:
        ans = 0
else:
    if k == 1:
        ans = 0
        bef = ""
        befchen = False
        trignum = 0
        for i in range(len(s)):
            now = s[i]
            if bef==now:
                if befchen == False:
                    ans += 1
                    befchen = True
                    trignum = i
            if  befchen == True:
                if trignum == i-1:
                    befchen = False
            bef = now

    elif k >=2:
        ans = 0
        bef = ""
        befchen = False
        trignum = 0
        for i in range(len(s)):
            now = s[i]
            if bef==now:
                if befchen == False:
                    #print(now)
                    ans += 1
                    befchen = True
                    trignum = i
            if  befchen == True:
                if trignum == i-1:
                    befchen = False
            bef = now
        
        if s[0]==s[-1]:
            if  s[-2]!=s[-1]:
                ans += 1

        #print(ans)
        ans *= k

print(ans)

Submission status: Wrong Answer

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

if len(S) == 1:
    print(K//2)
    exit()
minus = 0
if len(S) >= 3 and S[0] == S[1] == S[-1]:
    if S[0] != S[2] and S[-1] != S[-2]:
        minus = 1
cons = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cons += 1
        S[i+1] = '_'
cons2 = int(S[0] == S[-1])
if K == 1:
    print(cons)
    exit()
print(cons * K + cons2 * (K-1) - minus * (K-1))

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
count=1
ans=0
old='old'
for x in S:
    if old==x:
        count+=1
    else:
        ans+=count//2
        count=1
    old=x

ans+=count//2
check=0
check+=ans

ans-=count//2

for x in S:
    if old==x:
        count+=1
    else:
        ans+=count//2
        count=1
#     print(count)
    old=x

ans+=count//2
if ans==check*2:
    print(check*K)
if ans==check*2+1 and K!=1:
    print(check*K+1)
if ans==check*2+1 and K==1:
    print(check*K)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
n=len(s)
if n==1:
    print(k//2)
    exit()
if n==2:
    if s[0]==s[1]:
        print(k)
    else:
        print(0)
    exit()
tc=1
ac=0
p=s[0]
for i in range(1,n):
    if s[i]==p:
        tc+=1
    else:
        ac+=tc//2
        tc=1
        p=s[i]
else:
    ac+=tc//2
ans=ac*k
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
ret = 0
t = 0
if k > 0:
    for j in range(1, 100):
        if j >= len(s):
            break
        for i in range(len(s)-j):
            for u in range(j):
                if s[i + u] != s[i + u + 1]:
                    break
                if u == j-1:
                    if j % 2==1:
                        t += 1
                    else:
                        t -= 1
    ret += t * k
    if len(s) > 2:
        if s[0] == s[-1] and s[-2] != s[-1]:
            ret += (k - 1)

if len(s) == 1:
    ret += k // 2

print(ret)

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
k = I()
n = len(s)
res1 = 0
i = 0
while i < n:
    tmp = s[i]
    i += 1
    cnt = 1
    while i < n and tmp == s[i]:
        cnt += 1
        i += 1
    res1 += cnt//2
s = s+s
res = 0
i = 0
while i < 2*n:
    tmp = s[i]
    i += 1
    cnt = 1
    while i < 2*n and tmp == s[i]:
        cnt += 1
        i += 1
    res += cnt//2
#print(res,res1)
print(res*(k//2)+res1*(k%2))

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
S = S + S[0]
samecount = 1
count = 0
pre = ''
for s in S:
    if s == pre:
        samecount += 1
    else:
        count += samecount//2
        samecount = 1
    pre = s

ans = K * count
if samecount % 2 == 0:
    ans += K*(samecount-1)//2
    check = True
    samecount = 0
    pre = S[0]
    for s in S[1:]:
        if s == pre:
            samecount += 1
        else:
            break

    if samecount % 2 == 0:
        pass
    else:
        ans += K-1
else:
    ans += K*(samecount//2)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

a = list(input())
n = int(input())
ans = 0
if n == 1:
    kkk = s(a)
    for i in range(len(kkk)):
        if kkk[i][1] >= 2:
            ans += kkk[i][1]//2
    print(ans)
else:
    aa = a+a
    kkk = s(aa)
    ppp = s(a)
    if len(kkk) == 1:
        ans += len(kkk) * n //2
    else:
        aaa = kkk.pop(-1)

        for i in range(len(kkk)):
            ans += kkk[i][1]//2
        ans *= (n // 2)
        if n % 2 == 0:
            ans += aaa[1]//2
        else:
            if aaa[0] == ppp[0][0]:
                ppp[0][1] += aaa[1]
            else:
                ppp.append(aaa)
            for i in range(len(ppp)):
                ans += ppp[i][1]//2
        print(ans)

Submission status: Wrong Answer

Solution code:
def ContinueCnt(A):
    Datas, Cnts = [A[0]], [1]
    index = 0
    for i in range(1, len(A)):
        if A[i] == Datas[index]:
            Cnts[index] += 1
        else:
            Datas.append(A[i])
            Cnts.append(1)
            index += 1
    return Datas, Cnts


S = input()
K = int(input())
ans_1, ans_2 = 0, 0
Datas, Cnts = ContinueCnt(S)

# はじめに例外処理
if len(S) == 1:
    print(len(S) // 2)
    exit()

# 前の文字と同じ場合は書き換えてカウント
for si in range(1, len(S)):
    if S[si] == S[si - 1]:
        S = S[: si] + "?" + S[si + 1:]
        ans_1 += 1

# 最後の文字についてカウント
if S[-1] == S[0]:
    ans_2 = K - 1

# todo: とりあえず例外処理
if Datas[0] == Datas[-1] and Cnts[0] % 2 == 0 and Cnts[-1] % 2 == 1:
    print(ans_1 * K + ans_2 - (K - 1))
    exit()

print(ans_1 * K + ans_2)

Submission status: Wrong Answer

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

if len(S) == 1:
  print(K//2)
  exit()
  
SR=S+[S[0]]
cnt=0
for i in range(len(S)-1):
  if SR[i]==SR[i+1]==SR[i+2]:
    SR[i+1]=0
    cnt+=1

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

Submission status: Wrong Answer

Solution code:
a = list(input())
b = int(input())
c = len(a)
sum = 0
for i in range(0,c-1):
  if a[i]==a[i+1]:
    a[i+1]=" "
    sum+=1
print(sum*b)

Submission status: Wrong Answer

Solution code:
s_list = list(input())
k = int(input())
s_len_list = []
dbls_len_list = []
dbls_list = s_list * 2
temp_len = 1
ans = 0

for i in range(len(s_list)-1):
    if s_list[i+1] == s_list[i]:
        temp_len += 1
    else:
        s_len_list.append(temp_len)
        temp_len = 1
s_len_list.append(temp_len)

temp_len = 1
for i in range(len(dbls_list)-1):
    if dbls_list[i+1] == dbls_list[i]:
        temp_len += 1
    else:
        dbls_len_list.append(temp_len)
        temp_len = 1
dbls_len_list.append(temp_len)
# print(s_list)
# print(s_len_list)
# print(dbls_list)
# print(dbls_len_list)
if s_len_list[len(s_len_list)-1] // 2 != dbls_len_list[len(s_len_list)-1] // 2 and len(s_len_list) != 1:
    for i in s_len_list:
        ans += i // 2
    ans *= k
    ans += (dbls_len_list[len(s_len_list)-1] // 2 - s_len_list[len(s_len_list)-1] // 2)*(k-1)
else:
    for i in s_len_list:
        ans += i // 2
    ans *= k
print(ans)

Submission status: Wrong Answer

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

cnt = 0
L = len(S)

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

changed = False
Flg = False
for i in range(L-1):
    if not changed or i == L - 2:
        if i == L - 2:
            if S[i] == S[i+1]:
                cnt += 1
                changed = True
            else:
                if K > 1:
                    if S[0] == S[i+1]:
                        cnt += 1
                        changed = True
                        Flg = True
        else:
            if S[i] == S[i+1]:
                cnt += 1
                changed = True
    else:
        changed = False

cnt *= K
if Flg:
    cnt -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
lst = []

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

Submission status: Wrong Answer

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

count = 0
for i in range(int(len(s)/2)):
  tmp = s[i*2:i*2+3]
  if len(tmp) == 2:
    if tmp[0] == tmp[1]:
      count+=1
  elif tmp[0] == tmp[1] or tmp[2] == tmp[1]:
    count+=1
   
if len(s)%2==1:
  count = count*k
elif len(s)%2==0:
  count = (count-1)*k
elif len(s) == 2 and s[0] == s[1]:
  count = k
print(count)