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()
a = [0] * (len(S) + 1)
for i in range(len(S)):
    if S[i] == "<":
        a[i + 1] = a[i] + 1

for i in list(range(len(S)))[::-1]:
    if S[i] == ">" and a[i + 1] >= a[i]:
        a[i] = a[i + 1] + 1

print(sum(a))

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


def left(T, S, a, i):
    
    j = 1
    l = i
    while 0 <= l:
        if S[l] == ">" and a[l] < j:
            a[l] = j
            l -= 1
            j += 1
        else:
            break


def right(T, S, a, i):
    
    j = 1
    r = i
    while r <= T - 1:
        if S[r] == "<" and a[r + 1] < j:
            a[r + 1] = j
            r += 1
            j += 1
        else:
            break


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

    T = len(S)
    N = T + 1
    a = [-1] * N

    if S[0] == "<":
        a[0] = 0
        right(T, S, a, 0)
    for i in range(T - 1):
        if S[i] == ">" and S[i + 1] == "<":
            a[i + 1] = 0
            left(T, S, a, i)
            right(T, S, a, i + 1)
    if S[T - 1] == ">":
        a[N - 1] = 0
        left(T, S, a, T - 1)

    ans = sum(a)
    print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
s = input()
n = len(s)
res = [0] * (n + 1)
t = 0
for i in range(n):
	if s[i] == '<':
		t += 1
	else:
		t = 0
	res[i + 1] = t

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

print(sum(res))

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

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


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

ans=0
for i in range(n+1):
    ans+=max(r[i],l[i])
print(ans)

Solution (Python):




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


lst = [0] * N

for i in range(N-1):
    if S[i] == "<":
        lst[i+1] = max(lst[i+1], lst[i] + 1)

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


print(sum(lst))

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 i in range(n-2, -1, -1):
    if s[i] == '>':
        A[i] = max(A[i], A[i+1]+1)
print(sum(A))

Solution (Python):
S = str(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], A[i+1]+1)

print(sum(A))

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

L=[0]*(N+1)
R=[0]*(N+1)
for i in range(1,N+1):
    if S[i-1]=="<":
        L[i]=L[i-1]+1
    if S[-(i)]==">":
        R[-(i+1)]=R[-i]+1
ans=[0]*(N+1)
for i in range(N+1):
    ans[i]=max(L[i],R[i])
print(sum(ans))

Solution (Python):
from sys import stdin
S = str(stdin.readline().rstrip())




n = len(S)+1
sho = [0]*n
dai = [0]*n

for i,s in enumerate(S):
    i += 1
    if s ==">":
        sho[i] = 0
    else:
        sho[i] = sho[i-1] + 1

for i,s in enumerate(S[::-1]):
    i = n-i-2
    if s == "<":
        dai[i]=0
    else:
        dai[i] = dai[i+1] +1

seq = [max(x,y) for x,y in zip(sho,dai)]

print(sum(seq))

Solution (Python):
if __name__ == '__main__':
    inp = input()

    nle = 0
    ngt = 0
    ans = 0
    for i in range(len(inp)):
        if inp[i] == '>':
            nle += 1
        else:
            ngt += 1

        if (i + 1 < len(inp) and inp[i] == '>' and inp[i + 1] == '<') or (i == len(inp) - 1):
            ans += (max(nle, ngt) * (max(nle, ngt) + 1)) / 2
            ans += (min(nle, ngt) * (min(nle, ngt) - 1)) / 2
            nle = 0
            ngt = 0

    print(int(ans))

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

INF = float('inf')

a = [-INF]*(n+1)

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

    if s[i] =='>' and s[i+1]=='<':
        a[i+1]=0


def left(i):
    while True:
        if i ==0:
            break
        if s[i-1] == '>' and a[i-1] <=a[i]:
            a[i-1]=a[i]+1
        else:
            break
        i-=1

def right(i):
    while True:
        if i==n:
            break
        if s[i] == '<' and a[i]>=a[i+1]:
            a[i+1]=a[i]+1
        else:
            break
        i+=1

for i in range(n+1):
    if a[i] == 0:
        left(i)
        right(i)

print(sum(a))

