Problem:


Score : 300 points

Problem Statement

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.

Constraints

2 \leq N \leq 5 \times 10^5

S is a string of length N-1 consisting of < and >.

Input

Input is given from Standard Input in the following format:

S

Output

Find the minimum possible sum of the elements of a good sequence of N non-negative integers.

Sample Input 1

<>>

Sample Output 1

3

a=(0,2,1,0) is a good sequence whose sum is 3.
There is no good sequence whose sum is less than 3.

Sample Input 2

<>>><<><<<<<>>><

Sample Output 2

28



Sample input:
<>>


Sample output:
3

Submission status: Wrong Answer

Solution code:
S = list(input())
zeroone = []
for i in range(len(S)):
    if S[i] == "<":
        zeroone.append(1)
    else:
        zeroone.append(-1)

cnt = [0]
for i in range(len(zeroone)-1):
    if zeroone[i+1] != zeroone[i]:
        cnt.append(i+1)
cnt.append(len(zeroone))

ans = [0] * (len(zeroone)+1)
for j in range(0, cnt[1]):
    ans[j+1] = ans[j] + 1

for i in range(len(zeroone)-1):
    if zeroone[i+1] - zeroone[i] > 0:
        ans[i+1] = 0
        for j in range(i+1, cnt[cnt.index(i+1) + 1]):
            ans[j+1] = ans[j] + 1

        for k in range(cnt[cnt.index(i+1) - 1], i+1)[::-1]:
            ans[k] = max(ans[k+1] + 1, ans[k])

for k in range(cnt[-2], cnt[-1])[::-1]:
    ans[k] = max(ans[k+1] + 1, ans[k])

print(sum(ans))

Submission status: Wrong Answer

Solution code:
from itertools import groupby, chain

