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

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    s = list(input()[:-1].decode())
    n = len(s) + 1
    arr = [0] * n
    for i in range(n - 1):
        if s[i] == '<':
            arr[i + 1] = arr[i] + 1
        else:
            arr[i + 1] = 0
    for i in reversed(range(n - 1)):
        if s[i] == '>':
            arr[i] = max(arr[i], arr[i + 1] + 1)

    print(sum(arr))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

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

count=[0]*(N+1)
i=0
while i<N:
    if S[i]=='<':
        count[i+1]=count[i]+1
    i+=1

S=S[::-1]
count=count[::-1]
i=0
while i<N:
    if S[i]=='>':
        count[i+1]=max(count[i+1],count[i]+1)
    i+=1

print(sum(count))

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

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


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-1):
	if S[N-i-2] == ">":
		tmp_r += 1
		r[i+1] = tmp_r
	else:
		tmp_r = 0
r = r[::-1]

t = [max(r[i], l[i]) for i in range(N)]
print(sum(t))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


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

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





print(ans)

Solution (Python):



def main():
    S = input()
    n = len(S)+1
    left=[0]*n
    right=[0]*n
    for i,s in enumerate(S):
        if s=='<':
            left[i+1]=left[i]+1
    for i,s in enumerate(S[::-1]):
        if s=='>':
            right[n-i-2]=right[n-i-1]+1
    ret =0
    for i in range(n):
        ret+= max(left[i],right[i])
    print(ret)

if __name__ == '__main__':
    main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

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

ans = [-1]*(N)

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

if S[0] == "<":
	ans[0] = 0

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

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



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


print(sum(ans))

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

    idx_list = list([0])
    part = list()

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

    idx_list.append(len(S))

    if len(idx_list) == 1:
        part.append(S)
    else:
        for i in range(len(idx_list) - 1):
            part.append(S[idx_list[i]:idx_list[i+1]])

    ans = 0
    for p in part:
        G, L = 0, 0

        for j in range(len(p)):
            if p[j] == "<":
                G += 1
            else:
                L += 1

        tmp = 0
        if G < L:
            tmp += L*(L+1)//2 + G*(G-1)//2
        elif G > L:
            tmp += G*(G+1)//2 + L*(L-1)//2
        else:
            tmp += G*(G+1)//2 + L*(L-1)//2

        ans += tmp
        
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
S = input()

l = len(S)
x = [0]*(l+1)
y = [0]*(l+1)
for i in range(l):
    if S[i] == "<":
        x[i+1] = x[i]+1
for i in range(l):
    if S[l-i-1] == ">":
        y[l-i-1] = y[l-i]+1

res = 0
for a, b in zip(x, y):
    res += max(a, b)

print(res)

Solution (Python):

import collections
















import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

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

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

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


for i in range(ln-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)
if s[0]=="<":
    nari=0
    scnt,dcnt=0,1
else:
    nari=1
    scnt,dcnt=1,0
ans=0
sfla,dfla=0,0
for i in range(n):
    if nari==0:
        if s[i]=="<":
            scnt+=1
        elif s[i]==">":
            ans+=scnt*(scnt-1)//2
            sfla=scnt
            nari=1
            scnt=1
            dlas=0

    elif nari==1:
        if s[i]==">":
            dcnt+=1
        elif s[i]=="<":
            ans+=dcnt*(dcnt-1)//2
            dfla=dcnt
            nari=0
            dcnt=1
            dlas=1
            ans+=(max(dfla,sfla))
    
if dcnt!=1:
    ans+=dcnt*(dcnt+1)//2
elif scnt!=1:
    ans+=scnt*(scnt+1)//2
else: ans+=1
print(ans)

Solution (Python):
s = str(input())
di = []
k = 1
p = 0
for i in range(1,len(s)):
    if s[i-1] != s[i]:
        di.append(k)
        k = 1
        continue
    k += 1
di.append(k)
t = 1
p = 0
for l in range(1,len(s)):
    if s[l-1] == "<" and s[l] == ">":
        p += min(di[t-1],di[t])
        t += 1
    if s[l-1] == ">" and s[l] == "<":
        t += 1