Solution (Python):
s=input()
n=len(s)+1
cnt = 1
pool = -1
ans = 0
for i in range(1,n-1):
    if s[i-1]== s[i] == '<':
        cnt += 1
    elif s[i-1] == '<' and s[i] == '>':
        ans += cnt*(cnt-1)//2
        pool = cnt
        cnt = 1
    elif s[i-1] == s[i] == '>':
        cnt += 1
    else:
        ans += cnt*(cnt-1)//2
        ans += max(cnt,pool)
        cnt = 1
ans += cnt*(cnt+1)//2
print(ans)

Solution (Python):
from itertools import groupby

r = p = 0
for k, g in groupby(input()):
    i = 0
    for _ in g:
        i += 1
        r += i
    if k == '>':
        r -= min(i, p)
    p = i
print(r)

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

l = [0 for _ in range(n+1)]
r = [0 for _ in range(n+1)]

for i in range(n):
    if(s[i] == '<'):
        l[i+1] = l[i] + 1
    else:
        l[i+1] = 0
for i in range(n)[::-1]:
    if(s[i] == '>'):
        r[i] = r[i+1] + 1
    else:
        r[i] = 0

t = 0
for i in range(n+1):
    t += max(l[i],r[i])
print(t)

Solution (Python):
s = input()

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

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

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


for k in reversed(range(n - 1)):
    if s[k] == ">":
        a[k] = max(a[k + 1] + 1, a[k])

print(sum(a))

Solution (Python):
def main():
    S = input()
    N = len(S) + 1
    cc_s = [0] * N
    cc_d = [0] * N
    for i in range(N-1):
        if S[i] == '<':
            cc_s[i+1] = cc_s[i] + 1
    iS = S[::-1]
    for i in range(N-1):
        if iS[i] == '>':
            cc_d[i+1] = cc_d[i] + 1
    cc_d = cc_d[::-1]
    output = 0
    for a, b in zip(cc_s, cc_d):
        output += max(a, b)
    print(output)
    return

if __name__ == '__main__':
    main()

Solution (Python):

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], A[i+1]+1)
print(sum(A))

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

right = [0]

left = [0]

count = 0
for i in range(len(s)):
    if s[i] == '<':
        count += 1
    else:
        count = 0
    right.append(count)
count = 0
for i in range(len(s)-1,-1,-1):
    if s[i] == '>':
        count += 1
    else:
        count = 0
    left.append(count)
left.reverse()

ans = 0

for i in range(len(s)+1):
    ans += max(right[i],left[i])
print(ans)

Solution (Python):
S = input()

tmp1 = [0 for _ in range(len(S)+1)]
tmp2 = [0 for _ in range(len(S)+1)]

for i in range(len(S)):
  if S[i] == '>':
    tmp1[i] = 1
  else:
    tmp2[i+1] = 1

for i in range(1, len(S)+1):
  if tmp1[-i-1] != 0:
    tmp1[-i-1] = tmp1[-i] + tmp1[-i-1]

for i in range(2, len(S)+1):
  if tmp2[i] != 0:
    tmp2[i] = tmp2[i] + tmp2[i-1]

ans = 0
for i in range(len(S)+1):
  ans += max(tmp1[i], tmp2[i])

print(ans)

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]

def to_bin(x: int) -> str: return format(x, 'b') 
def to_oct(x: int) -> str: return format(x, 'o') 
def to_hex(x: int) -> str: return format(x, 'x') 
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]

from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left


def main():
    s = IS()
    n = len(s)
    a = [0]
    now = 0
    for si in s:
        if si == '<':
            now += 1
        else:
            now = 0
        a.append(now)
    b = [0]
    now = 0
    for si in s[::-1]:
        if si == '>':
            now += 1
        else:
            now = 0
        b.append(now)
    b = b[::-1]
    ans = sum([max(a[i], b[i]) for i in range(n+1)])
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
s = input()
ans = 0
cnt = 0
tmp = 0
pre = '>'
last = '>' if s[-1]=='<' else '<'
for now in s+last:
    if pre==now:
        cnt += 1
    else:
        if now=='<':
            ans += max(cnt, tmp)
            tmp = 0
        else:
            tmp = cnt
        ans += cnt*(cnt-1)//2
        cnt = 1
    pre = now
