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):
import numpy as np
S=input();T=S[::-1];a=[];c=0
for t in T:
    if t==">":
        c+=1
    else:
        c=0
    a.append(c)
A=np.array(a[::-1]+[0])
b=[];c=0
for s in S:
    if s=="<":
        c+=1
    else:
        c=0
    b.append(c)
B=np.array([0]+b)
print(np.maximum(A,B).sum())

Solution (Python):

import sys
import math
import numpy as np
import itertools


s = list(input())
t = [0]
now = 0
if s[0]=='<':
    now = 1
else:
    now = -1

for i in range(1,len(s)):
    if s[i]=='<' and now > 0:
        now += 1
    elif s[i]=='<' and now < 0:
        t.append(now)
        now = 1
    elif s[i]=='>' and now < 0:
        now -= 1
    elif s[i]=='>' and now > 0:
        t.append(now)
        now = -1
t.append(now)

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

print(answer)

Solution (Python):
s = input()
i = 0

l_count = 0
r_count = 0

check = 0

sum_value = 0

while i < len(s):
    if s[i] == '<':
        if r_count > 0:
            if check > r_count:
                sum_value += check
                n = r_count-1
                sum_value += n * (n + 1) // 2 
            else:
                n = r_count
                sum_value += n * (n + 1) // 2     
        l_count += 1
        r_count = 0
        
        
    elif s[i] == '>':
        if l_count > 0:
            check = l_count
            n = l_count-1
            sum_value += n * (n + 1) // 2
        l_count = 0
        r_count += 1
    i += 1
    
if l_count > 0:
    n = l_count
    sum_value += n * (n + 1) // 2  
if r_count > 0:
    n = r_count
    sum_value += n * (n + 1) // 2

print(sum_value)

Solution (Python):
S = input()
sign_list = []
count = 1


if S[0] == "<":
    flag = True
else:
    flag = False


S_dummy = S + "_"
for i in range(len(S_dummy) - 1):
    if S_dummy[i] == S_dummy[i + 1]:
        count += 1
    else:
        sign_list.append(count)
        count = 1


