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):
from collections import deque
S=input()
N=len(S)+1
X=[-1 for i in range(N)]
'''
 < > >
0 2 1 0
'''
q=deque([])
for i in range(N-2):
    if S[i]==">" and S[i+1]=="<":
        X[i+1]=0
        q.append(i+1)
if S[0]=="<":
    q.append(0)
    X[0]=0
if S[N-2]==">":
    q.append(N-1)
    X[N-1]=0

while(len(q)>0):
    r=q.popleft()
    for p in [r-1,r+1]:
        if not(0<=p<N):
            continue
        if (p<r and S[p]==">") or (p>r and S[r]=="<"):
            if X[p]<=X[r]:
                X[p]=X[r]+1
                q.append(p)

print(sum(X))

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

ans = 0
i = 0
while i < N and S[i]=='>':
    i += 1
ans += i*(i+1)//2

arr = [i]
while i < N:
    while i < N and S[i]=='<':
        i += 1
    arr.append(i)
    if i==N: break
    while i < N and S[i]=='>':
        i += 1
    arr.append(i)

arr = [b-a for a,b in zip(arr,arr[1:])]
for a,b in zip(arr[::2],arr[1::2]):
    if a<b: a,b = b,a
    ans += a*(a+1)//2
    ans += b*(b-1)//2
if len(arr)%2:
    ans += arr[-1]*(arr[-1]+1)//2

print(ans)

Solution (Python):
import numpy as np

S = list(map(str, input().rstrip()))

ans = np.zeros(len(S) + 1, dtype=np.int64)


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

ans = ans[::-1]

for i, s in enumerate(S[::-1]):
    if s == ">":
        ans[i+1] = max(ans[i+1], ans[i]+1)

print(ans.sum())

Solution (Python):
def main():
    s = input()
    arr = [0]*(len(s)+1)
    for i in range(len(s)):
        c = s[i]
        if c == "<":
            arr[i+1] = arr[i]+1
    for i in reversed(range(len(s))):
        c = s[i]
        if c == ">":
            arr[i] = max(arr[i], arr[i+1]+1)
    print(sum(arr))

if __name__ == "__main__":
    main()

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

node_value = 0
for i in range(len(S)):
    if S[i] == "<":
        node_value += 1
        A[i+1] = node_value
    else:
        node_value = 0

node_value = 0
for i in range(len(S)-1,-1,-1):
    if S[i] == ">":
        node_value += 1
        A[i] = max(A[i], node_value)
    else:
        node_value = 0

print(sum(A))

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

Solution (Python):
a=list(input())
count=1
ans = 0
temp = 0
for i in range(len(a)-1):
  if a[i] ==a[i+1]:
    count+=1
  else:
    if a[i]=='<':
      ans += count*(count+1)//2
      temp = count
      
      count = 1
      
    else:
      ans += count*(count+1)//2
      ans -= min(count, temp)
      
      count =1
else:
  if a[-1]=='<':
    ans += count*(count+1)//2
  else:
    ans += count*(count+1)//2
    ans -= min(count, temp)
print(ans)

Solution (Python):
a = input()
N = len(a)
c = []
temp = int(1)
ans = int(0)
for i in range(N):
    if i != N-1:
      if a[i] == a[i+1]:
        temp += 1
      else:
        c.append(temp)
        temp = 1
    else:
      if a[i-1] == a[i]:
        c.append(temp)
      else:
        c.append(1)

clen = len(c)

if a[0] == "<" and clen % 2 == 1:
    c.append(0)
elif a[0] == ">" and clen % 2 == 0:
    c.append(0)

if a[0] == "<":
    for i in range(0,clen,2):
        maxi = max([c[i],c[i+1]])
        mini = min([c[i],c[i+1]])
        ans += maxi*(maxi+1)/2
        ans += mini*(mini-1)/2
else:
    ans += c[0]*(c[0]+1)/2
    for i in range(1,clen,2):
        maxi = max([c[i],c[i+1]])
        mini = min([c[i],c[i+1]])
        ans += maxi*(maxi+1)/2
        ans += mini*(mini-1)/2
    
