Problem: Given is a string S of length N-1. Each character in S is `<` or `>`.  A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be _good_ when the following condition is satisfied for all i (1 \leq i \leq N-1):    * If S_i= `<`: a_i<a_{i+1}   * If S_i= `>`: a_i>a_{i+1}  Find the minimum possible sum of the elements of a good sequence of N non- negative integers.

Submission attempts (in order):
import re
def sum_z_to_k(k):
    ##print("k",k)
    return (k+1)*k/2

def set_min_lr(map_lr, i):
    if map_lr[i] == 0:
        l,r = 0,0
    elif map_lr[i] == 1:
        l,r = 0,1
    elif map_lr[i] == 2:
        l,r = 1,0
    elif map_lr[i] == 3:
        l,r = 1,1
    return l,r

S = str(input())
N = len(S) + 1
score = 0

S_split_tani = re.split("(><)", S)


map_lr = [0]*len(S_split_tani)
for i,s in enumerate(S_split_tani[:-1]):
    if s =="><":
        map_lr[i]=-1
        if map_lr[i-1]==1 or map_lr[i-1]==2:
            map_lr[i-1]=3
        else:
	        map_lr[i-1]=1

        if map_lr[i+1]==2 or map_lr[i+1]==1:
            map_lr[i+1]=3
        else:
    	    map_lr[i+1]=2
#print(map_lr)
for i,s in enumerate(S_split_tani):
    #print(score)
    if s =="><":
        continue
    else:
        min_l, min_r = set_min_lr(map_lr, i)
        rl = re.split("(<>)", s)
        #print("rl,min",rl,min_r,min_l)
        if len(rl) == 1:# none <>
            if len(rl[0]) == 0:# null
                if map_lr[i]==0:
                    pass
                else:
                  score += 1
            else:
                if ">" in rl[0]:
                    score += sum_z_to_k(len(rl[0]) + min_r)
                else:#<
                    score += sum_z_to_k(len(rl[0]) + min_l)
        elif len(rl) == 3:
            r = rl[2]
            l = rl[0]
            
            if len(r) == 0 and len(l) == 0:
                score+=1
            else:
                tmp_max = max(len(r) + min_r, len(l) + min_l)
                tmp_min = min(len(r) + min_r, len(l) + min_l)
                #print("tmp",tmp_min,tmp_max)
                score += sum_z_to_k(tmp_max+1)
                if tmp_min != 0:
                    score += sum_z_to_k(tmp_min)

print(score)

import re
def sum_z_to_k(k):
    ##print("k",k)
    return (k+1)*k/2

def set_min_lr(map_lr, i):
    if map_lr[i] == 0:
        l,r = 0,0
    elif map_lr[i] == 1:
        l,r = 0,1
    elif map_lr[i] == 2:
        l,r = 1,0
    elif map_lr[i] == 3:
        l,r = 1,1
    return l,r

S = str(input())
N = len(S) + 1
score = 0

S_split_tani = re.split("(><)", S)


map_lr = [0]*len(S_split_tani)
for i,s in enumerate(S_split_tani[:-1]):
    if s =="><":
        map_lr[i]=-1
        if map_lr[i-1]==1 or map_lr[i-1]==2:
            map_lr[i-1]=3
        else:
            map_lr[i-1]=1
        if map_lr[i+1]==2 or map_lr[i+1]==1:
            map_lr[i+1]=3
        else:
            map_lr[i+1]=2
#print(map_lr)
for i,s in enumerate(S_split_tani):
    #print(score)
    if s =="><":
        continue
    else:
        min_l, min_r = set_min_lr(map_lr, i)
        rl = re.split("(<>)", s)
        #print("rl,min",rl,min_r,min_l)
        if len(rl) == 1:# none <>
            if len(rl[0]) == 0:# null
                if map_lr[i]==0:
                    pass
                else:
                    score += 1
            else:
                if ">" in rl[0]:
                    score += sum_z_to_k(len(rl[0]) + min_r)
                else:#<
                    score += sum_z_to_k(len(rl[0]) + min_l)

        elif len(rl) == 3:
            r = rl[2]
            l = rl[0]
            
            if len(r) == 0 and len(l) == 0:
                score+=1
            else:
                tmp_max = max(len(r) + min_r, len(l) + min_l)
                tmp_min = min(len(r) + min_r, len(l) + min_l)
                #print("tmp",tmp_min,tmp_max)
                score += sum_z_to_k(tmp_max+1)
                if tmp_min != 0:
                    score += sum_z_to_k(tmp_min)

