TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
S = list(input())
K = int(input())

if(len(set(S)) == 1):
    print(len(S) // 2 * K)
else:
    m = 0
    ans = 0
    if(S[0] == S[-1]):
        l = 0
        r = len(S) - 1
        while(S[l] == S[l+1]):
            l += 1
        while(S[-r] == S[-r]):
            r += 1
        m = l//2 + r//2 - (l+r)//2
        m *= K - 1
    
    for i in range(len(S)-1):
        if(S[i] == S[i+1]):
            ans += 1
            S[i+1] = "3"
    ans *= K
    ans -= m
    print(ans)





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

if(len(set(S)) == 1):
    print(len(S) // 2 * K)
else:
    m = 0
    ans = 0
    if(S[0] == S[-1]):
        l = 0
        r = 0
        while(S[l] == S[l+1]):
            l += 1
        while(S[-r] == S[-r-1]):
            r += 1
        m = l + r - (l+r)//2
        m *= K - 1

    for i in range(len(S)-1):
        if(S[i] == S[i+1]):
            ans += 1
            S[i+1] = "3"
    ans *= K
    ans -= m
    print(ans)


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

if(len(set(S)) == 1):
    print(len(S) // 2 * K)
else:
    m = 0
    ans = 0
    if(S[0] == S[-1]):
        l = 0
        r = 0
        while(S[l] == S[l+1]):
            l += 1
        while(S[-r] == S[-r-1]):
            r += 1
        l += 1
        r += 1
        m = l//2 + r//2 - (l+r)//2
        m *= K - 1

    for i in range(len(S)-1):
        if(S[i] == S[i+1]):
            ans += 1
            S[i+1] = "3"
    ans *= K
    ans -= m
    print(ans)


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

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

    for i in a:
        ans += (i//2)*K

    if (S[0] == S[-1]):
        ans -= (a[0]//2 + a[-1]//2  - (a[0] + a[-1])//2)*(K-1)

    print(ans)

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
from collections import defaultdict

s = list(map(str, input().rstrip()))
k = int(input())

if all([x == s[0] for x in s]):
    print(len(s) * k // 2)
    sys.exit()

cnt = 0
if s[0] == s[-1]:
    cnt = 2
    start = 1
    goal = 1
    x = s[0]

    for i in s[1:]:
        if i == x:
            cnt += 1
            start += 1
        else:
            break

    for i in s[:-1][::-1]:
        if i == x:
            cnt += 1
            goal += 1
        else:
            break

d = defaultdict(int)

if cnt > 0:
    s = s[start:-goal]
prev = s[0]
tmp = 1

for i, x in enumerate(s[1:]):
    if prev == x and i == (len(s) - 1):
        tmp += 1
        d[tmp] += 1
    elif prev == x:
        tmp += 1
    else:
        d[tmp] += 1
        prev = x
        tmp = 1

if cnt > 0:
    d[cnt] += 1

ans = 0
for key, val in d.items():
    if key == 1:
        continue
    else:
        ans += (key) // 2 * val * k

if cnt > 0:
    ans -= cnt // 2

print(ans)

import sys
from collections import defaultdict

s = list(map(str, input().rstrip()))
k = int(input())
connection = False

if all([x == s[0] for x in s]):
    print(len(s) * k // 2)
    sys.exit()

cnt = 0
if s[0] == s[-1] and k != 1:
    connection = True
    cnt = 2
    start = 1
    goal = 1
    x = s[0]

    for i in s[1:]:
        if i == x:
            cnt += 1
            start += 1
        else:
            break

    for i in s[:-1][::-1]:
        if i == x:
            cnt += 1
            goal += 1
        else:
            break

d = defaultdict(int)

if connection:
    ss = s[:start]
    sg = s[-goal:]
    s = s[start:-goal]
    
prev = s[0]
tmp = 1
for i, x in enumerate(s[1:]):
    if prev == x and i == (len(s) - 2):
        tmp += 1
        d[tmp] += 1
    elif prev == x:
        tmp += 1
    else:
        d[tmp] += 1
        prev = x
        tmp = 1

if connection:
    d[cnt] += 1

ans = 0
for key, val in d.items():
    if key == 1:
        continue
    else:
        ans += key // 2 * val * k

if connection:
    ans -= cnt // 2
    ans += len(ss) // 2 + len(sg) // 2

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S=input()
K=int(input())
S2 = S*2
tmp=0
tmp2=0
for i in range(1,S):
    if S[i-1]==S[i]:
        S[i]="0"
        tmp += 1

for i in range(1,S2):
    if S2[i-1]==S2[i]:
        S2[i]="0"
        tmp2 += 1
print(tmp+(tmp2-tmp)*(K-1))

S=input()
K=int(input())
S2 = S*2
tmp=0
tmp2=0
for i in range(1,S):
    if S[i-1]==S[i]:
        S[i]="0"
        tmp += 1

for i in range(1,S2):
    if S2[i-1]==S2[i]:
        S[i]="0"
        tmp2 += 1
print(tmp+tmp*(K-1))

S=list(input())
K=int(input())
S2 = S*2
tmp=0
tmp2=0
for i in range(1,len(S)):
    if S[i-1]==S[i]:
        S[i]="0"
        tmp += 1

for i in range(1,len(S2)):
    if S2[i-1]==S2[i]:
        S2[i]="0"
        tmp2 += 1
if all([[S[i] == S[0]] for i in range(1,len(S))]):
    print((len(S)*K)//2)
    exit()
print(tmp+(tmp2-tmp)*(K-1))

S=list(input())
K=int(input())
S2 = S*2
tmp=0
tmp2=0

if all([S[i] == S[0] for i in range(1,len(S))]):
    print((len(S)*K)//2)
    exit()
for i in range(1,len(S)):
    if S[i-1]==S[i]:
        S[i]="0"
        tmp += 1

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

print(tmp+(tmp2-tmp)*(K-1))

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from itertools import groupby

s = input() 
k = int(input())

a = [sum(1 for _ in g) for _, g in groupby(s)]
print(a)

ans = 0
if len(a) == 1:
  ans = (len(s)*k)//2
else:
  for i in range (len(a)):
    ans = ans + a[i]//2
  if s[0] == s[-1]:
    ans = ans + (a[0]+a[-1])//2 - a[0]//2 - a[-1]//2

print(ans*k)


from itertools import groupby

s = input() 
k = int(input())

a = [sum(1 for _ in g) for _, g in groupby(s)]
#print(a)

ans = 0
chan = 0
if len(a) == 1:
  ans = (len(s)*k)//2
  print(ans)
else:
  for i in range (len(a)):
    ans = ans + a[i]//2
  if s[0] == s[-1]:
    chan = (a[0]+a[-1])//2 - a[0]//2 - a[-1]//2
  print(ans*k+chan*(k-1))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding:utf-8 -*-

s = input()
k = int(input())
flag = 1
lenth = 1
ans = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        lenth += 1
    else :
        flag = 0
    if flag == 0:
       ans += lenth//2
       lenth = 1
       flag = 1
ans += lenth//2
lenth = 1
flag = 1

ji = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        lenth += 1
    else :
        flag = 0
    if flag == 0:
       # print(lenth)
       if lenth%2 == 1:
            ji += 1
       break
if lenth%2 == 1:
    ji += 1
lenth = 1
flag = 1
for i in range(len(s)-1):

    if s[len(s)-i-1] == s[len(s)-1-(i+1)]:
        lenth += 1
    else :
        flag = 0
    if flag == 0:
       if lenth%2 == 1:
            ji += 1
       break
if lenth%2 == 1:
    ji += 1
ans = ans*k

if ji == 2:
    ans = ans+k-1
print(ans)

# -*- coding:utf-8 -*-

s = input()
k = int(input())
flag = 1
lenth = 1
ans = 0
flag2 = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        lenth += 1
    else :
        flag = 0
    if flag == 0:
       ans += lenth//2
       lenth = 1
       flag = 1
if lenth == len(s):
    print(lenth*k//2)
    flag2 = 4
ans += lenth//2
lenth = 1
flag = 1

ji = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        lenth += 1
    else :
        flag = 0
    if flag == 0:
       # print(lenth)
       if lenth%2 == 1:
            ji += 1
       break
if lenth%2 == 1 and flag ==1:
    ji += 1
lenth = 1
flag = 1
for i in range(len(s)-1):

    if s[len(s)-i-1] == s[len(s)-1-(i+1)]:
        lenth += 1
    else :
        flag = 0
    if flag == 0:
       # print(lenth)
       if lenth%2 == 1:
            ji += 1
       break
if lenth%2 == 1 and flag == 1:
    ji += 1
ans = ans*k

if flag2 == 0:
    if ji == 2 and s[0] == s[len(s)-1]:
        ans = ans+k-1
    if len(s) == 1:
        print(k//2)
    else:
        print(ans)



Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a = [input() for i in range(2)]

text = a[0]
iter = int(a[1])

text_list = list(text)
ren = []
start = text_list[0]
a = 0
for i in range(1,len(text_list)):
  if text_list[i] == start:
    a += 1
    if i == len(text_list)-1:
      ren.append(a)
  else:
    start = text_list[i]
    ren.append(a)
    a = 0

for i in range(len(ren)):
  ren[i] += 1

ans = 0
if text_list[0] == text_list[-1]:
  if ren[0] % 2 == 1 and ren[-1] % 2 == 1:
    for r in ren:
      ans += (r//2)
    ans *= iter
    ans += iter-1
  else:
    for r in ren:
      ans += (r//2)
      ans *= iter    
else:
  for r in ren:
    ans += (r//2)
  ans *= iter

print(ans)
    
  

a = [input() for i in range(2)]

text = a[0]
iter = int(a[1])

text_list = list(text)
ren = []
start = text_list[0]
a = 0
for i in range(1,len(text_list)):
  if text_list[i] == start:
    a += 1
    if i == len(text_list)-1:
      ren.append(a)
  else:
    start = text_list[i]
    ren.append(a)
    a = 0

for i in range(len(ren)):
  ren[i] += 1

if ren == []:
  ren = [1]
  
ans = 0
if len(ren) == 1:
  ans = ren[0] * iter // 2
elif text_list[0] == text_list[-1]:
  if ren[0] % 2 == 1 and ren[-1] % 2 == 1:
    for r in ren:
      ans += (r//2)
    ans *= iter
    ans += iter-1
  else:
    for r in ren:
      ans += (r//2)
    ans *= iter    
else:
  for r in ren:
    ans += (r//2)
  ans *= iter

print(ans)
    


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
import re
import math
import collections
import decimal
import bisect

# import copy
# import heapq
# from collections import deque



INF = sys.maxsize
# MOD = 10 ** 9 + 7

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


# ===CODE===


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

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

    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
    
    tmp=0
    if s[0]=="@" and k==1:
        tmp=1

    print(cnt*k-1)

if __name__ == '__main__':
    main()


import sys
import re
import math
import collections
import decimal
import bisect
import itertools

import copy

# import heapq
# from collections import deque



INF = sys.maxsize
# MOD = 10 ** 9 + 7

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


# ===CODE===


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

    if len(set(s))==1:
        print((len(s)*k)//2)
        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()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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]//2
    print(int(c*k))
elif d == 1:
    print(int(a[0]*k//2))
else:
    for i in range(1,d-1):
        c += a[i]//2
    c += (k-1)*((a[0]+a[d-1])//2) + a[0]//2 + a[d-1]//2
    print(int(c))


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]//2
    print(int(c*k))
elif d == 1:
    print(int(a[0]*k//2))
else:
    for i in range(1,d-1):
        c += a[i]//2
    c += (k-1)*((a[0]+a[d-1])//2) + a[0]//2 + a[d-1]//2
    print(int(c))
    print(a)


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-1):
        c += int(a[i]/2)
    c=c*k
    c += (k-1)*int((a[0]+a[d-1])/2) + int(a[0]/2) + int(a[d-1]/2)
    print(int(c))


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = list(input())
K = int(input())

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

ans = 0
judge = [False] * len(S)

for i in range(1, len(S)):
    if S[i-1] == S[i]:
        ans += 1
        judge[i] = True
        S[i] = '-1'
    
if not judge[len(S)-1] and S[0] == S[-1]:
    ans += 1

print(ans * K - 1)


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

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

cnt1 = 0
tmp = S[0]
for i in range(1, len(S)):
    if S[i] == tmp:
        cnt1 += 1
        S[i] = '.'
    tmp = S[i]

if S[0] == S[-1]:
    cnt2 = K-1
else:
    cnt2 = 0

print(cnt1 + cnt2)

s = list(input())
k = int(input())

if list(s[0]*len(s))==s:
	#print('a')
	print(len(s)*k//2)
	exit()

res = [1]
for i in range(len(s)-1):
	if s[i]==s[i+1]:
		res[-1] += 1
	else:
		res.append(1)
ans = 0
for i in res:
	ans += (i//2)*k
if s[0]==s[-1]:
	diff = (res[0]+res[-1])//2 -(res[0]//2 + res[-1]//2)
	ans += diff*(k-1)
print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
k = int(input())

count = 0
i=0
join_flag =0
join_n = 0

if len(s)==1:
  print(k//2)
    
elif len(s)==2:
  if s[0]==s[1]:
    print(k)
  else:
    print(0)
  
elif len(set(s))==1:
  print(len(s)*k //2)
  
else:
  while i<len(s)-1:
    if s[i] == s[i+1]:
      count+=1
      i+=2
    else:
      i+=1
  
  if (s[-1] == s[0]) :
    join_flag =1
    
  if join_flag:  
    
    left_len = 1
    right_len = 1

    for i in range(len(s)-1):
      if s[i] == s[i+1]:
        left_len +=1
      else:
        break

    for i in range(len(s)-1):    
      if s[-1-i]==s[-2-i]:
        right_len +=1
      else:
        break            
    
    if (left_len + right_len) %2 ==0:        
      join_n = k-1
    else:
      join_n = k//2

  print(count*k + join_n)    

s = input()
k = int(input())

count = 0
i=0
join_flag =0
join_n = 0

if len(s)==1:
  print(k//2)
    
elif len(s)==2:
  if s[0]==s[1]:
    print(k)
  else:
    print(0)
  
elif len(set(s))==1:
  print(len(s)*k //2)
  
else:
  while i<len(s)-1:
    if s[i] == s[i+1]:
      count+=1
      i+=2
    else:
      i+=1
  
  if (s[-1] == s[0]) :
    join_flag =1
    
  if join_flag:      
    left_len = 1
    right_len = 1

    for i in range(len(s)-1):
      if s[i] == s[i+1]:
        left_len +=1
      else:
        break

    for i in range(len(s)-1):    
      if s[-1-i]==s[-2-i]:
        right_len +=1
      else:
        break            
    
    if left_len %2 ==1 and right_len %2 ==1:
      join_n = k-1
    else:
      join_n =0
    
  print(count*k + join_n)    

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s=list(input())
k=int(input())
count,flag=0,0
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        s[i]="A"
        count +=1
if s[0]==s[-1] and s[-1]!="A":
    count +=1
    flag=1


print(count*k if flag==1 else (count*k)-1)

s=list(input())
n=len(s)
k=int(input())
S=s*3
for i in range(n*3-1):
    if S[i]==S[i+1]:S[i+1]="A"
    
A=S[:n].count("A")
B=S[n:n*2].count("A")
C=S[n*2:n*3].count("A")

if s.count(s[0])==n:print(n*k//2)
else:
    if k==1:print(A)
    elif k==2:print(A+B)
    else:print(A+B*(k-2)+C)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
n = len(s)
flg = 0
ans1 = 0
ans2 = 0
for i in range(1,n):
  if s[i] == s[i-1]:
    if flg == 0:
      flg = 1
      ans1 += 1
    else:
      flg = 0
s = s*2
n *= 2
flg = 0
for i in range(1,n):
  if s[i] == s[i-1]:
    if flg == 0:
      flg = 1
      ans2 += 1
    else:
      flg = 0
k = int(input())
print((k//2)*ans2+(k%2)*ans1)

s = input()
n = len(s)
flg = 0
ans1 = 0
ans2 = 0
for i in range(1,n):
  if s[i] == s[i-1] and flg == 0:
    flg = 1
    ans1 += 1
  else:
    flg = 0
s = s*2
n *= 2
flg = 0
for i in range(1,n):
  if s[i] == s[i-1] and flg == 0:
    flg = 1
    ans2 += 1
  else:
    flg = 0
k = int(input())
if len(set(list(s))) == 1:
  print(n*k//4)
elif ans2>ans1*2:
  print((k//2)*ans2+(k%2)*ans1+(k-1)//2)
else:
  print((k//2)*ans2+(k%2)*ans1)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s=input()
k=int(input())
c=0
b=[]
l=1
r=0
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    c+=1
  else:
    b.append(c)
    l=0
if s[0]==s[-1]:
  c+=b[0]
else:
  b.append(c)
  c=0
if l==1:
  print((len(s)*k)//2)
else:
  if s[0]==s[-1]:
    for i in range(len(b)-1):
      r+=(b[i+1]//2)*k
    print(r+b[0]+b[-1]+(c//2)*(k-1))
  else:
    for i in range(len(b)):
      r+=((b[i]//2)*k)
    print(r)

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
K = int(input())

s = [v for v in S]

block = []
count = 1

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        count += 1
        if i+2 == len(s):
            block.append(s[i]*count)
    else:
        block.append(s[i]*count)
        count = 1

z = len(block)
t = 0
d = 0

if not z == 1:
    for j in range(len(block)):
        x = len(block[j])
        if x == 1:
            continue
        else:
            if x%2 == 0:
                t += x/2
            elif x%2 == 1:
                t += x - (x+1)/2
    
    if block[0][0] == block[-1][-1]:
        joint = block[0] + block[-1]
        y = len(joint)
        if y%2 == 1:
            d = 0
        if y%2 == 0:
            d = 1
else:
    p = len(block[0])
    if p%2 == 0:
        t = p/2
    else:
        t = (p-1)/2
        if K%2 == 1:
            ans = t + p*(K-1)/2                       
            print(ans)
            exit()
        else:
            ans = p + p*(K-2)/2
            print(ans)
            exit()

ans = t*K + d*(K-1)
print(ans)

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

s = [v for v in S]

block = []
count = 1

if len(s) == 1:
    if K == 1:
        print(0)
        exit()
    else:
        if K%2 == 1:
            print((K-1)//2)
            exit()
        else:
            print(K//2)
            exit()

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        count += 1
        if i+2 == len(s):
            block.append(s[i]*count)
    else:
        block.append(s[i]*count)
        count = 1

z = len(block)
t = 0
d = 0

if not z == 1:
    for j in range(len(block)):
        x = len(block[j])
        if x == 1:
            continue
        else:
            if x%2 == 0:
                t += x//2
            elif x%2 == 1:
                t += x - (x+1)//2
    
    if block[0][0] == block[-1][-1]:
        joint = block[0] + block[-1]
        y = len(joint)
        if y%2 == 1:
            d = 0
        else:
            d = 1
else:
    p = len(block[0])
    if p%2 == 0:
        t = p//2
    else:
        t = (p-1)//2
        if K%2 == 1:
            ans = t + p*(K-1)//2                       
            print(ans)
            exit()
        else:
            ans = p + p*(K-2)//2
            print(ans)
            exit()

ans = t*K + d*(K-1)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
mycnt = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        mycnt += 1

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

elif S[0] != S[-1]:
    
    print(mycnt * K)

else:
    myleft = 1
    myright = 0
    mys = S[0]
    i = 1
    while S[i] == mys:
        myleft += 1
        i += 1
    
    myright = 0
    i = -1
    while S[i] == mys:
        myright += 1
        i -= 1
    print( (mycnt * K) - ( myleft//2 + myright//2 - (myright + myleft)//2 ) * ( K - 1 ) )
    

S = input()

K = int(input())

mycnt = 0
mynum = 1
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        mynum += 1
    else: 
        if mynum > 1:
            mycnt += mynum//2
            mynum = 1

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

elif S[0] != S[-1]:
    
    print(mycnt * K)

else:
    myleft = 1
    myright = 0
    mys = S[0]
    i = 1
    while S[i] == mys:
        myleft += 1
        i += 1
    
    myright = 0
    i = -1
    while S[i] == mys:
        myright += 1
        i -= 1
    print( (mycnt * K) - ( myleft//2 + myright//2 - (myright + myleft)//2 ) * ( K - 1 ) )

S = input()

#K = 1
K = int(input())

mycnt = 0
mynum = 1
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        mynum += 1
        
    else: 
        mycnt += mynum//2
        mynum = 1
    #print('mycnt=', mycnt)

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

elif S[0] != S[-1]:
    
    print(mycnt * K)

else:
    myleft = 1
    myright = 0
    mys = S[0]
    i = 1
    while S[i] == mys:
        myleft += 1
        i += 1
    
    myright = 0
    i = -1
    while S[i] == mys:
        myright += 1
        i -= 1
    print( (mycnt * K) - ( myleft//2 + myright//2 - (myright + myleft)//2 ) * ( K - 1 ) )
    

S = input()

#K = 1
K = int(input())

mycnt = 0
mynum = 1
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        mynum += 1
        
    else: 
        mycnt += mynum//2
        mynum = 1
    #print('mycnt=', mycnt)
if mynum > 1:
    mycnt += mynum//2 

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

elif S[0] != S[-1]:
    
    print(mycnt * K)

else:
    myleft = 1
    myright = 0
    mys = S[0]
    i = 1
    while S[i] == mys:
        myleft += 1
        i += 1
    
    myright = 0
    i = -1
    while S[i] == mys:
        myright += 1
        i -= 1
    #print(myleft, myright)
    print( (mycnt * K) - ( myleft//2 + myright//2 - (myright + myleft)//2 ) * ( K - 1 ) )

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s=input()
n=int(input())
ss=s+s
tmp1=0
tmps=""
for i in s:
    if tmps==i:
        tmp1+=1
        tmps=""
    else:
        tmps=i
tmp2=0
tmps=""
for i in ss:
    if tmps==i:
        tmp2+=1
        tmps=""
    else:
        tmps=i
sss=s+s+s
tmp3=0
tmps=""
for i in sss:
    if tmps==i:
        tmp3+=1
        tmps=""
    else:
        tmps=i

sa1=tmp2-tmp1
sa2=tmp3-tmp2
if n%2==1:
    print(tmp1+(sa1+sa2)*(n//2))
else:
    print(tmp1+(sa1+sa2)*(n//2-1)*sa1)

s=input()
n=int(input())
ss=s+s
tmp1=0
tmps=""
for i in s:
    if tmps==i:
        tmp1+=1
        tmps=""
    else:
        tmps=i
tmp2=0
tmps=""
for i in ss:
    if tmps==i:
        tmp2+=1
        tmps=""
    else:
        tmps=i
sss=s+s+s
tmp3=0
tmps=""
for i in sss:
    if tmps==i:
        tmp3+=1
        tmps=""
    else:
        tmps=i

sa1=tmp2-tmp1
sa2=tmp3-tmp2
if n%2==1:
    print(tmp1+(sa1+sa2)*(n//2))
else:
    print(tmp1+(sa1+sa2)*(n//2-1)+sa1)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s,k=input(),int(input())
c = 0
r = 0
ss = 0
l = 1
for c1, c2 in zip(s, s[1:]):
    if c1 == c2:
        c += 1
    else:
        r += (c+1)//2
        if ss == 0:
            ss = c+1
        l = c+1
        c = 0
if c:
    r += (c+1)//2
    l = c+1
    if ss == 0:
        ss = c+1
r *= k
if s[0] == s[-1] and (ss*l) % 2:
    r+=(k-1)



s,k=input(),int(input())
c = 0
r = 0
ss = 0
l = 1
for c1, c2 in zip(s, s[1:]):
    if c1 == c2:
        c += 1
    else:
        r += (c+1)//2
        if ss == 0:
            ss = c+1
        l = c+1
        c = 0
if c:
    r += (c+1)//2
    l = c+1
    if ss == 0:
        ss = c+1
r *= k
if len(s) == 1:
    r = k//2
elif ss == len(s):
    r = (k*ss)//2
elif s[0] == s[-1] and (ss*l) % 2:
    r+=(k-1)
print(r)



Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s=input()
k=int(input())
ans=0
for i in range(1,len(s),2):
    if s[i-1]==s[i]:
        ans+=1
print(ans*k)

s=list(input())
k=int(input())
s=s*1000
ans=0
for i in range(1,len(s)):
    if s[i-1]==s[i]:
        ans+=1
        s[i]="A"
print(ans*(k/1000))  

s=list(input())
k=int(input())
ss=s*2
a,b=0,0
i=1
while i<len(s):
    if s[i]==s[i-1]:
        i+=2
        a+=1
    else:
        i+=1
i=1        
while i<len(ss):
    if ss[i]==ss[i-1]:
        i+=2
        b+=1
    else:
        i+=1    
if len(set(s))==1:
    print(len(s)*k//2)
else:
    print(a+(b-a)*(k-1))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = list(input())
k = int(input())
if not s[0]==s[-1]:
  count1=0
  for i in range(len(s)-1):
    if s[i]==s[i+1]:
      s[i+1]=1
      count1+=1
  print(k*count1)
else:
  s[-1]=0
  count2=0
  for i in range(len(s)-1):
    if s[i]==s[i+1]:
      s[i+12]=1
      count2+=1
  print(k*count2+k)
 
  

s=list(input())
n=len(s)
k=int(input())
count=[]
i=0
while i<=n-1:
    j=0
    while i+j+1<=n-1 and s[i+j]==s[i+j+1]:
        j+=1
    count.append(j+1)
    i+=(j+1)

length=len(count)
if length==1:
    print((n*k)//2)
   
else:
    if s[0]==s[-1]:
        ans=0
        for l in range(length):
            if l!=0 and l!=length-1:
                ans+=(count[l]//2)*k
        ans+=(count[0]//2+count[-1]//2)
        ans+=((count[0]+count[-1])//2)*(k-1)
        print(ans)
    else:
        ans=0
        for m in count:
            ans+=(m//2)*k
        print(ans)



Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
k = int(input())


if len(set(s)) == 1:
    print((len(s) * k) // 2)


else :
    
    before_mozi = ''
    count_l = [0]
    same_f = False
    for mozi in s:
        if mozi == before_mozi:
            if not same_f:
                count_l.append(1)
            count_l[-1] += 1
            same_f = True
        else:
            same_f = False
        before_mozi = mozi

    result = sum([x // 2 for x in count_l]) * k

    
    
    if s[0] == s[-1] and (s[0] != s[1] or s[-1] != s[-2]):
        result += k-1

    print(result)


s = input()
k = int(input())


if len(set(s)) == 1:
    print(len(s) * k // 2)

else:
    count_l = []
    before_mozi = ''

    for mozi in s:
        if before_mozi == mozi:
            count_l[-1] += 1
        else:
            count_l.append(1)
        before_mozi = mozi

    
    if s[0] == s[-1]:
        result = sum([x//2 for x in count_l[1:-1]]) * k + count_l[0]//2 + count_l[-1]//2 + (count_l[0] + count_l[-1])//2 * (k-1)

    else:
        result = sum([x//2 for x in count_l]) * k

    print(result)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = int(readline().decode("utf-8").rstip())
K = int(readline())

last = ""
cnt = 0
for s in S:
    if last == s:
        cnt += 1
        last = ""
    else:
        last = s
        
print(cnt * K)


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = readline().decode("utf-8").rstrip()
K = int(readline())

last = ""
cnt = 0
for s in S:
    if last == s:
         += 1
        last = ""
    else:
        last = s
        
print(cnt * K)

#! /usr/bin/env python3

import sys
import numpy as np
from itertools import groupby
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = list(readline().decode().rstrip())
K = int(readline())

g = [len(list(g)) for _, g in groupby(S)]

if len(g) == 1:
    print(len(S) * K // 2)
else:
    acc = sum(l // 2 for l in g) * K
    if S[0] == S[-1] and g[0] % 2 == 1 and g[-1] % 2 == 1:
        acc += K - 1
    print(acc)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
k = int(input())

count = 0
change = False

for i in range(1, len(s)):
    if s[i-1] == s[i] and not change
        count += 1
        change = True
    else:
        change = False

count2 = 0
change2 = False
for i in range(2, len(s)):
    if s[i-1] == s[i] and not change2:
        count2 += 1
        change2 = True
    else:
        change2 = False


if len(s) == 1:
    print(k//2)
elif s[0] == s[-1] and not change:
    if change2:
        print((count+count2+1)*(k//2)+count*(k%2))
    else:
        print(count+(count2+1)*(k-1))
else:
    print(count*k)

s = input()
k = int(input())

count = 0
change = False

for i in range(1, len(s)):
    if s[i-1] == s[i] and not change:
        count += 1
        change = True
    else:
        change = False

count2 = 0
change2 = False
for i in range(2, len(s)):
    if s[i-1] == s[i] and not change2:
        count2 += 1
        change2 = True
    else:
        change2 = False


if len(s) == 1:
    print(k//2)
elif s[0] == s[-1] and not change:
    if change2:
        print((count+count2+1)*(k//2)+count*(k%2))
    else:
        print(count+(count2+1)*(k-1))
else:
    print(count*k)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def p(st):
    l=len(st)
    tc=1
    ac=0
    p=s[0]
    for i in range(1,l):
        if st[i]==p:
            tc+=1
        else:
            ac+=tc//2
            tc=1
            p=st[i]
    else:
        ac+=tc//2
    return ac

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()
ac=p(s)
if k>1:
    ac2=p(s+s)
    if ac==ac2:
        print(ac*k)
    elif ac2-ac==1:
        print(ac*k+(k-1))
    elif ac2-ac==2:
        print(ac*k+(k//2))
else:
    print(ac)

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
if s[0]==s[-1]:
    if s[0]!=s[1] and s[-1]!=s[-2]:
        ans+=k-1
    else:
        ans+=1
print(ans)

def p(st):
    l=len(st)
    tc=1
    ac=0
    p=s[0]
    for i in range(1,l):
        if st[i]==p:
            tc+=1
        else:
            ac+=tc//2
            tc=1
            p=st[i]
    else:
        ac+=tc//2
    return ac

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()
ac=p(s)
if k>1:
    ac4=p(s+s+s+s)
    if ac*4==ac4:
        print(ac*k)
    elif ac4-ac*4==3:
        print(ac*k+(k-1))
    elif ac4-ac*4==2:
        print(ac*k+(k//2))
else:
    print(ac)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

# 001101 -> [0,1,0,1],[2,2,1,1]
def press(array):
    pressed = []
    cnts = []
    remark = array[0]
    cnt = 0
    for i in range(len(array)):
        cnt += 1
        if i == len(array)-1:
            pressed.append(remark)
            cnts.append(cnt)
        elif array[i] != array[i+1]:
            pressed.append(remark)
            cnts.append(cnt)
            remark = array[i+1]
            cnt = 0
    return pressed,cnts

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

N = len(S)
ans = 0
res = 0
pressed, cnts = press(list(S))
for c in cnts:
    res += (c // 2) * K

if N == 1:
    ans += K // 2
elif N == 2:
    ans += res
elif N == 3 and S[0] == S[-1]:
    ans += res + K-1
elif S[0] == S[-1] and S[0] != S[1] and S[-2] != S[-1]:
    ans += res + K-1

print(ans)


#     S = S * K 
#     ans = 0
#     pressed, cnts = press(list(S))
#     for c in cnts:
#         ans += c // 2
#     print(ans)




# 001101 -> [0,1,0,1],[2,2,1,1]
def press(array):
    pressed = []
    cnts = []
    remark = array[0]
    cnt = 0
    for i in range(len(array)):
        cnt += 1
        if i == len(array)-1:
            pressed.append(remark)
            cnts.append(cnt)
        elif array[i] != array[i+1]:
            pressed.append(remark)
            cnts.append(cnt)
            remark = array[i+1]
            cnt = 0
    return pressed,cnts

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

N = len(S)
pressed, cnt = press(S)
if len(cnt) == 1:
    ans = N*K // 2
elif S[0] != S[-1]:
    ans = 0
    for c in cnt:
        ans += (c // 2) * K
else:
    ans = (cnt[0] + cnt[-1])//2 * (K-1)+ cnt[0]//2 + cnt[-1]//2
    for i in range(1,len(cnt)-1):
        ans += (cnt[i] // 2) * K

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from itertools import groupby
S = input()
k = int(input())

seq = [(s, len(list(k))) for s, k in groupby(S)]
print(*seq, sep="\n")

if len(seq) == 1:
    ans = (k * len(S)) // 2
else:
    if seq[0][0] != seq[-1][0]:
        ans = k*sum(a[1] // 2 for a in seq)
    else:
        left = seq[0][1]
        right = seq[-1][1]
        ans = k*sum(a[1] // 2 for a in seq[1:-1])
        ans += ((left + right) // 2) * (k - 1)
        ans += left // 2 + right // 2

print(ans)


from itertools import groupby
S = input()
k = int(input())

seq = [(s, len(list(k))) for s, k in groupby(S)]

if len(seq) == 1:
    ans = (k * len(S)) // 2
else:
    if seq[0][0] != seq[-1][0]:
        ans = k*sum(a[1] // 2 for a in seq)
    else:
        left = seq[0][1]
        right = seq[-1][1]
        ans = k*sum(a[1] // 2 for a in seq[1:-1])
        ans += ((left + right) // 2) * (k - 1)
        ans += left // 2 + right // 2

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
K = int(input())

# S = S * K

pre_s = ''
rep_count = 0
for s in S:
    if not pre_s:
        pre_s = s
        continue
    if pre_s == s:
        rep_count += 1
        pre_s = s.upper()
    else:
        pre_s = s

rep_count *= K
if S[0] == pre_s.lower():
    rep_count += K - 1

print(rep_count)





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

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

if len(set(S)) == 1 and len(S) % 2 == 1:
    print(len(S)*K//2)
    exit(0)

pre_s = ''
flag1 = 0
flag2 = 0
flag = True

pre_s = S[0]
flag1 = 1
for s in S[1:]:
    if pre_s == s:
        flag1 += 1
    else:
        break

if S[-1] == S[0]:
    pre_s = S[-1]
    flag2 = 1
    for i, s in enumerate(S[::-1]):
        if i == 0:
            continue
        if pre_s == s:
            flag2 += 1
        else:
            break

    # if flag1 > 0 and flag1 % 2 == 0 and flag2 % 2 != 0:
    if flag1 > 0 and flag1 % 2 == 0:
        flag = False

pre_s = ''
rep_count = 0
    

for s in S:
    if pre_s == s:
        rep_count += 1
        pre_s = s.upper()
    else:
        pre_s = s

rep_count *= K
if S[0] == pre_s and flag:
    rep_count += K - 1


print(rep_count)





Verdicts: Wrong Answer

Accepted
Problem: Given is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are described by a grid of characters S. If S_{i,j} is `1`, there is an edge connecting Vertex i and j; otherwise, there is no such edge.  Determine whether it is possible to divide the vertices into non-empty sets V_1, \dots, V_k such that the following condition is satisfied. If the answer is yes, find the maximum possible number of sets, k, in such a division.    * Every edge connects two vertices belonging to two "adjacent" sets. More formally, for every edge (i,j), there exists 1\leq t\leq k-1 such that i\in V_t,j\in V_{t+1} or i\in V_{t+1},j\in V_t holds.

Submission attempts (in order):
n=int(input())
dis=[[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
	x=input()
	for j in range(n):
		if x[j]=="1":
			dis[i][j]=int(x[j])
		else:
			dis[i][j]=10**9
d=[10**10]*n
d[0]=0
s=set()
for i in range(n):
	q=10**11
	for j in range(n):
		if (j not in s) and q>d[j]:
			q=d[j]
			lit=j
	s.add(lit)
	for j in range(n):
		if j not in s:
			if d[j]>d[lit]+dis[lit][j]:
				d[j]=d[lit]+dis[lit][j]
d.sort()
ans=n
if n==3:
	print(-1)
	exit()
for i in range(len(d)-1):
	if d[i]==d[i+1]:
		ans-=1
print(ans+1)

n=int(input())
s=[[0]*n for _ in range(n)]
for i in range(n):
	r=input()
	for j in range(n):
		if r[j]=="1":
			s[i][j]=1
ans=0
from collections import deque
for i in range(n):
	queue=deque([i])
	num=[-1]*n
	num[i]=0
	while queue:
		r=queue.popleft()
		for j in range(n):
			if s[r][j]==1 and num[j]==-1:
				num[j]=num[r]+1
				queue.append(j)
	MAX=max(num)
	p=[[]for _ in range(MAX+1)]
	for i in range(n):
		p[num[i]].append(i)
	ok=1
	for i in range(MAX+1):
		for x in p[i]:
			for y in p[i]:
				if s[x][y]==1:
					ok=0
					break
			if ok==0:
				break
		if ok==0:
			break
	if ok:
		ans=max(ans,MAX+1)
print(ans if ans else -1)

Verdicts: Wrong Answer

Accepted
Problem: Given is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are described by a grid of characters S. If S_{i,j} is `1`, there is an edge connecting Vertex i and j; otherwise, there is no such edge.  Determine whether it is possible to divide the vertices into non-empty sets V_1, \dots, V_k such that the following condition is satisfied. If the answer is yes, find the maximum possible number of sets, k, in such a division.    * Every edge connects two vertices belonging to two "adjacent" sets. More formally, for every edge (i,j), there exists 1\leq t\leq k-1 such that i\in V_t,j\in V_{t+1} or i\in V_{t+1},j\in V_t holds.

Submission attempts (in order):
print(-1)

from collections import deque
n = int(input())
route = [[] for i in range(n)]
for i in range(n):
    s = input()
    for j in range(n):
        if s[j] == "1":
            route[i].append(j)
            route[j].append(i)
ans = -1
for p in range(n):
    visit = [-1 for i in range(n)]
    visit[p] = 1
    d = deque()
    d.append(p)
    while d:
        now = d.popleft()
        for i in route[now]:
            if visit[i] == -1:
                visit[i] = visit[now] + 1
                d.append(i)
            elif abs(visit[i] - visit[now]) != 1:
                print(-1)
                exit()
    ans = max(ans,max(visit))
print(ans)

Verdicts: Wrong Answer

Accepted