print(int(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):

import sys



def input():
    return sys.stdin.readline().strip()


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


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    ans = 0
    left = 0
    right = 0
    for i in range(len(S) - 1):
        if S[i] + S[i + 1] == "><":
            right += 1
            tmp = max(left, right)
            ans += tmp
            ans += sum([i for i in range(left)])
            ans += sum([i for i in range(right)])
            right = 0
            left = 0
        else:
            if S[i] == ">":
                right += 1
            elif S[i] == "<":
                left += 1
    else:
        if S[-1] == "<":
            left += 1
        else:
            right += 1
        tmp = max(left, right)
        ans += tmp
        ans += sum([i for i in range(left)])
        ans += sum([i for i in range(right)])
    print(ans)
    return


if __name__ == "__main__":
    main()

Solution (Python):
S = input().rstrip() + "
s0 = S[0]
A, cnt = [], 1
for s in S[1:]:
    if s==s0: cnt+=1
    else: A.append(cnt); cnt=1
    s0 = s
res, st = 0, 0
if S[0]==">":
    res += A[0]*(A[0]+1)//2
    st=1
for i in range(st,len(A),2):
    if i+1==len(A): res += A[i]*(A[i]+1)//2; break
    p, q = A[i], A[i+1]
    if p < q:
        res += q*(q+1)//2 + p*(p-1)//2
    else:
        res += q*(q-1)//2 + p*(p+1)//2
print(res)

Solution (Python):

S = input()
N = len(S)

increasing = S[0] == '<'
A = [] if increasing else [1]
cnt = 0
for c in S:
    f = c == '<'
    if f == increasing:
        cnt += 1
    else:
        A.append(cnt*(increasing*2-1))
        increasing = not increasing
        cnt = 1
A.append(cnt*(increasing*2-1))

if A[-1] > 0:
    A.append(-1)

m = iter(A)
res = 0

for a,b in zip(m,m):
    b = -b
    if a > b:
        a,b = b,a
    res += ((a-1)*a+(b+1)*b)

print(res//2)

Solution (Python):
s = input()
l = [0]
m = [0]
a = 0
b = 0
arr = []
for i in range(len(s)):
  if s[i] == '<':
    a += 1
  else:
    a = 0
  l.append(a)

  if s[len(s) - i - 1] == '>':
    b += 1
  else:
    b = 0
  m.append(b)
m = m[::-1]

for i in range(len(l)):
  arr.append(max(l[i], m[i]))
ans = sum(arr)
print(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 = input()
N = len(S) + 1
A = [0]*N

cnt = 0
for i in range(N):
    A[i] = cnt
    if i == N-1:
        break
    if S[i] == "<":
        cnt += 1
    else:
        cnt = 0

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

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 = list(input())
data=[0]*(len(S)+1)
for i in range(len(S)):
  if S[i] == "<":
    data[i+1] = data[i] + 1
for i in range(len(S)):
  if S[len(S) - i - 1] == ">":
    data[len(S) -i -1] = max(data[len(S)-i]+1, data[len(S)-1-i])
print(sum(data))

Solution (Python):

import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


S = S()

lis = [0] * (len(S) + 1)  
left = [0] * (len(S) + 1)
right = [0] * (len(S) + 1)
left_count = 0
for i, s in enumerate(S):
    if (s == '<'):
        left_count += 1
        left[i+1] = left_count
    else:
        left_count = 0

right_count = 0
i = len(S)
for s in reversed(S):
    if (s == '>'):
        right_count += 1
        right[i-1] = right_count
    else:
        right_count = 0
    i -= 1


ans = 0
for l, r in zip(left, right):
    ans += max(l, r)
print(ans)

Solution (Python):
s = input()
count = 1; memo = 0; x = 0
for i in range(1, len(s)):
    if s[i-1] == "<" and s[i] == ">":
        x += count*(count-1)//2
        memo = count
        count = 1
    elif s[i-1] == ">" and s[i] == "<":
        x += count*(count-1)//2+max(count, memo)
        memo = 0
        count = 1
    else:
        count += 1
else:
    if s[-1] == "<":
        x += count*(count+1)//2
    else:
        x += count*(count-1)//2+max(count, memo)
print(x)

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

l = 0
r = 0
ans = 0
for i in range(n):
    if '<' == s[i]:
        if r != 0:
            M = max(l,r)
            m = min(l,r)
            ans += M*(M+1)//2 + m*(m-1)//2
            r = 0
            l = 0
        l += 1
    if '>' == s[i]:
        r += 1

M = max(l,r)
m = min(l,r)
ans += M*(M+1)//2 + m*(m-1)//2
print(ans)

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

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

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

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

if S[0]=='<':
    n[0]==0
if S[-1]=='>':
    n[-1]==0
for i in range(1,len(S)):
    if S[i-1]=='<' and S[i]=='<':
        n[i] = n[i-1]+1
        n[i+1]=n[i]+1
    elif S[i-1]=='>' and S[i]=='<':
        n[i] = 0
        n[i+1]=1
        
for i in range(len(S)-1,-1,-1):
    if S[i]=='>':
        n[i]=max(n[i],n[i+1]+1)
        
print(sum(n))

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


num = [-1]*(len(S)+1)
index0 = list()
than = 0

for i in range(len(S)):
    if(S[i] == '<'):
        if(than == 0):
            num[i] = 0
            index0.append(i)
        than = 1
    else:
        than = 0
if(S[-1] == '>'):
    num[-1] = 0
    index0.append(len(S)+1)

if(index0[0] == 0):
    i = 1
    while(True):
        num[i] = num[i-1]+1
        if(i >= len(S)):break
        if(S[i] == '>'):
            break
        i+=1
    index0.pop(0)
if(len(index0)>0):
    if(index0[-1] == len(S)+1):
        i = len(S)-1
        while(True):
            num[i] = num[i+1]+1
            i-=1
            if(i < 0):break
            if(S[i] == '<'):break
        index0.pop(-1)

while(len(index0)>0):
        for i in reversed(range(0,index0[0])):
            if(S[i] == '<'):
                break
            num[i] = max(num[i],num[i+1]+1)
        for i in range(index0[0]+1,len(S)+1):
            num[i] = max(num[i],num[i-1]+1)
            if(i >= len(S)):break
            if(S[i]== '>'):break
        index0.pop(0)

ans = 0
for i in range(len(num)):
    ans += num[i]
print(ans)

Solution (Python):
S=list(str(input()))
ans=0
sofar=0
j=1
nax=0
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        ans+=j
        j+=1
    elif S[i]=='<' and S[i+1]=='>':
        ans+=j
        nax=j
        j=1    
    else:
        ans+=j
        if nax!=0:
            ans-=j
        j=1
        nax=0
    if j>nax:
        ans-=nax
        nax=0
if j>nax:
    ans+=j
    ans-=nax
print(ans)

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()

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

total=0
if s[0]=='>':
  cnt=s.find('<')
  if cnt==-1:
    cnt=len(s)
    s=''
  else:
    s=s[cnt:]
  total+=sigma(cnt)
  
flag=True
while flag:
  l=[]
  index1=s.find('>')
  if index1!=-1:
    for i in range(index1):
      l.append(s[i])
    s=s[index1:]
  else:
    l.extend(['<']*len(s))
    s=''
    flag=False
  index2=s.find('<')
  if index2!=-1:
    for i in range(index2):
      l.append(s[i])
    s=s[index2:]
  else:
    l.extend(['>']*len(s))
    s=''
    flag=False
  cnt1=l.count('>')
  cnt2=l.count('<')
  if cnt2<=cnt1:
    total+=sigma(cnt1)+sigma(cnt2-1)
  else:
    total+=sigma(cnt2)+sigma(cnt1-1)

print(total)

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

Solution (Python):
S = input()
num = [0] * (len(S) + 1)
min_cnt = 0
plu_cnt = 0
flag = 0
ans = 0
if S[0] == ">":
    flag = 1
for i in range(len(S)):
    if flag == 1:
        if S[i] == "<":
            flag = 0
            plu_cnt = 0
        else:
            plu_cnt += 1
            ans += plu_cnt
    if S[i] == "<":
        if min_cnt == 0:
            plu_cnt += 1
        else: 
            M = max(plu_cnt, min_cnt)
            m = min(plu_cnt, min_cnt)
           
           
            ans += ((M + 1) * M) // 2
            ans += (m*(m-1))//2
            plu_cnt, min_cnt = 0, 0
            plu_cnt += 1
    elif S[i] == ">" and flag == 0:
        min_cnt += 1
if flag == 1:
    plu_cnt, min_cnt = 0, 0
M = max(plu_cnt, min_cnt)
m = min(plu_cnt, min_cnt)
ans += ((M + 1) * M)//2
ans += (m*(m-1))//2
print(ans)

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

for i in reversed(range(len(S))):
  if S[i] == '>':
    if value[i+1] == 0 and value[i] == 0:
      value[i] = 1
    elif value[i] <= value[i+1]:
      value[i] = value[i+1] + 1
print(sum(value))

Solution (Python):
S = input()
l = [0] * (len(S)+1)
r = [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] == '>':
        r[i] = r[i+1] + 1
print(sum([max(l[i],r[i]) for i in range(len(S)+1)]))

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

Solution (Python):

s = input()
data = []
cnt = 0
for i in range(len(s)-1):
    cnt += 1
    if s[i] != s[i+1]:
        if s[i] == "<" and s[i+1] == ">":
            data.append(cnt)
            data.append(-1)
        else:
            data.append(cnt)
        cnt = 0
data.append(cnt+1)

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

ans = 0
for i in range(len(data)):
    if data[i] != -1:
        for j in range(1, data[i]+1):
            ans += j


print(ans)

Solution (Python):
s = input()
n = len(s)
a = [0]
for i in range(n):
    if s[i] == ">":
        temp = a[-1] - 1
        a.append(temp)
        if i == n - 1 or s[i + 1] == "<":
            a[i + 1] = 0
            for j in range(i, -1, -1):
                if s[j] == ">":
                    if s[j - 1] == "<":
                        a[j] = max(a[j], a[j + 1] + 1)
                    else:
                        a[j] = a[j + 1] + 1
                else:
                    break
    else:
        a.append(a[-1] + 1)
print(sum(a))

Solution (Python):
import sys

input = sys.stdin.readline


def left(N, S, a, i):
    a[i + 1] = 0
    v = 0
    while True:
        if i == 0:
            a[i] = v + 1
            break
        if S[i - 1] == ">":
            v += 1
            a[i] = v
            i -= 1
        else:
            a[i] = max(a[i], v + 1)
            break


def right(N, S, a, i):
    a[i] = 0
    v = 0
    while True:
        if i == N - 1:
            a[i + 1] = v + 1
            break
        if S[i + 1] == "<":
            i += 1
            v += 1
            a[i] = v
        else:
            a[i + 1] = max(a[i + 1], v + 1)
            break


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

    a = [0] * (N + 1)
    if S[0] == "<":
        right(N, S, a, 0)
    if S[-1] == ">":
        left(N, S, a, N - 1)
    for i in range(N - 1):
        if S[i:i + 2] == "><":
            left(N, S, a, i)
            right(N, S, a, i + 1)
    
    ans = sum(a)
    print(ans)


if __name__ == "__main__":
    main()

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()
n = len(s) + 1

a = [-1] * n
tmp = 0

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

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

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

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

print(sum(a))

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

a = [-1] * n
tmp = 0

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

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

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

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

print(sum(a))

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



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

print(sum(A))

Solution (Python):
def r(i):
    indr = s.find('<', i)
    return indr - i if indr != -1 else n - i - 1
def l(i):
    indl = s.rfind('>', 0, i)
    return i - indl -1 if indl != -1 else i 
s = input()
n = len(s) + 1
print(sum([max(r(i), l(i)) for i in range(n)]))

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

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


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

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

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


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

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







tmp = [-1] * (len(S) + 1)

for i in range(len(S) - 1):
    if S[i] == ">" and S[i + 1] == "<":
        tmp[i + 1] = 0
        
if S[0] == "<":
    tmp[0] = 0

if S[-1] == ">":
    tmp[-1] = 0

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

print(sum(tmp))

Solution (Python):
s = list(input())
l2r = [0]
r2l = [0]
n = len(s)
for i in range(n):
  if s[i] == '<':
    l = l2r[i]
    l2r.append(l+1)
  else:
    l2r.append(0)

for j in range(n):
  if s[n-1-j] == '>':
    r2l.append(r2l[j]+1)
  else:
    r2l.append(0)
invr2l = r2l[::-1]
ans = []
for i in range(n+1):
  m = max(l2r[i],invr2l[i])
  ans.append(m)

print(sum(ans))

Solution (Python):
s=input()
n=len(s)+1
mountain=[0,0]
count=[0,0]
sum=0
for i in range(n-1):
    if s[i]=="<":
        mountain[1]+=1
    else:
        if mountain[1]>0:
            sum+=(mountain[0]*(mountain[0]-1)+mountain[1]*(mountain[1]+1))//2+max([0,mountain[0]-count[1]])
            count=mountain
            mountain=[1,0]
        else:
            mountain[0]+=1

sum+=(mountain[0]*(mountain[0]-1)+mountain[1]*(mountain[1]+1))//2+max([0,mountain[0]-count[1]])

print(sum)

Solution (Python):
s = input()
n = len(s)+1
ans = 0
ls = [0 for _ in range(n)]
rs = [0 for _ in range(n)]
for i in range(n-1):
    if s[i] == '<':
        ls[i+1] = ls[i]+1
for i in range(n-1):
    if s[-1-i] == '>':
        rs[-2-i] = rs[-1-i]+1
for i,j in zip(ls,rs):
    ans += max(i,j)
print(ans)

Solution (Python):
if __name__ == '__main__':
    S = input()
    n = len(S)
    l_res = [0]
    r_res = [0]
    for i in range(n):
        if S[i] == '<':
            l_res.append(l_res[i] + 1)
        else:
            l_res.append(0)
    inv_S = S[::-1]

    for i in range(n):
        if inv_S[i] == '>':
            r_res.append(r_res[i] + 1)
        else:
            r_res.append(0)
    res = 0
    for l_cnt, r_cnt in zip(l_res, r_res[::-1]):
        res += max(l_cnt, r_cnt)
    print(res)

Solution (Python):
if __name__ == '__main__':
    S = input()
    n = len(S)
    l_res = [0]
    r_res = [0]
    for i in range(n):
        if S[i] == '<':
            l_res.append(l_res[i] + 1)
        else:
            l_res.append(0)
    inv_S = S[::-1]

    for i in range(n):
        if inv_S[i] == '>':
            r_res.append(r_res[i] + 1)
        else:
            r_res.append(0)
    res = 0
    for l_cnt, r_cnt in zip(l_res, r_res[::-1]):
        res += max(l_cnt, r_cnt)
    print(res)

Solution (Python):
s = input()
n = len(s)+1
ls = [0]*n
rs = [0]*n
for i in range(n-1):
    if s[i] == "<":
        ls[i+1] = ls[i]+1
for i in range(n-1):
    if s[-1-i] == ">":
        rs[-2-i] = rs[-1-i]+1
ans = 0
for i,j in zip(ls,rs):
    ans += max(i,j)
print(ans)

Solution (Python):
s = input() + "."
comp = []

cur = s[0]
streak = 0
count = 0

for i in range(len(s)):
    if s[i] == cur:
        streak += 1
    else:
        if (len(comp) == 0):
            if cur == ">":
                count += streak*(streak+1)//2
            elif i == (len(s) - 1):
                count += streak*(streak+1)//2
        elif cur == ">":
            prevStreak = comp[-1][1]
            count += (prevStreak*(prevStreak+1) + streak*(streak+1)) // 2
            count -= min(streak, prevStreak)
        elif i == (len(s) - 1):
            if cur == "<":
                count += streak*(streak+1)//2

        comp.append((cur, streak))
        streak = 1
        cur = s[i]

print(count)

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

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

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

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


def main():
  S = input()[:-1]

  N = len(S)+1

  from_left = [0]*N
  from_right = [0]*N

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

  for i, s in enumerate(S[::-1]):
    i = N-2-i
    if s == '<':
      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)


if(__name__ == '__main__'):
  main()

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

Solution (Python):
s = input()
l, count = [], 0
for i in s:
    if i=='>': count+=1
    else:
        if count: l.append(count)
        count = 0
if count: l.append(count); count = 0
j = 0
ans = []
if s[0]=='<': ans.append(0)
else:
    ans.append(l[0])
    l[0]-=1

for i in range(len(s)):
    if s[i]=='<': ans.append(ans[-1]+1)
    else:
        if i==0: ans.append(ans[-1]-1); continue
        if l[j]==0: j+=1
        if ans[-1]>=l[j]:
            l[j]-=1
            ans.append(l[j])
                
        else:
            ans[-1]=l[j]
            l[j]-=1
            ans.append(l[j])
print(sum(ans))

Solution (Python):
s = input()

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

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

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

print(ans)

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    s = input().rstrip('\n')
    n = len(s)
    ansl = [0]*(n+1)
    for i in range(n):
        if s[i] == '<':
            ansl[i+1] = ansl[i]+1
    for i in reversed(range(n)):
        if s[i] == '>':
            ansl[i] = max(ansl[i+1]+1,ansl[i])
    print(sum(ansl))

if __name__ == '__main__':
    main()

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)
shift_max = [0]*(n+1)

big_run = 0
for i in range(n):
    if S[i] == '<':
        big_run += 1
    else:
        big_run = 0
    shift_max[i+1] = big_run
small_run = 0
for i in reversed(range(n)):
    if S[i] == '>':
        small_run += 1
    else:
        small_run = 0
    shift_max[i] = max(shift_max[i],small_run)

print(sum(shift_max))

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

big_run = 0
for i in range(n):
    if S[i] == '<':
        big_run += 1
    else:
        big_run = 0
    shift_max[i+1] = big_run
small_run = 0
for i in reversed(range(n)):
    if S[i] == '>':
        small_run += 1
    else:
        small_run = 0
    shift_max[i] = max(shift_max[i],small_run)


print(sum(shift_max))

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] == '>' and ans[i] <= ans[i+1]:
        ans[i] = ans[i+1]+1
