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):
def get_sequence(arr):
    if len(arr) == 0:
        return [], []
    elements = []
    nums = []
    n = 1
    prev = arr[0]
    for c in arr[1:]:
        if c == prev:
            n += 1
        else:
            elements.append(prev)
            nums.append(n)
            prev = c
            n = 1
    elements.append(prev)
    nums.append(n)
    return elements, nums

S = input()
ele, num = get_sequence(S)
ans = 0
s = (ele[0]=='>')

prev = 0
for n in num:
    if s:
        ans += max(n, prev)
    ans += n*(n-1)//2
    prev = n
    s = not s
if s:
    ans += n
print(ans)

Solution (Python):
def f(x):
    return (x + 1) * x // 2


def main():
    s = input()

    li = []
    prev = 0
    top = 0
    for i in range(len(s) - 1):
        cs = s[i:i+2]
        if cs == "<>":
            top = i + 1
        elif cs == "><":
            li.append((prev, top, i+1))
            prev = i + 1

    li.append((prev, top, len(s)))

    ans = 0
    for l, t, r in li:
        if l < t < r:
            ld = t - l
            rd = r - t
            mx = max(ld, rd)
            mn = min(ld, rd)
            sm = f(mx) + f(mn - 1)
            ans += sm

        else:
            sm = f(r - l)
            ans += sm

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
s = input()
N = len(s)
array = [0] * (N+1)
flg = False
for i in range(N):
    if s[i] == '<' and flg:
        array[i+1] = array[i] + 1
        continue
    if s[i] == '<':
        array[i+1] += 1
        flg = True
    else:
        flg = False
flg = False
for i in range(N):
    if array[N-(i+1)] > array[N-i]:
        continue
    if s[N-1-i] == '>' and flg:
        array[N-(i+1)] = array[N-i] + 1
        continue
    if s[N-1-i] == '>':
        array[N-(i+1)] += 1
        flg = True
    else:
        flg = False


print(sum(array))

Solution (Python):

S = list(input())
ans = 0
N = len(S)

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

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

i=0
tmp = 0
while (i<N):
    while (i<N and L[i] != 0): i+=1
    tmp = 0
    while (i<N and S[i] == '<'):
        tmp += 1
        L[i+1] = tmp
        i += 1
        

i=N
tmp = 0
while (i>0):
    while (i>0 and L[i] != 0): i-=1
    tmp = 0
    while (i>0 and S[i-1] == '>'):
        tmp += 1
        L[i-1] = max(L[i-1],tmp)
        i -= 1
    
print(sum(L))

Solution (Python):
S = input()

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

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):

    C = None
    n = 0
    l = []
    for c in S:
        if c != C:
            l.append((C, n))
            C = c
            n = 1
        else:
            n += 1
    l.append((C, n))
    l.pop(0)

    if l[0][0] == '>':
        l.insert(0, ('<', 0))
    if l[-1][0] == '<':
        l.append(('>', 0))

    ans = 0
    for i in range(0, len(l), 2):
        _, n1 = l[i]
        _, n2 = l[i+1]
        
        gn = max(n1, n2)
        ln = min(n1, n2) - 1
        ans += (gn**2 + gn)//2
        if ln > 0:
            ans += (ln**2 + ln)//2
    return ans


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()

Solution (Python):

import sys
sys.setrecursionlimit(10**8)


s = input().rstrip()
s = ">" + s + "<"
n = len(s)

lvs = []

ans = [-1] * n
lv = 0
for i, (ch1, ch2) in enumerate(zip(s, s[1:])):
    if ch1 == ">" and ch2 == "<":
        lv = 0
        ans[i+1] = lv
    if ch1 == "<":
        lv += 1
        ans[i+1] = lv

prev = s[-1]
lv = 0
for i in range(n-2, -1, -1):
    if s[i] == ">":
        lv += 1
        ans[i] = max(ans[i], lv)
    elif s[i] == "<":
        lv = 0
    prev = s[i]

print(sum(ans[1:]))

Solution (Python):
s=input()

temp=0
ans=0
check=0
for i in range(len(s)):
    if s[i]=='<':
        if temp>0 and s[i-1]=='>':
            ans=ans-(temp*check)
            temp=0
        
        check=0
        temp+=1
        ans+=temp
        i+=1
    else:
        check+=1
        temp-=1
        if temp<0:
            temp=0
            ans+=check
        else:
            ans+=temp
print(ans)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

S = str(input())
N = len(S)+1
a = [0]*N
ans = int(0)

SUMI = [0]*N
for i in range(N-1):
    SUMI[i+1] = SUMI[i] + (i+1)


k = 1
if S[0]==">":
    k*=(-1)
cur1 = int(0)
cur2 = int(0)
for i in S:
    if k==1:
        if i=="<":
            cur1 +=1
        else:
            k*=(-1)
            cur2 +=1
    else:
        if i==">":
            cur2 +=1
        else:
            k *=(-1)
            ans +=(SUMI[max(cur1,cur2)]+SUMI[max(min(cur1,cur2)-1,0)])
            cur1=1
            cur2=0


ans += (SUMI[max(cur1,cur2)]+SUMI[max(min(cur1,cur2)-1,0)])

print(ans)

Solution (Python):
s = input()
ans = 0
prev = None
l = 0
r = 0
for x in s:
  if x == '<':
    if prev == '>':
      mx = max(r, l)
      mn = min(r, l)
      ans += mx * (mx + 1) // 2 + mn * (mn - 1) // 2
      l = 0
      r = 0
    l += 1
  else:
    r += 1
  prev = x
else:
  mx = max(r, l)
  mn = min(r, l)
  ans += mx * (mx + 1) // 2 + mn * (mn - 1) // 2
print(ans)

Solution (Python):
S = str(input())
N = len(S) + 1
a = [-1] * N


def chmax(a, b):
    if a < b:
        a = b
    return a


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

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

for i in reversed(range(1, N)):
    if a[i] != -1 and S[i - 1] == ">":
        a[i - 1] = chmax(a[i - 1], a[i] + 1)

print(sum(a))

Solution (Python):
a=input()
ans=0
k=0
t=1
n=0
for i in range(len(a)):
  if t:
    if a[i]=="<":
      ans+=k
      k+=1
    else:
      n+=1
      t=0
  else:
    if a[i]==">":
      n+=1
    else:
      ans+=n*(n-1)//2
      ans+=max(k,n)
      n=0
      k=1
      t=1
if a[-1]=="<":
  ans+=k
else:
  ans+=n*(n-1)//2
  ans+=max(k,n)
print(ans)

Solution (Python):



import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 



s = input()
l = len(s)

def calc(a,b):
    c = max(a,b)
    d = min(a,b)
    return c*(c+1)//2 + (d-1)*d//2


now = ">"
ans = 0

cnt0 = 0 
cnt1 = 0 
for i in s:
    if now != i:
        now = i
        if i == "<":
            ans += calc(cnt0,cnt1)
            cnt0 = 1
            cnt1 = 0
        else: cnt1 += 1
    else:
        if i == ">": cnt1 += 1
        else: cnt0 += 1


if s[-1] == "<":
    ans += cnt0*(cnt0+1)//2
else:
    ans += calc(cnt0,cnt1)

print(ans)

Solution (Python):



import sys


def main():
    S = input()

    ary = [0]
    now = "<"

    for s in S:
        if s == now:
            ary[-1] += 1
        else:
            ary.append(1)
            now = s

    ans = 0
    for i in range(1, len(ary), 2):
        mi, ma = sorted([ary[i], ary[i-1]])
        ans += ma*(ma+1)//2
        ans += (mi-1)*mi//2
    if len(ary) % 2 == 1:
        ans += ary[-1]*(ary[-1]+1)//2
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
S=input()
S+="1"
A=[]
count1=0
count2=0
total=0
for i in range(600000):
    total+=i
    A.append(total)

total=0
for i in range(len(S)):
    if S[i]=="<":
        count1+=1
    if S[i]==">":
        count2+=1
    if S[i]==">" and S[i+1]=="<":
        total+=A[max(count1,count2)]
        if min(count1, count2) != 0:
            total+=A[min(count1,count2)-1]
        
        count1=0
        count2=0

total+=A[max(count1,count2)]
if min(count1,count2)!=0:
    total+=A[min(count1,count2)-1]




print(total)

Solution (Python):
S = input()
n = len(S)+1
A = [-1] * n
if (S[0] == '<'): A[0] = 0
if (S[-1] == '>'): A[-1] = 0
for i in range(n-2):
    if S[i] + S[i+1] == '><':
        A[i+1] = 0
for i in range(n-1):
    if (A[i] == -1): continue
    if S[i] == '<':
        A[i+1] = A[i] +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(input())
n=len(s)
l=[-1 for i in range(n+1)]
ct=0
ans=0
if s[0]=='<':l[0]=0
if s[n-1]=='>':l[n]=0
for i in range(n-1):
  if s[i]=='>' and s[i+1]=='<':
    l[i+1]=0
for i in range(n):
  if s[i]=='<':
    l[i+1]=l[i]+1
for i in range(n-1,-1,-1):
  if s[i]=='>':
    l[i]=l[i+1]+1

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

Solution (Python):
S = input()
N = len(S) + 1
ans = [0] * N
lc, rc = 0, 0
for i in range(N - 1):
    if S[i] == '<':
        ans[i + 1] = ans[i] + 1

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

print(sum(ans))

Solution (Python):
s = input()
n = len(s)
box = []

l = 1
for i in range(n-1):
    if s[i+1] == s[i]:
        l += 1
    else:
        box.append(l)
        l = 1
box.append(l)

def sum_(a):
    return (a+1) * a // 2

ans = 0
if s[0] == '>':
    ans += sum_(box[0])
    if (len(box)-1) % 2 == 1:
        ans += sum_(box[-1])
        for i in range(1, len(box)-1, 2):
            if box[i+1] >= box[i]:
                ans += sum_(box[i+1]) + sum_(box[i]-1)
            else:
                ans += sum_(box[i]) + sum_(box[i+1]-1)
    else:
        for i in range(1, len(box)-1, 2):
            if box[i+1] >= box[i]:
                ans += sum_(box[i+1]) + sum_(box[i]-1)
            else:
                ans += sum_(box[i]) + sum_(box[i+1]-1)
else:
    if len(box) % 2 == 1:
        ans += sum_(box[-1])
        for i in range(0, len(box) - 1, 2):
            if box[i + 1] >= box[i]:
                ans += sum_(box[i + 1]) + sum_(box[i] - 1)
            else:
                ans += sum_(box[i]) + sum_(box[i + 1] - 1)
    else:
        for i in range(0, len(box) - 1, 2):
            if box[i + 1] >= box[i]:
                ans += sum_(box[i + 1]) + sum_(box[i] - 1)
            else:
                ans += sum_(box[i]) + sum_(box[i + 1] - 1)

print(ans)

Solution (Python):
S = input()
n = len(S) + 1
S_ = ">" + S + "<"
A = [0 for _ in range(n)]
B = [0 for _ in range(n)]
for i in range(1, n):
    if S_[i] == "<":
        A[i] = A[i-1] + 1
for i in range(2, n+1):
    if S_[-i] == ">":
        B[-i] = B[-i+1] + 1
ans = 0
for i in range(n):
    ans += max(A[i], B[i])
print(ans)

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

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

ae = [0] * n
for j in range(n - 2, -1, -1):
    if s[j] == '>':
        ae[j] = ae[j + 1] + 1
    else:
        ae[j] = 0

print(sum([max(aw[i], ae[i]) for i in range(n)]))

Solution (Python):
S = input()

prev = S[0]
start = 0
ans = [0]
for i in range(len(S)):
    if S[i]==prev:
        if S[i]=="<":
            ans.append(ans[-1]+1)
        else:
            ans.append(ans[-1]-1)
    else:
        
        if prev==">":
            for j in range(start,i+1):
                if j==start:
                    ans[start] = max(ans[start],ans[start]-ans[-1])
                else:
                    ans[j]-=ans[-1]
        start = i
        prev = S[i]
        if S[i]=="<":
            ans.append(ans[-1]+1)
        else:
            ans.append(ans[-1]-1)

if prev==">":
    for j in range(start,len(S)+1):
        if j==start:
            ans[start] = max(ans[start],ans[start]-ans[-1])
        else:
            ans[j]-=ans[-1]


print(sum(ans))

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
 
def main():
    s = input().strip()
    
    
    
    
    
    
    
    
    
    
    
    fwd = [0]
    rev = [0]
    tmp = 0
    mn = 0
    for ch in s:
        
        if ch == "<":
            tmp += 1
        else:
            tmp = 0
        fwd.append(tmp)
 
    for ch in s[::-1]:
        
        if ch == ">":
            tmp += 1
        else:
            tmp = 0
        rev.append(tmp)
    rev.reverse()
    
    print(sum([max(i, j) for i, j in zip(fwd, rev)]))
 
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return
 
if __name__ == "__main__":
    main()

Solution (Python):
s = input()
ans = 0
now = s[0]
MAX = 1
n = 1
for i in s[1:]:
  if now != i:
    if i == ">":
      ans += n*(n-1)//2
      MAX = n
    else:
      ans += n*(n-1)//2 + max(MAX,n)
      MAX = 1
    n = 1
    now = i
  else:
    n += 1

MAX = max(MAX,n)
ans += n*(n-1)//2 + max(MAX,n)
print(ans)

Solution (Python):
s = input()
n = len(s)+1
A = [None]*n
flag = False
for i in range(n-1):
    if i==0 and s[i]=='<':
        A[0]=0
    elif 1<=i<=n-2 and s[i-1]=='>' and s[i]=='<':
        A[i]=0
    elif i==n-2 and s[i]=='>':
        A[n-1]=0
for i in range(n-1):
    if A[i]==0:
        flag = True
    if flag and s[i]=='<':
        A[i+1] = A[i]+1
    if flag and s[i]=='>':
        flag = False
for i in range(n-1):
    if A[-1-i]==0:
        flag = True
    if flag and s[-1-i]=='>':
        if A[-2-i] == None:
            A[-2-i] = A[-1-i]+1
        else:
            A[-2-i] = max(A[-2-i],A[-1-i]+1)
    if flag and s[-1-i]=='<':
        flag = False
print(sum(A))

Solution (Python):
import itertools
import re
s = input()
pattern = "<+|>+"
result = re.finditer(pattern, s)

lis_list = []
for res in result:
  tmp = res.group()
  
  if tmp[0]=="<":
    lis = list(range(len(res.group())+1))
  else:
    lis = list(reversed(list(range(len(res.group())+1))))

  lis_list.append(lis)



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

all = list(itertools.chain.from_iterable(lis_list))
print(sum(all))

Solution (Python):
s=input()
s=s+"X"
lists=[]
counter=1
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        counter+=1
    else:
        lists.append(counter)
        counter=1
n=len(lists)
if s[0]=="<" and s[-2]=="<":
    lists.append(1)
    
elif s[0]=="<" and s[-2]==">":
    pass
    
elif s[0]==">" and s[-2]=="<":
    lists.insert(0,1)
    lists.append(1)
    
elif s[0]==">" and s[-2]==">":
    lists.insert(0,1)
    
k=len(lists)//2
ans=0
for i in range(k):
    a=lists[i*2]
    b=lists[i*2+1]
    maxi=max(a,b)
    mini=min(a,b)
    ans+=maxi*(maxi+1)//2+mini*(mini-1)//2
print(ans)

Solution (Python):
from itertools import groupby
s=input()
if s[0]=='>':
  s='<'+s
g=groupby(s)
a=[]
for i,j in g:
  a.append(len(list(j)))
def sum(n):
  return n*(n+1)//2
x=0
if len(a)%2==1:
  a+=[1]
for i in range(0,len(a),2):
  x+=sum(min(a[i],a[i+1])-1)
  x+=sum(max(a[i],a[i+1]))
print(x)

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

now=0
chi=0
swit=0
kao=[]
if s[0]=='<':
    kao.append(0)

for i in range(ng):
    if s[i]=='>':
        swit=1
    else:
        if swit==1:
            kao.append(i)
        swit=0

if s[-1]=='>':
    kao.append(ng)


kaz=[-1]*(ng+1)
for k in kao:
    kaz[k]=0

for i in range(len(kao)):
    swit=0
    ima=kao[i]
    while swit==0:
        if ima+1<len(kaz):
            if s[ima]=='<':
                kaz[ima+1]=kaz[ima]+1
                ima+=1
            else:
                swit=1
        else:
            swit=1

for i in range(len(kao)):
    swit=0
    ima=kao[i]-1
    loop=0
    while swit==0:
        loop+=1
        if ima>=0:
            if s[ima]=='>':
                if kaz[ima]<kaz[ima+1]+1:
                    kaz[ima]=kaz[ima+1]+1
                ima-=1
            else:
                swit=1
        else:
            swit=1

print(sum(kaz))

Solution (Python):
s = list(input())
l_ans = [0 for _ in range(len(s)+1)]
r_ans = [0 for _ in range(len(s)+1)]
ans = [0 for _ in range(len(s)+1)]
l_level = 0
r_level = 0
for i in range(len(s)):
    if s[i] == '<':
        l_level += 1
    else:
        l_level = 0
    l_ans[i+1] = l_level

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

for i in range(len(ans)):
    ans[i] = max(l_ans[i], r_ans[i])


print(sum(ans))

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

N = len(Ss) - 1

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

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

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

Solution (Python):


import array
import math
import os
import sys


def main():
    S = inp()
    print(solve(S))


def solve(S):
    N = len(S) + 1
    A = [-1] * N

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

    for i in range(N):
        if A[i] != 0:
            continue

        j = i - 1
        while j >= 0 and S[j] == '>':
            A[j] = max(A[j], A[j + 1] + 1)
            j -= 1

        j = i + 1
        while j < N and S[j - 1] == '<':
            A[j] = max(A[j], A[j - 1] + 1)
            j += 1

    dprint(A)
    return sum(A)





DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


def rle(s):
    import itertools
    return list(map(lambda x: (x[0], len(list(x[1]))), itertools.groupby(s)))


s = rs()
ss = rle(s)
res = 0
index = 0
if ss[0][0] == '>':
    x = ss[0][1]
    res += x * (x + 1) // 2
    index = 1
for xx, yy in zip(ss[index::2], ss[index + 1::2]):
    x = xx[1]
    y = yy[1]
    z = max(x, y)
    w = min(x, y) - 1
    res += z * (z + 1) // 2 + w * (w + 1) // 2
if ss[-1][0] == '<':
    x = ss[-1][1]
    res += x * (x + 1) // 2
print(res)

Solution (Python):
S = input()

nums = []

cnt = 1
pre = S[0]

for i in range(1, len(S)):
    if pre != S[i]:
        nums.append(cnt)
        pre = S[i]
        cnt = 1
    else:
        cnt += 1

nums.append(cnt)

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


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

ans = 0
for i in range(len(nums) // 2):
    max_ = max(nums[2 * i], nums[2 * i+1])
    min_ = min(nums[2 * i], nums[2 * i+1])
    ans += cal_sum(max_)
    ans += cal_sum(min_ - 1)

print(ans)

Solution (Python):
s=input()
c,d,e,f=0,0,0,0
for i in s:
    if i=="<":
        if e==0:
            c+=1
        else:
            e=0
            c,d=max(c,d),min(c,d)
            f+=(c*(c+1))//2+(d*(d-1))//2
            c,d=1,0
    else:
        e=1
        d+=1
c,d=max(c,d),min(c,d)
print(f+(c*(c+1))//2+(d*(d-1))//2)

Solution (Python):
S = input()
ns = [0 for i in range(len(S) + 1)]

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

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

s = 0
for n in ns:
    s += n

print(s)

Solution (Python):
def main():
    s=list(input())
    key=0
    key2=0
    cnt1=0
    cnt2=0
    ans=0
    for i in range(len(s)):
        if key==0 and s[i]=="<":
            cnt1+=1
            key2=1
        elif key==0 and s[i]==">":
            key=1
            cnt2+=1
            key2=0
        elif key==1 and s[i]==">":
            cnt2+=1
            key2=0
        elif key==1 and s[i]=="<":
            M=max(cnt1,cnt2)
            m=min(cnt1,cnt2)
            ans+= (( M * (M+1) )//2 ) + (( m * (m-1) ) //2 )
            key=0
            key2=1
            cnt1=1
            cnt2=0
    if key==1:
        M=max(cnt1,cnt2)
        m=min(cnt1,cnt2)
        ans+= (( M * (M+1) )//2 ) + (( m * (m-1) ) //2 )
    if key2==1:
        ans+=(cnt1*(cnt1+1))//2
    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from itertools import groupby
    s=input()
    if(s[0]==">"):
        s="<"+s
    if(s[-1]=="<"):
        s=s+">"
    G=groupby(s)
    ans=0
    for i,g in enumerate(G):
        if(i%2==0):
            a=len(list(g[1]))
        else:
            b=len(list(g[1]))
            c=max(a,b)
            ans+=a*(a-1)//2+b*(b-1)//2+c
    print(ans)
resolve()

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

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

Solution (Python):

S = input()
now = 0
ans = 0
las = ""
lasstr = 0

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

for i in range(len(S)):

    if S[i] == "<":
        lis[i+1] = max(lis[i+1],lis[i]+1)



for i in range(len(S)):

    i = len(S)-1 - i

    if S[i] == ">":
        lis[i] = max(lis[i],lis[i+1]+1)


print (sum(lis))

Solution (Python):
s=input()
n=len(s)-1
cut =[-1]+ [i for i in range(len(s)-1) if s[i:i+2]=="><" ] + [n]
div = [s[cut[i]+1:cut[i+1]+1] for i in range(len(cut)-1)]
ans=0
for d in div:
    sr = d.count("<")
    sl = d.count(">")
    smax=max(sr,sl)
    smin=min(sr,sl)
    ans+=smax*(smax+1)//2 + smin*(smin-1)//2
print(ans)

Solution (Python):
s = input()
if s[0] == '>':
  s = '<' + s
if s[-1] == '<':
  s = s + '>'
feat = []
combo = 1
n = len(s)
for i in range(1,n):
  if s[i-1] == s[i]:
    combo += 1
  else:
    feat.append(combo)
    combo = 1
feat.append(combo)

m = len(feat)
ans = 0
for i in range(m):
  ans += feat[i] * (feat[i]-1) // 2
for j in range(m//2):
  ans += max( feat[2*j] , feat[2*j+1] )
print(ans)

Solution (Python):


s = input()
n = len(s)
ans = 0
t = 0
d = 0
m=0
for i in range(n):
    if s[i] == "<":
        d = 0
        t += 1
        ans += t
    else:
        if d==0:
            m = t
        t = 0
        d += 1
        ans += d-1
        if d-1 >= m:
            ans +=1
    
            
print(ans)

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

a = "<"
b = ">"

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

L = len(S)
t = 0

bc = 0
if S[0] == b:
  bc = 0
  for i in range(L):
    if S[i] == b:
      bc += 1
    else:
      t = i
      break
  else:
    print(nasu(bc))
    exit()
      
ans = nasu(bc)
bc = 0
ac = 0
f = True

while t < L:
  if f:
    if S[t] == a:
      ac += 1
    else:
      bc += 1
      f = False
  else:
    if S[t] == b:
      bc += 1
    else:
      if ac > bc:
        ac, bc = bc, ac
      ans += nasu(ac - 1) + nasu(bc)
      ac = 1
      bc = 0
      f = True
  t += 1

if bc != 0:
  if ac > bc:
    ac, bc = bc, ac
  ans += nasu(ac - 1) + nasu(bc)
else:
  ans += nasu(ac)

print(ans)

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

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

ans_r = [-1] * N
ans_r[-1] = 0
combo = 0
for j in range(N - 1):
    i = N - 2 - j
    if S[i] == '>':
        combo += 1
    else:
        combo = 0
    ans_r[i] = combo



ans = [max(tmp_l, tmp_r) for tmp_l, tmp_r in zip(ans_l, ans_r)]

print(sum(ans))

Solution (Python):
def main():
    s = input()
    max_ = 0
    min_ = 0
    cnt = 0
    l=[0]
    for i in range(len(s)):
        if s[i] == "<":
            cnt += 1
        else:
            cnt = 0
        l.append(cnt)
    cnt = 0
    for i in range(len(s),0,-1):
        if s[i-1] == ">":
            cnt += 1
        else:
            cnt = 0
        l[i-1]=max(l[i-1],cnt)
    print(sum(l))
main()

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

Solution (Python):
S = input()
a = 0
hoge = -1
v = 0
ans = 0
for i in S:
    if i == "<":
        a += 1
        ans += a
        v = a
        hoge = -1
    else:
        hoge += 1
        a = 0
        if hoge < v:
            ans += hoge
        else:
            ans += hoge+1
print(ans)

Solution (Python):
s = ">" + input() + "<"
n = len(s)-1
a = [10**10 for _ in range(n)]

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

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



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



print(sum(a))

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

S=input().strip()

from collections import deque
Q=deque(S)

ANS=0

count=0
while len(Q)>0 and Q[0]==">":
    count+=1
    Q.popleft()

ANS+=count*(count+1)//2
count=0

while len(Q)>0 and Q[-1]=="<":
    count+=1
    Q.pop()

ANS+=count*(count+1)//2

if Q==deque():
    print(ANS)
    sys.exit()

Q=list(Q)

count=1
LIST=[]

for i in range(1,len(Q)):
    if Q[i]==Q[i-1]:
        count+=1
    else:
        LIST.append(count)
        count=1

LIST.append(count)

for i in range(0,len(LIST),2):
    s,t=sorted((LIST[i],LIST[i+1]))

    ANS+=t*(t+1)//2+s*(s-1)//2

print(ANS)

Solution (Python):
s = input()
n = len(s)
INF = 10**9
ans = [INF] * (n+1)


memo = {}
if s[0] == "<":
    ans[0] = 0
    memo[0] = 1 
if s[n-1] == ">":
    ans[n] = 0
    memo[n] = 1
for i in range(n-1):
    if s[i] == ">" and s[i+1] == "<":
        ans[i+1] = 0
        memo[i+1] = 1
        

for i in memo:
    cnt = 1
    tmp = i - 1
    while True:
        if tmp >= 0 and s[tmp] == ">":
            ans[tmp] = cnt
            cnt += 1
            tmp -= 1
        else:
            break
    cnt = 1
    tmp = i
    while True:
        if tmp < n and s[tmp] == "<":
            ans[tmp+1] = cnt
            cnt += 1
            tmp += 1
        else:
            break

for i in range(n-1):
    if s[i] == "<" and s[i+1] == ">":
        ans[i+1] = max(ans[i], ans[i+2]) + 1
print(sum(ans))

Solution (Python):
import itertools
s = input()

ans = [0]
si = itertools.groupby(s)
for key, value in si:
    l = len(list(value))

    if key == "<":
        for i in range(1, l+1):
            ans.append(i)
    else:
        if ans[-1] < l:
            ans.pop()
            for i in range(1, l+1):
                ans.append(i)
        else:
            for i in range(1, l):
                ans.append(i)

print(sum(ans))

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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 LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = S()
    s.insert(0,">")
    n = len(s)
    s.append("<")
    f = [0]*n
    l = []
    for i in range(n):
        if s[i] == ">" and s[i+1] == "<":
            f[i] = 1
            l.append(i)
    ans = [0]*n
    for i in l:
        j = i
        while j < n-1 and not f[j+1] and s[j+1] == "<":
            ans[j+1] = max(ans[j+1],ans[j]+1)
            j += 1
    for i in l:
        j = i
        while j > 0 and not f[j-1] and s[j] == ">":
            ans[j-1] = max(ans[j-1],ans[j]+1)
            j -= 1
    print(sum(ans))
    return


if __name__ == "__main__":
    solve()

Solution (Python):

import math
def solve():
  s = input()
  n = len(s) + 1
  que = [0]*n
  que2 = [0]*n
  now = 0
  for i in range(n-1):
    if s[i] == "<":
      que[i+1] = now + 1
      now += 1
    else:
      now = 0
      que[i+1] = now

  s2 = s[::-1]
  now = 0
  for i in range(n-1):
    if s2[i] == ">":
      que2[i+1] = now+1
      now += 1
    else:
      now = 0
      que2[i+1] = now
  que2 = que2[::-1]
  ans = 0
  for i in range(n):
    ans += max(que[i],que2[i])
  print(ans)

solve()

Solution (Python):
S=input()
l=len(S)
L1=[0]*(l+1)
L2=[0]*(l+1)
for i in range(l):
    if S[i]=='<':
        L1[i+1]=L1[i]+1
    else:
        L1[i+1]=0
for i in reversed(range(l)):
    if S[i]=='>':
        L2[i]=L2[i+1]+1
    else:
        L2[i]=0
Ans=[0]*(l+1)
for i in range(l+1):
    Ans[i]=max(L1[i],L2[i])
print(sum(Ans))

Solution (Python):
S = input()

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

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