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 sys

S = input()

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

for i in range(len(S)):
    if S[i] == '<':
        a[i+1] = max(a[i+1], a[i]+1)

for i in range(len(S)):
    if S[-i-1] == '>':
        a[-i-2] = max(a[-i-1]+1, a[-i-2])

count = 0
for i in a:
    count += i
print(count)

Solution (Python):


def main():
    S = list(input())
    N = len(S)
    A = [0] * (N + 1)
    ans = 0

    for i in range(N):
        if S[i] == '<':
            A[i + 1] = A[i] + 1
    for i in range(N - 1, -1, -1):
        if S[i] == '>':
            if A[i] <= A[i + 1]:
                A[i] = A[i + 1] + 1

    ans = sum(A)

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
import itertools

import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


S = input()
S = S.replace('><', '>,<').split(',')
ans = 0
for w in S:
    a = w.count('<')
    b = w.count('>')
    mx = max(a, b)
    mn = min(a, b)
    ans += mx * (mx + 1) // 2 + (mn - 1) * mn // 2
print(ans)

Solution (Python):

s = str(input())
l = []
t = 0
for i in range(1,len(s)):
    if s[i] != s[i-1]:
        l.append(s[t:i])
        t = i
else:
    l.append(s[t:len(s)])


def calc(n):
    tmp = 0
    for i in range(1,n+1):
        tmp += i
    return tmp

left = 0
right = 0
ans = 0

for i,sg in enumerate(l):
    if sg[0]=='>':
        if left < len(sg):
            ans -= left
            ans += calc(len(sg))
        else:
            ans += calc(len(sg)-1)
    else:
        ans += calc(len(sg))
        left = len(sg)

print(ans)

Solution (Python):
S = input()
f = 0
x = 0
y = 0
Y = []
for i in range(len(S)):
  if S[i] == ">":
    if f == 1:
      y += 1
    elif f == 0:
      x = y
      y = 1
      f = 1
  else:
    if f == 0:
      y += 1
    else:
      Y.append([x, y])
      x = 0
      y = 1
      f = 0
if f == 0:
  Y.append([y, 0])
else:
  Y.append([x, y])
      
