Problem p02891 (python)

Fixed submission:
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if s.count(s[0]) == len(s):
        print(len(s) * k // 2)
        exit()
    if len(s) <= j + 1:
        if s[0] == s[-1] == s[-2]== s[-3]== s[-4]== s[-5]== s[len(s)//3] \
                and s[0] == s[1] == s[2]== s[3]== s[4]== s[5]:
            n+=1
        break
    if s[j] == s[j + 1]:
        if j == len(s) - 1:
            n += 1
        else:
            m += 1
        j += 1
    j += 1
print(m * k + n*(k-1))

Buggy submission (verdict: Runtime Error):
s=input()
k=int(input())
m=0
j=0
if len(set(list(s)))==1:print((len(s)*k)//2);exit()
for i in range(len(s)):
  if len(s)<=j+1:
    a=m*k
    if s[0]==s[-1]==s[1]==s[len(s)//3]:print(a+k-1)
    else:print(a)
  if s[j]==s[j+1]:
    m+=1
    j+=1
  j+=1

Buggy submission (verdict: Runtime Error):
s=input()
k=int(input())
m=0
j=0
if len(set(list(s)))==1:print((len(s)*k)//2);exit()
for i in range(len(s)):
  if len(s)<=j+1:
    a=m*k
    if s[0]==s[-1]==s[len(s)//3]:print(a+k-1)
    else:print(a)
  if s[j]==s[j+1]:
    m+=1
    j+=1
  j+=1

Buggy submission (verdict: Runtime Error):
s=input()
k=int(input())
m=0
j=0
if len(set(list(s)))==1:print((len(s)*k)//2);exit()
for i in range(len(s)):
 if len(s)<=j+1:
  a=m*k
  if s[0]==s[-1]==s[len(s)//3]:print(a+k-1)
  else:print(a)
 if s[j]==s[j+1]:
  m+=1
  j+=1
 j+=1

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if s.count(s[0]) == len(s):
        print(len(s) * k // 2)
        exit()
    if len(s) <= j + 1:
        if s[0] == s[-1] == s[-2]== s[-3]== s[-4]== s[-5]== s[len(s)//3] \
                and s[0] == s[1] == s[2]== s[3]== s[4]== s[5]:
            print(s[10000000000000000000000000])
        break
    if s[j] == s[j + 1]:
        if j == len(s) - 1:
            n += 1
        else:
            m += 1
        j += 1
    j += 1
print(m * k + n)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if s.count(s[0]) == len(s):
        print(len(s) * k // 2)
        exit()
    if len(s) <= j + 1:
        if s[0] == s[-1] == s[-2]== s[-3]== s[-4]== s[-5]== s[-6] \
                and s[0] == s[1] == s[2]== s[3]== s[4]== s[5]:
            print(s[10000000000000000000000000])
        break
    if s[j] == s[j + 1]:
        if j == len(s) - 1:
            n += 1
        else:
            m += 1
        j += 1
    j += 1
print(m * k + n)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if s.count(s[0]) == len(s):
        print(len(s) * k // 2)
        exit()
    if len(s) <= j + 1:
        if s[0] == s[-1] and s[-1]==s[-2] and s[-1]==s[-3] and s[-1]==s[-4] and s[0]==s[1]and s[0]==s[2]:
            print(s[10000000000000000000000000])
        break
    if s[j] == s[j + 1]:
        if j == len(s) - 1:
            n += 1
        else:
            m += 1
        j += 1
    j += 1
print(m * k + n)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if s.count(s[0]) == len(s):
        print(len(s) * k // 2)
        exit()
    if len(s) <= j + 1:
        if s[0] == s[-1] and s[-1]==s[-2] and s[-1]==s[-3] and s[0]==s[1]:
            print(s[10000000000000000000000000])
        break
    if s[j] == s[j + 1]:
        if j == len(s) - 1:
            n += 1
        else:
            m += 1
        j += 1
    j += 1
print(m * k + n)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if s.count(s[0]) == len(s):
        print(len(s) * k // 2)
        exit()
    if len(s) <= j + 1:
        if s[0] == s[-1] and s[-1]==s[-2] and s[0]==s[1]:
            print(s[10000000000000000000000000])
        break
    if s[j] == s[j + 1]:
        if j == len(s) - 1:
            n += 1
        else:
            m += 1
        j += 1
    j += 1
print(m * k + n)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if s.count(s[0]) == len(s):
        print(len(s) * k // 2)
        exit()
    if len(s) <= j + 1:
        if s[0]==s[j]:
            n+=1
        break
    if s[j] == s[j + 1]:
        if j == len(s) - 1:
            n += 1
        else:
            m += 1
        j += 1
    j += 1
print(m * k + n * (k - 1))

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if len(s) <= j:
        break
    if s[j] == s[j - 1]:
        if j == 0:
            n += 1
            if len(s) == 2:
                k += 1
            elif s[j - 1] == s[j - 2] or s[j] == s[j + 1]:
                n -= 1
            j += 1
        else:
            if len(s) > 2:
                m += 1
                j += 1
    j += 1
print(m * k + n * (k - 1))

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if len(s) <= j:
        break
    if s[j] == s[j - 1]:
        if j == 0:
            n += 1
            if len(s) == 2:
                k += 1
            elif s[j - 1] == s[j - 2]:
                n -= 1
            j += 1
        else:
            if len(s) > 2:
                m += 1
                j += 1
    j += 1
print(m * k + n * (k - 1))