ls = [e for e in range(max(di)+1)]
import numpy 
new_ls = numpy.cumsum(numpy.array(ls))
q = 0
for j in di:
    q += new_ls[j]
print(q-p)

Solution (Python):
































from collections import deque
S = input()
left = deque([0])
right = deque([0])
cnt = 0
for s in S:
    if s == '<':
        cnt += 1
    else:
        cnt = 0
    left.append(cnt)
cnt = 0
for s in S[::-1]:
    if s == '>':
        cnt += 1
    else:
        cnt = 0
    right.appendleft(cnt)
ans = 0
for l, r in zip(left, right):
    ans += max(l, r)
print(ans)

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

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

Solution (Python):
def mi():
    return map(int, input().split())

def main():
    S = input()
    N = len(S)+1
    l = [0]*N
    r = [0]*N
    ans = 0

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

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

    print(ans)

if __name__ == '__main__':
    main()

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

a1 = [0]*(l+1)
a2 = [0]*(l+1)

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

for i in range(l):
	if s[-i-1] == ">":
		a2[i+1] = a2[i] + 1
	else:
		a2[i+1] = 0

cnt = 0
for i in range(l+1):
	cnt += max(a1[i],a2[-i-1])

print(cnt)

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

S = ('<' if S[0] == '>' else '>') + S \
    + ('<' if S[-1] == '>' else '>') 
    
for i in range(n):
    if S[i : i + 2] == '><': 
        for j in range(i, 0, -1):   
            if S[j] == '<': break
            a[j - 1] = max(a[j - 1], a[j] + 1)
        for j in range(i + 1, n):   
            if S[j] == '>': break
            a[j] = max(a[j], a[j - 1] + 1)

print(sum(a))

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

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

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

ans = sum(a)
print(ans)

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

unfixed = set()
a = [0 for i in range(n+2)]
a[0] = -1
a[-1] = -1

for i in range(n+2):
    if i == 0 or i == n + 1 or s[i-1:i+1] == '><':
        j = i-1
        while 1 <= j <= n:
            if s[j-1:j+1] == '>>':
                a[j] = a[j+1] + 1
                j -= 1
            else:
                unfixed.add(j)
                break
        j = i + 1
        while 1 <= j <= n:
            if s[j-1:j+1] == '<<':
                a[j] = a[j-1] + 1
                j += 1
            else:
                unfixed.add(j)
                break

for j in unfixed:
    a[j] = max(a[j-1], a[j+1]) + 1

print(sum(a[1:-1]))

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

for i, c in enumerate(reversed(s)):
  if c == '>':
    dp[-i-2] = max(dp[-i-2], dp[-i-1] + 1)

print(sum(dp))

Solution (Python):
s = input()


left = 0
right = 0
ans = []
for i in range(len(s) + 1):
    if left == 0:
        
        for j in range(i - 1, -1, -1):
            if s[j] != '<':
                break
            else:
                left += 1
    else:
        if s[i - 1] == '<':
            left += 1
        else:
            left = 0
    
    if right == 0:
        for j in range(i, len(s)):
            if s[j] != '>':
                break
            else:
                right += 1
    else:
        if i == len(s):
            right = 0
        elif s[i] == '>':
            right -= 1
        else:
            right = 0
    ans.append(max(left, right))

print(sum(ans))

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


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


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





S = S()

data = []

prev = ">"
count = 0
for s in S:
  if s == prev:
    count += 1
  else:
    data.append(count)
    count = 1
  prev = s
data.append(count)
if S[-1] == ">":
  data.append(0)
  