def pairs(t):
    while True:
        x, y = next(t), next(t)
        a =[sum(1 for _ in g) for k, g in (x, y)]
        yield sum(x * (x - 1) // 2 for x in a) + max(a)

s = input()
t = groupby(s)
d = [(0, ())]
if s[0] == '<':
    t = chain(d, t)
if s[-1] == '>':
    t = chain(t, d)
print(sum(pairs(t)))

Submission status: Wrong Answer

Solution code:
S = input()
dp = []
cnt = 1
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 1
    else:
        dp.append(cnt)
        cnt = 1
dp.append(cnt)
ans = 0
if S[0] == '<':
    for i in range(0, len(dp)-1, 2):
        N = max(dp[i], dp[i+1])
        n = min(dp[i], dp[i+1])
        ans += sum(range(N+1)) + sum(range(n))
    if len(dp)%2 == 1:
        ans += sum(range(dp[-1]+1))
else:
    ans += dp[0]*(dp[0]-1)//2
    for i in range(1, len(dp)-1, 2):
        N = max(dp[i], dp[i+1])
        n = min(dp[i], dp[i+1])
        ans += sum(range(N+1)) + sum(range(n))
    if len(dp)%2 == 0:
        ans += sum(range(dp[-1]+1))
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
ans = 0
cnt = 0
tmp = 0
i = 0
while i < N - 1:
  cnt = 0
  tmp = 0
  if S[i] == "<":
    while S[i] == "<":
      cnt += 1
      if i == N - 1:
        ans += cnt * (cnt+1) // 2
        break
      if S[i+1] == ">":
        ans += cnt * (cnt + 1) // 2
        tmp = cnt
        cnt = 0
        i += 1
        while S[i] == ">":
          cnt += 1
          i += 1
          if i == N:
            i -= 1
            break
        ans += (cnt - 1) * (cnt) // 2
        if tmp >= cnt:
          pass
        else:
          ans += cnt - tmp
        cnt = 0
      else:
        i += 1
  else:
    while S[i] == ">":
      cnt += 1
      i += 1
      if i == N:
        i -= 1
        break
    ans += cnt * (cnt + 1) // 2
    cnt = 0
    if S[i] == "<":
      while S[i] == "<":
        if i == N - 1:
          ans += 1
          break
        cnt += 1
        if S[i+1] == ">":
          ans += cnt * (cnt + 1) // 2
          tmp = cnt
          cnt = 0
          i += 1
          while S[i] == ">":
            cnt += 1
            i += 1
            if i == N:
              i -= 1
              break
          ans += (cnt - 1) * (cnt) // 2
          if tmp >= cnt:
            pass
          else:
            ans += cnt - tmp
          cnt = 0
        else:
          i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import re
S = input()

po=[]
ne=[]
li = [m.span()[0] for m in re.finditer('><', S)]
result = []

n = 0
for i in S:
    if i == "<":
        n += 1
    else:
        break
po.append(n)
for i in li:
    s = "<"
    n = 0
    while s == S[i+1]:
        n += 1
        i += 1
        if i+1 >= len(S):
            break
    po.append(n)
for i in li:
    s = ">"
    n = 0
    while s == S[i]:
        n += 1
        i -= 1
    ne.append(n)
n = 0
for i in S[::-1]:
    if i == ">":
        n += 1
    else:
        break
ne.append(n)
for i,l in enumerate(po):
    if l < ne[i]:
        if l > 0:
            result.append((1/2)*(l-1)*l)
        if ne[i] > 0:
            result.append((1/2)*ne[i]*(ne[i]+1))
    else:
        if l > 0:
            result.append((1/2)*l*(l+1))
        if ne[i] > 0:
            result.append((1/2)*ne[i]*(ne[i]-1))
print(int(sum(result)))

Submission status: Wrong Answer

Solution code:
from itertools import*
s=input()
x=[[k,len(list(v))]for k,v in groupby(s)]

ans=0
#print(x)
for i in range(len(x)):
    try:
        if x[i][0]=="<" and x[i+1][0]==">":
            n=max(x[i][1],x[i+1][1])
            m=min(x[i][1],x[i+1][1])
            ans+=(n+1)*n//2+(m-1)*m//2
    except:
        break

if x[0][0]==">":
    y=x[0][1]
    ans+=y*(y+1)//2
if x[-1][0]=="<":
    y=x[0][1]
    ans+=y*(y+1)//2

print(ans)

Submission status: Wrong Answer

Solution code:
def a(S):
    a_list=[0]
    for S_i in S:
        if S_i == ">":
            a_list.append(a_list[-1] -1)
        
        else:
            a_list.append(a_list[-1] + 1)
    print(a_list)
    min_a_list = min(a_list)
    return sum(a_list) + len(a_list) * (-min_a_list)

def b(S):
    renzoku_list=[]
    count =0
    S =  S + "0"
    for i in range(1,len(S)):
        if S[i]== S[i-1]:
            count=count+1
        else:
            renzoku_list.append(count +1 )
            count = 0


    for i in range(len(renzoku_list)//2):
        if renzoku_list[2*i] > renzoku_list[2*i+1] :
            renzoku_list[2*i+1]= renzoku_list[2*i+1]-1
        else:
            renzoku_list[2*i]= renzoku_list[2*i] -1
    total =0
    for num in renzoku_list:
        total = total + num * (num +1)/2
    return int(total)



if __name__ == "__main__":
    S=input()
    result = b(S)
    print (result)

Submission status: Wrong Answer

Solution code:
# A - ><
S = str(input())

ans = 0
tmp = 0

for i in range(len(S)+1):
    if i == 0 and S[0] == "<":
        tmp = 0
    elif i == len(S) and S[i-1] == ">":
        tmp = 0
    elif i == len(S) and S[i-1] == "<":
        tmp += 1
#    elif i == len(S) and S[i] == ">":

    elif S[i-1] == ">" and S[i] == "<":
        tmp = 0
    elif i >= 3 and S[i-2] == "<" and S[i-1] == ">" and S[i] == ">":
        tmp = 1
    elif i >= 3 and S[i-2] == "<" and S[i-1] == ">" and S[i] == "<":
        tmp = 0
    else:
        tmp += 1
    ans += tmp

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

prev = None
result = 0

gt = 0
gt_min = 0
lt = 0

for x in S:
    if prev is None or prev != x:
        if x == '>':
            if prev is not None:
                gt_min = lt
                lt -= 1
                if lt > 0:
                    result += int((lt*(lt+1))/2)
        else:
            if prev is not None:
                result += int((gt*(gt+1))/2)
                if gt_min > gt:
                    result += gt_min - gt
        gt = lt = 0

    if x == '<':
        lt += 1
    else:
        gt += 1


    prev = x

if prev == '>':
    result += int((gt*(gt+1))/2)
    if gt_min > gt:
        result -= int((gt_min-gt*(gt_min-gt))/2)
else:
    result += 1

print(result)

Submission status: Wrong Answer

Solution code:
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)
#print(S_split_tani)

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]
            #print("len rl",len(r),len(l))
            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)

