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

print(sum(arr))

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

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

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

print(sum(A))

Solution (Python):
s = input()
l = len(s)
idx = []
for i in range(l-1):
    if s[i] == ">" and s[i+1] == "<":
        idx.append(i+1)

idx = [0]+idx+[l]

L = []
cnt = 0
for i in range(len(idx)-1):
    L = s[idx[i]:idx[i+1]]

    for j in range(len(L)):
        a = L.count("<")
        b = L.count(">")
        k = max(a,b)
        r = min(a,b)
    if r >=1:
        cnt += k*(k+1)//2 + r*(r-1)//2
    else:
        cnt += k*(k+1)//2

print(cnt)

Solution (Python):
s=input()
n=len(s)+1
a,b=[0]*n,[0]*n
temp=0
for i,val in enumerate(s):
    if val=="<": temp+=1
    else: temp=0
    a[i+1]=temp
temp=0
for i,val in enumerate(s[::-1]):
    if val==">": temp+=1
    else: temp=0
    b[n-i-2]=temp
ans=0
for i,j in zip(a,b): ans+=max(i,j)
print(ans)

Solution (Python):
s = input()
s_l = [0] * (len(s) + 1)
s_r = [0] * (len(s) + 1)
for i in range(len(s)):
    if s[i] == '<':
        s_l[i + 1] = s_l[i] + 1
for i in range(len(s)):
    if s[- i - 1] == '>':
        s_r[- i - 2] = s_r[- i - 1] + 1
        
ans = 0
for i, j in zip(s_l, s_r):
    ans += max(i, j)
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] == '>' and a[i] <= a[i+1]:
        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] == '>' and a[i] <= a[i+1]:
        a[i] = a[i+1] + 1
print(sum(a))

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

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

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

Solution (Python):
s = input()

n = len(s)+1
L = [0]*(n)

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

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

Solution (Python):
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    def n2(x):
        return x*(x+1)//2

    s = input()
    s +='.'
    ans = 0
    p = 0
    n = 0
    prev_p= 0
    for i in range(len(s)-1):
        if s[i] == '>':
            n += 1
            if s[i+1] == '<' or s[i+1] == '.':
                ans += n2(n)
                ans -= min(n, prev_p)
                n = 0
        else:
            p += 1
            if s[i+1] == '>':
                ans += n2(p)
                prev_p = p
                p = 0
            elif s[i+1] == '.':
                ans += n2(p)
                p = 0
    print(ans)




if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
n = len(s)+1
v1 = [None]*n
v2 = [None]*n
v1[0] = 0
v2[-1] = 0
v = 0
for i,c in enumerate(s):
    if c=="<":
        v += 1
    else:
        v = 0
    v1[i+1] = v
v = 0
for i,c in enumerate(s[::-1]):
    if c==">":
        v += 1
    else:
        v = 0
    v2[n-2-i] = v
ans = [max(v1[i], v2[i]) for i in range(n)]
print(sum(ans))

Solution (Python):
s=input()
ans=0
a=[0]
for i in s:
  if i=='<':
    if a[-1]>=0:a[-1]+=1
    else:a+=[1]
  else:
    if a[-1]<0:a[-1]-=1
    else:a+=[-1]