ans = sum(d*(d+1)//2 for d in data)

N = (len(data)-2)//2
gosa = sum(min(data[i*2+1],data[i*2+2]) for i in range(N))

print(ans-gosa)

Solution (Python):
s=str(input())
s=list(s)
temp=[]
cnt=0
ans=0
for i in range(len(s)):
  if s[i]=="<":
    if i!=0 and s[i-1]==">":
      temp.append(cnt)
      cnt=0
    cnt=cnt+1
  else:
    if i!=0 and s[i-1]=="<":
      temp.append(cnt)
      cnt=0
    cnt=cnt+1
temp.append(cnt)
if s[0]=="<":
  for i in range(0,len(temp)-1,2):
    tempmin=min(temp[i],temp[i+1])-1
    tempmax=max(temp[i],temp[i+1])
    temp[i]=tempmin
    temp[i+1]=tempmax
else:
  for i in range(1,len(temp)-1,2):
    tempmin=min(temp[i],temp[i+1])-1
    tempmax=max(temp[i],temp[i+1])
    temp[i]=tempmin
    temp[i+1]=tempmax
for i in range(len(temp)):
  ans=ans+temp[i]*(temp[i]+1)//2
print(ans)

Solution (Python):
s = list(input())
num = 0
n = len(s)
l = 0
i = 0
while i < n:
  if s[i] == '<':
    l+=num
    num+=1
    i+=1
    if i==n:
      l+=num
  else:
    cur = 0
    while i < n and s[i]=='>':
      i+=1
      cur+=1
    if cur <= num:
      l+=num
      cur-=1
    l+=(cur*(cur+1))//2
    num = 0
print(l)

Solution (Python):
s = list(input())
num = 0
n = len(s)
l = []
i = 0
while i < n:
  if s[i] == '<':
    l.append(num)
    num+=1
    i+=1
    if i==n:
      l.append(num)
  else:
    cur = 0
    while i < n and s[i]=='>':
      i+=1
      cur+=1
    if cur <= num:
      l.append(num)
      cur-=1
    l.append((cur*(cur+1))//2)
    num = 0
print(sum(l))

Solution (Python):
from math import *
from collections import *
from itertools import *
from bisect import *
from heapq import *
from operator import *
from sys import *
setrecursionlimit(100000000)


import os
import sys
from sys import *
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()



sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
z = lambda: sys.stdin.readline().rstrip("\r\n")



def op():
    return list(map(int,z().split()))
def o():
    return int(z())
def r(x):
    if type(x)==int:
        return range(x)
    else:return range(len(x))
def kl(con,x=0):
    if x==0:print('Yes') if con else print('No')
    elif x==1:print('yes') if con else print('no')
    elif x==2:print('YES') if con else print('NO')
MOD = 1000000007
MAX=float('inf')
MIN=-float('inf')
x=z()
c=0
f=0
l1,l2=[],[]
for i in x:
    if i=='<':
        c+=1
        l1.append(c)
    else:
        c=0
        l1.append(c)
for i in x[::-1]:
    if i=='>':
        c+=1
        l2.append(c)
    else:
        c=0
        l2.append(c)
l2=l2[::-1]
ans=[]
for i in r(len(x)-1):
      ans.append(max(l1[i],l2[i+1]))
ans.insert(0,l2[0])
ans.append(l1[-1])
print(sum(ans))

Solution (Python):
s=input()
ans=0
up=0
down=0
if(s[0]=='>'):
    down+=1
else:
    up+=1


for i in range(1,len(s)):
    if(s[i]=='>'):
        down+=1
    else:
        if(s[i-1]=='>'):
            high=max(up,down)
            low=min(up,down)
            ans+=(high+1)*(0+high)//2
            low-=1
            ans+=(low+1)*(0+low)//2
            up=1
            down=0
        else:
            up+=1
else:
    high=max(up,down)
    low=min(up,down)
    ans+=(high+1)*(0+high)//2
    low-=1
    ans+=(low+1)*(0+low)//2
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()
k = len(s)
a = [0]*(k+1)
for i in range(k):
  if s[i] == '<':
    a[i+1] = a[i]+1
for j in range(k-1,-1,-1):
  if s[j] == '>':
    a[j] = max(a[j],a[j+1]+1)
print(sum(a))

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

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

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

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

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

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

for idx in reversed(range(len(S))):
    if S[idx] == ">":
        A[idx] = max(A[idx], A[idx + 1] + 1)

print(sum(A))

Solution (Python):
string = input()

lt = True
ans = 0
l_cnt = 0
m_cnt = 0
if string[0] == ">":
    lt = False

for s in string:
    if s == "<":
        if not lt:
            a, b = max(l_cnt, m_cnt), min(l_cnt, m_cnt)
            ans += a * (a + 1) // 2 + b * (b - 1) // 2
            l_cnt = m_cnt = 0
        l_cnt += 1
        lt = True
    else:
        m_cnt += 1
        lt = False
a, b = max(l_cnt, m_cnt), min(l_cnt, m_cnt)
ans += a * (a + 1) // 2 + b * (b - 1) // 2
print(ans)

Solution (Python):
from collections import deque
S = input()
left = deque([0])
right = deque([0])
cnt = 0
for s in S:
    if s == '<':
        cnt += 1
    else:
        cnt = 0
    left.append(cnt)
cnt = 0
for s in S[::-1]:
    if s == '>':
        cnt += 1
    else:
        cnt = 0
    right.appendleft(cnt)
ans = 0
for l, r in zip(left, right):
    ans += max(l, r)
print(ans)

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

Solution (Python):

import math


def inp():
    return(int(input()))



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



def instr():
    s = input()
    return(list(s[:len(s)]))



def invr():
    return(map(int, input().split()))


a = input()
n = len(a)
coutn1 = [0] * (n+1)
coutn2 = [0] * (n+1)

for i in range(n):
    if a[i] == "<":
        coutn1[i+1] = coutn1[i] + 1
for i in range(n-1, -1, -1):
    if a[i] == ">":
        coutn2[i] = coutn2[i+1] + 1

total = 0

for i in range(n+1):
    total += max(coutn1[i], coutn2[i])
print(total)

Solution (Python):
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline



def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    S = gete()

    p = []
    nl, ng = 0, 0  

    for i, c in enumerate(S):
        if c == "<":
            nl += 1
        else:
            ng += 1

        if c == "<" and i < len(S) - 1 and S[i + 1] == ">":
            p.append((ng, nl))
            nl, ng = 0, 0

    p.append((ng, nl))

    ans = 0
    for i, q in enumerate(p):

        if i == 0 or p[i - 1][1] < q[0]:
            ans += q[0] * (q[0] + 1) // 2
        else:
            ans += q[0] * (q[0] - 1) // 2

        if i == len(p) - 1 or q[1] >= p[i + 1][0]:
            ans += q[1] * (q[1] + 1) // 2
        else:
            ans += q[1] * (q[1] - 1) // 2


    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
s=input()
sr=s[::-1]
cntl=0
cntr=0
ll=[0]
rl=[0]

for i in range(len(s)):
    if s[i]=="<":
        cntl+=1
    else:
        cntl=0
    
    if sr[i]==">":
        cntr+=1
    else:
        cntr=0
    ll.append(cntl)
    rl.append(cntr)
    
rrl=rl[::-1]
ans=[]
for i in range(len(s)+1):
    ans.append(max(rrl[i],ll[i]))

print(sum(ans))

Solution (Python):
from itertools import groupby
S=input()
T=groupby(S)
s=0
total=0
keys=[]
groups=[]
for key,group in T:
    keys.append(key)
    groups.append(len(list(group)))

if keys[0]==">":
    total+=sum([i for i in range(groups[0]+1)])
if keys[-1]=="<":
    total+=sum([i for i in range(groups[-1]+1)])
for i in range(len(keys)-1):
    if keys[i]=="<":
        if groups[i]<=groups[i+1]:
            total+=sum([j for j in range(groups[i])])
            total+=sum([j for j in range(groups[i+1]+1)])
        else:
            total+=sum([k for k in range(groups[i]+1)])
            total+=sum([k for k in range(groups[i+1])])
print(total)

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

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

Solution (Python):
S=input()
l=len(S)
A=[0]*(l+1)
B=[0]*(l+1)
for i in range(l):
  if S[i]=='<':
    A[i+1]=A[i]+1
  if S[l-i-1]=='>':
    B[l-i-1]=B[l-i]+1
print(sum([max(a,b) for a,b in zip(A,B)]))

Solution (Python):

S = input()
N = len(S)+1
INF = 1000000
ans = [0]*N
tmp = 0
for i in range(N-1):
    if S[i]=='<':
        tmp += 1
    else:
        tmp = 0
    ans[i+1] = tmp
tmp = 0
for i in range(N-2,-1,-1):
    if S[i]=='>':
        tmp += 1
    else:
        tmp = 0
    ans[i] = max(ans[i],tmp)
print(sum(ans))

Solution (Python):
s = input()
de_num = 0
le_num = 0
ans = [0]*(len(s)+1)

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

s = s[::-1]
ans.reverse()

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

print(sum(ans))

Solution (Python):
S = input()

bf = ''
idx = []
bdiff = 0
diff = 0
rlt = 0

for i in range(len(S)):
  if bf != S[i]:
    idx.append(i)
  bf = S[i]

idx.append(len(S))
for i in range(len(idx)-1): 
  diff = idx[i+1] - idx[i]
  rlt += diff*(diff+1)//2
  if S[idx[i]] == '>':
    if bdiff < diff:
      rlt -= bdiff
    else:
      rlt -= diff
  bdiff = diff

print(rlt)

Solution (Python):
def main():
    s = input()
    n = len(s) + 1
    ans = [-1] * (n)
    def right(i, ans):
        j = 1
        while True:
            ans[i + j] = max(ans[i + j], j)
            if i + j == n - 1:
                break
            if s[i + j] == '<':
                j += 1
            else:
                break
        return ans
    def left(i, ans):
        j = 1
        while True:
            ans[i - j] = max(ans[i - j], j)
            if i - j == 0:
                break
            if s[i - j - 1] == '>':
                j += 1
            else:
                break
        return ans
    for i in range(n):
        if i == 0:
            if s[i] == '<':
                ans[0] = 0
                ans = right(i, ans)
            else:
                pass
        elif i == n - 1:
            if s[i - 1] == '>':
                ans[n - 1] = 0
                ans = left(i, ans)
            else:
                pass
        else:
            if s[i] == '<' and s[i - 1] == '>':
                ans[i] = 0
                ans = right(i, ans)
                ans = left(i, ans)
            else:
                pass
    print(sum(ans))

if __name__ == '__main__':
    main()

Solution (Python):
import sys
S = list(input())
lis = [0] * (len(S)+1)
 
if len(S) == 1:
    print(1)
    sys.exit()
 
 

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

Solution (Python):
S = input()

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

Solution (Python):
S = input()
N = len(S)+1
a = [0] * N
for i in range(N-1):
	if S[i] == '<':
		a[i+1] = a[i]+1
for i in range(N-2, -1, -1):
  if S[i] == '>':
    a[i] = max(a[i+1]+1,a[i])
 
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]:
    if s[i]==">":
        a[i]=max(a[i+1]+1,a[i])
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 reversed(range(n)):
    if s[i]==">":
        a[i]=max(a[i+1]+1,a[i])
print(sum(a))

Solution (Python):
if __name__ == "__main__":
    S = input()
    count_right = 0
    count_left = 0
    prev = ""
    a = []

    current = 0
    for i, s in enumerate(S):
        if prev == ">" and s == "<":
            a.append((count_left, count_right))
            count_left = 0
            count_right = 0
        if s == ">":
            count_right += 1
            prev = ">"
            
        else:
            count_left += 1
            prev = "<"
    a.append((count_left, count_right))
    s = 0
    for x in a:
        large = max(x[0], x[1])
        small = min(x[0], x[1])
        s += sum(range(large + 1)) + sum(range(small))
    print(s)

Solution (Python):
S = input()
prev = ">"
terrain = []
curr = 0
for c in S:
    if c == prev:
        curr += 1
    else:
        prev = c
        terrain.append(curr)
        curr = 1
terrain += [curr]
ans = (terrain[0] * (terrain[0] + 1)) // 2
for up, down in zip(terrain[1::2], terrain[2::2]):
    if up < down:
        up, down = down, up
    down -= 1
    ans += (up * (up + 1)) // 2
    ans += (down * (down + 1)) // 2
if len(terrain) % 2 == 0:
    ans += terrain[-1] * (terrain[-1] + 1) // 2
print(ans)