Submission status: Wrong Answer

Solution code:
s=input()
d=[0]*(len(s)+1)
scount=0
ans=0
x=0
y=0
for i in range(1,len(s)-1):
  if s[i]==">":
    scount+=1
    Z=i
  elif s[i]=="<":
    d[i+1]=d[i]+1
    if scount>1:
      Q=scount
      for j in range(scount):
        d[i-scount+j]=Q
        Q-=1
    scount=0
    
if s[-1]==">":
  scount+=1
    
if scount>1:
  Q=scount
  if scount>d[Z-scount]:
    for j in range(scount):
      d[Z+1-scount+j]=Q
      Q-=1
  else:
    Q-=1
    for j in range(scount):
      d[Z+2-scount+j]=Q
      Q-=1
if s[-1]=="<":
    ans+=d[-1]+1
    scount=0
      
print(d)
print(sum(d)+ans)

Submission status: Wrong Answer

Solution code:
# A - ><
S = str(input())

ans = 0
tmp = 0

for i in range(len(S)+1):
    if i == 0 and S[0] == "<":
        tmp = 0
    elif i == len(S) and S[i-1] == ">":
        tmp = 0
    elif i == len(S) and S[i-1] == "<":
        tmp += 1
#    elif i == len(S) and S[i] == ">":

    elif S[i-1] == ">" and S[i] == "<":
        tmp = 0
    elif i >= 3 and S[i-2] == "<" and S[i-1] == ">" and S[i] == ">":
        tmp = 1
    else:
        tmp += 1
    ans += tmp

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
lst = [i for i in S]

k = 0
n = [k]
for i in range(len(lst)):
    if lst[i] == "<":
        n.append(n[i]+1)
    elif lst[i] == ">":
        n.append(n[i]-1)


mini = min(n)
for i in range(len(n)):
    n[i] = n[i] - mini


lst_t = list(reversed(lst))

for i in range(len(lst_t)):
    if lst_t[i] == "<":
        lst_t[i] == ">"
    elif lst[i] == ">":
        lst_t[i] == "<"
     
print(lst_t)
k = 0
n2 = [k]
for i in range(len(lst)):
    if lst_t[i] == "<":
        n2.append(n[i]+1)
    elif lst_t[i] == ">":
        n2.append(n[i]-1)



print(n2)

minimini = min(n2)
for i in range(len(n2)):
    n2[i] = n2[i] - minimini
print(n2)

j1= 0
for num in n:
    j1= j1 + num

j2= 0
for num in n2:
    j2= j2 + num  

l = [j1,j2]
M = min(l)
print(M)

Submission status: Wrong Answer

Solution code:
"""0<1 3>2>1>0<1<2 1>0<1<2<3<4<5 3>2>1>0<1
13 21 53 1
03 20 52 1
6 3 15 3 1 
0< 3>2>1>0 1<2<3 >0 <<<<< >>> <
0< 2>1>0"""

s = input()
s += "A"

g = []
l = []
cnt = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        cnt += 1
    elif s[i] == ">":
        g.append(cnt)
        cnt = 1
    else:
        l.append(cnt)
        cnt = 1
        
if len(g) < len(l):
    if s[0] == ">":
        g.insert(0,1)
    else:
        g.append(1)
else:
    if s[0] == ">":
        l.insert(0,1)
    else:
        l.append(1)

ll = []
for i in range(len(g)):
    if g[i] > l[i]:
        ll.append(g[i])
        ll.append(l[i]-1)
    else:
        ll.append(g[i]-1)
        ll.append(l[i])
ans = 0
for v in ll:
    ans += (1+v) * v/2

    
print(int(ans))

Submission status: Wrong Answer

Solution code:
S = input().strip()
V = []
for i in range(len(S)-1):
    if S[i]==">" and S[i+1]=="<":
        V.append(i+1)
if S[-1]==">":
    V.append(len(S))
B = [0 for _ in range(len(S)+1)]
for i in range(len(S)):
    if S[i]==">":
        B[i+1] = B[i]-1
    else:
        B[i+1] = B[i]+1