print(score)

import re
def sum_z_to_k(k):
    ##print("k",k)
    return (k+1)*k/2

def set_min_lr(map_lr, i):
    if map_lr[i] == 0:
        l,r = 0,0
    elif map_lr[i] == 1:
        l,r = 0,1
    elif map_lr[i] == 2:
        l,r = 1,0
    elif map_lr[i] == 3:
        l,r = 1,1
    return l,r

S = str(input())
N = len(S) + 1
score = 0

S_split_tani = re.split("(><)", S)


map_lr = [0]*len(S_split_tani)
for i,s in enumerate(S_split_tani[:-1]):
    if s =="><":
        map_lr[i]=-1
        if map_lr[i-1]==1 or map_lr[i-1]==2:
            map_lr[i-1]=3
        else:
	        map_lr[i-1]=1

        if map_lr[i+1]==2 or map_lr[i+1]==1:
            map_lr[i+1]=3
        else:
    	    map_lr[i+1]=2
#print(map_lr)
for i,s in enumerate(S_split_tani):
    #print(score)
    if s =="><":
        continue
    else:
        min_l, min_r = set_min_lr(map_lr, i)
        rl = re.split("(<>)", s)
        #print("rl,min",rl,min_r,min_l)
        if len(rl) == 1:# none <>
            if len(rl[0]) == 0:# null
                if map_lr[i]==0:
                    pass
                else:
                  score += 1
            else:
                if ">" in rl[0]:
                    score += sum_z_to_k(len(rl[0]) + min_r)
                else:#<
                    score += sum_z_to_k(len(rl[0]) + min_l)

        elif len(rl) == 3:
            r = rl[2]
            l = rl[0]
            
            if len(r) == 0 and len(l) == 0:
                score+=1
            else:
                tmp_max = max(len(r) + min_r, len(l) + min_l)
                tmp_min = min(len(r) + min_r, len(l) + min_l)
                #print("tmp",tmp_min,tmp_max)
                score += sum_z_to_k(tmp_max+1)
                if tmp_min != 0:
                    score += sum_z_to_k(tmp_min)

print(score)

import re
def sum_z_to_k(k):
    ##print("k",k)
    return (k+1)*k/2

def set_min_lr(map_lr, i):
    if map_lr[i] == 0:
        l,r = 0,0
    elif map_lr[i] == 1:
        l,r = 0,1
    elif map_lr[i] == 2:
        l,r = 1,0
    elif map_lr[i] == 3:
        l,r = 1,1
    return l,r

S = str(input())
N = len(S) + 1
score = 0

S_split_tani = re.split("(><)", S)


map_lr = [0]*len(S_split_tani)
for i,s in enumerate(S_split_tani[:-1]):
    if s =="><":
        map_lr[i]=-1
        if map_lr[i-1]==1 or map_lr[i-1]==2:
            map_lr[i-1]=3
        else:
	        map_lr[i-1]=1

        if map_lr[i+1]==2 or map_lr[i+1]==1:
            map_lr[i+1]=3
        else:
    	    map_lr[i+1]=2
#print(map_lr)
for i,s in enumerate(S_split_tani):
    #print(score)
    if s =="><":
        continue
    else:
        min_l, min_r = set_min_lr(map_lr, i)
        rl = re.split("(<>)", s)
        #print("rl,min",rl,min_r,min_l)
        if len(rl) == 1:# none <>
            if len(rl[0]) == 0:# null
                score += 1
            else:
                score += sum_z_to_k(len(rl[0]) + 1)
        elif len(rl) == 3:
            r = rl[2]
            l = rl[0]
            
            if len(r) == 0 and len(l) == 0:
                score+=1
            else:
                tmp_max = max(len(r) + min_r, len(l) + min_l)
                tmp_min = min(len(r) + min_r, len(l) + min_l)
                #print("tmp",tmp_min,tmp_max)
                score += sum_z_to_k(tmp_max+1)
                if tmp_min != 0:
                    score += sum_z_to_k(tmp_min)

print(score)

S = list(str(input()))
N = len(S) + 1

a = [0]*N

for i, s in enumerate(S):
  if s=="<":
    a[i+1]=a[i]+1
#back
S_ = list(reversed(S))
j=0
for s in S_:
  if s==">":
    if a[N-1-(j+1)]<=a[N-1-j]:
      a[N-1-(j+1)]=a[N-1-j]+1
  j+=1
print(sum(a))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted