Problem:
 Score : 300 points    Problem Statement Given is a string S of length N-1 .
Each character in S is < or > .  A sequence of N non-negative integers, a_1,a_2,\cdots,a_N , is said to be good when the following condition is satisfied for all i ( 1 \leq i \leq N-1 ):   If S_i=  < : a_i<a_{i+1}  If S_i=  > : a_i>a_{i+1}   Find the minimum possible sum of the elements of a good sequence of N non-negative integers.      Constraints  2 \leq N \leq 5 \times 10^5  S is a string of length N-1 consisting of < and > .         Input Input is given from Standard Input in the following format:  S       Output Find the minimum possible sum of the elements of a good sequence of N non-negative integers.        Sample Input 1 <>>      Sample Output 1 3  a=(0,2,1,0) is a good sequence whose sum is 3 .
There is no good sequence whose sum is less than 3 .       Sample Input 2 <>>><<><<<<<>>><      Sample Output 2 28

Solution (Python):



import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=SI()
if s[0]!="<":
    s="<"+s
if s[-1]!=">":
    s=s+">"

state="<"
strs=[]
count=0
for i in range(len(s)):
    if state=="<":
        if s[i]=="<":
            count+=1
        else:
            strs.append(count)
            count=1
            state=">"
    else:
        if s[i]==">":
            count+=1
        else:
            strs.append(count)
            count=1
            state="<"
strs.append(count)

ans=0
for i in range(len(strs)//2):
    u=min(strs[2*i],strs[2*i+1])
    v=max(strs[2*i],strs[2*i+1])
    ans+=(u-1)*u//2+v*(v+1)//2
print(ans)

Solution (Python):
S = list(input())
N = len(S)+1
cnt = [0] * N
j = 0
k = 0

for i in range(N-2):
    if S[i] == S[i+1]:
        k += 1
    
    else:
        k += 1
        cnt[j] = k
        j += 1
        k = 0

if S[N-2] == S[N-3]:
    cnt[j] = k + 1
else:
    cnt[j] = 1

ans = 0
if S[0] == "<":
    st = 0
else:
    ans += cnt[0]*(cnt[0]+1)//2
    st = 1

for k in range(st,N,2):
    if cnt[k] != 0:
        m = min(cnt[k],cnt[k+1])
        M = max(cnt[k],cnt[k+1])
        ans += m*(m-1)//2 + M*(M+1)//2 
    else:
        break
print(ans)

Solution (Python):
s = input()
n = len(s) + 1
alist = [0]*n
slist = []
k = 0
for i in range(1,n-1):
    if s[i-1] == '>' and s[i] == '<':
        slist.append(s[k:i])
        k = i
slist.append(s[k:])

ans = 0

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

Solution (Python):
s = input()
left = 0
cou = 0
k = 0
l = [0 for i in range(len(s)+1)]
for i in range(len(s)):
  s1 = s[i]
  a1 = l[i]

  if s1=='<':
    l[i+1] = l[i]+1
    left = 0
    k = l[i+1]
  else:
    l[i+1] = l[i]-1
    left += 1
    if l[i+1]>=0:
      l[i+1] = 0
    else:
      l[i+1] =0
      if k>=left:
        cou += left-1
      else:
        cou += left
print(cou+sum(l))

Solution (Python):
import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() 
ni = lambda: int(readline().rstrip()) 
nm = lambda: map(int, readline().split()) 
nl = lambda: list(map(int, readline().split())) 

ans = []
s = ns()
n = len(s) + 1
now = 0
min_now = 0

ri = deque()
le = deque()

now = 0
for i in range(n-1):
    if s[i] == '<':
        now += 1
    else:
        now = 0
    le.append(now)
now = 0
for i in range(n-1):
    if s[(n-2)-i] == '>':
        now += 1
    else:
        now = 0
    ri.appendleft(now)
le.appendleft(0)
ri.append(0)

for i in range(n):
    ans.append(max(le.popleft(), ri.popleft()))

print(sum(ans))

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

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

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) - 1, -1, -1):
    if s[i] == ">":
        data[i] = max(data[i], data[i + 1] + 1) 
print(sum(data))