for j in V:
    if B[j]<0:
        B[j] = 0
        cur = j-1
        while cur>=0 and S[cur]==">":
            if cur>0:
                B[cur] = max(B[cur],B[cur+1]+1)
            elif cur==0:
                if S[cur]==">":
                    B[cur] = B[cur+1]+1
                else:
                    B[cur] = 0
            cur -= 1
    elif B[j]>0:
        B[j] = 0
        cur = j-1
        while cur>=0 and S[cur]==">":
            if cur-1>=0 and S[cur-1]==">":
                B[cur] = B[cur+1]+1
            elif cur-1>=0 and S[cur-1]=="<":
                B[cur] = max(B[cur],B[cur+1]+1)
            cur -= 1
    cur = j
    while cur<len(S) and S[cur]=="<":
        B[cur+1] = B[cur]+1
        cur += 1
print(sum(B))

Submission status: Wrong Answer

Solution code:
S = input()
slst = [[] for _ in range(len(S) + 1)]
tmp = S[0]
cnt = 0
index = 0
for i in range(len(S)):
    if tmp == S[i]:
        cnt += 1
    else:
        slst[index].append(tmp)
        slst[index].append(cnt)
        index += 1
        tmp = S[i]
        cnt = 1

slst[index].append(tmp)
slst[index].append(cnt)

dp = [0] * (len(S) + 1)
if slst[0][0] == '<':
    dp[0] = 0
else:
    dp[0] = slst[0][1]

index = 1
tmpv = dp[0]
tmpi = 0
for i in range(len(S)):
    if slst[i] == []:
        break

    if slst[i][0] == '>':
        dp[index] = dp[index - 1] + ((slst[i][1]) * ((slst[i][1] - 1))) // 2
        index += 1
    else:
        if slst[i + 1] == []:
            dp[index] = dp[index - 1] + ((slst[i][1] + 1) * ((slst[i][1]))) // 2
            index += 1
        else:
            if slst[i][1] < slst[i + 1][1]:
                tdp = 0
                for k in range(slst[i][1]):
                    tdp += slst[i + 1][1] - k
                dp[index] = dp[index - 1] + tdp
                index += 1

            else:
                dp[index] = dp[index - 1] + ((slst[i][1] + 1) * ((slst[i][1]))) // 2
                index += 1


print(dp[index - 1])

Submission status: Wrong Answer

Solution code:
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)
#print(S_split_tani)

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]
            #print("len rl",len(r),len(l))
            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)

Submission status: Wrong Answer

Solution code:
# ><
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

S = si()
L = []
LS = []
t = 1
t_str = ''
for i in range(len(S)-1):
    if i == 0:
        t = 1
        t_str = S[i]

    if t_str == S[i] and S[i]==S[i+1]:
        t += 1
    else:
        L.append(t)
        LS.append(t_str)
        t = 1
        t_str = S[i+1]
    
    if i == len(S)-2:
        L.append(t)
        LS.append(t_str)

# print(L)
odd = 0
even = 0
for i in range(len(L)):
    if i%2 == 0:
        odd = 0
        even = 0

        odd = L[i]
    
    if i%2 == 1:
        even = L[i]
        if odd < even:
            L[i-1] -= 1
        elif odd > even:
            L[i] -= 1

# print(L)
ans = 0
for i in range(len(L)):
    l = L[i]
    ans += (l*(l+1))/2
    if len(L)>1 and i !=len(L)-1:
        if i%2==0 and L[i]==L[i+1]:
            if LS[i]=='<':
                ans -= L[i]
    if i%2 == 1:
        if i == len(L)-1 and LS[i]=='>':
            ans =ans


print(int(ans))

Submission status: Wrong Answer

Solution code:
def solve(char):
    b = list(char)
    s = 0
    
    if b[0] == "<":
      x = 0
    else:
      x = 1
    
    for i in range(1, len(b)-1):
      if b[i] == "<" and b[i-1] == ">":
        x = 0
        
      elif b[i] == ">" and b[i-1] == "<":
        x = x + 1     
        s = s + x
        x = 0
           
      else:
        x = x + 1
        s = s + x 
    
    if b[len(b)-1] == "<":
      s = s + x + 1
        
    return s
    

if __name__ ==  "__main__":
    a = solve(input())
    print(a)

Submission status: Wrong Answer

Solution code:
# ><
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

S = si()
L = []
LS = []
t = 1
t_str = ''
for i in range(len(S)-1):
    if i == 0:
        t = 1
        t_str = S[i]

    if t_str == S[i] and S[i]==S[i+1]:
        t += 1
    else:
        L.append(t)
        LS.append(t_str)
        t = 1
        t_str = S[i+1]
    
    if i == len(S)-2:
        L.append(t)
        LS.append(t_str)

# print(L)
odd = 0
even = 0
for i in range(len(L)):
    if i%2 == 0:
        odd = 0
        even = 0

        odd = L[i]
    
    if i%2 == 1:
        even = L[i]
        if odd < even:
            L[i-1] -= 1
        elif odd > even:
            L[i] -= 1

# print(L)
ans = 0
for i in range(len(L)):
    l = L[i]
    ans += (l*(l+1))/2
    if len(L)>1 and i !=len(L)-1:
        if i%2==0 and L[i]==L[i+1]:
            if LS[i]=='<':
                ans -= L[i]
    if i%2 == 1:
        if i == len(L)-1 and LS[i]=='>':
            ans -= L[i]


print(int(ans))

Submission status: Wrong Answer

Solution code:
S = list(input())
zeroone = []
for i in range(len(S)):
    if S[i] == "<":
        zeroone.append(1)
    else:
        zeroone.append(-1)

cnt = [0]
for i in range(len(zeroone)-1):
    if zeroone[i+1] != zeroone[i]:
        cnt.append(i+1)
cnt.append(len(zeroone))

ans = [0] * (len(zeroone)+1)
for j in range(0, cnt[1]):
    ans[j+1] = ans[j] + 1
for k in range(cnt[-2], cnt[-1])[::-1]:
    ans[k] = max(ans[k+1] + 1, ans[k])

for i in range(len(zeroone)-1):
    if zeroone[i+1] - zeroone[i] > 0:
        ans[i+1] = 0
        for j in range(i+1, cnt[cnt.index(i+1) + 1]):
            ans[j+1] = ans[j] + 1
        for k in range(cnt[cnt.index(i+1) - 1], i+1)[::-1]:
            ans[k] = max(ans[k+1] + 1, ans[k])
print(sum(ans))

Submission status: Wrong Answer

Solution code:

S = input()
str_list = list(S)
count = 0
dict = {}
dict[0] = 0
for c, i in enumerate(str_list,1):
    if i == '<':
        count += 1
        dict[c] = count
    else:
        count -= 1
        dict[c] = count

d = list()
for i in range(len(dict)-2):
    if dict[i] > dict[i+1] and dict[i+1] < dict[i+2]:
        d.append(dict[i+1])
if len(d) != 0:
    for i in range(len(dict)):
        dict[i] -= max(d)

while(min(dict.values())<0):
    min_v = abs(min(dict.values()))
    min_k = min(dict, key=dict.get)
    for i in range(min_k,len(dict)):
        dict[i] += min_v
        if min_k == len(dict)-1:
            break
        elif dict[i] - min_v > dict[i+1]:
            break
        elif dict[i+1] > dict[i] and dict[i+1] > dict[i] - min_v:
            break
        elif dict[i+1] < dict[i] and dict[i+1] < dict[i]-min_v:
            break

    for i in range(min_k,0,-1):
        if i != min_k:
            dict[i] += min_v
        if dict[i] - min_v > dict[i-1]:
            break
        elif dict[i-1] > dict[i] and dict[i-1] > dict[i] - min_v:
            break
        elif dict[i-1] < dict[i] and dict[i-1] < dict[i]-min_v:
            break

print(sum(dict.values()))

Submission status: Wrong Answer

Solution code:
# A - ><
S = str(input())

ans = 0
tmp = 0
# if S[0] == "<":
#     tmp = 0
# else:
#     tmp = 1


for i in range(len(S)+1):
    if i == 0 and S[0] == "<":
        tmp = 0
    elif i == len(S) and S[i-1] == ">":
        tmp = 0
    elif i == len(S) and S[i-1] == "<":
        tmp += 1
#    elif i == len(S) and S[i] == ">":

    elif S[i-1] == ">" and S[i] == "<":
        tmp = 0
    elif i > 3 and S[i-2] == "<" and S[i-1] == ">" and S[i] == ">":
        tmp = 1
    else:
        tmp += 1
    ans += tmp

print(ans)

Submission status: Wrong Answer

Solution code:
S = input().strip()
V = []
for i in range(len(S)-1):
    if S[i]==">" and S[i+1]=="<":
        V.append(i+1)
if S[-1]==">":
    V.append(len(S))
B = [0 for _ in range(len(S)+1)]
for i in range(len(S)):
    if S[i]==">":
        B[i+1] = B[i]-1
    else:
        B[i+1] = B[i]+1
for j in V:
    if B[j]<0:
        B[j] = 0
        cur = j-1
        while cur>=0 and S[cur]==">":
            if cur>0:
                B[cur] = max(B[cur],B[cur+1]+1)
            cur -= 1
    elif B[j]>0:
        B[j] = 0
        cur = j-1
        while cur>=0 and S[cur]==">":
            if cur-1>=0 and S[cur-1]==">":
                B[cur] = B[cur+1]+1
            elif cur-1>=0 and S[cur-1]=="<":
                B[cur] = max(B[cur],B[cur+1]+1)
            cur -= 1
    cur = j
    while cur<len(S) and S[cur]=="<":
        B[cur+1] = B[cur]+1
        cur += 1
print(sum(B))

Submission status: Wrong Answer

Solution code:
S = list(input())

DEBUG =False
val = 0
sum_val = 0

updown = []
SAME_FLAG = False
cnt = 0
for i in range(len(S)):
    cnt += 1
    if S[i] == '<':
        mul = 1
    elif S[i] == '>':
        mul = -1
    
    if i == len(S)-1 or S[i] != S[i+1]:
        updown.append(cnt*mul)
        cnt = 0
if DEBUG:
    print(updown)

for i in range(len(updown)):  
    
    if i == len(updown)-1:
        if SAME_FLAG: 
            sum_ser = sum(list(range(abs(updown[i]))))
        else:
            sum_ser = sum(list(range(abs(updown[i])+1)))

    elif (updown[i]>0 and updown[i+1]<0)  or SAME_FLAG is True:
        sum_ser = sum(list(range(abs(updown[i]))))
        SAME_FLAG = False
    else:
        sum_ser = sum(list(range(abs(updown[i]+1))))
        if abs(updown[i]) == abs(updown[i+1]):
            SAME_FLAG = True
    
    if DEBUG:
        print('i=%d : ele = %d : sum_ser = %d'%(i,abs(updown[i]),sum_ser))
    sum_val += sum_ser
print(sum_val)

Submission status: Wrong Answer

Solution code:
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)
#print(S_split_tani)

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]
            #print("len rl",len(r),len(l))
            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)

Submission status: Wrong Answer

Solution code:
S = list(input())

DEBUG =True
val = 0
sum_val = 0

updown = []
SAME_FLAG = False
cnt = 0
for i in range(len(S)):
    cnt += 1
    if S[i] == '<':
        mul = 1
    elif S[i] == '>':
        mul = -1
    
    if i == len(S)-1 or S[i] != S[i+1]:
        updown.append(cnt*mul)
        cnt = 0
if DEBUG:
    print(updown)

for i in range(len(updown)):  
    
    if i == len(updown)-1:
        if SAME_FLAG: 
            sum_ser = sum(list(range(abs(updown[i]))))
        else:
            sum_ser = sum(list(range(abs(updown[i])+1)))

    elif (updown[i]>0 and updown[i+1]<0)  or SAME_FLAG is True:
        sum_ser = sum(list(range(abs(updown[i]))))
        SAME_FLAG = False
    else:
        sum_ser = sum(list(range(abs(updown[i]+1))))
        if abs(updown[i]) == abs(updown[i+1]):
            SAME_FLAG = True
    
    if DEBUG:
        print('i=%d : ele = %d : sum_ser = %d'%(i,abs(updown[i]),sum_ser))
    sum_val += sum_ser
print(sum_val)

Submission status: Wrong Answer

Solution code:
def calc(n):
    return n * (n+1) / 2

S = list(input())

prev = S[0]
series = 1
l = []

for i in range(1, len(S)):
    if prev == S[i]:
        series += 1
    else:
        l.append((prev, series))
        prev = S[i]
        series = 1

l.append((prev, series))

prev_max = l[0][1]
prev = calc(prev_max)
res = prev

print(l)

for s, n in l[1::]:
    if s == '<':
        prev = calc(n)
        prev_max = n
        res += prev
    else:
        if n >= prev_max:
            res -= prev_max
            prev = calc(n)
            res += prev
        else:
            prev = calc(n-1)
            res += prev

    print(res)