print(sum(ans))

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

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

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

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()

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]:
    if s[i] == ">":
        if a[i] <= a[i+1]:
            a[i] = a[i+1] + 1

print(sum(a))

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

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

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

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

for i in range(len(S)):
  if S[i] == "<":
    s_Count += 1
    if i == len(S)-1:
      max_sb = max(s_Count,b_Count)
      min_sb = min(s_Count,b_Count) - 1
      ans += max_sb * (max_sb+1) / 2 + min_sb * (min_sb+1) / 2
      s_Count = 0
      b_Count = 0
  elif S[i] == ">":
    b_Count += 1
    if i == len(S)-1 or S[i+1] == "<":
      max_sb = max(s_Count,b_Count)
      min_sb = min(s_Count,b_Count) - 1
      ans += max_sb * (max_sb+1) / 2 + min_sb * (min_sb+1) / 2
      s_Count = 0
      b_Count = 0
print(int(ans))

Solution (Python):
s = input()
left, right = [0,], [0,]
a, b = 0, 0
for i in range(len(s)):
    a = a+1 if s[i] == '<' else 0
    left.append(a)
    b = b+1 if s[-1*(i+1)] == '>' else 0
    right.append(b)

right.reverse()
ans = sum(max(x, y) for x, y in zip(left, right))
print(ans)

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

for idx in range(l):
    if s[idx] is '<':
        lst[idx+1] = max(lst[idx+1], lst[idx]+1)

for inv in range(1, l+1):
    if s[-inv] is '>':
        lst[-(inv+1)] = max(lst[-(inv+1)], lst[-inv]+1)


print(sum(lst))

Solution (Python):
s = list(input())
n = len(s)
s.append('<')
mini = 0
maxi = 0
p = 0

for i in range(n):
    if s[i] == '<':
        mini += 1
    else:
        maxi += 1
        if s[i+1] == '<':
            m = max(mini,maxi)
            p += (1 + m) * m // 2
            m = min(mini,maxi) - 1
            p += (1 + m) * m // 2
            mini = 0
            maxi = 0

if mini != 0:
    print(p + ((1+mini) * mini // 2))
else:
    print(p)

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

def main():
    s = input()
    ans, i, j = 0, 0, 0
    while i < len(s):
        if s[i] == '<':
            j = 0
            while i<len(s) and s[i] == '<':
                ans += j
                j += 1
                i += 1
        else:
            k = 1
            while i<len(s) and s[i] == '>':
                ans += k
                k += 1
                i += 1
            if j > k - 1:
                ans = ans - (k - 1) + j
    if s[-1] == '<':
        ans += j
    print(ans)
                
            
if __name__ == '__main__':
    main()

Solution (Python):


S = input()

A = [-1] * (len(S) + 1)

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

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

for i in reversed(range(len(S))):
    if S[i] == '>' and A[i] <= A[i+1]:
        A[i] = A[i+1] + 1

ans = 0
for a in A:
    ans += a
print(ans)