Solution (Python):
s = input()
right_cnt = 0
left_cnt = 0
total = 0
for i in range(len(s)):
  if s[i] == '<' and left_cnt == 0:
    right_cnt += 1
  elif s[i] == '<' and left_cnt > 0:
    k = max(right_cnt, left_cnt)
    l = min(right_cnt, left_cnt)
    total += (((k+1)*k) + (l*(l-1)))//2
    right_cnt = 1
    left_cnt = 0
  elif s[i] == '>':
    left_cnt += 1
k = max(right_cnt, left_cnt)
l = min(right_cnt, left_cnt)
total += (((k+1)*k) + (l*(l-1)))//2
print(total)

Solution (Python):
s = input()
prev = s[0]
n = len(s)
cnt= 0
L = [0]*(n+1)
R = [0]*(n+1)
for i in range(n):
    if s[i] =="<":
        cnt+=1
    else:
        cnt=0
    L[i+1] = cnt
s= s[::-1]
for i in range(n):
    if s[i] ==">":
        cnt+=1
    else:
        cnt=0
    R[i+1] = cnt
ans = 0
for i in range(n+1):
    ans+=max(L[i],R[-i-1])
print(ans)

Solution (Python):
import sys
def S(): return sys.stdin.readline().rstrip()
S = S()
seq = [0]*(len(S)+1)
for i in range(len(S)):
    if S[i]=='<':
        seq[i+1] = seq[i]+1
for j in range(len(S)-1,-1,-1):
    if S[j]=='>':
        seq[j] = max(seq[j],seq[j+1]+1)
print(sum(seq))

Solution (Python):
import sys
def S(): return sys.stdin.readline().rstrip()
S = S()
seq = [0]*(len(S)+1)
for i in range(len(S)):
    if S[i]=='<':
        seq[i+1] = seq[i]+1
for j in range(len(S))[::-1]:
    if S[j]=='>':
        seq[j] = max(seq[j],seq[j+1]+1)
print(sum(seq))

Solution (Python):
import itertools,sys
def S(): return sys.stdin.readline().rstrip()
S = S()
groupby_S = itertools.groupby(S)
ans = 0
rangeN = [i for i in range(len(S)+1)]
rangeN_accumulate = list(itertools.accumulate(rangeN))
group = []
temp = []
for k,g in groupby_S:
    if k=='<':
        temp.append(len(list(g)))
    else:
        temp.append(len(list(g)))
        group.append(temp)
        temp = []
group.append(temp)
for x in group:
    if len(x)==0:
        continue
    elif len(x)==1:
        ans += rangeN_accumulate[x[0]]
    else:
        a,b = max(x),min(x)-1
        ans += rangeN_accumulate[a]
        ans += rangeN_accumulate[b]
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    s=input()
    ls=len(s)
    a=[0]*(ls+1)
    for i in range(ls):
        if s[i]=='<':
            a[i+1]=a[i]+1
    for j in reversed(range(ls)):
        if s[j]=='>':
            a[j]=max(a[j+1]+1,a[j])
    print(sum(a))
resolve()

Solution (Python):
def main():
    S = input()
    smaller_cnt = [0]  
    seq_cnt = 0
    for c in S:
        if c != '<':
            seq_cnt = 0
        else:
            seq_cnt += 1
        smaller_cnt.append(seq_cnt)
    larger_cnt = [0]  
    for c in S[::-1]:
        if c != '>':
            seq_cnt = 0
        else:
            seq_cnt += 1
        larger_cnt.append(seq_cnt)
    larger_cnt.reverse()
    ans = 0
    for x, y in zip(smaller_cnt, larger_cnt):
        ans += max([x, y])
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

import math

def main():
    s = str(input())
    first = s[0]
    cnt_l = []
    tmp_cnt = 1
    prev_s = first
    for curr_s in s[1:]:
        if prev_s != curr_s:
            cnt_l.append(tmp_cnt)
            tmp_cnt = 1
        else:
            tmp_cnt+=1
        prev_s = curr_s
    cnt_l.append(tmp_cnt)

    ans_l = []
    last_num = 0
    if first == '>':
        down_cnt = cnt_l[0]
        for d in range(down_cnt):
            ans_l.append(down_cnt-d)
        cnt_l = cnt_l[1:]

    
    
    ans_l.append(0)
    last_num = 0
    for i in range(math.ceil(len(cnt_l)/2)):
        
        up_cnt = cnt_l[i*2]
        if i*2+1 >= len(cnt_l):
            down_cnt = 0
        else:
            down_cnt = cnt_l[i*2+1]
        
        
        for u in range(up_cnt):
            if u != up_cnt-1:
                last_num+=1
                ans_l.append(last_num)
            else:
                last_num = max(last_num+1, down_cnt)
                ans_l.append(last_num)
        for d in range(down_cnt):
            if d==0:
                if last_num > down_cnt:
                    last_num = down_cnt-1
                else:
                    last_num-=1
                ans_l.append(last_num)
            else:
                last_num-=1
                ans_l.append(last_num)

    
    print(sum(ans_l))

if __name__ == "__main__":
    main()

Solution (Python):

S = input()
List=[0]*(len(S)+1)
i=0
while i<len(S):
    if S[i]=="<":
        List[i+1]=List[i]+1
    i+=1
j=1
while j<=len(S):
    if S[-j]==">":
        List[-(j+1)]=max(List[-j]+1,List[-(j+1)])
    j+=1
print(sum(List))

Solution (Python):
import numpy as np
s = list(input())

judge = 0
judge_min = 0
base = np.zeros(len(s))
for i in range(len(s)):
  if s[-(i+1)] == ">":
    judge += 1
    base[-(i+1)] = judge
  elif s[-(i+1)] == "<":
    judge = 0

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

print(int(ans))

Solution (Python):
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)


def solve(s):
    start_up = s[0] == "<"
    curr_up = start_up
    counts = [1]
    for c in s[1:]:
        if curr_up == (c == "<"):
            counts[-1] += 1
        else:
            curr_up = not curr_up
            counts.append(1)

    curr_up = start_up
    result = counts[0]*(counts[0]-1)//2
    if not curr_up:
        result += counts[0]
    for i in range(1, len(counts)):
        if curr_up:
            result += max(counts[i-1], counts[i])
        result += counts[i]*(counts[i]-1)//2
        curr_up = not curr_up
    if curr_up:
        result += counts[-1]

    return result


if __name__ == "__main__":
    s = str_in()
    out(solve(s))

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

ans = 0

cnt0 = 0
if S[0] == ">":
    cnt0 += 1
    j = 1
    while j <= len(S)-1 and S[j] == ">":
        cnt0 += 1
        j += 1
ans += cnt0*(cnt0+1)//2


for i in range(1, N-1):
    if S[i-1] == "<" and S[i] == ">":
        j = i-1
        k = i+1
        cnt1 = 0
        cnt2 = 0
        if S[i-1] == "<" and i >= 0:
            while j >= 0 and S[j] == S[i-1] :
                cnt1 += 1 
                j -= 1
        if S[i] == ">":
            while k <= N-1 and S[i] == S[k-1]:
                cnt2 += 1
                k += 1 
        ans += max(cnt1, cnt2)*(max(cnt1, cnt2)+1)//2
        ans += (min(cnt1, cnt2)-1)*(min(cnt1, cnt2))//2


cntn = 0
if S[-1] == "<":
    cntn += 1
    j = -2
    while j >= -len(S) and S[j] == "<":
        cntn += 1
        j -= 1
ans += cntn*(cntn+1)//2


print(ans)

Solution (Python):
def cum(n):
  cum = 0
  for i in range(n+1):
    cum += i
  return cum


s = input()

tmp = s[0]
count = 0
l = []

for each in s:
  if each == tmp:
    count += 1
  else:
    l.append(count)
    count = 1
    tmp = each

l.append(count)

ans = 0
if s[0] == "<":
  for i in range(0,len(l),2):
    tmp = l[i:i+2]
    if len(tmp) == 1:
      ans += cum(tmp[0])
    else:
      ans += cum(max(tmp)) + cum(min(tmp)-1)
else:
  ans += cum(l[0])
  for i in range(1, len(l),2):
    tmp = l[i:i+2]
    if len(tmp) == 1:
      ans += cum(tmp[0])
    else:
      ans += cum(max(tmp)) + cum(min(tmp)-1)

print(ans)

Solution (Python):
s = str(input()) + '0'
ans = [0] * (len(s))

cnt = 0
for i in range(len(s)):
    ans[i] = cnt
    if s[i] == '<':
        cnt += 1
    else:
        cnt = 0

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

print(sum(ans))

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

Solution (Python):
S = input()

N1 = [0]*(len(S)+1)
N2 = [0]*(len(S)+1)

count1 = 0
count2 = 0

for i in range(len(S)):
  if S[i] == "<":
    count1 += 1
    N1[i+1] = count1
  else:
    count1 = 0
    
for i in range(len(S)):
  if S[-(i+1)] == ">":
    count2 += 1
    N2[-(i+2)] = count2
  else:
    count2 = 0
ans = 0
for i in range(len(N1)):
  ans += max(N1[i],N2[i])
print(ans)

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

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

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

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 = list(map(str, input().rstrip()))

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

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

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

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

print(sum(ans))

Solution (Python):
s = input()
n = len(s)
dp = [0]*(n+1)
t = 0
for e,i in enumerate(s,1):
    if i=='<' :
        dp[e]=dp[e-1]+1

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

print(sum(dp))

Solution (Python):
S=list(str(input()))
a=[]
b=[]

count = 1
direction=S[0]
for i in range(1,len(S)):
  if S[i]== direction:
    count += 1
  else:
    a.append(S[i-1])
    b.append(count)
    direction=S[i]
    count=1
a.append(S[-1])
b.append(count)
m=max(b)+1
dp=[0]*m
for i in range(1,m):
  dp[i] += dp[i-1]+i
ans=0
for i in range(1,len(a)):
  if a[i-1]=='<' and a[i]=='>':
    ans+=dp[max(b[i-1],b[i])] + dp[min(b[i-1],b[i])-1]
  
if a[0]=='>':
  ans+=dp[b[0]]
if a[-1]=='<':
  ans+=dp[b[-1]]
print(ans)

Solution (Python):



import itertools

s_list = input()

n = len(s_list) + 1
a_list = [0]*n
tmp_list = [0]*n

gr = itertools.groupby(s_list)

idx = 0
_tmp = 0
for key, group in gr:
    _num = sum(1 for _ in group)
    if key == "<":
        a_list[idx:idx+_num+1] = list(range(_num+1))
    else:
        a_list[idx] = max(_tmp,_num)
        a_list[idx+1:idx+_num] = list(range(_num-1,0,-1))
        tmp_list[idx] = _num
    idx += _num
    _tmp = _num



print(sum(a_list))

Solution (Python):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    S = input()

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


if __name__ == '__main__':
    main()

Solution (Python):
def sigma(x):
    a = 0
    for i in range(x):
        a += i + 1
    return a

s = input()
ans = 0
prev = ''
cnt = 0
p_cnt = 0
for i in s:
    if i == prev:
        cnt += 1
    else:
        if i =='<':
            ans += sigma(cnt - 1) + max(cnt, p_cnt)
        else:
            ans += sigma(cnt - 1)
        prev = i
        p_cnt = cnt
        cnt = 1
else:
    if prev == '<':
        ans += sigma(cnt)
    else:
        ans += sigma(cnt - 1) + max(cnt, p_cnt)
print(ans)

Solution (Python):
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():  
    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))    
if __name__ == '__main__':
    main()

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):
s = input()
lens = len(s)

if s[0] == ">":
	gcnt, lcnt = 0, 1
else:
	gcnt, lcnt = 1, 0
ans = 0

for i in range(lens-1):
	if s[i] == ">":
		if s[i+1] == "<":
			ans += (gcnt*(gcnt-1))//2
			ans += (lcnt*(lcnt-1))//2
			ans += max(gcnt, lcnt)
			gcnt = 1
			lcnt = 0
		else:
			lcnt += 1
	else:
		if s[i+1] == "<":
			gcnt += 1
		else:
			lcnt += 1

ans += (gcnt*(gcnt-1))//2
ans += (lcnt*(lcnt-1))//2
ans += max(gcnt, lcnt)
print(ans)

Solution (Python):
def main():
    A = list(input())
    cnt = 0
    nums_right = []
    nums_left = []
    current_right = 0
    current_left = 0
    for a in A:
        nums_right.append(current_right)
        if a == "<":
            current_right += 1
        else:
            current_right = 0
    else:
        nums_right.append(current_right)

    for a_ in A[::-1]:
        nums_left.append(current_left)
        if a_ == ">":
            current_left += 1
        else:
            current_left = 0
    else:
        nums_left.append(current_left)

    nums_left = nums_left[::-1]

    for nr, nl in zip(nums_right, nums_left):
        cnt += max(nr, nl)
    print(cnt)


if __name__ == '__main__':
    main()

Solution (Python):
s = input()

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

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

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

Solution (Python):
S = list(map(str, input()))
N = len(S)+1
List = [0]*N
rightcount = 0
leftcount = 0

if S[0] == "<":
    leftcount+=1
else:
    rightcount+=1

for i in range(1, N-1):
    if S[i] == "<":
        leftcount+=1
        if S[i-1] == "<":
            List[i] = List[i-1]+1
        elif S[i-1] == ">":
            for j in range(rightcount):
                List[i-j] = j
            if List[i-rightcount]<=List[i-rightcount+1]:
                List[i-rightcount] = List[i-rightcount+1] + 1
            rightcount = 0


    if S[i] == ">":
        rightcount+=1
        if S[i-1] =="<":
            for j in range(leftcount+1):
                List[i-j] = leftcount - j
            leftcount = 0

if S[N-2] == "<":
    List[N-1] = List[N-2] + 1
else:
    for j in range(rightcount):
        List[N-1-j] = j
    if List[N-1-rightcount]<=List[N-1-rightcount+1]:
        List[N-1-rightcount] = List[N-1-rightcount+1] + 1

print(sum(List))

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

Solution (Python):
s=input()
n=len(s)
l=[[0,0] for i in range(n+1)]
ri,le=0,0
for i in range(n):
    l[i][0]=le
    l[-1-i][1]=ri
    if "<"==s[i]:le+=1
    else:le=0
    if ">"==s[-1-i]:
        ri+=1
    else:ri=0

l[n][0]=le
l[0][1]=ri
print(sum(max(a,s) for a,s in l))

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

S = input()

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

ans = 0
for t in S:
    a = t.count(">")
    b = t.count("<")
    tmp = max(a, b) + sum(range(a)) + sum(range(b))
    ans += tmp
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):
s = input()

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

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

for j in range(larger_count+1):
    a[len(a)-j-1] = max(a[len(a)-j-1], j)

print(sum(a))

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

Solution (Python):

import itertools
S = input()
RevS = reversed(S)
L = [0]
R = [0]
cur = 0
for s in S:
    if s == "<":
        cur += 1
    else:
        cur = 0
    L.append(cur)
cur = 0
for r in RevS:
    if r == ">":
        cur += 1
    else:
        cur = 0
    R.append(cur)
R.reverse()
ans = 0
for n in range(len(S)+1):
    ans += max(L[n],R[n])
print(ans)

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

ans = 0

for s in S:
    small = s.count('<')
    big = s.count('>')
    tmp = max(small,big)\
        + (max(small,big)-1)*max(small,big)//2\
        + (min(small,big)-1)*min(small,big)//2
    ans += tmp
print(ans)

Solution (Python):
import numpy as np
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)
    else:
        a[i] = max(a[i],a[i+1]+1)

for i in range(len(S)-1,-1,-1):
    if S[i] == '<':
        a[i+1] =max(a[i+1], a[i]+1)
    else:
        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] = max(a[i+1], a[i]+1)
    if s[n-i-1] == '>':
        a[n-i-1] = max(a[n-i-1], a[n-i]+1)
print(sum(a))

Solution (Python):
S = input()
num = []
pre = S[0]
cnt = 0
for s in S:
    if s == pre:
        cnt += 1
    else:
        num.append(cnt)
        pre = s
        cnt = 1
num.append(cnt)

if S[0] == '>':
    num = [1] + num
if S[-1] == '<':
    num += [1]

ans = 0
for i in range(0, len(num), 2):
    b = max(num[i], num[i+1])
    c = min(num[i], num[i+1])
    ans += (b*(b+1))//2 + ((c-1)*c)//2
print(ans)

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

lr = []
num = []
a = S[0]
cnt = 0
for s in S:
    if s == a:
        cnt += 1
    else:
        num.append(cnt)
        if a == '<':
            lr.append(1)
        else:
            lr.append(0)
        a = s
        cnt = 1
num.append(cnt)
if a == '<':
    lr.append(1)
else:
    lr.append(0)

ans = 0
if (len(lr) == 1 and lr[0] == 0) or (len(lr) > 1 and lr[0] == 0):
    ans += (num[0]*(num[0]+1))//2
    lr, num = lr[1:], num[1:]
if (len(lr) == 1 and lr[0] == 1) or (len(lr) > 1 and lr[-1] == 1):
    ans += (num[-1]*(num[-1]+1))//2
    lr.pop()
    num.pop()

if not lr:
    print(ans)
    exit()

for i in range(0, len(lr), 2):
    if num[i] == num[i+1]:
        b = num[i]
        c = num[i]
    elif num[i] < num[i+1]:
        b = num[i+1]
        c = num[i]
    else:
        b = num[i]
        c = num[i+1]
    ans += (b*(b+1))//2 + ((c-1)*c)//2
print(ans)

Solution (Python):
s=input()
s+='?'
x=[]
ch=1
if s[0]=='>':
    x.append(0)
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        ch+=1
    else:
        x.append(ch)
        ch=1
x.append(0)
a=0
for i in range(len(x)-1):
    if i%2==0 and x[i]<=x[i+1]:
        a+=x[i+1]
        for j in range(x[i]):
            a+=j
        for j in range(x[i+1]):
            a+=j
    elif i%2==0 and x[i]>x[i+1]:
        a+=x[i]
        for j in range(x[i]):
            a+=j
        for j in range(x[i+1]):
            a+=j
if (len(x)-1)%2==1:
    for j in range(x[len(x)-1]):
        a+=j
print(a)

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

i = 0
left = 0
right = 0
ans = 0
tmp = 0

while i < n-1:
	if s[i] == '<':
		break
	i += 1
	tmp += 1
ans += tmp * (tmp + 1) // 2
while i < n-1:
	if i == n-2:
		if s[i] == '>':
			right += 1
			break
		else:
			left += 1
			break
	if s[i] == '<' and s[i+1] == '>':
		left += 1
		while True:
			if s[i+1+right] == '>':
				right += 1
				if i+1+right == n-1:
					break
			else:
				break
		if left >= right:
			ans += left * (left + 1) // 2 + (right - 1) * right // 2
		else:
			ans += right * (right + 1) // 2 + (left - 1) * left // 2
		i += right + 1
		left = 0
		right = 0
	elif s[i] == '<':
		left += 1
		i += 1

print(ans + left * (left + 1) // 2 + right * (right + 1) // 2 )

Solution (Python):
def compute_score(sub):
    max_i = max(sub)
    min_i = min(sub)
    score = max_i * (max_i + 1) * (1 /2) + min_i * (min_i - 1) * (1/2)
    return score

S = input()
sub = [0, 0]
ans = 0
flag = False
for s in S:
    if s == '<' and flag:
        ans += compute_score(sub)
        sub = [0, 0]
        flag = False
    if s == '>':
        flag = True
    if s == '<':
        sub[0] += 1
    else:
        sub[1] += 1
ans += compute_score(sub)
print(int(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 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):
def main():
	S = input()
	h = [0] * (len(S) + 1)

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

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

	print(sum(h))

if __name__ == "__main__":
	main()

Solution (Python):
s = input()
n=len(s)
R=[0]*(n+1)
L=[0]*(n+1)
for i in range(n):
    if s[i]=='<':
        R[i+1]=R[i]+1
for i in range(n-1,-1,-1):
    if s[i]=='>':
        L[i]=L[i+1]+1
res = [x if x>y else y for x,y in zip(R,L)]
print(sum(res))

Solution (Python):
s = input()
cnt = 0
n = len(s)
al = [0]*(n+1)
ag = [0]*(n+1)
for i in range(n):
    if s[i] == '<':
        al[i+1] = al[i] + 1
for i in range(n-1, -1, -1):
    if s[i] == '>':
        ag[i] = ag[i+1] + 1
a = [x if x > y else y for x, y in zip(al, ag)]
print(sum(a))

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

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

for i in range(n)[::-1]:
    if s[i] == '>':
        a_greater[i] = a_greater[i+1] + 1

a = [x if x > y else y for x, y in zip(a_less, a_greater)]

print(sum(a))

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

A = [0 for _ in range(n)]
for i in range(n - 1):
    prev = A[i]
    if S[i] == "<":
        A[i + 1] = max(A[i + 1], prev + 1)

for i in range(n - 1):
    j = n - i - 2
    prev = A[j + 1]
    if S[j] == ">":
        A[j] = max(A[j], prev + 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 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
from sys import stdin

s = stdin.readline().rstrip()
n = len(s)
s = '|' + s + '|'
r = [0] * (n + 1)
l = [0] * (n + 1)

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

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

print(ans)

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

sstreak = 0
bstreak = 0
for i in range(len(S)):
  if S[i] == "<":
    if 0 < bstreak:
      A[i-bstreak] = max(bstreak, sstreak)
      bstreak -= 1
      while 0 < bstreak:
        A[i-bstreak] = bstreak
        bstreak -= 1
      sstreak = 0
    A[i] = sstreak
    sstreak += 1
  else:
    bstreak += 1
i+=1
if S[-1] == "<":
  A[i] = sstreak

if 0 < bstreak:
  A[i-bstreak] = max(bstreak, sstreak)
  bstreak -= 1
  while 0 < bstreak:
    A[i-bstreak] = bstreak
    bstreak -= 1

print(sum(A))

Solution (Python):

def main():
    S = list(input())
    lenS = len(S)
    bfr = -1
    cnt = 0
    ans = []
    dwn = 0
    S.append('<')
    while cnt <= lenS:
        nxt = S[cnt]
        if nxt == '<' and dwn == 0:
            ans.append(max(0,bfr+1))
            bfr = max(0, bfr+1)
            cnt += 1
        elif nxt == '<' and dwn > 0:
            ans.append(max(bfr+1, dwn))
            ans += range(dwn-1, -1, -1)
            bfr = 0
            cnt += 1
            dwn = 0
        else:
            dwn += 1
            cnt += 1
    
    print(sum(ans))

if __name__ == "__main__":
    main()

Solution (Python):
import sys
import re
import math
import collections
import decimal
import bisect
import itertools







INF = sys.maxsize


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    s = list(sys.stdin.readline())
    del s[len(s)-1]
    l = len(s) + 1
    ans = [0] * l

    tmp = 1
    for i in range(len(s)):
        if s[i] == "<":
            ans[i + 1] = tmp
            tmp += 1
        else:
            tmp = 1

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

    print(sum(ans))

if __name__ == '__main__':
    main()

Solution (Python):
s=input()
SUM=0
p=0;q=0
b=0

j=0
while s[j]==">":
    j+=1
    if j==len(s):
        break
SUM+=(1+j)*j//2
if j!=len(s):
    h=s[j]
    for i in range(j,len(s)):
        if s[i]==h and b==0:
            p+=1
        if s[i]!=h:
            q+=1
            b=1
        if (s[i]==h and b==1) or (i==len(s)-1):
            w1=max(p,q)
            w2=min(p,q)
            SUM+=(1+w1)*w1//2+w2*(w2-1)//2
            if (s[i]==h and b==1) and (i==len(s)-1):
                SUM+=1
            b=0
            p=1;q=0
        
print(SUM)

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

s='|'+s+'|'

dp=[0]*(n+1)



R = [0]*(n+1)
L = [0]*(n+1)


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

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

print(ans)

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

s='|'+s+'|'

dp=[0]*(n+1)



R = [0]*(n+1)
L = [0]*(n+1)


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

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

print(ans)