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=input()
N=[[0,0] for i in range(len(S)+1)]

for i in range(len(S)):
    if(S[i]=="<"):
        N[i+1][0]=N[i][0]+1
    
    if(S[-1-i]==">"):
        N[-2-i][1]=N[-1-i][1]+1
s=0
for i in range(len(N)):
    s+=max(N[i][0],N[i][1])
print(s)

Solution (Python):
import numpy as np

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

for i in reversed(range(n)):
    if s[i] == ">":
        ans[i] = max(ans[i+1]+1,ans[i])

print(sum(ans))

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

for i in reversed(range(n)):
    if s[i] == ">":
        ans[i] = max(ans[i+1]+1, ans[i])

print(sum(ans))

Solution (Python):
S=input()
import itertools
A=[]
for key,g in itertools.groupby(S):
  A.append([key,len(list(g))])
ans=0
open=True
cur=0
for i in range(len(A)):
  key=A[i][0]
  n=A[i][1]
  if (i==0 and key==">") or (i==len(A)-1 and key=="<"):
    ans+=n*(n+1)//2
  else:
    if open:
      cur=n
      open=False
    else:
      if n>cur:
        cur-=1
      else:
        n-=1
      ans+=cur*(cur+1)//2+n*(n+1)//2
      open=True
print(ans)

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

A = [0 for _ in range(N)]

for i, s in enumerate(S):
    if i + 1 < N and s == '<':
        A[i + 1] = max(A[i + 1], A[i] + 1)

for i, s in zip(range(N)[::-1], S[::-1]):
    if i - 1 >= 0 and s == '>':
        A[i - 1] = max(A[i - 1], A[i] + 1)

print(sum(A))

Solution (Python):
S=input()
N=len(S)+1
L=[0 for i in range(N)]
R=[0 for i in range(N)]
for i in range(1,N):
    if S[i-1]==">":
        L[i]=0
    else:
        L[i]=L[i-1]+1
for i in range(N-2,-1,-1):
    if S[i]=="<":
        R[i]=0
    else:
        R[i]=R[i+1]+1


X=[max(L[i],R[i]) for i in range(N)]
print(sum(X))

