Problem p02891 (python)

Fixed submission:
S = input()
K = int(input())
a = []
ans = 0
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] :
        count += 1
    else:
        if count!=0:
            ans += (count+1)//2
            a.append(count+1)
            count = 0
if count !=0:
    ans += (count+1)//2 
ans = ans*K
a.append(0)
if len(S) == 1:
    ans = K//2
else:    
    
    if (count+1)%2==1 and a[0]%2 == 1 and S[0]== S[1] and S[0] == S[len(S)-1]:
    
        ans+=K-1
    if S[0]!= S[1] and (count+1)%2 ==1 and  S[0] == S[len(S)-1]:
        ans+=K-1
    if count+1 == len(S):
        if len(S)%2==1:
            ans = (len(S)*K)//2
 
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
a = []
ans = 0
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] :
        count += 1
    else:
        if count!=0:
            ans += (count+1)//2
            a.append(count+1)
            count = 0
if count !=0:
    ans += (count+1)//2 
ans = ans*K
a.append(0)
if len(S) == 1:
    ans = K//2
    print(ans)
    break
if (count+1)%2==1 and a[0]%2 == 1 and S[0]== S[1] and S[0] == S[len(S)-1]:
    
    ans+=K-1
if S[0]!= S[1] and (count+1)%2 ==1 and  S[0] == S[len(S)-1]:
    ans+=K-1

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
a = []
ans = 0
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] :
        count += 1
    else:
        if count!=0:
            ans += (count+1)//2
            a.append(count+1)
            count = 0
if count !=0:
    ans += (count+1)//2 
ans = ans*K
a.append(0)
if (count+1)%2==1 and a[0]%2 == 1 and S[0]== S[1] and S[0] == S[len(S)-1]:
    
    ans+=K-1
if S[0]!= S[1] and (count+1)%2 ==1 and  S[0] == S[len(S)-1]:
    ans+=K-1
if len(S) == 1:
    ans = K//2
 
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
a = []
ans = 0
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] :
        count += 1
    else:
        if count!=0:
            ans += (count+1)//2
            a.append(count+1)
            count = 0
if count !=0:
    ans += (count+1)//2 
ans = ans*K
a.append(0)
if (count+1)%2==1 and a[0]%2 == 1 and S[0]== S[1]:
    
    ans+=K-1
if S[0]!= S[1] and (count+1)%2 ==1:
    ans+=K-1
if len(S) == 1:
    ans = K//2
 
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
a = []
ans = 0
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] :
        count += 1
    else:
        if count!=0:
            ans += (count+1)//2
            a.append(count+1)
            count = 0
if count !=0:
    ans += (count+1)//2 
ans = ans*K
if (count+1+a[0])%2 == 0  and len(a)!=0 and S[0]==S[1] :
    ans+=K-1

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
a = []
ans = 0
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] :
        count += 1
    else:
        if count!=0:
            ans += (count+1)//2
            a.append(count)
            count = 0
if count !=0:
    ans += (count+1)//2 
ans = ans*K
if (count+a[0])%2 == 0 and count!=0 and len(a)!=0 and S[0]==S[1] :
    ans+=K-1

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
a = [0]
ans = 0
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] :
        count += 1
    else:
        if count!=0:
            ans += (count+1)//2
            a.append(count)
            count = 0
if count !=0:
    ans += (count+1)//2 
ans = ans*K
if (count+a[1])%2 == 0 and count!=0:
    ans+=K-1

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
a = []
ans = 0
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] :
        count += 1
    else:
        if count!=0:
            ans += (count+1)//2
            a.append(count)
            count = 0
if count !=0:
    ans += (count+1)//2 
ans = ans*K
if (count+a[0])%2 == 0 and count!=0:
    ans+=K-1

print(ans)