print(int(res))

Submission status: Wrong Answer

Solution code:
# ><
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

S = si()
L = []
LS = []
t = 1
t_str = ''
for i in range(len(S)-1):
    if i == 0:
        t = 1
        t_str = S[i]

    if t_str == S[i] and S[i]==S[i+1]:
        t += 1
    else:
        L.append(t)
        LS.append(t_str)
        t = 1
        t_str = S[i+1]
    
    if i == len(S)-2:
        L.append(t)

# print(L)
odd = 0
even = 0
for i in range(len(L)):
    if i%2 == 0:
        odd = 0
        even = 0

        odd = L[i]
    
    if i%2 == 1:
        even = L[i]
        if odd < even:
            L[i-1] -= 1
        elif odd > even:
            L[i] -= 1

# print(L)
ans = 0
for i in range(len(L)):
    l = L[i]
    ans += (l*(l+1))/2
    if len(L)>1 and i !=len(L)-1:
        if i%2==0 and L[i]==L[i+1]:
            if LS[i]=='<':
                ans -= L[i]
print(int(ans))

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math


S = stdin.readline().rstrip()
maximum = []
minimum = []
if (S[0] == '<'):
    minimum.append(0)
if (S[0] == '>'):
    maximum.append(0)
if (S[len(S)-1] == '<'):
    maximum.append(len(S))
if (S[len(S)-1] == '>'):
    minimum.append(len(S))

for num in range(0, len(S)):
    if (num == len(S) - 1):
        break
    if (S[num] == '<' and S[num + 1] == '>'):
        maximum.append(num + 1)
    if (S[num] == '>' and S[num + 1] == '<'):
        minimum.append(num+1)
tes = (maximum + minimum)
tes.sort()
result = 0
for pos in range(len(tes)):
    if (pos == 0):
        continue
    if (pos % 2 == 1 and pos != (len(tes)-1)):
        continue

    if (pos % 2 == 0):
        numA = 0
        for num in range(tes[pos - 1]-tes[pos-2]+1):
            numA += num
        numB = 0
        for num in range(tes[pos]-tes[pos-1]+1):
            numB += num
        ree = numA+numB
        if (numB >= numA):
            ree -= (tes[pos - 1] - tes[pos - 2])
        elif (numA > numB):
            ree -= (tes[pos] - tes[pos - 1])
        result += ree
    elif (pos % 2 == 1):
        numC = 0
        for num in range(tes[pos] - tes[pos - 1] + 1):
            numC += num
        result += numC
print(result)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
ans = 0
cnt = 0
tmp = 0
i = 0
while i < N - 1:
  cnt = 0
  tmp = 0
  if S[i] == "<":
    while S[i] == "<":
      if i == N - 1:
        ans += 1
        break
      cnt += 1
      if S[i+1] == ">":
        ans += cnt * (cnt + 1) // 2
        tmp = cnt
        cnt = 0
        i += 1
        while S[i] == ">":
          cnt += 1
          i += 1
          if i == N:
            i -= 1
            break
        ans += (cnt - 1) * (cnt) // 2
        if tmp >= cnt:
          pass
        else:
          ans += cnt - tmp
        cnt = 0
      else:
        i += 1
  else:
    while S[i] == ">":
      cnt += 1
      i += 1
      if i == N:
        i -= 1
        break
    ans += cnt * (cnt + 1) // 2
    cnt = 0
    if S[i] == "<":
      while S[i] == "<":
        if i == N - 1:
          ans += 1
          break
        cnt += 1
        if S[i+1] == ">":
          ans += cnt * (cnt + 1) // 2
          tmp = cnt
          cnt = 0
          i += 1
          while S[i] == ">":
            cnt += 1
            i += 1
            if i == N:
              i -= 1
              break
          ans += (cnt - 1) * (cnt) // 2
          if tmp >= cnt:
            pass
          else:
            ans += cnt - tmp
          cnt = 0
        else:
          i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
S=list(input())
ans=[0]*(len(S)+1)
j=1
sum=0
for i in range(len(S)):
  if S[i] == "<":
    ans[j] += ans[j-1]+1
  else:
    ans[j] += ans[j-1]-1
  j+=1
for a in ans:
  sum+=abs(a)
print(ans)
print(sum)