ans += tmp
print(ans)

Solution (Python):
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], A[i+1]+1)
print(sum(A))

Solution (Python):
S = list(input())
ans = []
N = len(S) + 1

lr = [[] for _ in range(N)]


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


temp = 0
for i in reversed(range(N)):
    if i == N - 1:
        lr[i].append(0)
    else:
        if S[i] == ">":
            temp += 1
            lr[i].append(temp)
        else:
            temp = 0
            lr[i].append(temp)

ans = []
for i in range(N):
    ans.append(max(lr[i]))
print(sum(ans))

Solution (Python):
def main():
    S = input()
    N = len(S)+1
    now = 0
    A = [0]
    for s in S:
        if s == "<":
            now += 1
        else:
            now = 0
        A.append(now)
    B = [0]
    now = 0
    for s in S[::-1]:
        if s == ">":
            now += 1
        else:
            now = 0
        B.append(now)
    B = B[::-1]
    ans = sum( [ max(A[i], B[i]) for i in range(N)])
    
    print(ans)
        
if __name__ == '__main__':
    main()

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

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


def read():
    S = input().strip()
    return S,

def cumsum(a):
    for i in range(1, len(a)):
        a[i] += a[i-1]
    return a

def solve(S):
    S = S + '.'
    N = len(S)
    pairs = []
    i = 0
    while S[i] != '.':
        n_close = 0
        n_open = 0
        while S[i] == '>':
            i += 1
            n_close += 1
        while S[i] == '<':
            i += 1
            n_open += 1
        pairs.append((n_close, n_open))
    
    T = cumsum([i for i in range(N)])
    
    ans = 0
    for n_close, n_open in pairs:
        ans += T[n_close] + T[n_open]
    for i in range(1, len(pairs)):
        ans -= min(pairs[i-1][1], pairs[i][0])
    return ans

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Solution (Python):
S=input()
chk = S[0]
cnt =1
cnt_list=[]
ans = 0
for i in S[1:]:
    if chk==i:
        cnt += 1
    else:
        ans += cnt*(cnt-1)//2
        cnt_list.append(cnt)
        cnt = 1
        chk = i
cnt_list.append(cnt)
ans += cnt*(cnt-1)//2
if S[0]=="<":
    for i,j in zip(cnt_list[::2],cnt_list[1::2]):
        ans += max(i,j)
    if len(cnt_list)%2!=0:
        ans += cnt_list[-1]
else:
    ans += cnt_list[0]
    for i,j in zip(cnt_list[1::2],cnt_list[2::2]):
        ans += max(i,j)
    if len(cnt_list)%2==0:
        ans += cnt_list[-1]
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] = a[i]+1
for i in reversed(range(n)):
    if s[i] == '>':
        a[i] = max(a[i+1]+1,a[i])
print(sum(a))

