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

Solution (Python):
s = list(str(input()))

from collections import deque

ans = []
_x = s[0]
l= 1
for x in s[1:]:
    if x == _x:
        l += 1
    else:
        ans.append(l)
        _x = x
        l = 1
ans.append(l)

ans = deque(ans)



_ans = 0
if s[0] == '<':
    while len(ans)>1:
        a = ans.popleft()
        b = ans.popleft()
        
        _ans += (max(a,b)*(max(a,b)+1))//2
        
        _ans += (min(a,b)-1)*(min(a,b))//2
        
    if len(ans)==1:
        c = ans.popleft()
        _ans += c*(c+1)//2
        

else:
    d = ans.popleft()
    _ans += d*(d+1)//2
    

    while len(ans)>1:
        a = ans.popleft()
        b = ans.popleft()
        
        _ans += (max(a,b)*(max(a,b)+1))//2
        
        _ans += (min(a,b)-1)*(min(a,b))//2
        

    if len(ans)==1:
        c = ans.popleft()
        _ans += c*(c+1)//2
        

print(_ans)

Solution (Python):
s = str(input())
s_length = len(s)
answer = 0
cnt = 0
t = 0
_t = 0
for i in range(s_length):
  if s[i] == '<':
    t += 1
    cnt = 0
    answer += t
  else:
    if t == 0:
      if _t <= cnt:
        t = 0
        cnt += 1
        answer += cnt 
      else:
        t = 0
        cnt += 1
        answer += cnt - 1
    else:
      _t = t
      t = 0
      answer += cnt * 1
      cnt += 1
print(answer)

Solution (Python):
s = input()
lr = []
if s[len(s)-1] == '>':
    s_add = s + '<'
else:
    s_add = s + '>'
cnt = 1
for i in range(1,len(s_add)):
    if s_add[i] == s_add[i-1]:
        cnt += 1
    else:
        lr.append(cnt)
        cnt = 1

if s[0] == '<':
    num = 0
    for i,val in enumerate(lr):
        if val != 1:
            for j in range(1,val):
                num += j
        if i%2 == 0:
            if i+1 > len(lr)-1:
                num += lr[i]
            else:
                num += max(lr[i],lr[i+1])
else:
    num = 0
    for i,val in enumerate(lr):
        if val != 1:
            for j in range(1,val):
                num += j
        if i%2 == 1:
            if i+1 > len(lr)-1:
                num += lr[i]
            else:
                num += max(lr[i],lr[i+1])
        if i == 0:
            num += lr[i]
    

print(num)

Solution (Python):

S = input()
N = len(S) + 1
result = [ -1 for i in range(N) ]

def countContinueChar(index):
    startChar = S[index]
    count = 0
    for i in range(index, N-1):
        if S[i] != startChar:
            break
        count += 1
    return count

def getValueOfIndex(index, current, prev = '', preprev = ''):
    if S[index] == '<':
        if prev == '>':
            return 0
        else:
            return current + 1
    else:
        if prev == '<':
            v = countContinueChar(index)
            if v < current + 1:
                return current + 1
            else:
                return v
        else:
            if preprev == '<' and prev == '>':
                return countContinueChar(index)
            else:
                if prev != '>':
                    return countContinueChar(index)
                else:
                    return current - 1

current = -1
prev = ''
preprev = ''
sum = 0
for i in range(N):
    if i == N-1:
        if S[-1] == '<':
            result[i] = current + 1
            sum += current + 1
        
            
        break
    if i > 0:
        prev = S[i - 1]
    if i > 1:
        preprev = S[i - 2]
    current = getValueOfIndex(i, current, prev, preprev)
    
    sum += current


print(sum)

Solution (Python):
s = list(input())
N = len(s)
a = [0] * (10+N)
if(s[0] == '<'): p = 0
else: p = 1
count = 0
count2 = 0
A = 0
start = 0
end = 0

for i in range(N):
    if ((s[i] == '>')& (p == 0)):
        
        count2 += 1
        p = 1
        max_ = i
    elif(p == 0):
        
        count += 1
    elif(s[i] == '<'):
        
        end = i
        if(count > count2):
            count2 -=1
            A += count*(count+1)/2
            A += count2*(count2+1)/2
        else:
            count -=1
            A += count*(count+1)/2
            A += count2*(count2+1)/2
        p = 0
        start = i
        count = 1
        count2 = 0
        max_ = 0
    else:
        
        count2 += 1
