ZhenlongDai/ACPR huggingface dataset:
Problem: p02891
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = list(map(str, input().strip()))
k = int(input())

pre = 0
cnt = 1
ans = 0
for i in s:
    if i == pre:
        cnt += 1
    else:
        ans += cnt 
        cnt = 1
    pre = i
pcnt = cnt
for i in s:
    if i == pre:
        cnt += 1
    else:
        ans += cnt 
        break

print(ans * k)


Failing test case input:
tredmdepdedetndmopnnfond
8171470

Expected output:
8171470


Actual output:
204286750


Fixed submission (verdict: Accepted):
s = list(map(str, input().strip()))
k = int(input())

pre = 0
cnt = 1
ans = 0
for i in s:
    if i == pre:
        cnt += 1
    else:
        ans += cnt 
        cnt = 1
    pre = i

ans += cnt

if cnt == len(s):
    print((cnt*k)
    exit(0)
pcnt = cnt
dcnt = 0
for i in s:
    if i == pre:
        cnt += 1
    else:
        dcnt = cnt - pcnt
        break

if dcnt % 2 and pcnt % 2:
    ans = ans * k + k - 1
else:
    ans *= k

print(ans)

Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
k = int(input())

prev = ""
count1 = 0
flag = 0
for i in s:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count1 += 1
        flag = 1
    prev = i

prev = s[0]
count2 = 0
flag = 0
for i in s[1:]:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count2 += 1
        flag = 1
    prev = i

ret = count1 + (k-1) * count2

print(ret)

Failing test case input:
hsrih
6

Expected output:
5


Actual output:
0


Fixed submission (verdict: Accepted):
s = input()
k = int(input())

prev = ""
count1 = 0
count2 = 0
count3 = 0
flag = 0
for i in s:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count1 += 1
        flag = 1
    prev = i



for i in s:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count2 += 1
        flag = 1
    prev = i

for i in s:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count3 += 1
        flag = 1
    prev = i

if k % 2 == 1:
    ret = count1 + (k-1) 
else:
    ret = count1 + ((k-1)

print(ret)
Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.buffer.readline
S = list(input())[: -1]
ls = S * 2
K = int(input())
left = 0
mid = 0
right = 0
last = 0
i = 0
while i < len(S):
  if ls[i] == ls[i + 1]:
    left += 1
    if i == len(S) - 1:
      last = 1
    i += 1
  i += 1
i = 0 + last
while i < len(S):
  if ls[i] == ls[i + 1]:
    mid += 1
    i += 1
  i += 1
i = 0 + last
while i < len(S) - 1:
  if ls[i] == ls[i + 1]:
    right += 1
    i += 1
  i += 1
print(left + mid * max(K - 2, 0) + right)

Failing test case input:
iirhs
1

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.buffer.readline
S = list(input())[: -1]
ls = S * 2
K = int(input())
if len(S) == 1:
  print(K 
  exit(0)
if S.count(S[0]) == len(S):
  print(len(S) * K 
  exit(0)
left = 0
mid = 0
right = 0
last = 0
i = 0
while i < len(S):
  if ls[i] == ls[i + 1]:
    left += 1
    if i == len(S) - 1:
      last = 1
    i += 1
  i += 1
i = 0 + last
while i < len(S):
  if ls[i] == ls[i + 1]:
    mid += 1
    i += 1
  i += 1
i = 0 + last
while i < len(S) - 1:
  if ls[i] == ls[i + 1]:
    right += 1
    i += 1
  i += 1
if K == 1:
  i = 0
  res = 0
  while i < len(S) - 1:
    if ls[i] == ls[i + 1]:
      res += 1
      i += 1
    i += 1
  print(res)
else:
  print(left + mid * max(K - 2, 0) + right)

Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import re
import math
import collections
import decimal
import bisect







INF = sys.maxsize


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    s = list(input())
    k = ni()

    cnt = 0
    for i in range(len(s)):
        next = i + 1 if i < len(s) - 1 else 0
        if s[i] == s[next]:
            s[next] = "@"
            cnt+=1

    print(cnt*k)

if __name__ == '__main__':
    main()


Failing test case input:
hssih
3

Expected output:
5


Actual output:
6


Fixed submission (verdict: Accepted):
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

import copy






INF = sys.maxsize


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    s = list(input())
    k = ni()

    if len(set(s))==1:
        print((len(s)*k)
        exit(0)

    def changer(sss):
        ts = sss.copy()
        cnt = 0
        for i in range(1, len(ts)):
            if ts[i] == ts[i - 1]:
                ts[i] = "@"
                cnt += 1

        return cnt

    print(changer(s) + (k - 1) * (changer(s + s) - changer(s)))


if __name__ == '__main__':
    main()
Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S=input()
K=int(input())
L=len(S)
cnt=0
ren=1

if L==1:
  ans= K
elif L==2:
  if S[0]==S[1]:
    ans = K
  else:
    ans = 0
else:  
  if S[0]!=S[-1]:
    for i in range(1,L):  
      if S[i]==S[i-1]:
        ren +=1
        if i==L-1:
          cnt += ren
      else:
        cnt += ren
        ren=1        
  else:
    pass
  
    


Failing test case input:
tredmdepdedetndmopnnfond
14180048

Expected output:
14180048


Actual output:

Fixed submission (verdict: Accepted):
S=input()
K=int(input())
N=len(S)

if S.count(S[0])==N:
  ans= K*N
else:
  h=0
  for i in range(N):
    if S[i]==S[0]:
      h +=1
    else:
      break
  t=0
  for i in range(N-1,-1,-1):
    if S[i]==S[-1]:
      t +=1
    else:
      break
  ren=1
  cnt=0
  for i in range(h,N-t):
    if S[i]==S[i-1]:
      ren +=1
      if i==N-t-1:
        cnt += ren
    else:
      cnt += ren
      ren=1    
      
  if S[0]==S[-1]:
    
    ans= h
  else:
    
    ans= (h
print(ans)

Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

def main():
    S = input().rstrip()
    K = int(input())
    S += S[0]
    cur, cnt = S[0], 0
    for s in S[1:]:
        if s == cur:
            cur = "."
            cnt += 1
        else:
            cur = s
    ans = cnt * K
    print(ans)


if __name__ == "__main__":
    main()

Failing test case input:
hssih
2

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):

from itertools import groupby


def main():
    S = input().rstrip()
    K = int(input())
    cnt = [len(tuple(s)) for _, s in groupby(S)]  
    if S[0] == S[-1] and K > 1:
        if len(cnt) == 1:  
            ans = cnt[0] * K 
        else:  
            ans = cnt[0] 
            ans += sum(i 
    else:
        ans = sum(i 
    print(ans)


if __name__ == "__main__":
    main()

Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = list(input())
k = int(input())

ans = 0
i = 1
while i < len(s):
    cnt = 1
    if s[i] == s[i - 1] and i < len(s):
        i += 1
        cnt += 1
    ans += cnt 
    i += 1
cnt = 0
if s[0] == s[len(s) - 1] and s[len(s) - 1] != s[len(s) - 2]:
    cnt += 1
print(ans * k + cnt * (k - 1))    

Failing test case input:
enomftppfentrdecpnemeedn
1594731

Expected output:
3189462


Actual output:
36678813


Fixed submission (verdict: Accepted):
s = list(input())
k = int(input())
x = []
ans = 0
cnt = 1
for i in range(len(s)):
    if i < len(s) - 1 and s[i] == s[i + 1]:
        cnt += 1
    else:
        ans += cnt 
        x.append(cnt)
        cnt = 1
cnt = 0
if s[0] == s[len(s) - 1]:
    cnt = x[0] 

print(ans * k - cnt * (k - 1) if len(set(s)) != 1 else len(s) * k
Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = str(input())
K = int(input())
tmp = 1
cnt1 = 0
cnt2 = 0
for i in range(1, len(S)):
    if S[i-1] == S[i]:
        tmp += 1
    else:
        cnt1 += tmp 
        tmp = 1
if tmp > 1:
    cnt1 += tmp
S2 = S + S
tmp = 1
for i in range(1, len(S2)):
    if S2[i-1] == S2[i]:
        tmp += 1
    else:
        cnt2 += tmp 
        tmp = 1
if tmp > 1:
    cnt2 += tmp
if K == 1:
    print(cnt1)
else:
    print((cnt2 - cnt1) * (K-2) + cnt2)

Failing test case input:
enomntppfdntedecpedmredn
2389896

Expected output:
2389896


Actual output:
57357503


Fixed submission (verdict: Accepted):
S = str(input())
K = int(input())
tmp = 1
cnt1 = 0
cnt2 = 0
for i in range(1, len(S)):
    if S[i-1] == S[i]:
        tmp += 1
    else:
        cnt1 += tmp 
        tmp = 1
if tmp == len(S):
        print(len(S) * K 
        exit()
if tmp > 1:
    cnt1 += tmp
S2 = S + S
tmp = 1
for i in range(1, len(S2)):
    if S2[i-1] == S2[i]:
        tmp += 1
    else:
        cnt2 += tmp 
        tmp = 1
if tmp > 1:
    cnt2 += tmp
if K == 1:
    print(cnt1)
else:
    print((cnt2 - cnt1) * (K-2) + cnt2)

Problem: p02891
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from itertools import groupby
s = list(input())
k = int(input())

G = []
for key, group in groupby(s):
    G += [list(group)]
count = 0

if s[0]!=s[-1]:
    for g in G:
        count += len(g)
    print(count*k)
else:
    d = len(G[0])
    for g in G:
        count += len(g)
    print(count*k + d*(k-1))

Failing test case input:
coonoooooonteeeeeeeedest
1894324309

Expected output:
15154594472


Actual output:
45463783416


Fixed submission (verdict: Accepted):
from itertools import groupby
s = list(input())
k = int(input())

G = []
for key, group in groupby(s):
    G += [list(group)]

count = 0

if len(G)==1:
    print(len(s)*k

elif s[0]!=s[-1]:
    for g in G:
        count += len(g)
    print(count*k)

else:
    d = len(G[0]+G[-1])
    for g in G:
        count += len(g)
    print(count*k + d*(k-1))

Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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
            c = 1
        ps = s
        
    if c != 1:
        ans += c 
    
    return ans * K

print(solve())

Failing test case input:
tredmdepdedetndmopnnfond
5168106

Expected output:
5168106


Actual output:
10336212


Fixed submission (verdict: Accepted):
from itertools import groupby

def solve():
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            return a[0] * K 
        else:
            ans = a[0] 
            ans += sum(n 
            return ans
    else:
        return sum(n 
    
print(solve())
Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = list(input())
k = int(input())
count = 0
if len(s) == 1:
    count = int(k / 2)
elif k >= 3:
    t1 = s * 5
    for i in range(len(t1) - 1):
        if t1[i] == t1[i + 1]:
            t1.pop(i + 1)
            t1.insert(i + 1, "")
            count += 1
    if count % 5 == 0:
        count = (count / 5) * k
    else:
        count = ((count + 2) / 5) * k - 2
else:
    t1 = s * k
    for i in range(len(t1) - 1):
        if t1[i] == t1[i + 1]:
            t1.pop(i + 1)
            t1.insert(i + 1, "")
            count += 1
print(int(count))


Failing test case input:
hssih
3

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
s = list(input())
k = int(input())
count = 0
s1 = list(set(s))
if len(s1) == 1:
    count = int((k * len(s)) / 2)
elif k >= 3:
    t1 = s * 5
    for i in range(len(t1) - 1):
        if t1[i] == t1[i + 1]:
            t1.pop(i + 1)
            t1.insert(i + 1, "")
            count += 1
    if count % 5 == 0:
        count = (count / 5) * k
    elif (count + 1) % 5 == 0:
        count = ((count + 1) / 5) * k - 1
    else:
        count = ((count + 2) / 5) * k - 2
else:
    t1 = s * k
    for i in range(len(t1) - 1):
        if t1[i] == t1[i + 1]:
            t1.pop(i + 1)
            t1.insert(i + 1, "")
            count += 1
print(int(count))

Problem: p02891
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

import math


def solve(*args: str) -> str:
    s = args[0]
    k = int(args[1])

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

    return str(
        min(count_adjacent_dup(s), count_adjacent_dup(s[::-1])) * k
    )


def count_adjacent_dup(s: str) -> int:
    ret = 0
    cnt = 0

    for i in range(len(s)):
        if s[i] == s[(i+1) % len(s)]:
            cnt += 1
        else:
            ret += math.ceil(cnt/2)
            cnt = 0

    if 0 < cnt:
        ret += math.ceil(cnt/2)

    return ret


if __name__ == "__main__":
    print(solve(*[input() for _ in range(2)]))


Failing test case input:
hsrih
6

Expected output:
5


Actual output:
6


Fixed submission (verdict: Accepted):

import math


def solve(*args: str) -> str:
    s = args[0]
    k = int(args[1])

    if all([s[0] == c for c in s]):
        return str(int(len(s) * k / 2))

    H = s[0]

    ret = 0
    h = 0
    t = 0
    if H == s[-1] and 1 < k:
        h = t = 1
        while H == s[h] and h < len(s):
            h += 1

        while H == s[-t-1] and t < len(s):
            t += 1
        ret += int((h + t) / 2) * (k - 1) + int(h/2) + int(t/2)

    ret += count_adjacent_dup(s[h:len(s)-t]) * k

    return str(ret)


def count_adjacent_dup(s: str) -> int:
    ret = 0
    cnt = 0

    for i in range(len(s) - 1):
        if s[i] == s[i+1]:
            cnt += 1
        else:
            ret += math.ceil(cnt/2)
            cnt = 0

    if 0 < cnt:
        ret += math.ceil(cnt/2)

    return ret


if __name__ == "__main__":
    print(solve(*[input() for _ in range(2)]))
Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
hssih
6

Expected output:
11


Actual output:
6


Fixed submission (verdict: Accepted):
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 = count
      firstChart = S[i-1]
    else:
      ans += math.ceil(count/2)*K
    flag = True
    count = 0

if flag:
  if firstChart == S[len(S)-1]:
    ans += (firstCount + count + 2) 
    ans += math.ceil(count/2)
    ans += math.ceil(firstCount/2)
  else:
    ans += math.ceil(count/2)*K
    ans += math.ceil(firstCount/2)*K
else:
  ans += (count+1)*K
if len(S) == 1:
  if K == 1:
    print("0")
  else:
    print(math.ceil(K
else:
  print(ans)
Problem: p02891
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string



def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7



show_flg=False
show_flg=True

a=StoI()
a=a+[a[0]]
k=I()
n=len(a)
p=a[0]
t=0
for i in range(n-1):
    if p==a[i+1]:
        t+=1
        p=-1
    else:
        p=a[i+1]

print(t*k)


Failing test case input:
hssih
6

Expected output:
11


Actual output:
12


Fixed submission (verdict: Accepted):
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string



def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7



show_flg=False
show_flg=True

def naive(b,k):
    a=b*k
    n=len(a)
    
    p=a[0]
    t=0
    for i in range(n-1):
        if p==a[i+1]:
            t+=1
            p=-1
        else:
            p=a[i+1]
            
    return t


b=StoI()
a=b
k=I()
n=len(a)
p=a[0]
t=0

if len(b)*k<10:
    print(naive(b,k))
    exit()


for i in range(n-1):
    if p==a[i+1]:
        t+=1
        p=-1
    else:
        p=a[i+1]

odd=naive(b,3)-naive(b,1)
even=naive(b,4)-naive(b,2)
if k%2==1:
    ans=naive(b,1)+(k
else:


    ans=naive(b,2)+(k
print(ans)

Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
k = int(input())
c = 0
d = 0
a = []
s += "A"
for i in range(len(s)-1):
    if (s[i] == s[i+1]):
        c += 1
    else:
        a.append(c+1)
        d += 1
        c = 0
c = 0
if s[0] != s[len(s)-2]:
    for i in range(d):
        c += int(a[i]/2)
    print(int(c*k))
elif d == 1:
    print(int(a[0]*k/2))
else:
    for i in range(1,d):
        c += int(a[i]/2)
    c += (k-1)*int((a[0]+a[d-1])/2) + int(a[0]/2) + int(a[d-1]/2)
    print(int(c))

Failing test case input:
hssih
2

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
s = input()
k = int(input())
c = 0
d = 0
a = []
s += "A"
for i in range(len(s)-1):
    if (s[i] == s[i+1]):
        c += 1
    else:
        a.append(c+1)
        d += 1
        c = 0
c = 0
if s[0] != s[len(s)-2]:
    for i in range(d):
        c += a[i]
    print(int(c*k))
elif d == 1:
    print(int(a[0]*k
else:
    for i in range(d):
        c += a[i]
    c = c*k - (k-1)*(a[0]
    print(int(c))
Problem: p02891
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import string


def count_changes(s, k, pool, prev=None):
    if k == 0:
        return 0, None, None
    t = s * k
    count = 0
    i = 0
    prev = prev or t[0]
    for cur in t[1:]:
        if cur == prev:
            count += 1
            prev = pool[i]
            i = (i + 1) % length
        else:
            prev = cur
    return count, i, prev


if __name__ == '__main__':
    s = input()
    k = int(input())
    pool = list(set(string.ascii_lowercase) - set(s))
    length = len(pool)
    if k <= 2:
        print(count_changes(s, k, pool)[0])
    else:
        base_count, i, prev = count_changes(s, 3, pool)
        d, rest = divmod(k, 3)
        print(base_count * d + count_changes(s, rest, pool, prev)[0])


Failing test case input:
rq
206

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
def count_changes(s, k, prev=None):
    count = 0
    for _ in range(k):
        for cur in s:
            if cur == prev:
                count += 1
                prev = None
            else:
                prev = cur
    return count, prev


if __name__ == '__main__':
    s = input()
    k = int(input())
    if len(set(s)) == 1:
      print((len(s) * k) 
      exit()
    if k <= 10 ** 8:
        print(count_changes(s, k)[0])
    else:
        base_count, prev = count_changes(s, 3)
        d, rest = divmod(k, 3)
        res = base_count * d
        if rest:
            res += count_changes(s, rest, prev)[0]
        elif s[0] == prev:
            res += (d - 1)
        print(res)

Problem: p02891
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

S = input()

K = int(input())

now = 1
ans = 0

for i in range(len(S)-1):

    if S[i+1] == S[i]:
        now += 1

    else:

        ans += now 
        now = 1

ans += now 



S2 = S + S

now = 1
ans2 = 0
for i in range(len(S2)-1):

    if S2[i+1] == S2[i]:
        now += 1

    else:

        ans2 += now 
        now = 1



ans2 += now 
sub = ans2 - ans




print (ans + sub * (K-1))

Failing test case input:
fnomftppfemurdecpndmeedm
1085

Expected output:
2170


Actual output:
26040


Fixed submission (verdict: Accepted):
import sys

S = input()

K = int(input())

now = 1
ans = 0

same = False
dic = {}
for i in S:
    if i not in dic:
        dic[i] = 1

if len(dic) == 1:
    print (len(S) * K 
    sys.exit()

for i in range(len(S)-1):

    if S[i+1] == S[i]:
        now += 1

    else:

        ans += now 
        now = 1

ans += now 



S2 = S + S

now = 1
ans2 = 0
for i in range(len(S2)-1):

    if S2[i+1] == S2[i]:
        now += 1

    else:

        ans2 += now 
        now = 1



ans2 += now 
sub = ans2 - ans




print (ans + sub * (K-1))
Problem: p02891
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

import math


def solve(*args: str) -> str:
    s = args[0]
    k = int(args[1])

    if all([s[0] == c for c in s]):
        return str(int(len(s) * k / 2))

    return str(
        min(count_adjacent_dup(s), count_adjacent_dup(s[::-1])) * k
    )


def count_adjacent_dup(s: str) -> int:
    ret = 0
    cnt = 0

    for i in range(len(s)):
        if s[i] == s[(i+1) % len(s)]:
            cnt += 1
        else:
            ret += math.ceil(cnt/2)
            cnt = 0

    if 0 < cnt:
        ret += math.ceil(cnt/2)

    return ret


if __name__ == "__main__":
    print(solve(*[input() for _ in range(2)]))


Failing test case input:
hssih
2

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):

import math


def solve(*args: str) -> str:
    s = args[0]
    k = int(args[1])

    if all([s[0] == c for c in s]):
        return str(int(len(s) * k / 2))

    H = s[0]

    ret = 0
    h = 0
    t = 0
    if H == s[-1] and 1 < k:
        h = t = 1
        while H == s[h] and h < len(s):
            h += 1

        while H == s[-t-1] and t < len(s):
            t += 1
        ret += int((h + t) / 2) * (k - 1) + int(h/2) + int(t/2)

    ret += count_adjacent_dup(s[h:len(s)-t]) * k

    return str(ret)


def count_adjacent_dup(s: str) -> int:
    ret = 0
    cnt = 0

    for i in range(len(s) - 1):
        if s[i] == s[i+1]:
            cnt += 1
        else:
            ret += math.ceil(cnt/2)
            cnt = 0

    if 0 < cnt:
        ret += math.ceil(cnt/2)

    return ret


if __name__ == "__main__":
    print(solve(*[input() for _ in range(2)]))

Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S=list(input())
K=int(input())
l=[1]
for i in range(len(S)-1):
    if S[i]==S[i+1]:l[-1]+=1;
    else:l.append(1)
if len(l)==1:ans = len(S)*K/2;
else:
    l2=[i/2 for i in l]
    if S[0]==S[-1]:
        ht=(l[0]+l[-1])
        ans=l2.pop(0)
        ans+=l2.pop(-1)
        ans+=sum(l2)*K
        ans+=ht*(K-1)
    else:
        ans=sum(l2)*K
print(int(ans))
    


Failing test case input:
enomntppfdntedecpedmredn
3101202

Expected output:
3101202


Actual output:
37214424


Fixed submission (verdict: Accepted):
S=list(input())
K=int(input())
l=[1]
for i in range(len(S)-1):
    if S[i]==S[i+1]:l[-1]+=1;
    else:l.append(1)
if len(l)==1:ans = len(S)*K
else:
    l2=[i
    if S[0]==S[-1]:
        ht=(l[0]+l[-1])
        ans=l2.pop(0)
        ans+=l2.pop(-1)
        ans+=sum(l2)*K
        ans+=ht*(K-1)
    else:
        ans=sum(l2)*K
print(int(ans))
Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
K = int(input())

import re

def nchars(s, n):
    
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

S = "cooooooooonteeeeeeeeeest"
K = 999993333

ans = 0





con = list(nchars(S, 2))

for coni in con:
    if int(len(coni))%2==0:
        print("even")
    elif int(len(coni))%2==1:
        print("odd")
    else:
        print("break")

    print(int(len(coni)/2))
    ans +=int(len(coni)/2)

print(ans*K)


Failing test case input:
rr
597

Expected output:
597


Actual output:
odd
4
even
5
8999939997


Fixed submission (verdict: Accepted):
import re

def nchars(s, n):
    
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

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

con = list(nchars(S, 1))

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

else:
    cons = []
    for coni in con:
        cons.append(int(len(coni)/2))

    c1 = cons[0]

    c2 = 0
    for i in range(len(cons)):
        if i != 0 and i != len(cons)-1:
            c2 += cons[i]

    if con[0][0]==con[-1][0]:
        c3 = int(len(con[0]+con[-1])/2)
    else:
        c3 = int(len(con[0])/2) + int(len(con[-1])/2)

    c4 = int(cons[-1])

    print(int(c1 + c2*K + c3 *(K-1) + c4))

Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import floor, ceil
s = input()
k = int(input())

def f(s):
    b = ''
    ret = 0
    for i in s:
        if i==b:
            b = ''
            ret += 1
            continue
        b = i
    return ret

b = f(s*2) - f(s*1)
c = f(s*3) - f(s*2)
print(b*floor(k/2) + c*ceil(k/2))

Failing test case input:
hssih
2

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
from math import floor, ceil
s = input()
k = int(input())

def f(s):
    b = ''
    ret = 0
    for i in s:
        if i==b:
            b = ''
            ret += 1
            continue
        b = i
    return ret

b = f(s*2) - f(s*1)
c = f(s*3) - f(s*2)
print(f(s) + b*floor(k/2) + c*ceil(k/2-1))
Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    S = input()
    K = int(input())
    ans = 0
    L = len(S)
    if L == 1:
        ans = K
        print(ans)
        exit()
    cnt = 1
    for i in range(L):
        if i < L-1 and S[i] == S[i+1]:
            cnt += 1
        else:
            ans += cnt
            cnt = 1
    ans *= K
    if S[0] == S[-1]:
        t = S[0]
        i = 0
        a = 0
        b = 0
        while S[i] == t and i < L:
            a += 1
            i += 1
            if i >= L:break
        i = L-1
        while S[i] == t and i >= 0:
            b += 1
            i -= 1
            if i < 0:break
        tmp = a
        tmp *= (K-1)
        ans -= tmp
    print(ans)
if __name__ == "__main__":
    main()


Failing test case input:
cooooooooonteeeeeeeedest
999993333

Expected output:
7999946664


Actual output:
23999839992


Fixed submission (verdict: Accepted):
def main():
    S = input()
    K = int(input())
    ans = 0
    L = len(S)
    s = set([i for i in S])
    if len(s) == 1:
        print((L*K)
        exit()
    cnt = 1
    for i in range(L):
        if i < L-1 and S[i] == S[i+1]:
            cnt += 1
        else:
            ans += cnt
            cnt = 1
    ans *= K
    if S[0] == S[-1]:
        t = S[0]
        i = 0
        a = 0
        b = 0
        while i < L and S[i] == t:
            a += 1
            i += 1

        i = L-1
        while i >= 0 and S[i] == t:
            b += 1
            i -= 1

        tmp = a
        tmp *= (K-1)
        ans -= tmp
    print(ans)
if __name__ == "__main__":
    main()

Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
K = int(input())

S = S + S
i = 0
count = 0
while i < len(S)-1:
  if S[i] == S[i+1]:
    count += 1
    i += 2
    continue
  i += 1
one_time = count 
two_time = count 

print(one_time + two_time * (K - 1))

Failing test case input:
tsedeeeeeeeetnoooooooooc
999993333

Expected output:
7999946664


Actual output:
15999893328


Fixed submission (verdict: Accepted):
S = input()
K = int(input())

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

if count % 3 == 0:
  print(count 
elif count % 3 == 1:
  print(count 
elif count % 3 == 2:
  print((count+1)
Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import re

def nchars(s, n):
    
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]
S = input()
K = int(input())

con = list(nchars(S, 1))

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

else:
    cons = []
    for coni in con:
        cons.append(int(len(coni)/2))

    c1 = cons[0]

    c2 = 0
    for i in range(len(cons)):
        if i != 0 and i != len(cons)-1:
            c2 += cons[i]

    c3 = int(len(con[0]+con[len(cons)-1])/2)

    c4 = int(cons[len(cons)-1])

    print(int(c1 + c2*K + c3 *(K-1) + c4))


Failing test case input:
tsedeeeeeeeetnoooooonooc
54816478

Expected output:
438531824


Actual output:
493348301


Fixed submission (verdict: Accepted):
import re

def nchars(s, n):
    
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

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

con = list(nchars(S, 1))

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

else:
    cons = []
    for coni in con:
        cons.append(int(len(coni)/2))

    c1 = cons[0]

    c2 = 0
    for i in range(len(cons)):
        if i != 0 and i != len(cons)-1:
            c2 += cons[i]

    if con[0][0]==con[-1][0]:
        c3 = int(len(con[0]+con[-1])/2)
    else:
        c3 = int(len(con[0])/2) + int(len(con[-1])/2)

    c4 = int(cons[-1])

    print(int(c1 + c2*K + c3 *(K-1) + c4))

Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
k = int(input())
query = []
query2 = []
tmp = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    tmp += 1
  else:
    query.append(tmp)
    tmp = 1
query.append(tmp)
tmp = 1
s2 = s+s
for i in range(len(s2)-1):
  if s2[i] == s2[i+1]:
    tmp += 1
  else:
    query2.append(tmp)
    tmp = 1
query2.append(tmp)
ans1 = 0
ans2 = 0
for i in query:
  ans1 += i
for i in query2:
  ans2 += i

if k== 1:
  print(ans1)
else:
  ans = ans1+(ans2-ans1)*(k-1)
  print(ans)

Failing test case input:
enomntppfdntedecpfemredn
4134275

Expected output:
4134275


Actual output:
99222600


Fixed submission (verdict: Accepted):
s = input()
k = int(input())
query = []
query2 = []
tmp = 1
if len(set(s)) == 1:
  print(len(s)*k
  exit()

for i in range(len(s)-1):
  if s[i] == s[i+1]:
    tmp += 1
  else:
    query.append(tmp)
    tmp = 1
query.append(tmp)
tmp = 1
s2 = s+s
for i in range(len(s2)-1):
  if s2[i] == s2[i+1]:
    tmp += 1
  else:
    query2.append(tmp)
    tmp = 1
query2.append(tmp)
ans1 = 0
ans2 = 0
for i in query:
  ans1 += i
for i in query2:
  ans2 += i

if k== 1:
  print(ans1)
else:
  ans = ans1+(ans2-ans1)*(k-1)
  print(ans)
Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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 
            rep = 1

if rep > 1:
    ans += 1

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)

Failing test case input:
dnonoooooentedeepeeedest
17669775

Expected output:
70679100


Actual output:
176697750


Fixed submission (verdict: Accepted):
s = input()
k = int(input())

ans = 0
rep = 1
first_rep = 1

tmp = None
for i in s:
    if tmp:
        if tmp == i:
            first_rep += 1
        else:
            break
    else:
        tmp = i

if first_rep == len(s):
    print(len(s) * k 
    exit(0)


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 
            rep = 1

if rep > 1:
    ans += rep 

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


print(ans * k + start_eq_end)

Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
K = int(input())
N = len(S)

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))



Failing test case input:
issii
2

Expected output:
4

Actual output:
5


Fixed submission (verdict: Accepted):
S = input()
K = int(input())
N = len(S)

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)

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*K + ((front+back)
Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
K = int(input())

a = S[0]
c = 0
g = []

for i in range(len(S)):
    if a == S[i]:
        c += 1
    else:
        g.append(c)
        a = S[i]
        c = 1

g.append(c)

if len(g) == 1:
    c = len(S) * K / 2
elif S[0] == S[-1]:
    c = int(g[0] / 2)
    c += int(g[-1] / 2)

    for i in range(1, len(g) - 1):
        c += int(g[i] / 2) * (K - 1)
else:
    c = 0
    for i in g:
        c += int(i / 2) * K


print(int(c))



Failing test case input:
hirsh
6

Expected output:
5


Actual output:
0


Fixed submission (verdict: Accepted):
S = input()
K = int(input())

a = S[0]
c = 0
g = []

for i in range(len(S)):
    if a == S[i]:
        c += 1
    else:
        g.append(c)
        a = S[i]
        c = 1

g.append(c)

if len(g) == 1:
    c = len(S) * K / 2
elif S[0] == S[-1]:
    c = int(g[0] / 2)
    c += int(g[-1] / 2)
    c += int((g[0]+g[-1]) / 2) * (K-1)

    for i in range(1, len(g) - 1):
        c += int(g[i] / 2) * K
else:
    c = 0
    for i in g:
        c += int(i / 2) * K


print(int(c))

Problem: p02891
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s=str(input())
k=int(input())
s=list(s)
s2=s+s
cnt=0
temp1=0
temp2=0
for i in range(1,len(s)):
  if s[i]==s[i-1]:
    cnt=cnt+1
  if s[i]!=s[i-1]:
    temp1=temp1+(cnt+1)
    cnt=0
temp1=temp1+(cnt+1)
cnt=0
for i in range(1,len(s2)):
  if s2[i]==s2[i-1]:
    cnt=cnt+1
  if s2[i]!=s2[i-1]:
    temp2=temp2+(cnt+1)
    cnt=0
temp2=temp2+(cnt+1)
cnt=0
if k==1:
  print(temp1)
else:
  print(temp1+(temp2-temp1)*(k-1))

Failing test case input:
enomntppfdntedecpedmredn
3101202

Expected output:
3101202


Actual output:
74428848


Fixed submission (verdict: Accepted):
s=str(input())
k=int(input())
s=list(s)
s2=s+s
cnt=0
temp1=0
temp2=0
l=0
for i in range(1,len(s)):
  if s[i]==s[i-1]:
    cnt=cnt+1
    l=l+1
  if s[i]!=s[i-1]:
    temp1=temp1+(cnt+1)
    cnt=0
temp1=temp1+(cnt+1)
cnt=0
for i in range(1,len(s2)):
  if s2[i]==s2[i-1]:
    cnt=cnt+1
  if s2[i]!=s2[i-1]:
    temp2=temp2+(cnt+1)
    cnt=0
temp2=temp2+(cnt+1)
cnt=0
if l==len(s)-1:
  print(k*len(s)
elif k==1:
  print(temp1)
else:
  print(temp1+(temp2-temp1)*(k-1))
Problem: p02891
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import string


def count_changes(s, k, prev=None):
    count = 0
    for _ in range(k):
        for cur in s:
            if cur == prev:
                count += 1
                prev = None
            else:
                prev = cur
    return count


if __name__ == '__main__':
    s = input()
    k = int(input())
    if k <= 2:
        print(count_changes(s, k))
    else:
        base_count = count_changes(s, 3)
        d, rest = divmod(k, 3)
        res = base_count * d
        if rest:
            res += count_changes(s, rest)
        print(res)

Failing test case input:
hirsh
6

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
def count_changes(s, k, prev=None):
    count = 0
    for _ in range(k):
        for cur in s:
            if cur == prev:
                count += 1
                prev = None
            else:
                prev = cur
    return count, prev


if __name__ == '__main__':
    s = input()
    k = int(input())
    if len(set(s)) == 1:
      print((len(s) * k) 
      exit()
    if k <= 10 ** 8:
        print(count_changes(s, k)[0])
    else:
        base_count, prev = count_changes(s, 3)
        d, rest = divmod(k, 3)
        res = base_count * d
        if rest:
            res += count_changes(s, rest, prev)[0]
        elif s[0] == prev:
            res += (d - 1)
        print(res)

Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = list(input())
k = int(input())
sl = len(s)

d, l, r = s[0], 0, 0

if d == s[-1]:
    for i in range(1, sl):
        if s[i] != d:
            l = i
            break
    
    for i, c in enumerate(s[::-1]):
        if c != d:
            r = i
            break

ans = l
s = s[l:sl-r]
cnt = 0

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

ans += cnt * k

print(ans)


Failing test case input:
hssih
3

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
s = list(input())
k = int(input())
sl = len(s)

if len(set(s)) == 1:
    print(sl*k
    exit()

d, l, r = s[0], 0, 0

if d == s[-1]:
    for i in range(1, sl):
        if s[i] != d:
            l = i
            break
    
    for i, c in enumerate(s[::-1]):
        if c != d:
            r = i
            break

ans = l
s = s[l:sl-r]
cnt = 0

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

ans += cnt * k

print(ans)
Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
s = list(input())
ss = s[:]
k = int(input())
cnt = 0

if len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2)
else:
    cnt = 0
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt += 1
            s[i + 1] = '*'
    cnt *= k
    if s[0] == s[-1]:
        a = 0
        for i in range(len(s) - 1):
            if ss[i] == ss[i + 1]:
                a += 1
        b = 0
        for j in range(len(s)-1, 0, -1):
            if ss[j] == ss[j - 1]:
                b += 1
        cnt -= (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2))
print(cnt)

Failing test case input:
hirsh
6

Expected output:
5


Actual output:
0


Fixed submission (verdict: Accepted):
import math
s = list(input())
ss = s[:]
k = int(input())
cnt = 0

if len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2)
else:
    cnt = 0
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt += 1
            s[i + 1] = '*'
    cnt *= k
    if ss[0] == ss[-1]:
        a = 1
        for i in range(len(ss) - 1):
            if ss[i] == ss[i + 1]:
                a += 1
            else:
                break
        b = 1
        for j in range(len(ss) - 1, 0, -1):
            if ss[j] == ss[j - 1]:
                b += 1
            else:
                break
        cnt -= (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2))
print(cnt)

Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
k=int(input())
p=s[0]
cnt=1
q=[]
for i in range(len(s)-1):
	if s[i+1]==p:
		cnt+=1
	else:
		q.append(cnt)
		cnt=1
		p=s[i+1]
q.append(cnt)
if q[-1]%2==0:
	cnt=True
else:
	cnt=False
ans=0
if cnt==True:
	for i in range(len(q)):
		ans+=q[i]
	print(ans*k)
	exit()
for i in range(len(q)):
	ans+=q[i]
ans*=k
if s[0]==s[-1]:
	ans+=k-1
print(ans)




Failing test case input:
cnonooooopntedeeeeeedest
17669775

Expected output:
88348875


Actual output:
424074600


Fixed submission (verdict: Accepted):
s=input()
k=int(input())
p=s[0]
cnt=1
q=[]
for i in range(len(s)-1):
	if s[i+1]==p:
		cnt+=1
	else:
		q.append(cnt)
		cnt=1
		p=s[i+1]
q.append(cnt)
if q[-1]%2==0:
	cnt=True
else:
	cnt=False
ans=0
if cnt==True:
	for i in range(len(q)):
		ans+=q[i]
	print(ans*k)
	exit()
if len(q)==1:
	print(len(s)*k
	exit()
for i in range(len(q)-2):
	ans+=q[i+1]
ans*=k
ans+=q[0]
if s[0]==s[-1]:
	ans+=(q[0]+q[-1])
	ans+=q[-1]
	print(ans)
	exit()
else:
	ans=0
	for i in range(len(q)):
		ans+=q[i]
	print(ans*k)
Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
K = int(input())

def one(S):
    c = 0
    r = 1
    pre = ""
    for s in S:
        if pre == s:
            r += 1
        else:
            c += r 
            r = 1
        pre = s
    c += r 
    return c

def two(S):
    c = 0
    r = 1
    pre = ""
    for s in S*2:
        if pre == s:
            r += 1
        else:
            c += r 
            r = 1
        pre = s
    c += r 
    return c

o = one(S)
t = two(S)

print(o * K + (t-o*2)*(K-1))

Failing test case input:
fnomftppfemurdecpndmeedm
1220

Expected output:
2440


Actual output:
29281


Fixed submission (verdict: Accepted):
S = input()
K = int(input())

f = False
pre = S[0]
for s in S:
    if pre != s:
        break
else:
    f = True

def one(S):
    c = 0
    r = 1
    pre = ""
    for s in S:
        if pre == s:
            r += 1
        else:
            c += r 
            r = 1
        pre = s
    c += r 
    return c

def two(S):
    c = 0
    r = 1
    pre = ""
    for s in S*2:
        if pre == s:
            r += 1
        else:
            c += r 
            r = 1
        pre = s
    c += r 
    return c

o = one(S)
t = two(S)

if f:
    print(len(S)*K
else:
    print(o*K + (t-o*2)*(K-1))

Problem: p02891
Buggy submission (Python (3.8.2), verdict: Wrong Answer):


def main():
    S = input()
    K = int(input())

    cnt = 0
    ans = 0
    s_temp = ""
    for s in S:
        if s_temp == s:
            cnt += 1
            s_temp = s
        else:
            ans += cnt 
            cnt = 1
            s_temp = s
    ans += cnt 
    ans *= K
    if S[0] == S[-1] and cnt % 2 == 1:
        ans += K - 1

    print(ans)


if __name__ == "__main__":
    main()

Failing test case input:
oo
13

Expected output:
13


Actual output:
26


Fixed submission (verdict: Accepted):


def main():
    S = input()
    K = int(input())

    cnt = 0
    ans = 0
    s_temp = S[0]
    fcnt = 0
    for s in S:
        if s_temp == s:
            cnt += 1
            s_temp = s
        else:
            ans += cnt 
            if fcnt == 0:
                fcnt = cnt
            cnt = 1
            s_temp = s
    if fcnt == 0:
        fcnt = cnt
    ans += cnt 
    ans *= K
    if len(S) == fcnt:
        ans = (len(S) * K) 
    elif S[0] == S[-1]:
        ans -= (fcnt 

    print(ans)


if __name__ == "__main__":
    main()
Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = list(input())
k = int(input())

l = len(s)

ss = s + s
ll = len(ss)

single = 0
cnt = 0

for i in range(1, l):
    if s[i - 1] == s[i]:
        if cnt == 0:
            single += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                single += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0

double = 0
cnt = 0

for i in range(1, ll):
    if ss[i - 1] == ss[i]:
        if cnt == 0:
            double += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                double += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0

if single * 2 == double:
    ans = single * k
else:
    if k % 2 == 0:
        ans = double * k 
    else:
        ans = double * k 
print(ans)

Failing test case input:
hirsh
6

Expected output:
5


Actual output:
6


Fixed submission (verdict: Accepted):
s = list(input())
k = int(input())

l = len(s)

ss = s + s
ll = len(ss)

single = 0
cnt = 0

for i in range(1, l):
    if s[i - 1] == s[i]:
        if cnt == 0:
            single += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                single += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0

double = 0
cnt = 0

for i in range(1, ll):
    if ss[i - 1] == ss[i]:
        if cnt == 0:
            double += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                double += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0

if len(set(s)) == 1:
    ans = double * (k 
elif single * 2 == double:
    ans = single * k
else:
    ans = single + (single + 1) * (k - 1)


print(ans)

Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
K = int(input())

X = []
b = S[0]
cnt = 1
for i in range(1, len(S)):
    s = S[i]
    if b == s:
        cnt += 1
    else:
        X.append([b, cnt])
        cnt = 1
        b = s
X.append([b, cnt])

result = 0
for x in X:
    result += x[1] 

result = result * K
if len(X) != 1 and X[0][0] == X[-1][0] and (X[0][1] + X[-1][1]) % 2 == 0:
    result += (X[0][1] + X[-1][1]) 
print(result)


Failing test case input:
fnouftppgemmceerpndmeedm
3

Expected output:
12


Actual output:
72


Fixed submission (verdict: Accepted):
S = input()
K = int(input())

X = []
b = S[0]
cnt = 1
for i in range(1, len(S)):
    s = S[i]
    if b == s:
        cnt += 1
    else:
        X.append([b, cnt])
        cnt = 1
        b = s
X.append([b, cnt])

result = 0
if len(X) == 1:
    print(X[0][1] * K 
elif X[0][0] == X[-1][0]:
    s = X.pop(0)
    e = X.pop()
    for x in X:
        result += x[1] 
    result *= K

    result += s[1] 
    result += e[1] 
    x = (s[1] + e[1]) 
    result += x * (K - 1)
    print(result)
else:
    for x in X:
        result += x[1] 
    result *= K
    print(result)
Problem: p02891
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    S = input()
    K = int(input())
    ans = 0

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

    if ans is 0 and S[0] is S[-1]:
        print(K - 1)
    else:
        print(ans * K)


if __name__ == "__main__":
    main()


Failing test case input:
hssih
3

Expected output:
5


Actual output:
3


Fixed submission (verdict: Accepted):
def main():
    S = input()
    K = int(input())
    ans = 0

    if len(set(S)) is 1:
        print(len(S) * K 
        return

    i = 0
    cnt = [1]
    while i < len(S) - 1:
        if S[i] is S[i + 1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
        i += 1

    for v in cnt:
        ans += (v 

    if S[0] is S[-1]:
        if cnt[0] % 2 == cnt[-1] % 2 == 1:
            ans += K - 1

    print(ans)


if __name__ == "__main__":
    main()

Problem: p02891
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
S = input()
K = int(input())
n = len(S)
print(S*3)
S_3 = list(S * 3)
c_1 = 0
c_2 = 0
c_3 = 0
for i in range(n*3-1):
    if S_3[i] == S_3[i+1]:
        if i < n-1:
            c_1 += 1
        elif i < n*2-1:
            c_2 += 1
        else:
            c_3 += 1
        S_3[i+1] = "_"

if K == 1:
    c = 0
    for i in range(n-1):
        if S[i] == S[i+1]:
            c += 1
else:
    c = c_1 + c_2 * (K-2) + c_3
print(c)



Failing test case input:
tsedeeeeeeeetnoooooonooc
1894324309

Expected output:
15154594472


Actual output:
tsedeeeeeeeetnoooooonooctsedeeeeeeeetnoooooonooctsedeeeeeeeetnoooooonooc
15154594472


Fixed submission (verdict: Accepted):
import sys

S = input()
K = int(input())
n = len(S)

if S == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":
  print(49499999950)
  sys.exit()

if n == 1:
  print(K 
  sys.exit()

S_3 = list(S * 3)
c_1 = 0
c_2 = 0
c_3 = 0
for i in range(n*3-1):
    if S_3[i] == S_3[i+1]:
        if i < n-1:
            c_1 += 1
        elif i < n*2-1:
            c_2 += 1
        else:
            c_3 += 1
        S_3[i+1] = "_"

if K == 1:
    c = 0
    for i in range(n-1):
        if S[i] == S[i+1]:
            c += 1
else:
    c = c_1 + c_2 * (K-2) + c_3
print(c)