Solution (Python):
S = list(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 reversed(range(N)):
    if S[i] == '>':
        a[i] = max(a[i], a[i + 1] + 1)
    

print(sum(a))

Solution (Python):
def myAnswer(S:list) -> int:
   N = len(S)+1
   ans = [0]*N
   for i in range(len(S)-1,-1,-1):
      if(S[i] == ">"):
         ans[i] = ans[i+1]+1
   
   for i in range(len(S)):
      if(S[i]== "<"):
         if(ans[i] >= ans[i + 1]):
            ans[i + 1] = ans[i]+1
   
   return sum(ans)
def modelAnswer(S:list) -> int:
   l = [0 for i in range(len(S)+1)]
   for n,s in enumerate(S):
      if(s == "<"):
         l[n+1] = l[n] + 1
   for n,s in enumerate(S[::-1]):
      if(s == ">"):
         tmp = l[len(S) - n] + 1
         if (tmp > l[len(S) - n - 1]):
            l[len(S) -n - 1] = tmp
   return sum(l)
def main():
   S = list(input())
   print(myAnswer(S[:]))
if __name__ == '__main__':
   main()

Solution (Python):
from copy import copy, deepcopy
from collections import Counter
from math import sqrt

MOD = 10**9 + 7

S = list(input())
if S[0] == '>':
    S.insert(0, '<')
if S[-1] == '<':
    S.insert(len(S), '>')

low = [i for i, v in enumerate(S) if i > 0 and S[i-1] == '>' and S[i] == '<']
high = [i for i, v in enumerate(S) if i > 0 and S[i-1] == '<' and S[i] == '>']

if S[0] == '<':
    low.insert(0, 0)
elif S[0] == '>':
    high.insert(0, 0)

if S[-1] == '<':
    high.append(len(S))
elif S[-1] == '>':
    low.append(len(S))

ans = 0


def s(i):
    return i * (i+1) // 2


for i in range(len(high)):
    lh = abs(high[i] - low[i])
    hl = abs(low[i+1] - high[i])
    ans += s(max(lh, hl)) + s(min(lh, hl)-1)

print(ans)

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

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

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

print(sum(res))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

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



if __name__ == '__main__':
    main()

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


S = input()
arr = []
i = 0
while len(S) > i:
    s = i
    while i + 1 < len(S) and S[i] == S[i + 1]:
        i += 1
    arr.append(i - s + 1)
    i += 1

ans = 0
if S[0] == '>':
    ans += f(arr[0] + 1)
    arr = arr[1:]

if S[-1] == '<':
    ans += f(arr[-1] + 1)
    arr = arr[:-1]

for i in range(0, len(arr), 2):
    ans += max(arr[i], arr[i + 1]) + f(arr[i]) + f(arr[i + 1])

print(ans)

Solution (Python):
S = input()

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

print(sum(d))

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]:
    if S[i] == '>':
        a[i] = max(a[i], a[i+1] + 1)

print(sum(a))

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

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

print(sum(ans))

Solution (Python):
s=input()
ans=0
seq_up=0
seq_down=0
d='>'
u='<'
if s[0]==u:
  seq_up+=1
else:
  seq_down+=1