if(count > count2):
    count2 -=1
    A += count*(count+1)/2
    A += count2*(count2+1)/2
else:
    count -=1
    A += count*(count+1)/2
    A += count2*(count2+1)/2
print(int(A))

Solution (Python):



def solve(*args: str) -> str:
    S = args[0]
    A = [0 for _ in range(len(S)+1)]

    h = []

    cnt = 0

    

    
    
    
    

    
    
    
    
    

    m = 0
    for n in range(1, len(S)+1):
        if 0 < m:
            A[n] = m
            m -= 1
        elif S[n-1] == '<':
            A[n] = A[n-1]+1
        else:
            m = 0
            while n+m < len(S) and S[n+m] == '>':
                m += 1

            A[n-1] = max(m+1, A[n-1])
            A[n] = m
            m -= 1

    
    
    

    return str(sum(A))


if __name__ == "__main__":
    print(solve(*[input() for _ in range(1)]))

Solution (Python):
S = list(input())
A = []
i = 0
if S[0] == "<":
    temp = [0,1]
else:
    temp = [0,-1]
for i in range(1,len(S)):
    if S[i-1] == "<" and S[i] == ">":
        A.append(temp)
        temp = [0]   
        if S[i] == ">":
            temp.append(temp[-1]-1)
        else:
            temp.append(temp[-1]+1)
    else:
        if S[i] == ">":
            temp.append(temp[-1]-1)
        else:
            temp.append(temp[-1]+1)
A.append(temp)

sumj = 0
for j in A:
    minj = min(j)
    for k in range(len(j)):
        j[k] += -minj
    sumj += sum(j)
m = []
for l in range(len(A)-1):
    m.append(min(A[l][-1],A[l+1][0]))

print(sumj-sum(m))

Solution (Python):
s = input()

total_sum = 0
minus = 0
plus = 0
sum = 0

for i in s:
    if i == '<':
        if minus > 0:
            if plus < minus:
                sum = (int)((minus * (minus + 1) + plus * (plus - 1)) / 2)
            else:
                sum = (int)((minus * (minus - 1) + plus * (plus + 1)) / 2)
            minus = 0
            plus = 0
            total_sum = total_sum + sum
        plus = plus + 1
    else:
        minus = minus + 1

if plus < minus:
    sum = (int)((minus * (minus + 1) + plus * (plus - 1)) / 2)
else:
    sum = (int)((minus * (minus - 1) + plus * (plus + 1)) / 2)

print(total_sum + sum)

Solution (Python):
S = input()

ans = [0] * (len(S) + 1)


prev = ""
for i in range(len(S)):
    
    if S[i] == "<":
        ans[i + 1] = ans[i] + 1
        prev = "<"

    
ans.reverse()
for i in range(len(S)):
    
    
    
    
    if S[len(S)-1-i] == ">" and not ans[i] < ans[i+1]:
        ans[i + 1] = ans[i] + 1
        prev = ">"
    

print(sum(ans))

Solution (Python):
s = str(input())
 
s_length = len(s)
 
answer = 0
cnt = 0
t = 0
_t = 0
for i in range(s_length):
  if s[i] == '<':
    t += 1
    cnt = 0
    answer += t
  else:
    if t == 0:
      if _t <= cnt:
        t = 0
        cnt += 1
        answer += cnt 
      else:
        t = 0
        cnt += 1
        answer += cnt - 1
    else:
      _t = t
      t = 0
      answer += cnt * 1
      cnt += 1
      
print(answer)

Solution (Python):
S = input()
if S[0] == ">":
  S = "<" + S
if S[-1] == ">":
  S = S + "<"
elif S[-1] == "<":
  S = S + "><"
L = []
T = []

now = S[0]
for i in range(len(S)):
  if now == ">" and S[i] == "<":
    now = S[i]
    L.append(2)
  elif now == "<" and S[i] == ">":
    now = S[i]
    L.append(1)
  else:
    L.append(0)    
if L.count(2) == 0:
  L.append(2)
  