ans = 0
if flag:
    for i in range(len(sign_list) // 2):
        s_count = sign_list[i * 2]
        d_count = sign_list[i * 2 + 1]

        if s_count <= d_count:
            ans += d_count * (d_count + 1) / 2 + s_count * (s_count - 1) / 2
        else:
            ans += s_count * (s_count + 1) / 2 + d_count * (d_count - 1) / 2
    
    if len(sign_list) % 2 != 0:
        ans += sign_list[-1] * (sign_list[-1] + 1) / 2

else:
    ans += sign_list[0] * (sign_list[0] + 1) / 2

    for i in range((len(sign_list) - 1) // 2):
        s_count = sign_list[i * 2 + 1]
        d_count = sign_list[i * 2 + 2]

        if s_count <= d_count:
            ans += d_count * (d_count + 1) / 2 + s_count * (s_count - 1) / 2
        else:
            ans += s_count * (s_count + 1) / 2 + d_count * (d_count - 1) / 2
    
    if len(sign_list) % 2 == 0:
        ans += sign_list[-1] * (sign_list[-1] + 1) / 2


print(int(ans))

Solution (Python):
S=input()
N=len(S)
a = 0
b = 0
ans=0
for x in range(0,N-1):
    if S[x] == '<':
        a += 1
    else:
        b += 1
    if S[x] == '>' and S[x+1] == '<':
        if a > b:
            b -= 1
        else:
            a -= 1
        if a < 0:
            a = 0
        if b < 0:
            b = 0
        for y in range (0,a+1):
            ans += y
        for z in range (0,b+1):
            ans += z
        a = 0
        b = 0
if S[N-1] == '<':
        a += 1
else:
        b += 1
if a > b:
    b -= 1
else:
     a -= 1
for y in range (0,a+1):
    ans += y
for z in range (0,b+1):
    ans += z
print(ans)

Solution (Python):


S = list(input().strip())
S_count = []
len_S = len(S)

if S[0] == '>':
    S_count.append(0)

loc_index = 0
for i in range(len_S - 1):
    if S[i] != S[i+1]:
        S_count.append(i + 1 - loc_index)
        loc_index = i + 1

S_count.append(len_S - loc_index)

if len(S_count) % 2 != 0:
    S_count.append(0)


def value(x0, x1):
    v = 0
    x_max = max(x0, x1)
    x_min = min(x0, x1)
    for j in range(x_max):
        v += j+1
    for k in range(x_min):
        v += k
    return v


result = 0
left = 0
right = 1
for g in range(len(S_count) // 2):
    result += value(S_count[left], S_count[right])
    left += 2
    right += 2

print(result)

Solution (Python):


s = input()
lst = []
tmp = ''
cnt = 1
for c in s:
    if tmp == c:
        cnt += 1
    else :
        lst.append(cnt)
        cnt = 1
    tmp = c
lst.append(cnt)

ans = 0

if s[0] == '<':
    idx = 1
else:
    idx = 0
if (len(lst) - idx ) % 2 == 1:
    lst.append(1)
for i in range(idx,len(lst),2):
    if lst[i] > 1:
        if lst[i] <= lst[i+1]:
            lst[i] -= 1
        ans += lst[i] * (lst[i]+1) // 2
    if lst[i+1] > 1:
        if lst[i] > lst[i+1]:
            lst[i+1] -= 1
        ans += lst[i+1] * (lst[i+1]+1) // 2
    if lst[i] == 1 and lst[i+1] == 1:
        ans += 1
    
print(ans)

Solution (Python):

import math
s = input()
bigger=0
smaller=0
count = 0
bigger=1 if s[0]=="<" else 0 
smaller=1 if s[0]==">" else 0 


for i in range(len(s)-1):
    if (s[i]==">" and s[i+1]=="<"):
        count += (max(bigger,smaller))*((max(bigger,smaller))+1)/2
        count += (min(bigger,smaller)-1)*(min(bigger,smaller))/2 if (min(bigger,smaller)-1)!=0 else 0
        bigger = 1
        smaller = 0
    elif (s[i]=="<" and s[i+1]=="<"):
        bigger += 1
    elif (s[i]=="<" and s[i+1]==">"):
        smaller += 1
    elif (s[i]==">" and s[i+1]==">"):
        smaller += 1
count += (max(bigger,smaller))*((max(bigger,smaller))+1)/2
count += (min(bigger,smaller)-1)*(min(bigger,smaller))/2 if (min(bigger,smaller)-1)!=0 else 0

print(int(count))

Solution (Python):
def solve_a(s):
    n = len(s) + 1
    
    left = [0] * n
    for i in range(1, n):
        if s[i - 1] == "<":
            left[i] = left[i - 1] + 1
    
    right = [0] * n
    for i in range(n - 2, -1, -1):
        if s[i] == ">":
            right[i] = right[i + 1] + 1
    return sum([max(left[i], right[i]) for i in range(n)])


def main():
    s = list(input())
    res = solve_a(s)
    print(res)


def test():
    assert solve_a(list("<>>")) == 3
    assert solve_a(list("<>>><<><<<<<>>><")) == 28


if __name__ == "__main__":
    test()
    main()

Solution (Python):
import itertools
s=input()
splitlist=[[k, len(list(g))] for k, g in itertools.groupby(s)]
n=len(splitlist)


def total(lst):
	return lst[1]*(lst[1]+1)//2


ans=total(splitlist[0])
for i in range(1,n):
	ans+=total(splitlist[i])
	if splitlist[i][0]==">":
		ans-=min(splitlist[i-1][1],splitlist[i][1])
print(ans)

Solution (Python):
s = input()

ans = 0
l = 0
r = 0
p = 0
for i in range(len(s)):
    if s[i] == ">":
        l += 1
    else:
        r += 1

    if i == len(s) - 1:
        break
        
    if s[i] == ">" and s[i+1] == "<":
        x = max(l, r)
        y = min(l, r)
        ans += x * (x+1) / 2
        if y == 0:
            ans += 0
        else:
            ans += y * (y-1) / 2
        l = 0
        r = 0
        p = i+1

if p != len(s) + 1:
    x = max(l, r)
    y = min(l, r)
    ans += x * (x+1) / 2
    if y == 0:
        ans += 0
    else:
        ans += y * (y-1) / 2


print(int(ans))

Solution (Python):
s=list(input())
n=len(s)+1
l=[]

for i in range(n-1):
    if s[i:i+2]==[">","<"]:
        l.append(i+1)

m=0
if l==[]:
        a=s.count("<")
        b=s.count(">")
        m=m+(max(a,b)+1)*max(a,b)//2+(min(a,b)+1)*min(a,b)//2-min(a,b)


else:
    l.insert(0,0)
    l.append(n)
    for i in range(len(l)-1):
        a=s[l[i]:l[i+1]].count("<")
        b=s[l[i]:l[i+1]].count(">")
        m=m+(max(a,b)+1)*max(a,b)//2+(min(a,b)+1)*min(a,b)//2-min(a,b)

print(m)

Solution (Python):
a=input()

lenS=len(a)
b1=list()
b2=list()
c=a[0]
b1.append(1)
b2.append(a[0])
max_count=1
for i in range(1,len(a)):
  if c!=a[i]:
    c=a[i]
    b1.append(1)
    b2.append(a[i])
  else:
    b1[-1]+=1
    
      
      


N=len(b1)
ans=list()
if a[0]=='<':
  ans+=list(range(b1[0]+1))
else:
  ans+=list(range(b1[0]+1))[::-1]

for i in range(1,N):
  if b2[i]=='<':
    ad=list(range(b1[i]+1))
  else:
    ad=list(range(b1[i]+1)[::-1])
  if ans[-1]<ad[0]:
    del ans[-1]
  else:
    del ad[0]
  ans+=ad

print(sum(ans))

Solution (Python):

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    s = input()

    g = []

    p = ' '
    o = 0
    for c in s:
        if p == c:
            o += 1 
        else:
            if p != ' ':
                g.append([p, o])
            o = 1
        p = c
    g.append([p, o])

    s = c = 0
    for i in g:
        if i[0] == '<':
            s += (i[1] * (2 * c + 1 + i[1])) // 2
            c += i[1]
        elif c < i[1]:
            s += (i[1] - c) + (i[1] * (i[1] - 1)) // 2
            c = 0
        else:
            s += (i[1] * (i[1] - 1)) // 2
            c = 0

    print(s)




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

Solution (Python):
S = input()
l = 0
b = 0
k = 0
sum = 0
for i in range(len(S)):
    k += 1
    if i == len(S)-1 or (S[i] != S[i+1]):
        sum += k * (k + 1) / 2
        if S[i] =="<":
            l = k
            k = 0
        if S[i] ==">":
            b = k
            k = 0
            sum -= min(l, b)

print(int(sum))

Solution (Python):
l = input()

n = [0  for i in range(len(l)+1)]
c = 1
i=1
for x in l:
    if x == '<':
        n[i] = c
        c+=1
    else:
        c=1
    i+=1
c=1
i=1
n_=[0 for i in range(len(l)+1)]
for x in reversed(l):
    if x == '>':
        n_[i] = c
        c+=1
    else:
        c=1
    i+=1

n_=list(reversed(n_))

ans = [max(n[i],n_[i]) for i in range(len(l)+1)]
print(sum(ans))

Solution (Python):
S=input()
S_rev=S[::-1]

import numpy as np

arr_rev=[]
cnt=0
for s_rev in S_rev:
    if s_rev==">":
        cnt+=1
    else:
        cnt=0
    arr_rev.append(cnt)

A=np.array(arr_rev[::-1]+[0])

arr=[]
cnt=0
for s in S:
    if s=="<":
        cnt+=1
    else:
        cnt=0
    arr.append(cnt)

B=np.array([0]+arr)

print(sum(np.maximum(A,B)))

Solution (Python):
s = input()
n = len(s)+1
a = [0]*n
l = []
c = 0
for i in range(len(s)-1):
  if s[i] != s[i+1]:
    l.append([s[c], c, i-c+1])
    c = i+1
l.append([s[c], c, len(s)-c])

for i in l:
  if i[0] == "<":
    for j in range(i[2]+1):
      a[i[1]+j] = max(a[i[1]+j], j)
  else:
    for j in range(i[2]+1):
      a[i[1]+j] = max(a[i[1]+j], i[2]-j)
      
print(sum(a))

Solution (Python):
s = input()
ans_array = [0]*(len(s) + 1)

i = 0
while i < len(s):
  char = s[i]
  
  
  count = 1
  for j in range(i+1, len(s)):
    if s[j] == char:
      count = count +1
    else:
      break
  if char == '<':
    tmp = 0
    for k in range(count+1):
      ans_array[i+k] = tmp
      tmp = tmp + 1
  else:
    tmp = count
    start = 0
    if ans_array[i] > count:
      tmp = tmp - 1
      start = 1
      

    for k in range(start, count+1): 
      ans_array[i+k] = tmp
      tmp = tmp - 1
      
  i = i + count

print(sum(ans_array))

Solution (Python):
import re

s = str(input())

s = re.sub('><', '>,0,<', s)

if s[0] == '<' :
  s = '0,' + str(s)
  
if s[-1] == '>' :
  s = str(s) + ',0'
  
s = re.sub('<>', '<,>', s) 

s = s.split('0')

sum = 0

for i in s:
  i = i.split(',')
  cnt = 0
  for j in range(len(i)):
    Len = int(len(i[j]))
    cnt = cnt + 1
    sum = sum + Len * (Len + 1) / 2
    if cnt > 3:
      des = min([len(i[1]),len(i[2])])
      sum = sum - des
    
print(int(sum))

Solution (Python):
s = input()
n = len(s)

calc = False
ans = 0
left = 0
right = 0
for i in range(n):
    if i == n-1:
        if s[i] == '<':
            left += 1
            calc = True
        else:
            right += 1
            calc = True
    else:
        if s[i] == '<':
            left += 1
        else:
            right += 1
            if s[i+1] == '<':
                calc = True
    if calc:
        if left >= right:
            ans += left*(left+1)//2
            ans += right*(right-1)//2
            calc = False
            left = 0
            right = 0
        else:
            ans += right*(right+1)//2
            ans += left*(left-1)//2
            calc = False
            left = 0
            right = 0

print(ans)

Solution (Python):
S = '>' + input() + '<='
l = len(S)
A = [0] * (l-2)
zero_posi = []
max_posi = []

for i in range(l-2):
    now = S[i]
    nex = S[i+1]
    if S[i] == '>' and S[i+1] =='<':
        A[i] = 0
        zero_posi.append(i)

while zero_posi:
    start = zero_posi.pop()
    count = 0
    for i in range(start, -1, -1):
        A[i] = max(A[i], count)
        count += 1
        if S[i-1] == '<':
            A[i-1] = max(A[i], count)
            break

    count = 0
    for i in range(start, l-2):
        A[i] = max(A[i], count)
        count += 1
        if S[i + 1] == '>':
            break

ans = sum(A)
print(ans)

Solution (Python):

s = input()
if s[0] ==">":
    s = "<"+s
if s[-1]=="<":
    s = s +">"

l=len(s)
upp = 0
dwn = 0
ans = 0
U = []
D = []
for i in range(l):
    if s[i] == "<":
        if dwn:
            D.append(dwn)
            ans += dwn*(dwn+1)//2
            dwn = 0
        upp+=1
    else:
        if upp:
            U.append(upp)
            ans += upp*(upp+1)//2
            upp=0
        dwn += 1
ans += dwn*(dwn+1)//2
for i in range(len(D)):
    ans -= min(U[i],D[i])
print(ans-1)

Solution (Python):
import sys
s = tuple(map(str, input().split("><")))
n = len(s)
ans = 0
def calc(x, y):
    return (x*(x-1) + y*(y-1))/2 + max(x, y)
if n == 1:
    a = s[0].count("<")
    b = s[0].count(">")
    print(int(calc(a, b)))
    sys.exit()
for i in range(n):
    if i == 0:
        a = s[i].count("<")
        b = s[i].count(">") + 1
    elif i == n - 1:
        a = s[i].count("<") + 1
        b = s[i].count(">")
    else:
        a = s[i].count("<") + 1
        b = s[i].count(">") + 1
    ans += calc(a, b)

print(int(ans))

Solution (Python):
moji=input()
s=[]

for c in moji:
    if(c=="<"):
        s.append(1)
    else:
        s.append(-1)



temp=0

yama=[]


n=len(s)+1
a=[-1]*(n)


for i in range(n-1):
    temp+=s[i]
    if(i==n-2):
        yama.append(temp)
    else:
        if(s[i]*s[i+1]==-1):
            yama.append(temp)
            temp=0



l=len(yama)
ans=0
for i in range(l):
    if(i==0 and yama[i]<0):
        tasu=-yama[i]
        ans+=(tasu+1)*tasu//2
        continue
    if(i==l-1 and yama[i]>0):
        tasu=yama[i]
        ans+=(tasu+1)*tasu//2
        continue
    if(i==l-1):
        continue
    if(yama[i]<0 or yama[i+1]>0):
        continue
    dai=max(yama[i],-yama[i+1])
    sho=min(yama[i],-yama[i+1])
    ans+=(dai+1)*dai//2
    ans+=sho*(sho-1)//2

print(ans)

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

vA = [0,] * N
vZ = []
p = ">"
for i,s in enumerate(S):
    if p+s == "><":
        vZ.append(i)
    p = s
if S[-1] == ">":
    vZ.append(N-1)



for z in vZ:
    if z == N-1:
        break
    t = z
    while t<N-1 and S[t] == "<":
        vA[t+1] = vA[t] + 1
        t += 1



for z in vZ:
    if z == 0:
        continue
    t = z
    while t>0 and S[t-1] == ">":
        vA[t-1] = max(vA[t] + 1, vA[t-1])
        t -= 1


print(sum(vA))

Solution (Python):

import sys


def solve(S: str):
    
    S = ">"+S+"<"
    answer = [0]*(len(S)+1)
    between_index = []
    prev = ">"
    for i in range(len(S)):
        if prev == ">" and S[i]=="<":
            between_index.append(i)
        
        prev = S[i]
    if prev == ">":
        between_index.append(len(S))

    for index in between_index:
        for left in range(index-2,-1,-1):
            if S[left]=="<":
                answer[left+1] = max(answer[left+1],answer[left+2]+1)
                break
            else:
                answer[left+1]=answer[left+2]+1
        for right in range(index+1,len(S)):
            if S[right]==">":
                answer[right] = max(answer[right],answer[right-1]+1)
                break
            else:
                answer[right]=answer[right-1]+1
            
    answer = answer[1:len(answer)-1]
    print(sum(answer))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  
    solve(S)

if __name__ == '__main__':
    main()

Solution (Python):
S = input()
lens1 = False
snum = [0]
st = 0
end = 0
count = 1
result = 0

if len(S) == 1:
    result = 1
    lens1 = True
else:
    for i, s in enumerate(S):
        if i == 0:
            if s == '>':
                st = 1
        elif i == len(S) - 1 :
            if s == '<':
                end = 1
            if s != S[i-1]:
                snum.append(count)
                snum.append(1)
            else:
                snum.append(count+1)
        elif s != S[i-1]:
            snum.append(count)
            count = 1
        else:
            count += 1

snum.append(0)

if not lens1:
    for i in range(1, len(snum)-1):
        n = snum[i]
        if st:
            if i % 2 == 0 and n <= snum[i+1]:
                result += int(n * (n - 1) / 2)
            elif i % 2 != 0 and n < snum[i-1]:
                result += int(n * (n - 1) / 2)
            else:
                result += int(n * (n + 1) / 2)
        else:
            if i % 2 == 1 and n <= snum[i+1]:
                result += int(n * (n - 1) / 2)
            elif i % 2 == 0 and n < snum[i-1]:
                result += int(n * (n - 1) / 2)
            else:
                result += int(n * (n + 1) / 2)

print(result)

Solution (Python):
S = list(input())
if S == ['>'] or S == ['<']:
    print(1)
    exit()
m = 0
n = 0
s = 0
l = []
if S[0] == '>':
    l.append(0)
    p = '>'
else:
    p = '<'
c = 1
for i in range(1, len(S)):
    if S[i] == p:
        c += 1
    else:
        l.append(c)
        c = 1
        p = S[i]
if c != 0:
    l.append(c)
if S[-1] == '<':
    l.append(0)

ans = 0

def calc(x):
    if x == 0:
        return 0
    elif x == 1:
        return 1
    else:
        return (1 + x) * x // 2

for i in range(0, len(l), 2):
    
    ans += calc(l[i]) + calc(l[i + 1]) - min(l[i], l[i + 1])
print(ans)

Solution (Python):
s = input()
ans = 0
cnt1, cnt2 = 0, 0
a = []
if s[0] == '>':
    a.append(0)
for c in s:
    if c == '<':
        if cnt2:
            a.append(cnt2)
            cnt2 = 0
        cnt1 += 1
    else:
        if cnt1:
            a.append(cnt1)
            cnt1 = 0
        cnt2 += 1
if cnt1:
    a.append(cnt1)
else:
    a.append(cnt2)
if len(a) % 2:
    a.append(0)
for i in range(1, len(a), 2):
    ans += ((a[i] - 1) * a[i] + (a[i - 1] - 1) *
            a[i - 1]) // 2 + max(a[i], a[i - 1])
print(ans)

Solution (Python):
import math

S = input()
pad = []

if S[0] == "<":
    left_flag = True
    count = 0
    for k in S:
        if left_flag and k == "<":
            count += 1
        elif left_flag and k == ">":
            pad.append(count)
            left_flag ^= 1
            count = 1
        elif (not left_flag) and k == ">":
            count += 1
        else:
            pad.append(-count)
            left_flag ^= 1
            count = 1
    if left_flag:
        pad.append(count)
    else:
        pad.append(-count)


    result = 0
    for i, j in zip(pad[0::2], pad[1::2]):
        if i > abs(j):
            result += sum(range(i + 1)) + sum(range(abs(j)))
        else:
            result += sum(range(i)) + sum(range(abs(j) + 1))
    if len(pad) % 2 == 1:
        result += sum(range(abs(pad[-1] + 1)))
    print(result)

else:
    left_flag = False
    count = 0
    for k in S:
        if left_flag and k == "<":
            count += 1
        elif left_flag and k == ">":
            pad.append(count)
            left_flag ^= 1
            count = 1
        elif (not left_flag) and k == ">":
            count += 1
        else:
            pad.append(-count)
            left_flag ^= 1
            count = 1
    if left_flag:
        pad.append(count)
    else:
        pad.append(-count)

    result = sum(range(abs(pad[0]) + 1))
    for i, j in zip(pad[1::2], pad[2::2]):
        if i > abs(j):
            result += sum(range(i + 1)) + sum(range(abs(j)))
        else:
            result += sum(range(i)) + sum(range(abs(j) + 1))
    if len(pad) % 2 == 0:
        result += sum(range(abs(pad[-1] + 1)))
    print(result)

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

memo = ""
cnt = 0
before_cnt = 0
ans = 0

for x in s:
    if memo == "":
        memo = x
    
    if memo == x:
        cnt += 1
    else:
        ans += cnt * (cnt+1) // 2
        if before_cnt < cnt:
            if memo == ">":
                ans -= before_cnt
        else:
            if memo == ">":
                ans -= cnt
        before_cnt = cnt
        cnt = 1
        memo = x
else:
    ans += cnt * (cnt+1) // 2
    if before_cnt < cnt:
        if memo == ">":
            ans -= before_cnt
    else:
        if memo == ">":
            ans -= cnt
    before_cnt = cnt
    cnt = 0

print(ans)

Solution (Python):
S = input()
if S[0] == '>':
    S = '<' + S
if S[- 1] == '<':
    S = S + '>'
    
N = len(S)
res = 0
    
i = 0
while i < N and S:
    a = 1
    while i + a < N and S[i + a] == '<':
        a += 1
    i += a
    d = 1
    while i + d < N and S[i + d] == '>':
        d += 1
    i += d
    x = max(a, d)
    y = min(a, d)
    res += x*(x + 1)//2 + y*(y - 1)//2
print(res)

Solution (Python):
S = str(input())
N = len(S) + 1
a = [0]*N
if '>' not in S or '<' not in S:
    print(N*(N-1)//2)
    exit()
res = 0
st = 1
if S[0] == '>':
    st = S.index('<')
    res += st*(st+1)//2
ed = 0
a = 0
b = 0
for i in range(st, N-1):
    if S[i-1] == '>' and S[i] == '<':
        if i != st:
            res += max([a+1,b]) + a*(a+1)//2 + b*(b-1)//2
        if i==N-2:
            ed = -2
            break
        a = 0
        b = 0
        ed = i
    elif i==N-2 and S[i] == '>':
        res += max([a+1,b+1]) + a*(a+1)//2 + b*(b+1)//2
        ed = i
    elif S[i] == '<':
        a += 1
    elif S[i] == '>':
        b += 1
if ed == -2:
    res += 1
elif ed != N-2:
    res += (N-1-ed)*(N-ed)//2
print(res)

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

import re
S=input()
T = re.findall('<+|>+', S)
N=[len(i) for i in T]
sum_=0
A=[]
B=[]
if '<' in T[0]:
    A.append(0)
    B.append(len(T[0]))
    
for i,s in enumerate(T):
    if '>' in s:
        if i+1 < len(T):
            
            A.append(len(T[i]))
            B.append(len(T[i+1]))
if '>' in T[-1]:
    
    A.append(len(T[-1]))
    B.append(0)
sum_=0
for i in range(len(A)-1):
    if B[i] < A[i+1]:
        sum_ += f(A[i+1])
        sum_ += f(B[i]-1)
    else:
        sum_ += f(B[i])
        sum_ += f(A[i+1]-1)
sum_ += f(A[0])
sum_ += f(B[-1])
print(sum_)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
left = 0
right = 0
for i in range(len(S)):
  if S[i] == ">":
    left += 1
  else:
    break
for i in range(len(S)):
  if S[len(S)-i-1] == "<":
    right += 1
  else:
    break



if right != 0:
  S = S[left:-right]
else:
  S = S[left:]

ruiseki = [0] * len(S)
r, l = 0, 0










left_box = []
right_box = []

count = 0
for i in range(len(S)):
  if S[i] == "<":
    count += 1
  else:
    if count != 0:
      left_box.append(count)
    count = 0
if count != 0:
  left_box.append(count)
      


for i in range(len(S)):
  if S[i] == ">":
    count += 1
  else:
    if count != 0:
      right_box.append(count)
    count = 0
if count != 0:
  right_box.append(count)



  
m = []
for i in range(len(right_box)):
  r = right_box[i]
  l = left_box[i]
  m.append(max(r, l))

count = 0

for i in range(len(m)):
  for j in range(1, m[i]+1):
    count += j



ans = 0

def wa(num):
  wa = 0
  for i in range(1,num+1):
    wa += i
  return wa

def small_wa(num):
  wa = 0
  for i in range(0, num):
    wa += i
  return wa

for i in range(len(right_box)):
  r = right_box[i]
  l = left_box[i]
  b = max(r, l)
  s = min(r, l)
  a = small_wa(s) + wa(b)
  ans += a
  



ans += wa(left) + wa(right)
print(ans)

Solution (Python):
s=input()
n=len(s)+1
ans=[-1 for i in range(n)]
st=False
for i in range(1,n):
    if s[i-1]=="<":
        if st:
            st=False
            ans[i-1]=0
    else:
        st=True
if s[0]=="<":
    ans[0]=0
else:
    d=0
    for i in range(1,n):
        if s[i-1]==">":
            d+=1
        else:
            break
    ans[0]=d

co=0
for i in range(n-1,0,-1):
    if s[i-1]==">":
        ans[i]=co
        co+=1
    else:
        if co>0:
            ans[i]=co
        co=0

for i in range(1,n):
    if s[i-1]=="<" and ans[i]==-1:
        ans[i]=ans[i-1]+1
    elif s[i-1]=="<" and ans[i]!=-1:
        ans[i]=max(ans[i],ans[i-1]+1)
print(sum(ans))

Solution (Python):

s = input()
n = len(s)+1
a = [[] for i in range(n)]
ch = [[] for i in range(n)]
b = [0 for i in range(n)]
for i in range(len(s)):
    if s[i]==">":
        a[i+1].append(i) 
        ch[i].append(i+1)    
    else:
        a[i].append(i+1)
        ch[i+1].append(i)
st = []


for i in range(n):
    if ch[i]==[]:
        st.append(i)

for vertex in st:
    q = [vertex]
    ct = 0
    while(q):
        curr = q.pop()
        for nb in a[curr]:
            b[nb] = max(b[nb], b[curr]+1)
            q.append(nb)
print(sum(b))

Solution (Python):
def f_a():
    s = input()
    c, l, ans = 0, [], 0
    for i in range(1, len(s)):
        c += 1
        if s[i-1]!=s[i]:
            l.append(c); c = 0
    l.append(c+1)

    if s[-1]=="<":
        ans += sum(range(l[-1]+1))
        l.pop()

    while len(l)>1:
        a, b = l[-1], l[-2]
        ans += sum(range(a)) + sum(range(b))
        ans += max(a, b)
        l.pop(); l.pop()

    if len(l)>0:
        ans += sum(range(l[-1]+1))

    print(ans)


if __name__ == "__main__":
    f_a()

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

a = [0]*N
for i in range(N-1):
    if(s[i] == "<"):
        a[i+1] = a[i]+1

for j in range(N-2,-1,-1):
    if(s[j] == ">"):
        if(a[j] <= a[j+1]):
            a[j] = a[j+1]+1

print(sum(a))

Solution (Python):

import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

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

    s = 0
    x = 0
    while x != n-1:
        if S[x] == ">":
            x+= 1
        else:
            break
    s += x*(x+1)//2

    if x == n-1:
        print(s)
        exit()


    a = 0
    b = 0
    f = 0
    for i in range(x, n-1):
        if S[i] == ">":
            f = 1
            b += 1
        elif f == 0:
            a += 1
        else:
            if a == b:
                s += a*a
            elif a > b:
                s += a*(a+1)//2 + b*(b-1)//2
            else:
                s += a*(a-1)//2 + b*(b+1)//2
            f = 0
            a = 1
            b = 0



    if S[n-2] == ">":
        if a == b:
            s += a*a
        elif a > b:
            s += a*(a+1)//2 + b*(b-1)//2
        else:
            s += a*(a-1)//2 + b*(b+1)//2
    else:
        s += a*(a+1)//2




    print(s)





if __name__ == '__main__':
    main()

Solution (Python):
s = input()
n = len(s)
list0 = list()
list2 = list()
ans = 0
for i in range(n-1):
    if s[i:i+2] == '><':
        list0.append(i+1)
    elif s[i:i+2] == '<>':
        list2.append(i+1)

if s[0] == '<':
    list0.insert(0, 0)
else:
    if len(list0):
        p1 = list0[0]
    else:
        p1 = n
    ans += 1/2 * p1 * (p1 + 1)



if s[-1] == '>':
    list0.append(n)
else:
    if len(list0):
        p1 = n - list0[-1]
    else:
        p1 = n
    ans += 1/2 * p1 * (p1 + 1)

for i in range(len(list2)):
    p1 = max(list2[i] - list0[i], list0[i+1] - list2[i])
    p2 = min(list2[i] - list0[i], list0[i+1] - list2[i])
    ans += 1/2 * p1 * (p1 + 1) + 1/2 * p2 * (p2 - 1)

print(int(ans))