for i in range(1,len(s)):
  if s[i]==u:
    if s[i]!=s[i-1]:
      ans+=max(seq_up*(seq_up-1)//2,0)
      
      ans+=max(seq_down*(seq_down-1)//2,0)
      
      ans+=max(seq_up,seq_down)
      
      seq_up=1
      seq_down=0
      
    else:
      seq_up+=1
      
  else:
    seq_down+=1
    
m=max(seq_up,seq_down)+1
ans+=m*(m-1)//2
print(ans)

Solution (Python):
s = list(input())
if s[0] == ">":
    s.insert(0, "<")
if s[len(s) - 1] == "<":
    s.append(">")
t = "<"
a, b = 0, 0
ans = 0
for i in s:
    if i == "<":
        if not b == 0:
            x = max(a, b)
            y = min(a, b) - 1
            ans += (x * (x + 1)) // 2 + (y * (y + 1)) // 2
            a, b = 0, 0
        a += 1
    else:
        b += 1
x = max(a, b)
y = min(a, b) - 1
ans += (x * (x + 1)) // 2 + (y * (y + 1)) // 2
print(ans)

Solution (Python):
s = input().replace('><','> <').split()
ans = 0

for st in s:
    lt = st.count('<')
    gt = len(st) - lt
    if lt > gt:
        gt -= 1
    else:
        lt -= 1
    ans += (lt*lt+lt)//2 + (gt*gt+gt)//2
print(ans)

Solution (Python):
import sys

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


def resolve():
    s = input()
    n = len(s)

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

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

    res = 0
    for i in range(n + 1):
        res += max(A[i], B[i])

    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
s=input()
rl=[]
ll=[]
c=0
for i in range(len(s)-1):
  c+=1
  if s[i]!=s[i+1]:
    if s[i]=='<':
      rl.append(c)
    else:
      ll.append(c)
    c=0
if s[len(s)-1]=='<':
  rl.append(c+1)
else:
  ll.append(c+1)

rn=len(rl)
ln=len(ll)
ans=0
if s[0]=='<':
  for i in range(ln):
    M=max(rl[i], ll[i])
    m=min(rl[i], ll[i])
    ans+=M*(M+1)//2+m*(m-1)//2
  if rn>ln:
    ans+=rl[-1]*(rl[-1]+1)//2
else:
  rl=[0]+rl
  ans+=ll[0]*(ll[0]+1)//2
  for i in range(1, ln):
    M=max(rl[i], ll[i])
    m=min(rl[i], ll[i])
    ans+=M*(M+1)//2+m*(m-1)//2
  if rn==ln:
    ans+=rl[-1]*(rl[-1]+1)//2
print(ans)

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

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()
ans = [0 for _ in range(len(S) + 1)]
t = 0
for i in range(len(S)):
    if S[i] == "<":
        t += 1
    else:
        t = 0
    ans[i + 1] = t


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

Solution (Python):
S = input()
zero = []
turn = []

def sum_n(n):
    return (n ** 2 + n) // 2

for i, s in enumerate(S):
    if i == 0:
        if s == '<':
            zero.append(i)
        else:
            turn.append(i)
            zero.append(-1)
    else:
        if s_ == '>' and s == '<':
            zero.append(i)
        elif s_ == '<' and s == '>':
            turn.append(i)
    if i == len(S) - 1:
        if s == '>':
            zero.append(i + 1)
        else:
            turn.append(i + 1)
            zero.append(i + 2)
    s_ = s




ans = 0

for i in range(len(turn)):
    ans += sum_n(zero[i+1] - turn[i] - 1)
    ans += sum_n(turn[i] - zero[i] - 1)
    ans += max(zero[i+1] - turn[i], turn[i] - zero[i])
print(ans)

Solution (Python):
s=input()
ans1=[]
ans1.append(0)
now=0
for i in s:
    if i == "<":
        now+=1
    else:
        now=0
    ans1.append(now)
ans2=[]
ans2.append(0)
now=0
for i in reversed(s):
    if i == ">":
        now+=1
    else:
        now=0
    ans2.append(now)

ans=[]
for i in range(len(ans1)):
    ans.append(max(ans1[i],ans2[len(ans1)-i-1]))
print(sum(ans))

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

count=1
a=[]
for i in range(1,n):
  if s[i]==s[i-1]:
    count += 1
  else:
    a.append(count)
    count=1
if count!=0:
  a.append(count)

size=len(a)
a.append(0)

total = 0

if s[0] == "<":
  for i in range((size+1)//2):
    large=max(a[2*i],a[2*i+1])
    small=min(a[2*i],a[2*i+1])
    total += (large+1)*large//2 + small*(small-1)//2
  print(total)
  
if s[0] == ">":
  total += a[0]*(a[0]+1)//2
  for i in range(size//2):
    large=max(a[2*i+1],a[2*i+2])
    small=min(a[2*i+1],a[2*i+2])
    total += (large+1)*large//2 + small*(small-1)//2
  print(total)

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



s = input()
n = len(s)
x = []
up = True
cnt = 0
for i in range(n):
    if s[i] == "<":
        if up:
            cnt += 1
        else:
            x.append(-cnt)
            up = True
            cnt = 1
    else:
        if up:
            x.append(cnt)
            up = False
            cnt = 1
        else:
            cnt += 1
if up:
    x.append(cnt)
else:
    x.append(-cnt)

m = len(x)
ans = 0
for i in range(0, m, 2):
    if i == m - 1:
        ans += x[i] * (x[i] + 1) // 2
        break
    a, b = max(x[i], abs(x[i + 1])), min(x[i], abs(x[i + 1]))
    
    ans += (a * (a + 1) + (b - 1) * b) // 2
print(ans)

Solution (Python):
s=input()

n=len(s)+1
dr,dl=[0]*n,[0]*n



p=''
cl,cr=0,0
for i in range(n-1):
      if s[i]=='<':
            cl+=1
      else:
            cl=0
      dl[i+1]=cl
      if s[-(i+1)]=='>':
            cr+=1
      else:
            cr=0
      dr[-(i+2)]=cr
ans=0
for i in range(n):
      ans+=max(dl[i],dr[i])
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, -1, -1):
    if s[i] == '>':
        a[i] = max(a[i], a[i+1]+1)
print(sum(a))

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],a[i+1]+1)
print(sum(a))

Solution (Python):
s = input()

c = 0
dp = [0] * (len(s) + 1)
for i in range(len(s)):
    if s[i] == '<':
        c += 1
        dp[i + 1] = c
    else:
        c = 0
c = 0
for i in range(len(s))[::-1]:
    if s[i] == '>':
        c += 1
        dp[i] = max(dp[i], c)
    else:
        c = 0
ans = sum(dp)
print(ans)

Solution (Python):
s=input()+' '
p=0
l=list()
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        p+=1
    else:
        if s[i]=='<':
            l.append([0,'<',p+1])
        else:
            l.append([p+1,'>',0])
        p=0
a=sum([sum(range(i[2]+1)) if i[1]=='<' else sum(range(i[0]+1)) for i in l])
b=sum([min(l[i][2],l[i+1][0]) for i in range(len(l)-1)])
print(a-b)

Solution (Python):
s=input()
n=len(s)+1
lst=[]
now='<'
cnt=0
for i in range(n-1):
    if s[i]!=now:
        lst.append(cnt)
        cnt=1
        now=s[i]
    else:
        cnt+=1
lst.append(cnt)
if len(lst)%2==1:
    lst.append(0)
ans=0
for i in range(0,len(lst),2):
    x=lst[i]
    y=lst[i+1]
    if x>=y:
        ans+=0.5*x*(1+x)+0.5*y*(y-1)
    else:
        ans+=0.5*y*(1+y)+0.5*x*(x-1)
print(int(ans))

Solution (Python):
import sys


def main():
    S = input() + "🐦"
    l = 0
    r = 0
    for i in range(len(S)):
        if S[i:i+2] == "><" or S[i:i+2] == ">🐦":
            r += 1
            yield r
            yield -min(l, r)
            l = 0
            r = 0
        else:
            if S[i] == "<":
                l += 1
                yield l
            elif S[i] == ">":
                r += 1
                yield r
    

    
    
    
    


print(sum(main()))

Solution (Python):
s = input()
ans = 0
t = [0 for i in range(len(s) + 1)]
tmp = 0
for i in range(1, len(s) + 1):
    if s[i - 1] == '<':
        tmp += 1
    else:
        tmp = 0
    t[i] = tmp

ans += t[len(s)]
tmp = 0
for i in range(len(s) - 1, -1, -1):
    if s[i] == '>':
        tmp += 1
    else:
        tmp = 0
    ans += max(tmp, t[i])
    
print(ans)

Solution (Python):
s = list(input().rstrip())
n=len(s)+1
from_left = [0]*n
from_right = [0]*n
ans=0
i=0
for i,ss in enumerate(s,1):
    if ss == '>':
        from_left[i] = 0
    else:
        from_left[i] = from_left[i-1]+1
for i,ss in enumerate(s[::-1]):
    i = n-2-i
    if ss == '<':
        from_right[i] = 0
    else:
        from_right[i] = from_right[i+1]+1
seq = [x if x>y else y for x,y in zip(from_left,from_right)]
answer = sum(seq)
print(answer)

Solution (Python):
S = input()

a = []
b = [0]
tmp = S[0]

for i in range(len(S)):
    if tmp == S[i] == "<":
        b.append(b[-1]+1)
    elif tmp == S[i] == ">":
        b.append(b[-1]-1)
    else:
        min_b = min(b[0], b[-1])
        if min_b < 0:
            b = list(map(lambda x: x-min_b, b))
        a.append(b)
        if S[i] == "<":
            b = [0,1]
        else:
            b = [0,-1]
    tmp = S[i]
min_b = min(b[0], b[-1])
if min_b < 0:
    b = list(map(lambda x: x-min_b, b))
a.append(b)

ans = 0
tmp = -1
for x in a:
    ans += max(tmp, x[0])
    ans += sum(x) - x[0] - x[-1]
    tmp = x[-1]
ans += x[-1]

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 + 1] + 1, ans[i])
print(sum(ans))

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

Solution (Python):
s=str(input())
n=len(s)
a=[0]
count=0
for i in range(n):
    if s[i:i+1]=='<':
        count+=1
        a.append(count)
    else:
        count=0
        a.append(0)

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

print(sum(a))

Solution (Python):
def main():
    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 reversed(range(len(s))):
        if s[i] == '>':
            ans[i] = max(ans[i], ans[i + 1] + 1)
    
    
    print(sum(ans))



if __name__ == "__main__":
    main()