countl, countr = 0, 0
flag = 0
for i in range(len(L)):
  if L[i] == 0 and flag == 0:
    countl += 1
  elif L[i] == 0 and flag == 1:
    countr += 1
  elif L[i] == 1:
    flag = 1
    countr += 1
  else: 
    if countl > countr:
      T.append((countl)*(countl+1)//2)
      T.append((countr)*(countr-1)//2)
    else:
      T.append((countl)*(countl-1)//2)
      T.append((countr)*(countr+1)//2)
    flag = 0
    countl, countr = 1, 0

print(sum(T))

Solution (Python):
s=input()
if s[-1]=='<':
  s+='>e'
else:
  s+='ee'

result=0
count=0
count2=0
pre='s'
for i in range(len(s)-1):
  count+=1
  if s[i]!=s[i+1]:
    if s[i]=='>':
      count-=1
      result+=count*count/2+count/2
      count+=1
      result+=max(count,count2)
    else:
      count-=1
      result+=count*count/2+count/2
      count2=count+1
    count=0
print(int(result))

Solution (Python):


S = input()




if(S[0] == "<"):
    flag=0
else:
    flag=1

sum_count = 0
count=1
tmp_count = 1
for i in range(1, len(S)):
    if(S[i-1] == "<" and S[i] == "<"):
        count+=1
        tmp_count += 1
        
    elif(S[i-1] == "<" and S[i] == ">"):
        sum_count += int(((count-1)*count)/2)
        
        count=1
        
    elif(S[i-1] == ">" and S[i] == "<"):
        if(tmp_count > count):
            sum_count += int(((count+1)*count)/2 + (tmp_count - count))
        else:
            sum_count += int(((count+1)*count)/2)
        
        count=1
        tmp_count = 1
        
    elif(S[i-1] == ">" and S[i] == ">"):
        count+=1

if(S[-1] == ">"):
    if(tmp_count > count):
        sum_count += int(((count+1)*count)/2 + (tmp_count - count))
    else:
        sum_count += int(((count+1)*count)/2)
else:
    sum_count += int(((count+1)*count)/2)
  
  
print(sum_count)

Solution (Python):
def f(x):
    return x*(x+1)//2


s = input()
ans = 0
if len(set(s)) == 1:
    ss = len(s)
    ans = ss*(ss+1)//2
    print(ans)
    exit()

ss = s.replace('><' , '> <')
lst = ss.split()

for l in lst:
    a = l.count('<')
    b = l.count('>')
    
    if a == 0:
        ans += f(b)
    elif b == 0:
        ans += f(a)
    else:
        mn = min(a,b)
        mx = max(a,b)
        ans += f(mx) + f(mn-1)
print(ans)

Solution (Python):
S = input()
N = len(S)+1

i = 0
total = 0

def suma(n):
    if n <= 1:
        return 0
    return (n-1)*n//2

while True:
    j = S.find('><', i)
    if j == 0:
        total += 1
        i = j+1
    elif j > 0:
        t = S[i:j+1]
        tl = len(t)
        tc_s = t.count('<')
        tc_b = t.count('>')
        if t == tc_s or tl == tc_b:
            total += suma(tl+1)
        elif tc_s >= tc_b:
            total += suma(tc_s+1) + suma(tc_b)
        elif tc_s < tc_b:
            total += suma(tc_s) + suma(tc_b+1)
        i = j+1
    else:
        t = S[i:]
        tl = len(t)
        tc_s = t.count('<')
        tc_b = t.count('>')
        if t == tc_s or tl == tc_b:
            total += suma(tl+1)
        elif tc_s > tc_b:
            total += suma(tc_s+1) + suma(tc_b-1)
        elif tc_s < tc_b:
            total += suma(tc_s-1) + suma(tc_b+1)
        else:
            total += suma(tc_s+1) + suma(tc_b)
        break
print(total)

Solution (Python):
import sys
from io import StringIO
import unittest
import math


def resolve():
    s = input()

    if s == '<' or s == '>':
        print(1)
        return

    upDownList = []
    count = 1
    before = s[0]
    c = None
    for i in range(1, len(s)):
        c = s[i]

        if c != before:
            if c == '>':
                upDownList.append(count)
            elif c == '<':
                upDownList.append(-1 * count)
            else:
                raise Exception()
            count = 0

        count += 1
        before = c

    if c == '<':
        upDownList.append(count)
    elif c == '>':
        upDownList.append(-count)
    else:
        raise Exception()
    

    beforeIsUp = False
    before = 0
    count = 0
    for i in range(len(upDownList)):
        upDown = upDownList[i]

        for i in range(abs(upDown)+1):
            count += i

        if beforeIsUp:
            if before > abs(upDown):
                count -= abs(upDown)
            else:
                count -= before

        if upDown > 0:
            beforeIsUp = True
            before = upDown
        else:
            beforeIsUp = False
        

    print(count)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """<>>"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """<>>><<><<<<<>>><"""
        output = """28"""
        self.assertIO(input, output)


if __name__ == "__main__":
    
    resolve()

Solution (Python):
s = list(input())

lens = len(s)
if lens == 1:
  print(1)
  exit()
  
li = [0] * (len(s) + 1)
for itr, val in enumerate(s):
  if itr == 0:
    if val == "<":
      li[0] = 0
  else:
    if (s[itr - 1] == "<" and s[itr] == "<"):
      li[itr] = li[itr - 1] + 1


    if s[itr] == "<" and itr == lens - 1:
      li[itr + 1] = li[itr] + 1

for itr, val in enumerate(reversed(s)):
  if itr == 0:
    if val == ">":
      li[lens] = 0
  else:
    if s[lens - itr - 1] == ">" and s[lens - itr] == ">":
      li[lens - itr] = li[lens - itr + 1] + 1
    if s[0] == ">":
      li[0] = li[1] + 1
      
for itr, val in enumerate(s):
  if itr > 0:
    if s[itr - 1] == "<" and s[itr] == ">":
      li[itr] = max(li[itr - 1],li[itr + 1]) + 1 

print(sum(li))

Solution (Python):
def souwa(n):
  return n * (n + 1) // 2

arr = input().replace('><', "> <").split()
res = 0
for s in arr:
  a = s.count("<")
  b = len(s) - a
  if(a < b):
    res += souwa(a - 1)
    res += souwa(b)    
  else:
    res += souwa(a)
    res += souwa(b - 1)
print(res)

Solution (Python):
s = input()
n = len(s) + 1
s = s[0] + s + s[-1]

A = [0]
for i in range(n-1):
    if s[i] == '>' and s[i+1] =='>':
        A[-1] -= 1
    elif s[i] == '<' and s[i+1] =='<':
        A[-1] += 1
    else:
        A.append(0)
        if s[i+1] == '<':
            A[-1] += 1
        else:
            A[-1] -= 1

if s[0] == '>':
    A = [0] + A
if s[-1] == '<':
    A = A + [0]

m = len(A)
ans = 0

for j in range(m):
    A[j] = abs(A[j])
for i in range(m//2):
    a = max(A[2*i], A[2*i+1])
    b = min(A[2*i], A[2*i+1])
    ans += (a*(a+1)+b*(b-1))//2
            
        

print(ans)

Solution (Python):
s=str(input())
n=len(s)
i=0
ans=0
c=0
d=0
j=0
while i < n:
	if s[i] == "<":
		c=c+1
		ans=ans+c
		j=0
	else:
		j=j+1
		if j > 1:
			if d >= j:
				ans=ans+j-1
			else:
				ans=ans+j
		elif i == 0:
			ans=1
		else:
			d=c
		c=0
	i=i+1
print(ans)

Solution (Python):
a = list(input())
count=1
answer=0
newlist=[]
masklist=[]
def Souwa(n):
    s=(1/2)*int(n)*int((n+1))
    return int(s)

for i in range(len(a)):
    if i==len(a)-1:
        newlist.append(count)
    elif a[i] =="<" and a[i+1]==">":
        newlist.append(count)
        masklist.append(1)
        count=1
    elif a[i]==">" and a[i+1]=="<":
        newlist.append(count)
        masklist.append(0)
        count=1
    else:
        count+=1

for i in range(len(masklist)):
    if masklist[i]==1:
        if newlist[i]<newlist[i+1]:
            newlist[i]-=1
        else:
            newlist[i+1]-=1

for i in range(len(newlist)):
    answer+=Souwa(newlist[i])
print(answer)

Solution (Python):
import numpy as np

S = input()
L = []
N = len(S)

if S[-1] == '<':
    S += '><'
else:
    S += '<>'

index = 0
for n in range(N+1):
    if S[n: n + 2] == '><':
        L.append(S[index: n + 1])
        index = n + 1


def calc(string):
    K = len(string)
    c = K
    for k in range(K - 1):
        if string[k: k + 2] == '<>':
            c = k + 1
            break
    a = min(c, K - c)
    b = max(c, K - c)
    return a * (a - 1) // 2 + b * (b + 1) // 2


ans = 0
for string in L:
    ans += calc(string)

print(ans)

Solution (Python):
import numpy as np



S = input()
set_array = []
prev_set_len = 0
total = 0

prev_check_point = 0
mountains = []
valleys = [0]
for i in range(len(S)-1):
    if S[i] == "<" and S[i+1] == ">":
        mountains.append(i+1)
    elif S[i] == ">" and S[i+1] == "<":
        valleys.append(i+1)

valleys.append(len(S))

if len(mountains) == 0 and len(valleys) == 2:
    print((len(S)+1)*len(S)//2)
    exit()
if len(mountains) == 0 and len(valleys) == 3:
    left = valleys[1]
    right = len(S) - valleys[1]
    total += (left+1)*left//2
    total += (right+1)*right//2
    print(total)
    exit()

if valleys[1] < mountains[0]:
    left = valleys[1]
    total += (left+1)*left//2
    valleys.remove(0)

for i, mountain in enumerate(mountains):
    left = mountain - valleys[i]
    right = valleys[i+1] - mountain

    if left > right:
        total += (left+1)*left//2
        total += (right-1+1)*(right-1)//2
    else:
        total += (right+1)*right//2
        total += (left-1+1)*(left-1)//2

if valleys[-2] > mountains[-1]:
    right = len(S) - valleys[-2]
    total += (right+1)*right//2


print(total)

Solution (Python):
from sys import stdin 
s = stdin.readline().rstrip()
a = [0] * (len(s) + 1)
t = 1
for i in range(len(s)):
    if i == 0:
        if s[i] == '<':
            k = 0
        else:
            k = 1
    if s[i] == '<' and k == 0:
        a[i+1] = a[i] + 1
    elif s[i] == '<' and k == 1:
        if a[i] < 0:
            min = (-1) * a[i]
            a[i] = 0
            for j in range(t, i):
                a[j] += min
            if t > 1:
                if a[t-2] > a[t]:
                    a[t-1] = a[t-2] + 1
                else:
                    a[t-1] = a[t] + 1
            else:
                a[t-1] = a[t] + 1
        else:
            a[i] = 0
        a[i+1] = a[i] + 1
        k = 0
    elif s[i] == '>' and k == 1:
        a[i+1] = a[i] - 1
    elif s[i] == '>' and k == 0:
        a[i+1] = 0
        t = i+1
        k = 1
    if i == len(s)-1 and s[i] == '>':
        if a[i+1] < 0:
            min = (-1) * a[i+1]
            a[i+1] = 0
            for j in range(t, i+1):
                a[j] += min
        if t > 1:
            if a[t-2] > a[t]:
                a[t-1] = a[t-2] + 1
            else:
                a[t-1] = a[t] + 1
        else:
            a[t-1] = a[t] + 1
print(sum(a))

Solution (Python):
S = input()

results = []

l_delete_flag = False
r_delete_flag = False


if S[0] == ">":
    S = S + "S"
    cnt = 0
    i = 1
    while S[i] == ">":
        results.append(i + 1)
        i += 1
    results.append(1)
    S = S.rstrip("S")
    l_delete_flag = True


if S[-1] == "<":
    S = "S" + S
    i = len(S) - 1
    r = 1
    while S[i] == "<":
        results.append(r)
        r += 1
        i -= 1
    S = S.lstrip("S")
    r_delete_flag = True

if l_delete_flag:
    S = S.lstrip(">")


if r_delete_flag:
    S = S.rstrip("<")
    


if S:
    end_flag = False
    l_cnt = 0
    m_cnt = 0
    for i, s in enumerate(S):
        if end_flag:
            l_cnt = 0
            m_cnt = 0
            end_flag = False
        
        if s == "<":
            l_cnt += 1
        else:
            m_cnt += 1
        
        if (i == len(S) - 1) or ((s == ">") and (S[i + 1] == "<")):
            if l_cnt > m_cnt:
                results.append(int((l_cnt * (l_cnt + 1)) / 2))
                results.append(int((m_cnt * (m_cnt - 1)) / 2))
            else:
                results.append(int((m_cnt * (m_cnt + 1)) / 2))
                results.append(int((l_cnt * (l_cnt - 1)) / 2))
            end_flag = True

print(sum(results))

Solution (Python):
n = list(input())
counter = 1
directions = []
list = []
def add_up(x):
    added = (1/2) * x * (x + 1)
    return added
for i in range(len(n)-1):
    if n[i] == n[i+1]:
        counter += 1
    else:
        directions.append(counter)
        counter = 1
directions.append(counter)
if n[0] == "<":
    for i in range(0,len(directions)-1,2):
        if directions[i] >= directions[i+1]:
            directions[i+1] -= 1
        else:
            directions[i] -= 1
else:
    for i in range(1,len(directions)-1,2):
        if directions[i] >= directions[i+1]:
            directions[i+1] -= 1
        elif directions[i] < directions[i+1]:
            directions[i] -= 1
for direction in directions:
    list.append(add_up(direction))
print(round(sum(list)))

Solution (Python):
s=input()
a=[]
b=1
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        b+=1
    elif s[i]!=s[i+1]:
        a.append(b)
        b=1
    if i==len(s)-2:
        a.append(b)

if len(a)%2==0:
    if s[0]=="<":
        for i in range(0,len(a),2):
            if a[i]>=a[i+1]:
                a[i+1]-=1
            else:
                a[i]-=1
    else :
        for i in range(1,len(a)-1,2):
            if a[i]>=a[i+1]:
                a[i+1]-=1
            else:
                a[i]-=1

else:
    if s[0]=="<":
        for i in range(0,len(a)-1,2):
            if a[i]>=a[i+1]:
                a[i+1]-=1
            else:
                a[i]-=1
    else :
        for i in range(1,len(a),2):
            if a[i]>=a[i+1]:
                a[i+1]-=1
            else:
                a[i]-=1   

def wa(n):
    return (n+1)*n//2
d=[]
if a==[]:
  print(1)
else:
  for i in range(len(a)):
    d.append(wa(a[i]))
  print(sum(d))

Solution (Python):
S = list(str(input()))

count = 0
count_bef = 0
count_list=[]
count_list2=[]
minus = []
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    count += 1
  elif not S[i] ==S[i+1]:
    count_list.append(int((count+1)*(count+2)/2))
    count_list2.append(count+1)
    count = 0
count_list.append(int((count+1)*(count+2)/2))
count_list2.append(count+1)
if S[0] == "<":
  for i in range(len(count_list2)//2):
    minus.append(min(count_list2[2*i], count_list2[2*i+1]))
elif S[0] == ">":
  try:
    for i in range(len(count_list2)//2):
      minus.append(min(count_list2[2*i+1], count_list2[2*i+2]))
  except IndexError:
    pass



print(sum(count_list)-sum(minus))

Solution (Python):
s = input()
s0 = s[0]
count = 1
nodes = []
ans = 0
for i in range(1, len(s)):
  if s0 == s[i]:
    count += 1
  elif s0 == '>':
    s0 = s[i]
    nodes.append(-count)
    count = 1
  else:
    s0 = s[i]
    nodes.append(count)
    count = 1
if s0 == '>':
  nodes.append(-count)
else:
  nodes.append(count)

for i in range(1, len(nodes)):
  if nodes[i] < 0:
    if abs(nodes[i]) > abs(nodes[i - 1]):
      nodes[i] = abs(nodes[i])
      nodes[i - 1] -= 1
    else:
      nodes[i] = abs(nodes[i])
      nodes[i] -= 1
nodes[0] = abs(nodes[0])
for i in nodes:
  ans += (i * (i + 1)) // 2
print(ans)

Solution (Python):
S = str(input())
l = 0
r = 0
ans = 0
tmp = S[0]
if tmp == ">":
    r = 1
else:
    l = 1
for i in range(1,len(S)):
    if tmp == ">" and S[i] == "<":
        ans += max(l, r) * (max(l, r) + 1) / 2 + min(l, r) * (min(l, r) - 1) / 2
        l = 1
        r = 0
        tmp = S[i]
    else:
        if S[i] == ">":
            r += 1
        else:
            l += 1
        tmp = S[i]
ans += max(l, r) * (max(l, r) + 1) / 2 + min(l, r) * (min(l, r) - 1) / 2
print(int(ans))

Solution (Python):
import sys

iter_num = 5 * (10**5) + 10
sys.setrecursionlimit(iter_num)

s = input()
n = len(s) + 1

a = [0 for _ in range(n)]
next_num=0

def solve(num):
	global next_num
	if num == 0:
		if s[0] == '<':
			a[num] = 0
			next_num = 1
			return 0
		else:
			next_num = 1
			a[num] = solve(num+1) + 1
	if num == n-1:
		if s[n-2] == '>':
			next_num = -1
			a[num] = 0
			return 0
		else:
			a[num] = solve(num-1) + 1
			next_num = -1
			return a[num]

	if s[num-1] == '>' and s[num] == '<':
		next_num = num+1
		a[num] = 0
		return 0
	elif s[num-1] == '>' and s[num] == '>':
		a[num] = solve(num+1) + 1
		return a[num]
	elif s[num-1] == '<' and s[num] == '>':
		next_num = num+1
		a[num] = max(solve(num-1),solve(num+1)) + 1
		return a[num]
	else:
		
		a[num] = a[num-1] + 1
		next_num = num+1
		return a[num]

while next_num != -1:
	solve(next_num)


print(sum(a))

Solution (Python):
from sys import stdin

s = stdin.readline().rstrip()
li = [0]*(len(s)+1)
point = 0
for i in range(len(s)):
    if s[i] == "<":
        point += 1
        li[i+1] = point
    else:
        point = 0

li = li[::-1]
s = s[::-1]
ns = ""

for i in s:
    if i == "<":
        ns += ">"
    else:
        ns += "<"

point = 0

for i in range(len(ns)):
    if ns[i] == "<" and li[i+1] <= point:
        point += 1
        li[i+1] = point
    elif i == 0 or ns[i] == "<" and li[i+1] > point:
        point = 0
    else:
        point = 0

print(sum(li))

Solution (Python):
S = str(input())
a = []
ans = 0

def sumn(x):
    y = x * (x+1)//2
    return y
    
cnt = 1

if len(S) == 1:
    ans = 1
    print(ans)
else:
    for i in range(len(S)-1):
        if S[i+1] == S[i]:
            cnt += 1
            if i+1 == len(S)-1:
                a.append(cnt)
        
        else:
            a.append(cnt)
            cnt = 1
            if i+1 == len(S)-1:
                a.append(cnt)
            
    if S[0] == '<':
        for i in range(len(a)):
            if i % 2 == 0:
                ans += sumn(a[i])
            else:
                if a[i] > a[i-1]:
                    ans += (sumn(a[i]) - a[i-1])
                else:
                    ans += sumn(a[i]-1)
    else:
        for i in range(len(a)):
            if i == 0:
                ans += sumn(a[i])
            elif i % 2 == 1:
                ans += sumn(a[i])
            else:
                if a[i] > a[i-1]:
                    ans += (sumn(a[i]) - a[i-1])
                else:
                    ans += sumn(a[i]-1)
    print(ans)

Solution (Python):
S=input()
N=len(S)
ren=[]
a=1
if N==1:
  print(1)
  exit()
for i in range(N-1):
  if S[i]==S[i+1]:
    a+=1
  else:
    ren.append(a)
    a=1
  if i==N-2:
    ren.append(a)
      
M=len(ren)
ma=max(ren)
su=0
if S[0]=="<":
  if M%2==0:
    for k in range(M//2):
      if ren[2*k]<ren[2*k+1]:
        su=su+ren[2*k]*(ren[2*k]-1)//2+ren[2*k+1]*(ren[2*k+1]+1)//2
      else:
        su=su+ren[2*k]*(ren[2*k]+1)//2+ren[2*k+1]*(ren[2*k+1]-1)//2
  else:
    for k in range(M//2):
      if ren[2*k]<ren[2*k+1]:
        su=su+((ren[2*k]*(ren[2*k]-1))//2)+(ren[2*k+1]*(ren[2*k+1]+1)//2)
      else:
        su=su+ren[2*k]*(ren[2*k]+1)//2+ren[2*k+1]*(ren[2*k+1]-1)//2
    su+=ren[-1]*(ren[-1]+1)//2
if S[0]==">":
  su+=ren[0]*(ren[0]+1)//2  
  if (M-1)%2==0:
    for k in range((M-1)//2):
      if ren[1+2*k]<ren[1+2*k+1]:
        su=su+ren[1+2*k]*(ren[1+2*k]-1)//2+ren[1+2*k+1]*(ren[1+2*k+1]+1)//2
      else:
        su=su+ren[1+2*k]*(ren[1+2*k]+1)//2+ren[1+2*k+1]*(ren[1+2*k+1]-1)//2
  else:
    for k in range((M-1)//2):
      if ren[1+2*k]<ren[1+2*k+1]:
        su=su+ren[1+2*k]*(ren[1+2*k]-1)//2+ren[1+2*k+1]*(ren[1+2*k+1]+1)//2
      else:
        su=su+ren[1+2*k]*(ren[1+2*k]+1)//2+ren[1+2*k+1]*(ren[1+2*k+1]-1)//2
    su+=ren[-1]*(ren[-1]+1)//2
print(su)

Solution (Python):
def main():
    s = input()
    f1 = False
    f2 = False
    l = [1]
    if s[0] == "<":
        f1 = True
        l.insert(0,0)
    if s[-1] == ">":
        f2 = True
    sm = [i for i in range(0,len(s)+1)]
    for i in range(1,len(sm)):
        sm[i] = sm[i-1]+sm[i]
    lap = l.append
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            l[-1] += 1
        else:
            lap(1)
    dlist = []
    plist = []
    dap = dlist.append
    pap = plist.append
    if f2:
        l.append(0)
    for i in range(len(l)//2):
        dap(l[2*i])
        pap(l[2*i+1])   
    for i in range(1,len(dlist)):
        x = dlist[i]
        y = plist[i-1]
        if y <= x:
            dlist[i] = sm[x]
            plist[i-1] = sm[max([0,y-1])]
        else:
          dlist[i] = sm[max([0,x-1])]
          plist[i-1] = sm[y]
    dlist[0] = sm[dlist[0]]
    plist[-1] = sm[plist[-1]]
    print(sum(dlist)+sum(plist))
    
if __name__ == '__main__':
    main()

Solution (Python):
s=list(input())
a=[0]*(len(s)+1)
if s[0]=='<':
    a[0]=0
    l=0
    while s[l]=='<':
        a[l+1]=a[l]+1
        l+=1
        if l>len(s)-1:
          break
if s[len(s)-1]=='>':
    a[len(s)]=0
    m=len(s)-1
    while s[m]=='>':
        a[m]=a[m+1]+1
        m-=1
        if m<0:
          break
for i in range(len(s)-1):
    if s[i]=='>' and s[i+1]=='<':
        a[i+1]=0
        k=i
        t=i+1
        while s[k]=='>':
            a[k]=a[k+1]+1
            k-=1
            if k<0 or k>len(s)-1:
                break
        while s[t]=='<':
            a[t+1]=a[t]+1
            t+=1
            if t<0 or t>len(s)-1:
                break
for i in range(len(s)-1):
    if s[i]=='<' and s[i+1]=='>':
        a[i+1]=max(a[i],a[i+2])+1
print(sum(a))

Solution (Python):
import sys
input = sys.stdin.readline

S = input().strip()
a = 0
sum_a = 0
c = 0
for s in S:
    if s == '<':
        if c > a:
            sum_a += int((1 + c) * c / 2 - a)
            a = 1
            sum_a += 1
            c = 0
        elif c > 0:
            sum_a += int((c) * (c - 1) / 2)
            a = 1
            sum_a += 1
            c = 0
        else:
            a += 1
            sum_a += a
            c = 0
    else:
        c += 1
else:
    if c > a:
        sum_a += int((1 + c) * c / 2  - a)
        a = 1
        c = 0
    elif c > 0:
        sum_a += int((c) * (c - 1) / 2)
        a = 1
        c = 0

print(sum_a)

Solution (Python):
s=input()
n=len(s)+1
list=[]
stock1 = 0
stock2 = 0
for i in range(0,n-1):
    if s[i] == "<":
        if i==0 or (i>0 and s[i-1]==">"):
            for j in range(0,stock1+1):
                if j == 0:
                    list.append(max(stock1,stock2)-j)
                else:
                    list.append(stock1-j)
            stock1 = 0
            stock2 = 1
        else:
            list.append(list[i-1]+1)
            stock2 += 1
    else:
        stock1 += 1

if s[-1] == ">":
    for j in range(0,stock1+1):
        if j == 0:
            list.append(max(stock1,stock2)-j)
        else:
            list.append(stock1-j)
else:
    list.append(list[-1]+1)

ans=0
for i in list:
    ans += i

print(ans)

Solution (Python):
s=list(input())
a=[0]*(len(s)+1)
if s[0]=='<':
    a[0]=0
    l=0
    while s[l]=='<':
        a[l+1]=a[l]+1
        l+=1
        if l>len(s)-1:
          break
if s[len(s)-1]=='>':
    a[len(s)]=0
    m=len(s)-1
    while s[m]=='>':
        a[m]=a[m+1]+1
        m-=1
        if m<0:
          break
for i in range(len(s)-1):
    if s[i]=='>' and s[i+1]=='<':
        a[i+1]=0
        k=i
        t=i+1
        while s[k]=='>':
            a[k]=a[k+1]+1
            k-=1
            if k<0 or k>len(s)-1:
                break
        while s[t]=='<':
            a[t+1]=a[t]+1
            t+=1
            if t<0 or t>len(s)-1:
                break
for i in range(len(s)-1):
    if s[i]=='<' and s[i+1]=='>':
        a[i+1]=max(a[i],a[i+2])+1
print(sum(a))