ans = 0
for y in Y:
  M = max(y)
  m = min(y)
  ans += (M * (M+1) // 2 + m * (m-1) // 2)
print(ans)

Solution (Python):
s=input()
l=[]
i=0
while i<len(s):
  k=0
  while s[i]=='<' if i<len(s) else False:
    k+=1
    i+=1
  if k>0:
    l.append(k)
  k=0
  while s[i]=='>' if i<len(s) else False:
    k+=1
    i+=1
  if k>0:
    l.append(k)
sm=0
for i in l:
  sm+=(i*(i+1))//2
for i in range(0 if s[0]=='<' else 1,len(l)-1,2):
  sm-=min(l[i],l[i+1])
 
  
print(sm)

Solution (Python):



ans = 0
S = input().replace('><', '>,<').split(',')
for s in S:
    n = s.count('<')
    m = s.count('>')
    ans += (n*(n-1))//2 + (m*(m-1))//2 + max(n, m)

print(ans)

Solution (Python):
S = input()
N = len(S)
ans = [0] * (N + 1)
for i in range(N):
    if S[i] == "<":
        ans[i + 1] = ans[i] + 1
for i in range(N - 1, -1, -1):
    if S[i] == ">":
        if ans[i] <= ans[i + 1]:
            ans[i] = ans[i + 1] + 1
print(sum(ans))

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

n = len(s)

L = [0]*(n+1)
cnt = 0
for i in range(n):
    if s[i] == '<':
        cnt += 1
    else:
        cnt = 0
    L[i+1] = cnt


R = [0]*(n+1)
cnt = 0
for i in reversed(range(n)):
    if s[i] == '>':
        cnt += 1
    else:
        cnt = 0
    R[i] = cnt

A = [0]*(n+1)
for i in range(n+1):
    A[i] = max(L[i], R[i])
print(sum(A))

Solution (Python):



from math import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq














import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7


INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
S = input()
n = len(S)
lis = [0] * (len(S)+1)
for i in range(n):
    if S[i] == '<':
        lis[i+1] = max(lis[i+1],lis[i] + 1)
for i in range(n-1,-1,-1):
    if S[i] == '>':
        lis[i] = max(lis[i], lis[i+1]+1)
print(sum(lis))

Solution (Python):
S = list(input().replace("><", ">,<").split(","))
ans = 0
for s in S:
    n = s.count("<")
    m = s.count(">")
    ans += (n * (n - 1)) // 2 + (m * (m - 1)) // 2 + max(n, m)
print(ans)

Solution (Python):
def input_int():
    return(int(input()))

def input_int_list():
    return(list(map(int,input().split())))

def input_int_map():
    return(map(int,input().split()))

def run():
    S = list(input())

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

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

    for i in range(len(S)):
        if S[i] == '<':
            left[i + 1] += 1 + left[i]

    for i in range(len(S) - 1, -1, -1):
        if S[i] == '>':
            right[i] = right[i + 1] + 1

    ans = [0] * (len(S) + 1)
    for i in range(len(S) + 1):
        ans[i] = max(left[i], right[i])
    print(sum(ans))

run()

Solution (Python):
S = input().replace("><", ">,<").split(",")
ans = 0
for s in S:
    n = s.count("<")
    m = s.count(">")
    ans += (n * (n - 1)) // 2 + (m * (m - 1)) // 2 + max(n, m)
print(ans)

Solution (Python):
S = input()
ans = 0
S = S.replace("><", ">,<").split(",")
for s in S:
  a = s.count(">")
  b = s.count("<")
  ans += a * (a - 1) // 2 + b * (b - 1) // 2 + max(a, b)
print(ans)

Solution (Python):
S = input().strip()
N = len(S)+1
A = [0 for _ in range(N)]
flag = -1
B = []
for i in range(N-1):
    if flag==-1 and S[i]=="<":
        B.append(i)
        flag = 1
    elif flag==1 and S[i]==">":
        flag = -1
if flag==-1:
    B.append(N-1)
for b in B:
    for i in range(b,N-1):
        if S[i]=="<":
            A[i+1] = max(A[i+1],A[i]+1)
        else:break
    for i in range(b-1,-1,-1):
        if S[i]==">":
            A[i] = max(A[i],A[i+1]+1)
        else:break
print(sum(A))

Solution (Python):
s = input()
N = len(s)+1
res = []
ans = 0
i = 0
while i < N-1:
    seq = 1
    while i < N - 2 and s[i] == s[i + 1]:
        i += 1
        seq += 1
    res.append(seq)
    i += 1

if s[0] == '>':
    ans += res[0] * (res[0] + 1) // 2
    res = res[1:]
if s[-1] == '<':
    ans += res[-1] * (res[-1]+1)//2
    res = res[:-1]

for i in range(len(res) // 2):
    tmp = max(res[2 * i], res[2 * i + 1])
    tmp2 = min(res[2 * i], res[2 * i + 1])
    ans += tmp * (tmp + 1) // 2
    ans += tmp2 * (tmp2-1) //2
print(ans)

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

for i in range(len(s)):
    if s[i] == '<':
        al[i+1] = max(al[i]+1, al[i+1])

for i in range(len(s)-1, -1, -1):
    if s[i] == '>':
        al[i] = max(al[i+1]+1, al[i])

print(sum(al))

Solution (Python):
S = input().replace("><", "> <").split()
ans = 0
for s in S:
    up = s.count("<")
    down = len(s) - up
    if up < down: 
        up -= 1
        ans += up * (up+1) // 2 + down * (down+1) // 2
    else:
        down -= 1
        ans += up * (up+1) // 2 + down * (down+1) // 2
print(ans)

Solution (Python):
s = input()

def addAll(end):
  return (end * (end + 1)) // 2

total = 0
index = 0

while len(s) > index:
  leftCount = 0
  rightCount = 0
  while len(s) > index and s[index] == "<":
    leftCount += 1
    index += 1
  while len(s) > index and s[index] == ">":
    rightCount += 1
    index += 1
  maxCount = max(leftCount, rightCount)
  minCount = min(leftCount, rightCount)
  total += addAll(maxCount) + addAll(max(minCount - 1, 0))

print(total)

Solution (Python):
s = input()

l = [0]
for c in s:
    if c == "<":
        l.append(l[-1]+1)
    else:
        l.append(0)

r = [0]
for c in s[::-1]:
    if c == ">":
        r.append(r[-1]+1)
    else:
        r.append(0)

ans = 0
for a, b in zip(l, r[::-1]):
    ans += max(a, b)
print(ans)

Solution (Python):
s = input()
a = [0] * (len(s) + 1)
for i in range(len(s)):
    if s[i] == '<':
        a[i+1] = a[i] + 1
    
for i in range(len(s))[::-1]:
    if s[i] == '>':
        a[i] = max(a[i+1] + 1,a[i])
print(sum(a))

Solution (Python):
def renketu(base,a,b):
    if base == 1:
        b.reverse()
    max_ = max(a[-1],b[0])
    a.pop(-1)
    b[0] = max_
    a.extend(b)
    return a,b
    
s = [*input()]
if len(s) == 1:
    print(1)
    exit()
hugo = ["<", ">"]
a = [0]
b = []
base = -1
for i in range(len(s) - 1):
    if base == -1: 
        base = hugo.index(s[i])
        b = [0,1]
    elif base != hugo.index(s[i]): 
        
        a,b = renketu(base,a,b)
        
        b = [0,1]
        base = hugo.index(s[i])
    else: 
        b.append(b[-1] + 1) 
if hugo.index(s[-1]) == base: 
    b.append(b[-1] + 1)
    a,b = renketu(base,a,b)
else:
    
    a,b = renketu(base,a,b)
    
    if hugo.index(s[-1]) == 1:
        b = [1,0]
    else:
        b = [0,1]
    max_ = max(a[-1],b[0])
    b[0] = max_
    a.pop(-1)
    a.extend(b)
    
print(sum(a))

Solution (Python):
s = [*input()]
if len(s) == 1:
    print(1)
    exit()
hugo = ["<", ">"]
a = [0]
b = []
base = -1
for i in range(len(s) - 1):
    if base == -1: 
        base = hugo.index(s[i])
        b = [0,1]
    elif base != hugo.index(s[i]): 
        
        if base == 1:
            b.reverse()
        max_ = max(a[-1],b[0])
        a.pop(-1)
        b[0] = max_
        a.extend(b)
        
        b = [0,1]
        base = hugo.index(s[i])
    else: 
        b.append(b[-1] + 1) 
if hugo.index(s[-1]) == base: 
    b.append(b[-1] + 1)
    if base == 1:
        b.reverse()
    max_ = max(a[-1],b[0])
    b[0] = max_
    a.pop(-1)
    a.extend(b)    
else:
    
    if base == 1:
        b.reverse()
    max_ = max(a[-1],b[0])
    b[0] = max_
    a.pop(-1)
    a.extend(b)
    
    
    if hugo.index(s[-1]) == 1:
        b = [1,0]
    else:
        b = [0,1]
    max_ = max(a[-1],b[0])
    b[0] = max_
    a.pop(-1)
    a.extend(b)
    
print(sum(a))

Solution (Python):
S = list(input())
before = 0
last_upper = -1
count = 0
answer = 0
for i, s in enumerate(S):
  
  if s == '<':
    if before < 0 and last_upper < i-1:
      answer += abs(before)*(i-last_upper)
      before = 0
    elif before > 0 and last_upper < i-1:
      answer -= before*(i-last_upper-1)
      before = 0
    before += 1
    answer += before
    last_upper = i
  else:
    before -= 1
    answer += before

if before < 0:
  answer += abs(before)*(len(S)-last_upper)
elif before > 0:
  answer -= before*(len(S)-last_upper-1)
print(answer)

Solution (Python):
s = input()
n = len(s) 
aa = ['.'] * (n + 1)

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

for i in range(n-1):
  if s[i] ==  '>' and s[i+1] == '<':
    aa[i+1] = 0 
  elif s[i] == '<' and s[i+1] == '>':
    aa[i+1] = n
    
z = [i for i,x in enumerate(aa) if x == 0]
m = [i for i, x in enumerate(aa) if x == n]


for i in range(len(z)-1):
  aa[m[i]] = max(m[i]-z[i], z[i+1]-m[i])
  aa[m[i]+1] = z[i+1]-m[i]-1
  for j in range(z[i]+1, m[i]):
    aa[j] = aa[j-1] +1
  for k in range(m[i]+2,z[i+1]):
    
    aa[k] = aa[k-1]-1
for i in range(z[-1], n+1):
  if aa[i] == '.':
    aa[i] = aa[i-1]+1
for i in range(z[0]):
  if aa[i] == '.':
    aa[i] = z[0] - i
    

print(sum(aa))

Solution (Python):
s = input()
n = len(s) 
aa = ['.'] * (n + 1)

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

for i in range(n-1):
  if s[i] ==  '>' and s[i+1] == '<':
    aa[i+1] = 0 
  elif s[i] == '<' and s[i+1] == '>':
    aa[i+1] = n
    
z = [i for i,x in enumerate(aa) if x == 0]
m = [i for i, x in enumerate(aa) if x == n]


for i in range(len(z)-1):
  aa[m[i]] = max(m[i]-z[i], z[i+1]-m[i])
  aa[m[i]+1] = z[i+1]-m[i]-1
  for j in range(z[i]+1, m[i]):
    aa[j] = aa[j-1] +1
  for k in range(m[i]+2,z[i+1]):
    
    aa[k] = aa[k-1]-1
for i in range(z[-1], n+1):
  if aa[i] == '.':
    aa[i] = aa[i-1]+1
for i in range(z[0]):
  if aa[i] == '.':
    aa[i] = z[0] - i
    

print(sum(aa))

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

ans = [[0, 0] for _ in range(n)]

for i in range(1, n):
    if s[i-1] == '<':
        ans[i][0] = ans[i-1][0] + 1

for i in range(0, n-1):
    if s[n-2-i] == '>':
        ans[n-2-i][1] = ans[n-1-i][1] + 1
print(sum(max(i) for i in ans))

Solution (Python):
S = input()

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

for i in range(len(S)):
    if S[i] == "<":
        ans[i+1] = max(ans[i+1], ans[i]+1)
    
for i in range(len(S)):
    i = len(S)-1 - i
    if S[i] == ">":
        ans[i] = max(ans[i],ans[i+1]+1)

print(sum(ans))

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

s = list(map(lambda x : 1 if x == '<' else -1, input()))
l = [s[0]]
for c in s[1:]:
    if c * l[-1] > 0:
        l[-1] += c
    else:
        l.append(c)
ans = 0
now = 0
for c in l:
    if c < 0:
        ans -= min(now, abs(c))
    ans += sigma(abs(c))
    now = abs(c)
print(ans)

Solution (Python):

S = input()
ans = [0] * (len(S)+1)
for i in range(len(S)):
  if S[i] == "<":
    ans[i+1] = max(ans[i+1],ans[i]+1)
  
for i in range(len(S)-1,-1,-1):
  if S[i] == ">":
    ans[i] = max(ans[i],ans[i+1]+1)

print(sum(ans))

Solution (Python):
s=input()
a=[0]*(len(s)+1)
for i in range(len(s)):
    if s[i]=="<":
        a[i+1]=a[i]+1
for i in range(len(s)-1,-1,-1):
    if s[i]==">":
        a[i]=max(a[i],a[i+1]+1)
print(sum(a))

Solution (Python):
s = input()
l = [0]*(len(s)+1)
for i in range(len(s)):
    if s[i] == "<":
        l[i+1] = l[i]+1
for i in range(len(s)-1, -1, -1):
    if s[i] == ">":
        l[i] = max(l[i], l[i+1]+1)
print(sum(l))

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

for i in range(len(s)):
    if s[i] == '<':
        a[i+1] = max(a[i+1], a[i]+1)

for i in range(len(s)-1, -1, -1):
    if s[i] == '>':
        a[i] = max(a[i], a[i+1]+1)

print(sum(a))

Solution (Python):
s=input()+"<"; n=len(s)

bef=-1 ;ans=0 ;i=0
while i<n:
    
    if s[i]=="<":
        ans+=bef+1
        bef+=1
        i+=1
    else:
        cnt=0
        for j in range(i,n):
            if s[j]==">":
                ans+=cnt
                cnt+=1
            else:
                ans+=cnt
                break
        ans+= max(0, bef+1-cnt)
        bef=0
        i+= cnt +1
print(ans)

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

S=tuple(input().strip())
N=len(S)+1
sets = []
count = 0

for c in S:
    d = 1 if c == '<' else -1
    if count * d < 0:
        sets.append(count)
        count = d
    else:
        count += d
sets.append(count)

sum = 0
for i in range(len(sets)):
    k=sets[i]
    if k > 0:
        sum += (k*(k+1))//2
    else:
        sum += (k*(k-1))//2
        if i > 0:
            sum -= min(sets[i-1], -k)

print(sum)

Solution (Python):
s = input()
n = len(s)
L=[0]
R=[0]
cnt = 0

for i in range(n):
    if s[i] == '<':
        cnt += 1
    else:
        cnt = 0
    L.append(cnt)
cnt = 0
s = s[::-1]
for i in range(n):
    if s[i]  == '>':
        cnt += 1
    else:
        cnt = 0
    R.append(cnt)

R = R[::-1]
ans = 0
for i in range(n+1):
    ans += max(R[i], L[i])

print(ans)

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

l=[0 for i in range(sl+1)]
for i in range(sl):
    if s[i]=='<':
        l[i+1]=max(l[i]+1, l[i+1])

for i in reversed(range(sl)): 
    if s[i]=='>':
        l[i]=max(l[i+1]+1, l[i])

print(sum(l))

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

l=[0 for i in range(sl+1)]
for i in range(sl):
    if s[i]=='<':
        l[i+1]=max(l[i]+1, l[i+1])

for i in range(sl-1,-1,-1): 
    if s[i]=='>':
        l[i]=max(l[i+1]+1, l[i])

print(sum(l))

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    s = S()
    
    llst = [0 for _ in range(len(s)+2)]
    rlst = [0 for _ in range(len(s)+2)]

    for i in range(1, len(s)+1):
        if s[i-1] == "<":
            llst[i] = llst[i-1] + 1
    
    for i in range(len(s)-1, -1, -1):
        if s[i] == ">":
            rlst[i] = rlst[i+1] + 1
    
    ans = 0

    for i in range(len(s)+1):
        ans += max(llst[i], rlst[i])

    print(ans)

main()

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    s = S()
    s = s.split("><")
    ans_lst = []

    for part in s:
        lnum = part.count("<")
        rnum = part.count(">")      
        ans_lst.append(lnum*(lnum+1)//2 + rnum*(rnum+1)//2 + max(lnum,rnum)+1)


    if len(s) == 1:
        lnum = s[0].count("<") -1
        rnum = s[0].count(">") -1
        ans_lst[0] = lnum*(lnum+1)//2 + rnum*(rnum+1)//2 + max(lnum,rnum)+1
    else:
        lnum = s[0].count("<") -1
        rnum = s[0].count(">")
        ans_lst[0] = lnum*(lnum+1)//2 + rnum*(rnum+1)//2 + max(lnum,rnum)+1

        lnum = s[-1].count("<")
        rnum = s[-1].count(">") -1
        ans_lst[-1] = lnum*(lnum+1)//2 + rnum*(rnum+1)//2 + max(lnum,rnum)+1

    ans = sum(ans_lst)
    print(ans)

main()

Solution (Python):
import sys
import copy
import math
import itertools
import numpy as np
S=input()
N = len(S)+1
a = [0]*N
b = [0]*N
for i in range(N-1):
    if S[i]=="<":
        a[i+1]=a[i]+1

for i in reversed(range(N-1)):
    if S[i]==">":
        b[i]=b[i+1]+1

for i in range(N):
    if a[i] < b[i]:
        a[i]=b[i]

print(sum(a))

Solution (Python):
s=input()
 
sl=len(s)+1
l=[0]*sl
 
for i in range(sl-1):
  if s[i]=="<":
    l[i+1]=l[i]+1
    
for i in range(sl-2,-1,-1):
  if s[i]==">":
    l[i]=max(l[i+1]+1, l[i])
    
print(sum(l))

Solution (Python):
s = input()

a = [0] * (len(s) + 1)

for i in range(len(s)):
    if s[i] == '<':
        a[i+1] = max(a[i+1], a[i] + 1)
for i in range(len(s)-1, -1, -1):
    if s[i] == '>':
        a[i] = max(a[i], a[i+1] + 1)

print(sum(a))

Solution (Python):
from itertools import*;r=p=0
for k,g in groupby(input()):x=len(list(g));r=r+x*(x+1)//2-min(x,p)*(k=='>');p=x
print(r)

Solution (Python):



S = input()
ret = 0


i = 0
while i < len(S) and S[i] == ">":
    i += 1
    ret += i


n_up = 0
n_down = 0
while i < len(S):
    n_up = 0
    n_down = 0
    while i < len(S) and S[i] == "<":
        n_up += 1
        i += 1
        if i >= len(S):
            break
    while i < len(S) and S[i] == ">":
        n_down += 1
        i += 1
        if i >= len(S):
            break
    if n_up < n_down:
        n_up, n_down = n_down, n_up

    ret += ((n_up+1) * n_up) // 2
    ret += (n_down * (n_down-1)) // 2
    
print(ret)

Solution (Python):
s = input()
n = len(s)
L=[0]
R=[0]
cnt = 0

for i in range(n):
    if s[i] == '<':
        cnt += 1
    else:
        cnt = 0
    L.append(cnt)
cnt = 0
s = s[::-1]
for i in range(n):
    if s[i]  == '>':
        cnt += 1
    else:
        cnt = 0
    R.append(cnt)

R = R[::-1]
ans = 0
for i in range(n+1):
    ans += max(R[i], L[i])

print(ans)

Solution (Python):
s = input()

up = 0
down = 0
prev_x = ''
up_cnt = 0
down_cnt = 0
ans = 0

for i in range(len(s)):
    if (prev_x =='<'or prev_x ==''):
        if s[i] == '<':
            up_cnt += 1
        else: 
            up = up_cnt
            up_cnt = 0
            down_cnt =+1
            
    else: 
        if s[i] == '>':
            down_cnt += 1
        else: 
            down = down_cnt
            down_cnt =0
            up_cnt += 1
            if up == 0:
                ans += (down*(down+1))/2
            else:
                if up > down:
                    ans += (up*(up+1))/2 + (down*(down-1))/2
                else:
                    ans += (up*(up-1))/2 + (down*(down+1))/2
    prev_x = s[i]

if up_cnt > 0 and down_cnt == 0:
    ans += (up_cnt*(up_cnt+1))/2
elif down_cnt > 0 and up_cnt == 0:
    if up > down_cnt:
        ans += (up*(up+1))/2 + (down_cnt*(down_cnt-1))/2
    else:
        ans += (up*(up-1))/2 + (down_cnt*(down_cnt+1))/2

print(int(ans))

Solution (Python):
S = input()

N = len(S)
num = 0
L = [0]
R = [0]
cnt = 0

for i in range(N):
    if S[i] == "<":
        cnt += 1
    else:
        cnt = 0
    L.append(cnt)

ans = 0
S = S[::-1]
cnt = 0

for i in range(N):
    if S[i] == ">":
        cnt += 1
    else:
        cnt = 0
    R.append(cnt)

R = R[::-1]

for i in range(N+1):
    ans += max(L[i], R[i])

print(ans)

Solution (Python):
def resolve():
    S = list(input())
    ans = [0 for _ in range(len(S) + 1)]
    cnt = 0
    for i in range(len(S)):
        if S[i] == "<":
            cnt += 1
            ans[i + 1] = max(cnt, ans[i + 1])
        else:
            cnt = 0
    cnt = 0
    for i in range(len(S), 0, -1):
        if S[i - 1] == ">":
            cnt += 1
            ans[i - 1] = max(cnt, ans[i - 1])
        else:
            cnt = 0
    print(sum(ans))


resolve()

Solution (Python):
import sys
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush

sys.setrecursionlimit(10**6)
INF = 10**20

def mint():
    return map(int,input().split())
def lint():
    return map(int,input().split())
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])

S = input()
N = len(S)+1
L = [0]*N
R = [0]*N
for i in range(N-1):
    L[i+1] = L[i]+1 if S[i]=='<' else 0
for i in range(N-2,-1,-1):
    R[i] = R[i+1]+1 if S[i]=='>' else 0
ans = [max(l,r) for l,r in zip(L,R)]
print(sum(ans))

Solution (Python):
S=input()

A=[0]*(len(S)+1)
for i in range(len(S)):
    if S[i]=='<':
        A[i+1]=max(A[i+1],A[i]+1)
    
for i in range(len(S)-1,-1,-1):
    if S[i]=='>':
        A[i]=max(A[i],A[i+1]+1)

print(sum(A))

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 memo == ">":
            if before_cnt < cnt:
                ans -= before_cnt
            else:
                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()

sl=len(s)+1
l=[0]*sl

for i in range(sl-1):
  if s[i]=="<":
    l[i+1]=l[i]+1
    
for i in range(sl-2,-1,-1):
  if s[i]==">":
    l[i]=max(l[i+1]+1, l[i])
    
print(sum(l))

Solution (Python):
S = list(input())
 
left = [0]*(len(S)+1)
 
right = [0]*(len(S)+1)
 
for i in range(len(S)):
    if S[i] == '<':
        left[i+1] += 1+left[i]
 
for i in range(len(S)-1,-1,-1):
    if S[i] == '>':
        right[i] = right[i+1]+1
 
ans = [0]*(len(S)+1)
for i in range(len(S)+1):
    ans[i] = max(left[i],right[i])
print(sum(ans))

Solution (Python):
def main():
    S = input()
    N = len(S)+1
    a = [0]*(N)
    
    for i in range(N-1):
        if S[i] == '<':
            a[i+1] = max(a[i]+1,a[i+1])
    
    
    for i in range(N-2,-1,-1):
        
        if S[i] == '>':
            a[i] = max(a[i+1]+1,a[i])
    ans = 0
    
    for i in range(N):
        ans += a[i]
    return ans

print(main())

Solution (Python):
s = input()
ans = [0 for i in range(len(s)+1)]

for i in range(len(s)):
    if s[i] == '<':
        ans[i+1] = max(ans[i+1],ans[i]+1)
for i in range(len(s)-1,-1,-1):
    if s[i] == '>':
        ans[i] = max(ans[i],ans[i+1]+1)

print(sum(ans))

Solution (Python):
import itertools as it

S = input()
R = [(k,len(list(g))) for k,g in it.groupby(S)]


tot = 0
n = 0
for k,val in R:
  if k == "<":
    n = val
    tot += n*(n+1)/2
  elif k == ">":
    tot += max(0,val-n)
    tot += val*(val-1)/2
    n = 0
  
print(int(tot))

Solution (Python):
S = input()
ans = [0]*(len(S)+1)

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

for i in range(len(S)-1, -1, -1):
    if S[i] == ">":
        ans[i] = max(ans[i], ans[i+1]+1)
print(sum(ans))

Solution (Python):
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  


S = LS2()
N = len(S)+1

ANS = [0]*N
for i in range(N-1):
    if S[i] == '<':
        ANS[i+1] = ANS[i]+1

for i in range(N-2,-1,-1):
    if S[i] == '>':
        ANS[i] = max(ANS[i],ANS[i+1]+1)

print(sum(ANS))

Solution (Python):
S = input()
L = len(S)
if S[0] == ">":
    S = "<"+S
else:
    S = ">"+S
if S[L] == ">":
    S = S+"<"
else:
    S = S+">"
count = 0
ans = 0
kari = 0
for i in range(L+1):
    if S[i] == "<" and S[i+1] == ">":
        kari = count
        count = 1
    elif S[i] == ">" and S[i+1] == "<":
        ans += max(kari, count)
        count = 1
    else:
        ans += count
        count += 1

if S[L] == "<" and S[L+1] == ">":
    ans += kari
print(ans)

Solution (Python):
S = input()
ans = [0] * (len(S) + 1)
for i in range(len(S)):
    if S[i] == '<':
        ans[i + 1] = ans[i] + 1
for i in range(len(S) - 1, -1, -1):
    if S[i] == '>':
        ans[i] = max(ans[i], ans[i + 1] + 1)
print(sum(ans))

Solution (Python):
def main():
    examA()

def examA():
    S = SI()
    S = ">" + S + "<"
    N = len(S)
    A = [0]*(N)
    i = 0
    while(i<N-1):
        r = i + 1
        if S[i]==">" and S[i+1]=="<":
            A[i+1] = 0
            l = i-1
            cur = 0
            while(0<=l):
                cur += 1
                A[l] = max(A[l], cur)
                l -= 1
                if S[l+1]=="<":
                    
                    break
            r = i+1
            cur = 0
            while(r<N):
                cur += 1
                A[r] = max(A[r], cur)
                r += 1
                if r==N or S[r]==">":
                    break
        
        i = r
    
    A[-1] = 0
    ans = sum(A)
    print(ans)
    return

def examB():
    H, W = LI()
    A = [SI()for _ in range(H)]
    C = defaultdict(int)
    for a in A:
        for s in a:
            C[s] += 1
    B = sorted(C.items())
    
    flag_odd = not (H%2==1 and W%2==1)
    upper_2 = (H%2==1) * (W//2) + (W%2==1) * (H//2)
    for s,c in B:
        if c%2==1:
            if flag_odd:
                print("No")
                return
            flag_odd = True
        elif c%4==2:
            upper_2 -= 1
            if upper_2<0:
                print("No")
                return
    print("Yes")
    return

def examC():
    N, K = LI()
    P = LI()
    C = LI()

    if max(C)<0:
        print(max(C))
        return

    loop = [[0,0]for _ in range(N)]

    for i in range(N):
        checked = set()
        now = i
        score = 0
        while(now not in checked):
            checked.add(now)
            now = P[now]-1
            score += C[now]
        n = len(checked)
        for j in checked:
            loop[j] = [n,score]
    
    ans = 0
    for i in range(N):
        n,s = loop[i]
        score = 0
        if s>0:
            score += (K//n - 1) * s
        ans = max(ans,score)
        now = i
        for j in range(n + K%n):
            now = P[now] - 1
            score += C[now]
            ans = max(ans,score)

    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

def test():
    i = I()
    li = LI()
    lsi = LSI()
    si = LS()
    print(i)
    print(li)
    print(lsi)
    print(si)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,alphabet_convert,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 1<<31
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    main()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  


S = LS2()
N = len(S)+1

ANS = [0]*N
for i in range(N-1):
    if S[i] == '<':
        ANS[i+1] = ANS[i]+1

for i in range(N-2,-1,-1):
    if S[i] == '>':
        ANS[i] = max(ANS[i],ANS[i+1]+1)

print(sum(ANS))

Solution (Python):
s=input()
n=len(s)
ans=[0]*(n+1)
  
for i in range(0,n):
  if s[i]=='<':
    ans[i+1]=ans[i]+1
for i in range(n-1,-1,-1):
  if s[i]=='>':
    ans[i]=max(ans[i+1]+1,ans[i])
print(sum(ans))

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

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

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

for i in range(len(S)):
    if S[i] == '<':
        left[i+1] += 1+left[i]

for i in range(len(S)-1,-1,-1):
    if S[i] == '>':
        right[i] = right[i+1]+1

ans = [0]*(len(S)+1)
for i in range(len(S)+1):
    ans[i] = max(left[i],right[i])
print(sum(ans))

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

a = [0] * (n + 1)

for i in range(n):
    if s[i] == '<':
        a[i + 1] = max(a[i + 1], a[i] + 1)
for i in range(n - 1, -1, -1):
    if s[i] == '>':
        a[i] = max(a[i], a[i + 1] + 1)

print(sum(a))

Solution (Python):
s = input()
s += 'a'
cnts = []
prev = s[0]
cnt = 1
for i,si in enumerate(s[1:]):
    if prev == si:
        cnt += 1
    else:
        cnts.append(cnt)
        cnt = 1
    prev = si


ans = 0
c_num = 0
if s[0] == '<':
    for i,c in enumerate(cnts):
        if i%2 == 0:
            ans += c*(c-1)//2
            c_num = c-1
        else:
            ans += c*(c-1)//2
            ans += max(c,c_num+1)
    if s[-2] == '<':
        ans += cnts[-1]
        
    print(ans)

if s[0] == '>':
    ans = cnts[0]*(cnts[0]+1)//2
    for i,c in enumerate(cnts[1:]):
        if i%2 == 0:
            ans += c*(c-1)//2
            c_num = c-1
        else:
            ans += c*(c-1)//2
            ans += max(c,c_num+1)
        
    if s[-2] == '<':
        ans += cnts[-1]
    print(ans)