Solution (Python):
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(input()) 
def isn(): return input().split() 
def imn(): return map(int, input().split()) 
def iln(): return list(map(int, input().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

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

Solution (Python):
import math
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return math.gcd 
def lcm(a,b):return (a*b) // math.gcd(a,b) 
def iin(): return int(input()) 
def isn(): return input().split() 
def imn(): return map(int, input().split()) 
def iln(): return list(map(int, input().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

S=input()

l = len(S)
l_cnt = [0] * (l+1)
r_cnt = [0] * (l+1)
cnt = [0] * (l+1)
for i in range(l):
    if S[i] == '<':
        l_cnt[i+1] = l_cnt[i]+1
for i in range(l-1, -1, -1):
    if S[i] == '>':
        r_cnt[i] = r_cnt[i+1]+1
for i in range(l+1):
    cnt[i] = max(l_cnt[i], r_cnt[i])
print(sum(cnt))

Solution (Python):
S = input()
N = len(S)
A = [0] * (N + 1)
B = [0] * (N + 1)
for i in range(N):
    if S[i] == "<":
        A[i+1] = A[i] + 1
    else:
        A[i+1] = 0

for i in range(N-1, -1, -1):
    if S[i] == ">":
        B[i] = B[i+1] + 1
    else:
        B[i] = 0

print(sum([max(A[i], B[i]) for i in range(N + 1)]))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    s = S()
    l = len(s)
    if l == 2:
        if s == ">>" or s == "<<":
            return 3
        if s == "><":
            return 2
        return 1

    a = [-1] * (l+1)
    q = []
    v = [False] * (l+1)
    if s[0] == "<":
        q.append(0)
        v[0] = True
    if s[l-1] == ">":
        q.append(l)
        v[l] = True
    for i in range(1,l):
        if s[i-1:i+1] == "><":
            q.append(i)
            v[i] = True

    for qi in range(l+1):
        t = q[qi]
        if t == 0:
            a[t] = a[t+1] + 1
            if not v[t+1] and (v[t+2] or s[t+1] == "<"):
                q.append(t+1)
                v[t+1] = True
        elif t == l:
            a[t] = a[t-1] + 1
            if not v[t-1] and (v[t-2] or s[t-2] == ">"):
                q.append(t-1)
                v[t-1] = True
        else:
            a[t] = max(a[t+1], a[t-1]) + 1
            if not v[t+1] and (t == l-1 or v[t+2] or s[t+1] == "<"):
                q.append(t+1)
                v[t+1] = True
            if not v[t-1] and (t == 1 or v[t-2] or s[t-2] == ">"):
                q.append(t-1)
                v[t-1] = True

    
    
    
    
    
    return sum(a)


print(main())

Solution (Python):
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key


def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()

def main():
    S = rs()
    N = len(S)
    a = [0] * (N + 1)
    for i in range(N):
        if S[i] == '<':
            a[i + 1] = a[i] + 1
        else:
            a[i + 1] = a[i] - 1
    
    b = min(a)
    for i in range(N + 1): a[i] -= b
    l = []
    for i in range(N + 1):
        l.append((a[i],i))
    
    def cmp(_p, _q):
        if(_p[0] < _q[0]): return -1
        if(_p[0] > _q[0]): return 1
        return 0
    l = sorted(l, key=cmp_to_key(cmp))

    for dep, pos in l:
        if pos == 0:
            if S[pos] == '<':
                a[pos] = 0
            else:
                a[pos] = a[pos + 1] + 1
        elif pos == N:
            if S[pos - 1] == '>':
                a[pos] = 0
            else:
                a[pos] = a[pos - 1] + 1
        else:
            if S[pos - 1] == '<' and S[pos] == '<':
                a[pos] = a[pos - 1] + 1
            elif S[pos - 1] == '<' and S[pos] == '>':
                a[pos] = max(a[pos - 1], a[pos + 1]) + 1
            elif S[pos - 1] == '>' and S[pos] == '<':
                a[pos] = 0
            elif S[pos - 1] == '>' and S[pos] == '>':
                a[pos] = a[pos + 1] + 1
    
    print(sum(a))

if __name__ == "__main__":
    main()

Solution (Python):
def solve():
    S = input()
    lenS = len(S)
    sumS = 0
    N = [0] * (lenS + 1)
    zero = set()
    if S[0] == "<": zero |= {0}
    for i in range(lenS - 1):
        if S[i] == ">" and S[i+1] == "<": zero |= {i+1}
    if S[lenS-1] == ">": zero |= {lenS}

    for start in zero:
        pointer = start
        while pointer <= lenS - 1:
            if S[pointer] == "<":N[pointer + 1] = max(N[pointer] + 1, N[pointer + 1])
            else: break
            pointer += 1
        
        pointer = start - 1
        while pointer >= 0:
            if S[pointer] == ">": N[pointer] = max(N[pointer + 1] + 1, N[pointer])
            else: break
            pointer -= 1

    
    print(sum(N))

    return 0

if __name__ == "__main__": solve()

Solution (Python):
S = input().strip()
N = len(S)+1
A = [0 for _ in range(N)]
B = []
for i in range(N):
    if i==0 and S[i]=="<":
        B.append(0)
    elif i<N-2 and S[i]==">" and S[i+1]=="<":
        B.append(i+1)
    elif i==N-2 and S[i]==">":
        B.append(i+1)
for j in range(len(B)-1):
    ind0 = B[j]
    ind1 = B[j+1]
    c = ind0
    while S[c]=="<":
        A[c+1] = max(A[c+1],A[c]+1)
        c += 1
    c = ind1
    while S[c-1]==">":
        A[c-1] = max(A[c-1],A[c]+1)
        c -= 1
c = B[0]
if c>0:
    for i in range(c-1,-1,-1):
        A[i] = A[i+1]+1
c = B[-1]
if c<N-1:
    for i in range(c+1,N):
        A[i] = A[i-1]+1
print(sum(A))

Solution (Python):
s = input()
l = []
cnt = 0
flg = 0
for c in s:
    if (c == '<') ^ flg:
        cnt += 1
    else:
        l.append(cnt)
        flg ^= 1
        cnt = 1
l.append(cnt)
if len(l) % 2:
    l.append(0)
ans = 0
for i in range(len(l) // 2):
    x = l[i * 2]
    y = l[i * 2 + 1]
    ans += x * (x - 1) // 2 + y * (y - 1) // 2 + max(x, y)
print(ans)

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

Solution (Python):
s = input()
n = len(s)
forward = [0]*(n+1)
backward = [0]*(n+1)
for i in range(n):
    if s[i] == "<":
        forward[i+1] = forward[i] + 1

for i in range(n-1,-1,-1):
    if s[i] == ">":
        backward[i] = backward[i+1] + 1


ans = sum([max(x,y) for x,y in zip(forward,backward)])
print(ans)

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

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

Solution (Python):
s = input()
l = len(s)
A = [-1] * (l+1)

inf = float("inf")
tmp = ""
for i in range(l):
	if i == 0:
		if s[i] == ">":
			A[i] = inf
		else:
			A[i] = 0

		tmp = s[i]

	if s[i] == tmp:
		continue
	elif s[i] == ">" and tmp == "<":
		A[i] = inf
		tmp = ">"
	elif s[i] == "<" and tmp == ">":
		A[i] = 0
		tmp = "<"

if s[i] == ">":
	A[-1] = 0
else:
	A[-1] = inf

ans = 0
flg = 0
cnt = 0
pool = 0
for i in range(l+1):
	if A[i] == inf:
		flg = 1
		pool = cnt
		cnt = 0
		continue
	if A[i] == 0:
		if flg == 1:
			ans += max(pool, cnt) + 1
		flg = 0
		cnt = 0
		pool = 0
		continue
	
	cnt += 1
	ans += cnt

if flg == 1:
	ans += pool + 1


print(ans)

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

a=[0]*(N+1)
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] == '>':
        a[i]=max(a[i+1]+1,a[i])
print(sum(a))

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


def countConsecutive(s, ch):
    consecutive = [0] * N
    for i in range(1, N):
        if s[i - 1] == ch:
            consecutive[i] = consecutive[i - 1] + 1
    return consecutive



consecutiveLeft = countConsecutive(s, "<")

consecutiveRight = countConsecutive(s[::-1], ">")[::-1]


nums = [max(consecutiveLeft[i], consecutiveRight[i]) for i in range(N)]

print(sum(nums))

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

x=[0]*N
y=0

for i in range(N-1):
  if S[i]=="<":
    x[i+1]=x[i]+1
for j in range(N-1):
  i=N-2-j
  if S[i]==">":
    x[i]=max([x[i],x[i+1]+1])
print(sum(x))

Solution (Python):
s=input()
l=len(s)
c=0
m=0
s1=0
cc=0
k=0
for i in range(l):
    if s[i]=="<":
        c+=1
        s1+=c
        k=0
        cc=0
        m=0
    elif c==0:
        k-=1
        if k<0 and m==0:
            s1+=cc-k
            m=1
            cc+=1
        else:
            s1+=cc
        cc+=1
    else:
        k=c-1
        c=0
        cc+=1
print(s1)

Solution (Python):
L = input()
L = list(L.split('><'))
if len(L) == 1:
    a = [L[0].count('<'),L[0].count('>')]
    a_max = max(a)
    ans = a_max*(a_max+1)/2
else:
    ans = 0
    for i in range(len(L)):
        if i == 0:
            a = [L[i].count('<'),L[i].count('>')+1]
        elif i == len(L)-1:
            a = [L[i].count('<')+1,L[i].count('>')]
        else:
            a = [L[i].count('<')+1,L[i].count('>')+1]
        a_max = max(a)
        a_min = min(a)

        ans += a_max*(a_max+1)/2
        ans += a_min*(a_min-1)/2

print(int(ans))

Solution (Python):


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

ans = 0
a = [None]*N

prev = ">"
q=[]


for i in range(N-1):
    if prev==">" and S[i] == "<":
        a[i]=0
        q.append(i)
    prev = S[i]

if S[-1]==">":
    a[-1]=0
    q.append(N-1)

while len(q)!=0:
    i = q.pop()
    if i+1 < N:
        if S[i]=="<":
            if a[i+1]==None:
                a[i+1]=a[i]+1
                q.append(i+1)
            else:
                a[i+1]=max(a[i]+1,a[i+1])
    if i-1>=0:
        if S[i-1]==">":
            if a[i-1]==None:
                a[i-1]=a[i]+1
                q.append(i-1)
            else:
                a[i-1]=max(a[i]+1,a[i-1])

print(sum(a))

Solution (Python):
s = input()
a = []
for i in range(len(s)+1):a.append(0)
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):
import sys
s=input()
if s=='<':
  print(1)
  sys.exit()
if s[0]=='<':
  s=s[1:]
if s[-1]=='>':
  s=s[:-1]
s=list(s.split('><'))

ans=0
for i in s:
  a=[i.count('<'),i.count('>')]
  a_max=max(a)
  a_min=min(a)
  ans+=(a_max+1)*(a_max+2)//2
  ans+=a_min*(a_min+1)//2
print(ans)

Solution (Python):
S = input()

def g(X, s):
    res = 0
    yield 0
    for x in X:
        res = res + 1 if x == s else 0
        yield res

print(sum(map(max, g(S, "<"), list(g(S[::-1], ">"))[::-1])))

Solution (Python):
S = input().rstrip("\n")
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):
import re

def cha(s):
    s_ = []
    for i in s:
        s_.append(len(i))
    return s_
def sum_all(n):
    return n*(n-1)//2

if __name__=="__main__":
    s = input()
    top = s[0]
    c = 0
    if top == "<":
        s = re.split('(>+)',s)
        if s[-1] == "":
            s = s[:-1]
    else:
        s = re.split('(<+)',s)
        if s[-1] == "":
            s = s[:-1]
    s = cha(s)
    sum_top = 0
    sum_end = 0
    if top == ">":
        sum_top = sum_all(s[0]) + s[0]
        s = s[1:]
    if len(s)%2 == 1:
        sum_end = sum_all(s[-1])+s[-1]
        s = s[:-1]
    for i in range(0,len(s),2):
        c += sum_all(s[i])
        if s[i] >= s[i+1]:
            c += s[i] + sum_all(s[i+1])
        else:
            c += s[i+1]+sum_all(s[i+1])
    c += sum_end + sum_top

    print(c)

Solution (Python):
s=input()
s_l=[s[_] for _ in range(len(s))]
a_l=[0]*(len(s)+1)
for i in range(len(s)):
	if s[i]=='<':
		a_l[i+1]=a_l[i]+1
a_l.reverse()
s_l.reverse()
for j in range(len(s)):
	if s_l[j]=='>':
		a_l[j+1]=max(a_l[j]+1,a_l[j+1])
print(sum(a_l))

Solution (Python):
s = input().split('><')
if len(s) > 1:
  l = [s[0]+'>'] + list(map(lambda x: '<'+x+'>', s[1:-1])) + ['<'+s[-1]]
else:
  l = s
ans = 0
for block in l:
  left = block.count('<')
  right = block.count('>')
  m = max(left, right)
  ans += left * (left-1) // 2 + right * (right-1) // 2 + m
print(ans)

Solution (Python):
S = list(input())
numList = [0] * (len(S) + 1)
for i in range(len(S)):
    if S[i] == '<':
        numList[i + 1] = numList[i] + 1

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = read().rstrip().decode('utf-8')

S = S.replace('><','>,<').split(',')

answer = 0
for T in S:
    
    a = T.count('<')
    b = T.count('>')
    x = a * (a-1) // 2 + b * (b-1) // 2 + max(a,b)
    answer += x

print(answer)

Solution (Python):

s = input()
n = len(s)

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

cnt = 0
for i in range(n-1,-1,-1) :
    if s[i:(i+1)] == '>' :
        cnt += 1
        L[i] = max(L[i], cnt)
    else :
        cnt = 0

res = 0

for l in L :
    res += l
print(res)

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(S: str):
    N = len(S)
    l = [0] * (N+1)

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

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

    print(sum(l))

    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()
N = len(S)
l = [0] * (N + 1)

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

print(sum(l))

Solution (Python):
s=input()
cnt1=0
cnt2=1
ans=0
for i in range(len(s)-1):
    if s[i]==">" and s[i+1]=="<":
        a=max(cnt1,cnt2)
        b=max(min(cnt1,cnt2)-1,0)
        
        ans+=(a*(a+1)+b*(b+1))//2
        cnt1=0
        cnt2=1
    elif s[i]=="<":
        cnt1+=1
    else:
        cnt2+=1
if s[len(s)-1]=="<" and s[len(s)-2]=="<":
    cnt1+=1

a=max(cnt1,cnt2)
b=max(min(cnt1,cnt2)-1,0)
ans+=(a*(a+1)+b*(b+1))//2
print(ans)

Solution (Python):
Ss = '>' + input() + '<'

N = len(Ss) - 1

A1s = [0] * N
for i in range(N):
    if Ss[i:i+2] == '><':
        A1s[i] = 0
    elif Ss[i:i+2] != '>>':
        A1s[i] = A1s[i-1] + 1

A2s = [0] * N
for i in reversed(range(N)):
    if Ss[i:i+2] == '><':
        A2s[i] = 0
    elif Ss[i:i+2] != '<<':
        A2s[i] = A2s[i+1] + 1

As = [A1 if A1 >= A2 else A2 for A1, A2 in zip(A1s, A2s)]
print(sum(As))

Solution (Python):
S = input()
N = len(S) + 1
 
A = [0] * N
 
if S[0] == '<':
    A[0] = 0

if S[-1] == '>':
    A[-1] = 0

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

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

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

print(sum(A))

Solution (Python):


def resolve():
    S = input().rstrip()

    N = len(S)

    a, i, aa = "<", 0, []
    for c in S:
        if c == a:
            i += 1
        else:
            aa.append((a, i))
            i = 1
            a = c
    aa.append((a, i))

    if S[-1] == "<":
        aa.append((">", 0))

    pt = 0
    aaa = iter(aa)
    n = 0
    for a, b in zip(aaa, aaa):
        x, y = a
        n += y * (y - 1) // 2

        pt = y

        x, y = b

        if y > pt:
            pass
        else:
            n += pt
            y -= 1

        n += y * (y + 1) // 2

    print(n)




if __name__ == "__main__":
    resolve()

Solution (Python):
s = input()
length = len(s)
sum = 0
right = [0]
left = [0]
r = 0
for i in range(length):
  if s[i] == "<":
    r += 1
    right.append(r)
  else:
    r = 0
    right.append(r)
l = 0    
for i in range(length-1,-1,-1):
  if s[i] == ">":
    l += 1
    left.append(l)
  else:
    l = 0
    left.append(l)
left.reverse()

for i in range(length+1):
  sum += max(right[i],left[i])

print(sum)

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

A = [-1] * N

if S[0] == '<':
  A[0] = 0

if S[-1] == '>':
  A[-1] = 0

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

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

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

print(sum(A))

Solution (Python):
w1 = input()
length = len(w1)
num_list = [-1]*(length+1)
c1 = 0
c2 = 0
for i in range(length):
    if i==0 and w1[i] == "<":
        num_list[0] = 0
    if i==(length-1) and w1[i] == ">":
        num_list[length] = 0
    if not i==length-1:
        if w1[i] == ">" and w1[i+1] =="<":
            num_list[i+1] = 0

    if(w1[i] == "<"):
        num_list[i+1] = num_list[i] + 1

for i in range(length-1,-1,-1):
    if (w1[i] == ">"):
        if(num_list[i] < num_list[i+1] + 1):
            num_list[i] = num_list[i+1] + 1


print(sum(num_list))

Solution (Python):
s = input()

leng = len(s) + 1

lr = [0] * leng
rl = [0] * leng

for i in range(1, leng):
    if s[i - 1] == '<':
        lr[i] = lr[i - 1] + 1

for i in range(leng - 1, 0, -1):
    if s[i - 1] == '>':
        rl[i - 1] = rl[i] + 1

ans_list = [max(rl[i], lr[i]) for i in range(leng)]

print(sum(ans_list))

Solution (Python):

s = input()
i = 0
c = 0
res = 0
while i<len(s):
    j = i
    while j<len(s) and s[i]==s[j]:
        j += 1
    if s[i]=="<":
        res += (j-i)*(j-i+1)//2
        c = j-i
    else:
        res += (j-i)*(j-i+1)//2
        if c>j-i:
            res -= j-i
        else:
            res -= c

    i = j

print(res)

Solution (Python):
import re
from collections import Counter
s = input()
res = re.finditer(r"(<+>+)|(^>+)|(<+$)", s)

def calc(string):
    ct = Counter(string)
    cnt_d = ct[">"]
    cnt_s = ct["<"]
    if cnt_s > cnt_d:
        return (cnt_s * (cnt_s + 1) + (cnt_d - 1) * cnt_d) // 2
    elif cnt_s == cnt_d:
        return cnt_s * cnt_s
    else:
        return ((cnt_d + 1) * cnt_d + (cnt_s - 1) * cnt_s) // 2
score = 0
for r in res:
    score += calc(r.group())
print(score)

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

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

now = 0
for i in range(N - 2, -1, -1) :
  if S[i] == '>' :
    now += 1
    ret[i] = max(ret[i], now)
  else :
    now = 0
    
print(sum(ret))

Solution (Python):
S = input()

n = len(S)
N = n + 1

l = [0] * N
r = [0] * N
for i in range(1, N):
    if S[i - 1] == '<':
        l[i] = l[i - 1] + 1
for i in range(N - 1, 0, -1):
    if S[i - 1] == '>':
        r[i - 1] = r[i] + 1
print(sum([max(l[i], r[i]) for i in range(N)]))

Solution (Python):
S=input()
x=len(S)
temp=ans=check=0
for i in range(x):
  if S[i]=="<":
    if temp>0 and S[i-1]==">":
      ans=ans-(temp*check)
      temp=0    
    check=0
    temp+=1
    ans+=temp
  else:
    check+=1
    temp-=1
    if temp<0:
      temp=0
      ans+=check
    else:
      ans+=temp
print(ans)

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

for i in range(n):
  if s[i] == "<":
    v[i+1] = v[i] + 1

for j in range(n):
  if s[-j-1] == ">":
    if v[-j-2] <= v[-j-1]:
      v[-j-2] = v[-j-1] + 1

print(sum(v))

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

for i in range(n-1):
    if s[i] == "<":
        v[i+1] = v[i] + 1

for j in range(n-1):
    if s[-j-1] == ">":
        if v[-j-2] <= v[-j-1]:
            v[-j-2] = v[-j-1] + 1

print(sum(v))

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

for i in range(n-1):
    if s[i] == "<":
        v[i+1] = v[i] + 1

for j in range(n-1):
    if s[-j-1] == ">":
        if v[-j-2] <= v[-j-1]:
            v[-j-2] = v[-j-1] + 1

print(sum(v))

Solution (Python):
import unittest
import itertools
import sys

def triangle(n):
    return (n * (n+1)) // 2

def solve(problem):
    rl = [(k, len(list(g))) for (k, g) in itertools.groupby(problem)]
    print(rl, file=sys.stderr)

    result = 0
    pos = 0
    while pos < len(rl):
        if rl[pos][0] == '>':
            assert pos == 0
            result += triangle(rl[pos][1])
            pos += 1
        elif pos + 1 < len(rl): 
            result += triangle(max(rl[pos][1], rl[pos+1][1]))
            result += triangle(min(rl[pos][1], rl[pos+1][1]) - 1)
            pos += 2
        else: 
            result += triangle(rl[pos][1])
            pos += 1
    return result

class Tests(unittest.TestCase):
    def test_1(self):
        self.assertEqual(solve('<>>'), 3)

    def test_2(self):
        self.assertEqual(solve('<>>><<><<<<<>>><'), 28)

if __name__ == '__main__':
    print(solve(input().strip()))

Solution (Python):
S = input()
ans = 0

big = [0]*(len(S)+1)
for i in range(len(S)):
  if S[i] == "<":
    big[i+1] = big[i] +1
  else:
    big[i+1] = 0
  
small = [0]*(len(S)+1)
for i in range(len(S)-1, -1, -1):
  if S[i] == ">":
    small[i] = small[i+1] + 1
  else:
    small[i] = 0
    
for b, s in zip(big, small):
  ans += max(b, s)

print(ans)

Solution (Python):
import re
s = input()
ss = re.findall(r">+|<+",s,re.S)
count = 0
num = 0
if re.findall(">",ss[0],re.S):
    count += sum(range(len(ss[0])+1))
    del ss[0]
if ss and re.findall("<",ss[-1],re.S):
    count += sum(range(len(ss[-1])+1))
    del ss[-1]
for i in range(len(ss)-1):
    if num == 0:
        num = max(len(ss[i]),len(ss[i+1]))
        count += sum(range(max(len(ss[i]),len(ss[i+1]))+1))
        count += sum(range(min(len(ss[i]),len(ss[i+1]))))
    else:
        num = 0
print(count)

Solution (Python):
*s, = input()

less = [0]*(len(s)+1)
for i in range(len(s)):
    if s[i] == "<":
        less[i+1] = less[i] + 1

greater = [0]*(len(s)+1)
for i in range(len(s)-1, -1, -1):
    if  s[i] == ">":
        greater[i] = greater[i+1] + 1

ans = 0
for _l, _g in zip(less, greater):
    ans += max(_l, _g)

print(ans)

Solution (Python):
from sys import stdin
S = stdin.readline().rstrip()
N = len(S)+1
l = [0]*N
r = [0]*N
for i in range(N-1):
    if S[i] == '<':
        l[i+1] = l[i]+1 
for i in range(N-2, -1, -1):
    if S[i] == '>':
        r[i] = r[i+1]+1
ans = []
for ll, rr in zip(l, r):
    ans.append(max(ll, rr))
print(sum(ans))

Solution (Python):
from itertools import groupby
S = input()
if S[0] == ">":
    S = "<"+S
if S[-1] == "<":
    S += ">"

ans = 0
pair = [(s, len(list(l))) for s, l in groupby(S)]
for p, q in zip(pair[:-1:2], pair[1::2]):
    a, b = min(p[1], q[1]), max(p[1], q[1])
    ans += (a-1)*a//2
    ans += (b+1)*b//2

print(ans)

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

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

la = 0
ra = 0
ans = 0

for i in range(N-1):
    if S[i] == "<":
        la += 1
    else:
        ra += 1

    if S[i] == ">" and S[i+1] == "<":
        m = min(la,ra) - 1
        M = max(la,ra)
        ans += M*(M+1)//2 + m*(m+1)//2
        la = 0 
        ra = 0

if S[-1] == "<":
        la += 1
else:
    ra += 1

m = min(la,ra) - 1
M = max(la,ra)
ans += M*(M+1)//2 + m*(m+1)//2

print(ans)

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

a=[0]*(n+1)
for i in range(n):
    if s[i]=="<":
        a[i+1]=max(1+a[i],a[i+1])

s.reverse()
a.reverse()
for i in range(n):
    if s[i]==">":
        a[i+1]=max(1+a[i],a[i+1])
s.reverse()
a.reverse()
print(sum(a))

Solution (Python):





s = list(input())


memo = ''


cnt = 0


before_cnt = 0


ans = 0


for i in s:
    
    if memo == '':
        memo = i

    
    if memo == i:
        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 = i
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):
import sys
input = sys.stdin.readline

s = input()[:-1]

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

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

for i in range(len(a)):
    a[i] = max(l[i], r[i])

print(sum(a))