n=len(a)
for i in range(n//2):
  i*=2
  j=i+1
  if a[i]<abs(a[j]):
    x=abs(a[j])
    y=a[i]-1
  else:
    x=abs(a[j])-1
    y=a[i]
  ans+=x*(x+1)//2+y*(y+1)//2
ans+=n%2*a[-1]*(a[-1]+1)//2
print(ans)

Solution (Python):
s=list(input())
ans=0
i=0
comp_s=[]
while i<len(s):
    if s[i]=='<':
        comp_s.append('<')
        tmp=0
        while i<len(s) and s[i]=='<':
            i+=1
            tmp+=1
        comp_s.append(tmp)
    elif s[i]=='>':
        comp_s.append('>')
        tmp=0
        while i<len(s) and s[i]=='>':
            i+=1
            tmp+=1
        comp_s.append(tmp)

    
j=1
sdata=[]
if comp_s[0]=='>':
    sdata.append((0,comp_s[1]))
    j+=2
for i in range(j,len(comp_s)-2,4):
    sdata.append((comp_s[i],comp_s[i+2]))
if comp_s[-2]=='<':
    sdata.append((comp_s[-1],0))


for l,r in sdata:
    ans+=l*(l-1)//2+r*(r-1)//2+max(l,r)
print(ans)

Solution (Python):

s = input()
c = 0
a = 0
p = ""
n = 0
for i in s:
    if i != p:
        if i == "<":
            if c < 0:
                a -= c * n
            else:
                a -= c * (n - 1)
            n = 2
            c = 1
        else:
            n = 2
            c -= 1
    else:
        if i == "<":
            c += 1
            n += 1
        else:
            c -= 1
            n += 1
    a += c
    p = i
if p == ">":
    if c < 0:
        a -= c * n
    else:
        a -= c * (n - 1)
print(a)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import groupby
    s = input()
    ans = 0
    prev = 0

    for k, g in groupby(s):
        l = len(list(g))
        if k == "<":
            ans += l * (l + 1) // 2
            prev = l
        else:
            ans += l * (l + 1) // 2
            ans -= min(l, prev)

    print(ans)


if __name__ == '__main__':
    main()

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

A=[0]*N
B=[0]*N

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

for k in range((N-1)-1,-1,-1):
    if S[k]==">":
        B[k]=B[k+1]+1
        
print(sum(map(lambda x:max(A[x],B[x]),range(N))))

Solution (Python):
s = input()

cnt_l = [0]*(len(s)+1)
cnt_r = [0]*(len(s)+1)

for i in range(1, len(s)+1):
    if s[i-1] == "<":
        cnt_l[i] = cnt_l[i-1] + 1
    else:
        cnt_l[i] = 0

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

ans = 0
for l, r in zip(cnt_l, cnt_r):
    ans += max(l, r)
print(ans)

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

Solution (Python):
S = input()
N=len(S)+1
SS = '>'+S+'<'
a = [-1]*(N+2)
for i in range(N+1):
    if SS[i] == '>' and SS[i+1]=='<':
        a[i+1]=0
b = a[1:-1]
c = a[1:-1]

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


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

ans = 0
for bb,cc in zip(b,c):
    ans += max(bb,cc) 

print(ans)

Solution (Python):
S = input()

r = 0
l = 0
ans = 0
val = 0
for i in range(len(S)):
    if(S[i] == "<"):
        if(l == 1):
            r = 1
            if(val > l):
                ans += val
                val = 0
                l = 0
            else:
                ans += l
                l = 0
        elif(l > 1):
            if(val > l):
                ans += (l*(l+1))//2+(val-l)
                l = 0
                r = 1
                val = 0
            else:
                ans += (l*(l+1))//2
                l = 0
                r = 1
                val = 0
        else:
            r += 1
    else:
        if(r):
            ans += (r*(r-1))//2
            val = r
            l = 1
            r = 0
        else:
            l += 1
if(l):
    if(l == 1):
        if(val > l):
            ans += val
        else:
            ans += l
    else:
        if(val > l):
            ans += (l*(l+1))//2+(val-l)
        else:
            ans += (l*(l+1))//2
else:
    ans += (r*(r+1))//2
print(ans)

Solution (Python):
S = input()
lst = []
cnt = 0
if S[0] == '<':
    flg = 0
else:
    flg = 1
for i in range(len(S)):
    if flg == 0:
        if S[i] == '<':
            cnt += 1
        elif S[i] == '>':
            lst.append(['<',cnt])
            cnt = 1
            flg = 1
    elif flg == 1:
        if S[i] == '<':
            lst.append(['>', cnt])
            cnt = 1
            flg = 0
        elif S[i] == '>':
            cnt += 1
if flg == 0:
    lst.append(['<',cnt])
else:
    lst.append(['>', cnt])


ans = 0
for i in range(1,len(lst)):
    if lst[i-1][0] == '<' and lst[i][0] == '>':
       n = max(lst[i-1][1],lst[i][1])
       n2 = min(lst[i-1][1],lst[i][1])
       ans += n * (n+1) /2
       ans += (n2-1)*n2 / 2

if lst[0][0] == '>':
    n3 = lst[0][1]
    ans += n3 * (n3 + 1) / 2
if lst[-1][0] == '<':
    n4 = lst[-1][1]
    ans += n4 * (n4+1) /2
print(int(ans))

Solution (Python):
S = input()
N = len(S)+1
x = [0 for _ in range(N)]
l = 0
while(l<N-1):
    r = l+1
    while(r<N-1 and S[r]==S[l]):
        r += 1
    if S[l]=='<':
        x[l] = 0
        for i in range(l+1, r+1):
            x[i] = max(x[i], x[i-1]+1)
    else:
        x[r] = 0
        for i in range(r-1, l-1, -1):
            x[i] = max(x[i], x[i+1]+1)
    l = r
print(sum(x))

Solution (Python):
s=list(input())
num=[]
str1="<"
if s[0]=="<":
    num1=1
else:
    num.append(0)
    str1=">"
    num1=1
for i in range(len(s)-1):
    if str1==s[i+1]:
        num1+=1
    else:
        if str1=="<":
            str1=">"
        else:
            str1="<"
        num.append(num1)
        num1=1
num.append(num1)
ans=0
if str1=="<":
    num.append(0)
for i in range(len(num)//2):
    ans+=((num[i*2]+1)*num[i*2])//2
    ans+=((num[i*2+1]+1)*num[i*2+1])//2
    ans-=min(num[i*2],num[i*2+1])
print(ans)

Solution (Python):
S = input()
S = S.replace('><','> <').split()

ans = 0
for i in S:
    j = max(i.count('>'),i.count('<'))
    k = min(i.count('>'),i.count('<'))-1
    for a in range(1,j+1):
        ans += a
    for b in range(1,k+1):
        ans += b

print(ans)

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


s = S()
n = len(s)
a = [0] * (n + 1)
for i in range(len(s)):
    if '<' == s[i]:
        a[i + 1] = a[i] + 1
for i in reversed(range(len(s))):
    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 I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


s = S()
n = len(s)
ans = 0
cnt = 0
before_cnt = 0
now = s[0]
for x in s:
    if now == x:  
        cnt += 1
    else:  
        ans += cnt * (cnt + 1) // 2
        if now == '>':  
            if before_cnt < cnt:
                ans -= before_cnt
            else:
                ans -= cnt

        before_cnt = cnt
        cnt = 1
        now = x

ans += cnt * (cnt + 1) // 2
if now == '>':
    if before_cnt < cnt:
        ans -= before_cnt
    else:
        ans -= cnt
print(ans)

Solution (Python):
s=list(input())
l=len(s)
ans=0

if len(set(s))==1:
    for i in range(1,l+1):
        ans+=i
    print(ans)
    exit()

for i in range(l-1):
    if s[i]=="<" and s[i+1]==">":
        left=1
        right=1
        for j in range(i):
            if s[i-j-1]=="<":
                left+=1
            else:
                break
        for j in range(l-i-2):
            if s[i+j+2]==">":
                right+=1
            else:
                break
        p=max(left,right)
        q=min(left,right)
        for j in range(p):
            ans+=(j+1)
        for j in range(q-1):
            ans+=(j+1)
if s[0]==">":
    ans+=1
    for i in range(1,l):
        if s[i]==">":
            ans+=(i+1)
        else:
            break
if s[-1]=="<":
    ans+=1
    for i in range(2,l+1):
        if s[-i]=="<":
            ans+=i
        else:
            break
print(ans)

Solution (Python):


import sys
import numpy as np
from itertools import groupby
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = readline().decode().rstrip()
cnt = [0] * (len(S) + 1)

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

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

print(sum(cnt))

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

Solution (Python):
S = input()

ans = 0
l, r = 0, 0
i = 0
while i < len(S):
    while i < len(S) and S[i] == "<":
        l += 1
        i += 1
    while i < len(S) and S[i] == ">":
        r += 1
        i += 1
    ans += l * (l + 1) // 2
    ans += r * (r + 1) // 2
    ans -= min(l, r)
    l, r = 0, 0
print(ans)

Solution (Python):
s = list(input())
l = [-1]
i = 0

while i < len(s):
    if s[i] == "<":
        l.append(l[i] + 1)
    if s[i] == ">":
        cnt = 0
        while s[i + cnt] == ">":
            if i + cnt == len(s) -1:
                cnt += 1
                break
            cnt += 1
        if l[i] < cnt:
            l.append(cnt)
        else:
            l.append(l[i] + 1)
        i += cnt
        cnt -= 1
        while cnt != -1:
            l.append(cnt)
            cnt -= 1
    i += 1
if s[len(s) -1] == "<":
    l.append(l[i] + 1)
del l[0]
ans = sum(l)
print(ans)

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

Solution (Python):
S = input()
count_more = 0
count_less = 0
ans = 0
pre_si = '>'
for i, si in enumerate(S):
    if pre_si == '>' and si == '<':
        max_n = max(count_more, count_less)
        min_n = min(count_more, count_less)
        ans += (max_n+1)*(max_n)//2
        
        ans += (min_n)*(min_n-1)//2
        count_more = 0
        count_less = 0
        
    if si == '<':
        count_more += 1
    elif si == '>':
        count_less += 1
    pre_si = si
max_n = max(count_more, count_less)
min_n = min(count_more, count_less)
ans += (max_n+1)*(max_n)//2
ans += (min_n)*(min_n-1)//2
print(ans)

Solution (Python):
S = input()
st_list =  []

for i in range(len(S)+1):
    if i==0:
        if S[i] == '<':
            st_list.append(i)
    elif i == (len(S)):
        if S[i-1] == '>':
            st_list.append(i)
    else:
        if (S[i-1] == '>') & (S[i] == '<'):
            st_list.append(i)
ans = [0] * (len(S)+1)
for i in st_list:
    j = i +1
    if j > (len(S)):
        pass
    else:
        while S[j-1] == '<':
            ans[j] = ans[j-1]+1
            j += 1
            if j > (len(S)):
                break

for i in st_list:
    j = i -1

    if j < 0:
        pass
    else:
        while S[j] == '>':
            ans[j] = max(ans[j+1]+1,ans[j])
            j -= 1
            if j < 0:
                break

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

Solution (Python):
a = [0]
n = 0

def main():
    global n
    for s in input():
        if s == "<":
            nproc()
            a.append(a[-1]+1)
        else:
            n += 1
    nproc()
    print(sum(a))

def nproc():
    global n, a
    if n > 0 and n > a[-1]:
        a[-1] = n
    for i in list(range(n))[::-1]:
        a.append(i)
    n = 0

if __name__ == "__main__":
    main()

Solution (Python):
s = input()
n = len(s)
t = [0]*(n+1)
tmp=0
for i in range(n):
  tmp+=1
  if s[i]=="<":
    t[i]=tmp-1
    t[i+1]=tmp
  else:
    tmp=0
    
tmp=0
for j in range(n)[::-1]:
  tmp+=1
  if s[j]==">":
    t[j+1]=max(tmp-1,t[j+1])
    t[j]=max(tmp,t[j])
  else:
    tmp=0

print(sum(t))

Solution (Python):
def run_length(data, init=''):
    length = []
    tmp = init
    cnt = 0
    for c in data:
        if tmp != c:
            length.append(cnt)
            cnt = 0
        tmp = c
        cnt += 1
    length.append(cnt)
    return length


def resolve():
    s = input()
    if s[0] != '<':
        s = '<' + s
    if s[-1] != '>':
        s = s + '>'

    array = run_length(s)
    ans = 0
    for i in range(1, len(array), 2):
        a,b = array[i], array[i+1]
        mn = min(a,b) - 1
        mx = max(a,b)
        ans += (mn+1) * (mn) // 2 + mx * (mx+1) // 2
    
    
    print(ans)

if __name__ == "__main__":
    resolve()

Solution (Python):
s=input()

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

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

for j in range(len(s)-1,-1,-1):
    if s[j]=='>':
        if a[j]>a[j+1]+1:
            continue
        else:
            a[j]=a[j+1]+1

print(sum(a))

Solution (Python):
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    s = S()
    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 = open(0).read()

a = [0]
streak = 0

for c in s:
    if c == '<':
        streak += 1

    else:
        streak = 0
    a.append(streak)


b = [0]
streak = 0

for c in s[::-1]:
    if c == '>':
        streak += 1

    else:
        streak = 0

    b.append(streak)
b = b[::-1]

print(sum([max(x, y)for x, y in zip(a, b)]))

Solution (Python):
s = input()

cnt = 0
ans = 0
tmp = 0
check = 0
for x in s:
    cnt += 1
    if x == '<':
        if check != cnt - 1:
            ans -= tmp * (cnt - check - 1)
            tmp = 0
        tmp += 1
        ans += tmp
        check = cnt
    else:
        tmp -= 1
        ans += tmp
        if tmp < 0:
            ans += (cnt -  check + 1)
            tmp += 1

print(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 j in range(len(S)-1,-1,-1):
    if S[j]==">":
        left[j]=left[j+1]+1
        
total=0
for k in range(len(S)+1):
    total+=max(right[k],left[k])
print(total)

Solution (Python):
import sys
sys.setrecursionlimit(1000000)
s=input()

l=[-1 for _ in range(len(s)+1)]
def aa(ix,v): 

  if (ix>= len(s) and v==1) or (ix==0 and v==0-1):
    return
  if v==1 and s[ix]=="<" and l[ix+1]<=l[ix]:
    l[ix+1]=l[ix]+1
    aa(ix+1,1)
  elif v==-1 and s[ix-1]==">" and l[ix-1]<=l[ix]:
    l[ix-1]=l[ix]+1
    aa(ix-1,-1)
  return

for i in range(0,len(s)):
  if i ==0 and s[0]=="<":    
    l[0]=0
    aa(i,1)
  elif i==len(s)-1 and s[-1]==">":
    l[-1]=0
    aa(i+1,-1)
  elif s[i]==">" and s[i+1]=="<":
    l[i+1]=0
    aa(i+1,1)
    aa(i+1,-1)

print(sum(l))

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
total=0
for i in range(len(S)+1):
    total+=max(right[i],left[i])
print(total)

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 bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=input()
lns=len(s)
lst=[0]*(lns+1)

start=[]
if s[0]=="<":
    start.append(0)
for i in range(lns-1):
    if s[i]==">" and s[i+1]=="<":
        start.append(i+1)
if s[lns-1]==">":
    start.append(lns)

for i in start:
    d=deque([[i,0],[i,1]])
    while d:
        now,lr=d.popleft()
        
        if now-1>=0 and lr==0 and s[now-1]==">":
            lst[now-1]=max(lst[now-1],lst[now]+1)
            d.append([now-1,0])
        if now+1<=lns and lr==1 and s[now]=="<":
            lst[now+1]=max(lst[now+1],lst[now]+1)
            d.append([now+1,1])
    


print(sum(lst))

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

Solution (Python):
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

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

s = input()
l = []
t = [0,0]
b = s[0]
if b=="<":
	a = 0
else:
	a = 1

i=0
while 1:
	if i>len(s)-1:
		l.append(t)
		break
	else:
		if b==s[i]:
			t[a]+=1
			i+=1
		elif s[i]==">":
			a=1
			b = ">"
		else:
			b = "<"
			a=0
			l.append(t)
			t = [0,0]



ans = 0

for i in l:
	ans += TS(i[0]-1)
	ans += TS(i[1]-1)
	ans += max(i)

print(ans)

Solution (Python):
s=list(input())
k=0
bef="x"
n=[]
ans=0
def kai(n):
  if n==0:
    return 0
  ret=0
  for i in range(1,n+1):
    ret+=i
  return ret

for i in s:
  if bef!=i:
    if bef=="x":
      st=i
      bef=i
      k+=1
      continue
    bef=i
    n.append(k)
    k=0
  k+=1
n.append(k)
n.reverse()
if st==">":
  ans+=kai(n.pop())
while len(n)!=0:
  if len(n)==1:
    ans+=kai(n.pop())
  else:
    f=n.pop()
    s=n.pop()
    if f>s:
      ans+=kai(f)+kai(s-1)
    else:
      ans+=kai(f-1)+kai(s)
    

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 reversed(range(len(S))):
    if S[i] == ">":
        A[i] = max(A[i], A[i + 1] + 1)

print(sum(A))

Solution (Python):
s=input()
a,b,c,d=0,0,0,0
for i in range(len(s)):
 if s[i]==">":
  c=0;b+=1
  if b<=d:a+=b-1
  else:a+=b
 else:b=0;c+=1;a+=c;d=c
print(a)

Solution (Python):


s = input()

a = [0]*(len(s)+1)
if len(s) == 1:
    print(1)
    exit()
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
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

S = s()
n = len(S)
num = 1
num2 = 1
ans = 0
Flag = 0

for i in range(n-1):
    if S[i] == S[i+1]:
        ans += num
        num += 1
    if S[i] == "<" and S[i+1] == ">":
        num2 = num
        num = 1
        Flag = 1
    if S[i] == ">" and S[i+1] == "<":
        ans += max(num,num2)
        num = 1
        Flag = 0

if Flag:
    ans += max(num,num2)
else:
    ans += num

print(ans)

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

S = s()
N = len(S)
num = 1
num2 = 1
ans = 0
Flag = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        ans += num
        num += 1
    if S[i] == '>' and S[i+1] == '<':
        ans += max(num,num2)
        num = 1
        Flag = 0
    if S[i] == '<' and S[i+1] == '>':
        num2 = num
        num = 1
        Flag = 1
if Flag:
    ans += max(num2,num)
else:
    ans += num
print(ans)

Solution (Python):
s = input()

cnt = [1] if s[0] == "<" else [0, 1]

bc = s[0]

for i in range(1, len(s)):
    if s[i] == bc:
        cnt[-1] += 1
    else:
        cnt.append(1)
    bc = s[i]

if len(cnt) % 2 == 1:
    cnt.append(0)


ans = 0

for i in range(0, len(cnt), 2):
    ma = max(cnt[i], cnt[i + 1])
    mi = min(cnt[i], cnt[i + 1])
    ans += max(0, ma * (ma + 1) // 2)
    ans += max(0, (mi - 1) * mi // 2)

print(ans)

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

l = [0] * N
r = [0] * N

tmp_l = 0

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

        tmp_l += 1
        l[i + 1] = tmp_l
    else:
        tmp_l = 0

tmp_r = 0


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

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

print(ans)

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

ans = 0
def leftmore(ln):
    ret = [0]
    cur = 0
    for c in ln:
        if c == "<":
            cur += 1
        else:
            cur = 0
        
        ret.append(cur)
    return ret

def rightless(ln):
    revl = reversed(ln)
    ret = [0]
    cur = 0
    for c in revl:
        if c == ">":
            cur += 1
        else:
            cur = 0
        ret.append(cur)
    return list(reversed(ret))

lm = leftmore(s)
rl = rightless(s)
for i in range(len(s)+1):
    ans += max(lm[i],rl[i])
print(ans)

Solution (Python):
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10
    tmp = 0
    S = list(input())
    N = len(S)+1
    A = [0]*N
    num_conti = 0
    for i in range(N-1):
        if S[i] == '<':
            num_conti += 1
        else:
            num_conti = 0
        A[i+1] = num_conti
    num_conti = 0
    for i in range(N-2,-1,-1):
        if S[i] == '>':
            num_conti += 1
        else:
            num_conti = 0
        A[i] = max(A[i],num_conti)
    print(sum(A))
    dbg(A)





    
main()

Solution (Python):
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10
    tmp = 0
    S = input()
    min_num = 0
    tmp_sum = 0
    diffs = deque()
    prev = ''
    ans = down = up = 0
    for i,c in enumerate(S):
        
        if c == '<':
            
            if prev == '>':
                ans += down*(down-1)//2
                ans += max(down,up)
                down = up = 0
            ans += up
            up += 1
        
        else:
            down += 1

        prev = c

    
    if S[-1] == '>':
        ans += down*(down-1)//2
        ans += max(down,up)
    if S[-1] == '<':
        ans += up

    print(ans)



    
main()

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

s=0
f=0
g=0
h=0
for i in range(len(S)):
    if S[i]==">":
        g=0
        f+=1
        if h>=f:
            s+=f-1
        else:
            s+=f
        
    else:
        f=0
        g+=1
        s+=g
        h=g

print(s)

Solution (Python):
S = input()

def count_ll(l):

    ret = [0]
    cur = 0

    for c in l:
        if c == "<":
            cur += 1
        else:
            cur = 0
        
        ret.append(cur)
    
    return ret

def count_rg(l):

    revl = reversed(l)
    ret = [0]
    cur = 0

    for c in revl:
        if c == ">":
            cur += 1
        else:
            cur = 0
        
        ret.append(cur)
    
    return list(reversed(ret))

l = count_ll(S)
r = count_rg(S)



N = len(S) + 1

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

print(ans)

Solution (Python):
s=input()
ans=0
c=1
temp=0
for i in range(len(s)):
    if i==0:
        ans+=1
    else:
        if s[i]==">" and s[i]==s[i-1]:
            c+=1
            if temp>=c:
                ans+=c-1
            else:
                ans+=c
        elif s[i]==">" and s[i]!=s[i-1]:
            temp=c
            c=1
        elif s[i]=="<" and s[i]==s[i-1]:
            c+=1
            ans+=c
        elif s[i]=="<" and s[i]!=s[i-1]:
            c=1
            tmp=0
            ans+=1
    
print(ans)