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 main():
    S = input()
    from itertools import groupby
    ans = 0
    g = [(k, len(list(v))) for k, v in groupby(S)]
    p = 0
    m = 0
    if g[0][0] == '>':
        ans += g[0][1]*(g[0][1]+1)//2
        p += 1
    if g[-1][0] == '<':
        ans += g[-1][1]*(g[-1][1]+1)//2
        m += 1
    for i in range(p, len(g)-m, 2):
        if g[i][1] > g[i+1][1]:
            m = g[i+1][1]
            n = g[i][1]
        else:
            n = g[i+1][1]
            m = g[i][1]
        ans += (m-1)*m//2
        ans += n*(n+1)//2
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
S = input()

L = [0]*(len(S)+1)
R = [0]*(len(S)+1)
l = 0
for k in range(len(S)):
    if S[-k-1] == ">":
        l += 1
    else:
        l = 0
    L[-k-2] = l

r = 0
for k in range(len(S)):
    if S[k] == "<":
        r += 1
    else:
        r = 0
    R[k+1] = r

ans = 0
for k in range(len(S)+1):
    ans += max(L[k],R[k])
print(ans)

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

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

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

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

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

a_right = [0] * N
a_tmp = 0
for i in range(N - 1):
    if S[-1 - i] == '>':
        a_tmp += 1
    else:
        a_tmp = 0
    
    a_right[-2 - i] = a_tmp
        
a_ans = [max(li, ri) for li, ri in zip(a_left, a_right)]

print(sum(a_ans))

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 + 1] + 1, ans[i])
print(sum(ans))

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

s = STR()
n = len(s) + 1
arr = [0 for _ in range(n)]
for i in range(n - 1):
    if s[i] == '<':
        arr[i + 1] = arr[i] + 1
debug(arr)
for i in reversed(range(n - 1)):
    debug(i - 1, i)
    if s[i] == '>':
        arr[i] = max(arr[i], arr[i + 1] + 1)
debug(arr)
print(sum(arr))

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

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

for i in range(N):
    if S[N-i-1] == '>':
        B[N-i-1] = B[N-i]+1
    else:
        B[N-i-1] = 0

ans = 0
for i in range(N+1):
    ans += max(A[i], B[i])
print(ans)

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

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_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
A = [0]*N
B = [0]*N

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

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

B = B[::-1]

C = [0]*N
for i in range(N):
    C[i] = max(A[i], B[i])

print(sum(C))

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

Solution (Python):
s = input()
now = ">"
count = 0
result = 0
temp = 0
for c in s:
    if now == ">" and c == "<":
        now = "<"
        if temp < count:
            result += count
        else:
            result += temp
        count = 1
    elif now == "<" and c == ">":
        now = ">"
        temp = count
        count = 1
    else:
        result += count
        count += 1

if c == ">":
    if temp < count:
        result += count
    else:
        result += temp
else:
    result += count
print(result)

Solution (Python):
S = input()
last_char = ""
L_num = 0
R_num = 0
Sum = 0
for s in S:
    if last_char==">"and s=="<":
        n = max(L_num,R_num)
        m = min(L_num,R_num)
        Sum+=((n+1)*n/2) + ((m-1)*m/2)
        L_num = 0
        R_num = 0
    if s=="<":
        L_num+=1
    else:
        R_num+=1
    last_char=s
n = max(L_num,R_num)
m = min(L_num,R_num)
Sum+=((n+1)*n/2) + ((m-1)*m/2)
print(int(Sum))

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

Solution (Python):

s = list(input())
t = [0]* (len(s)+1)

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

Solution (Python):

s = list(input())
t = [0]* (len(s)+1)

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



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

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

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

l = l[::-1]
S = S[::-1]

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

print(sum(l))

Solution (Python):
s = input()
ans = 0
cnt = 1
l = []
for i in range(1, len(s)):
  if s[i] != s[i-1]:
    l.append(cnt)
    cnt = 1
  else:
    cnt += 1
l.append(cnt)
if s[0] == ">":
  ans += l[0]*(l[0]+1)//2
  l.pop(0)
for i in range(len(l)//2):
  if l[2*i] > l[2*i+1]:
    ans += l[2*i]*(l[2*i]+1)//2
    ans += l[2*i+1]*(l[2*i+1]-1)//2
  else:
    ans += l[2*i]*(l[2*i]-1)//2
    ans += l[2*i+1]*(l[2*i+1]+1)//2
if len(l)%2 == 1:
  ans += l[-1]*(l[-1]+1)//2
print(ans)

Solution (Python):
from itertools import groupby

s = input()

con = [sum(1 for _ in it) for k, it in groupby(s)]

idx = 0
cnt = 1
res = []
res.append(0) if s[0] == '<' else res.append(con[idx])
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        if s[i] == '<':
            res.append(cnt)
        else:
            res.append(con[idx]-cnt)
        cnt += 1
    else:
        idx += 1
        if s[i] == '<':
            res.append(max(cnt, con[idx]))
        else:
            res.append(0)
        cnt = 1
res.append(0) if s[-1] == '>' else res.append(con[-1])

print(sum(res))

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

Solution (Python):
s = input()

con = []
prev = s[0]
cnt = 1
for ss in s[1:]:
    if ss == prev:
        cnt += 1
    else:
        prev = ss
        con.append(cnt)
        cnt = 1
else:
    con.append(cnt)

idx = 0
cnt = 1
res = []
res.append(0) if s[0] == '<' else res.append(con[idx])
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        if s[i] == '<':
            res.append(cnt)
        else:
            res.append(con[idx]-cnt)
        cnt += 1
    else:
        idx += 1
        if s[i] == '<':
            res.append(max(cnt, con[idx]))
        else:
            res.append(0)
        cnt = 1
res.append(0) if s[-1] == '>' else res.append(con[-1])

print(sum(res))

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

Solution (Python):
S=input()
N=len(S)+1
A=[]
from itertools import groupby
if S[0]==">":
    S="<"+S
if S[-1]=="<":
    S+=">"
l=[len(list(g)) for k,g in groupby(S)]
ans=0
for i,j in zip(*[iter(l)] * 2):
    M=max(i,j)
    m=min(i,j)
    ans+=M*(M+1)//2 + m*(m-1)//2
print(ans)

Solution (Python):
from itertools import groupby
s=input()
t=[0]*(len(s)+1)

gr=groupby(s)
now=0

for key,group in gr:
    if key=="<":
        for i in range(now,now+len(list(group))):
            t[i+1]=t[i]+1
            now+=1
    else:
        for i in range(now,now+len(list(group)))[::-1]:
            t[i]=max(t[i+1]+1,t[i])
            now+=1
print(sum(t))

Solution (Python):
from itertools import groupby
s=input()
t=[0]*(len(s)+1)

gr=groupby(s)
now=0

for key,group in gr:
    if key=="<":
        for i in range(now,now+len(list(group))):
            t[i+1]=t[i]+1
            now+=1
    else:
        for i in range(now,now+len(list(group)))[::-1]:
            t[i]=max(t[i+1]+1,t[i])
            now+=1
print(sum(t))

Solution (Python):
S = list(input())
if S[0] != '<':
    S.insert(0,'<')
if S[-1] != '>':
    S.append('>')
con = []
count = 1
for i in range(len(S)-1):
    if S[i+1] == S[i]:
        count += 1
    else:
        con.append(count)
        count = 1
if S[-1] != S[-2]:
    count = 1
    con.append(count)
else:
    con.append(count)
ans = 0
for l in range(0,len(con)-1,2):
    if l % 2 == 0:
        f = con[l]
        b = con[l+1]
        if f >= b:
            ans += (1 + f)*f//2 + (b-1)*b//2
            
        else:
            ans += (1 + b)*b//2 + (f-1)*f//2
            
    else:
        pass
    
        
print(ans)

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

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

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

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

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

























res = [max(x, y) for x, y in zip(a, b)]


















print(sum(res))

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

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

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

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

Solution (Python):
import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
from io import BytesIO, IOBase
 



 
def sieve(n):
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r
 
def divs(n, start=1):
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors
 
def divn(n, primes):
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t
 
def flin(d, x, default=-1):
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return (default, default)
    else:
        return (left, right)
 
def ceil(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def prr(a, sep=' '): print(sep.join(map(str, a)))
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
 
 

 
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")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 

'''for _ in range(ii()):
    n=ii()
    a=li()
    m,k,md=0,0,0
    mn,mx=10**9+1,-10**9-1
    for i in range(n-1):
        if a[i]!=-1 and a[i+1]!=-1:
            m=max(m,abs(a[i]-a[i+1]))
    for i in range(1,n-1):
        if a[i]==-1:
            if a[i+1]!=-1:
                mn=min(mn,a[i+1])
                mx=max(mx,a[i+1])
            if a[i-1]!=-1:
                mn=min(mn,a[i-1])
                mx=max(mx,a[i-1])
    if mn==10**9+1 and mx==-10**9-1:
        print(0,0,sep=' ')
    else:
        md=(mn+mx+1)//2
        m=max(abs(mx-md),abs(mn-md),m)
        print(m,md,sep=' ')'''

'''for _ in range(ii()):
    n,m=mi()
    tg=n//2
    n0=n-m
    total=(n*(n+1))//2
    res=0
    if n0<n:
        if m>=tg:
            res=total-n0
        else:
            i=tg-m
            if n&1:
                nn0=2*i+1
            else:
                nn0=2*i
            res=total-((nn0*(nn0+1))//2)-(n0-nn0)
            
    print(res)'''



'''def solve():
    n=int(input())
    a=list(map(int,input().split()))
    diff=len(set(a))
    if diff==1: print (int((n*(n+1))/2))
    elif diff==n: print (1)
    else:
        i=j=ans=0
        ahead=True
        distinct={}
        while j<n:
            if ahead:
                distinct[a[j]]=distinct[a[j]]+1 if a[j] in distinct else 1
                if len(distinct)==diff:
                    ahead=False
                else:
                    j+=1
            else:
                ans+=n-j
                if distinct[a[i]]>1:
                    distinct[a[i]]-=1
                else:
                    distinct.pop(a[i])
                    j+=1
                    ahead=True
                i+=1
        print (ans)
 
solve()'''



'''s=input()
n=len(s)
i,cntl,cntg=0,0,0
res,fl,fg=0,0,0
while(i<n):
    if s[i]=='<':
        while(i<n and s[i]!='>'):
            fl=1
            cntl+=1
            i+=1
    else:
        while(i<n and s[i]!='<'):
            fg=1
            cntg+=1
            i+=1
    if fl==1 and fg==1:
        res+=max(cntl,cntg)
        cntl-=1
        cntg-=1
        res+=cntl*(cntl+1)//2
        res+=cntg*(cntg+1)//2
        fl,fg,cntl,cntg=0,0,0,0
if fl:
    res+=cntl*(cntl+1)//2
if fg:
    res+=cntg*(cntg+1)//2
print(res)'''






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

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

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

res = [max(x, y) for x, y in zip(a, b)]

print(sum(res))

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

for i in range(0, 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=list(input())

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

print(s)

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

a, b = 0, 0
for i in range(N-1):
  a += 1 if S[i] == '<' else -a
  A[i+1] = a
  
  b += 1 if S[-i-1] == '>' else -b
  B[-i-2] = b
  
ans = 0
for i in range(N):
  ans += max(A[i], B[i])
  
print(ans)

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

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

print(sum(A))

Solution (Python):
s=input()
cnt=0
prev=''
pre_max=0
ans=0
for w in s:
    if prev==w:
        cnt+=1
    else:
        ans+=cnt*(cnt+1)//2
        if w=='<':
            shou=min(pre_max, cnt)
            ans-=shou
        pre_max=0
        pre_max+=cnt
        cnt=1
    prev=w
ans+=cnt*(cnt+1)//2
if w=='>':
    shou=min(pre_max, cnt)
    ans-=shou
print(ans)

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

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

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

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

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

Solution (Python):



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

S = input()
a = [0]


sumS = 0
i = 0
base = 0
while i < len(S):
	j = 0
	
	while (i+j) < len(S) and S[i+j] != "<":
		j += 1
	if base > j:
		sumS += (base*1-j)

	sumS += sum(range(j+1))
	base = 0
	

	i += j

	j = 0
	while (i+j) < len(S) and S[i+j] != ">":
		j += 1

	sumS += sum(range(base,base+j))
	base += j

	i += j

sumS += base


print(sumS)

Solution (Python):
s = input()
ans = 0
flag = 0 
x = s[0]
r = 0 
l = 0 

if x==">":
    flag = 1
    l += 1
else:
    r += 1

for i in range(1,len(s)):
    if s[i]==x:
        if flag==1:
            l += 1
        else:
            r += 1
    else:
        if flag==1:
            ans += sum(range(max(r,l)+1)) + sum(range(min(r,l)))
            l = 0
            r = 1
            x = s[i]
            flag = 0
        else:
            x = s[i]
            l += 1
            flag = 1
ans += sum(range(max(r,l)+1)) + sum(range(min(r,l)))
print(ans)

Solution (Python):
def main():
    S = input()
    r = 0
    t = 0
    pp = 0
    d = False
    for s in S + '<':
        if s == '<':
            if d:
                r += max(pp, t)
                pp = 0
                t = 0
            else:
                r += t
        else:
            if d:
                r += t
            else:
                pp = t
                t = 0
        d = s == '>'
        t += 1

    return r
        

print(main())

Solution (Python):
def ss(n):
    return (n * (n+1))//2
def main():
    S = input()
    r = 0
    larger = (S[0] == '<')
    first = (S[0] == '<')
    t = 0
    l = []
    for i in S:
        if i == '<':
            if larger:
                t += 1
            else:
                larger = True
                l.append(t)
                t = 1
        else:
            if not larger:
                t += 1
            else:
                larger = False
                l.append(t)
                t = 1
    else:
        l.append(t)
    if len(l) == 1:
        r = ss(l[0])
    elif len(l) == 2 and first == False:
        r = ss(l[0]) + ss(l[1])
    elif first:
        p = l[0]
        for i, v in enumerate(l):
            r += ss(v)
            if i % 2 == 1:
                r -= min(v, p)
            p = v
    else:
        r = ss(l[0])
        p = l[1]
        for i, v in enumerate(l[1:]):
            r += ss(v)
            if i % 2 == 1:
                r -= min(v, p)
            p = v
    return r
print(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()

s = S.replace('<>', '<,>').replace('><', '>,<').split(',')
lst = [ss.count('<') - ss.count('>') for ss in s]

ans = [0]

for i in lst:
    if i > 0:
        ans += list(range(1,i+1))
    else:
        ans[-1] = max(ans[-1], -i)
        ans += list(range(-i-1,-1, -1))

print(sum(ans))

Solution (Python):
S = input()

lst = [1 if S[0]=='<' else -1]
pre = S[0]
for i in S[1:]:
    if i == pre:
        lst[-1] += 1 if i=='<' else -1
    else:
        lst.append(-1 if i=='>' else 1)
    pre = i    
ans = [0]

for i in lst:
    if i > 0:
        ans += list(range(1,i+1))
    else:
        ans[-1] = max(ans[-1], -i)
        ans += list(range(-i-1,-1, -1))

print(sum(ans))

Solution (Python):
S = input()

lst = [1 if S[0]=='<' else -1]
for i in range(1, len(S)):
    if S[i] == S[i - 1]:
        lst[-1] += 1 if S[i]=='<' else -1
    else:
        lst.append(-1 if S[i]=='>' else 1)
        
ans = [0]

for i in lst:
    if i > 0:
        ans += list(range(1,i+1))
    else:
        ans[-1] = max(ans[-1], -i)
        ans += list(range(-i-1,-1, -1))


print(sum(ans))

Solution (Python):
S = input()

lst = [1 if S[0]=='<' else -1]
for i in range(1, len(S)):
    if S[i] == S[i - 1]:
        lst[-1] += 1 if S[i]=='<' else -1
    else:
        lst.append(-1 if S[i]=='>' else 1)
        
ans = [0]

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

print(sum(ans))

Solution (Python):
S = input()

lst = [1 if S[0]=='<' else -1]
for i in range(1, len(S)):
    if S[i] == S[i - 1]:
        if S[i]=='<':lst[-1] += 1
        else: lst[-1] -= 1
    else:
        if S[i]=='>':lst.append(-1)
        else: lst.append(1)
ans = [0]

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

print(sum(ans))

Solution (Python):
s = str(input())
ans = [0 for _ in range(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):
S = input()
ans = [0 for i in range(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()
S = S.replace("><", ">,<").split(",")
Ans = 0
for T in S:
    a = T.count(">")
    b = T.count("<")
    for i in range(1, max(a, b) + 1):
        Ans += i
    for j in range(1, min(a, b)):
        Ans += j

print(Ans)

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

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

Solution (Python):

import sys

def nextSpan(s:str,begin:int):
    current = s[begin]
    r = 1
    for i in range(begin + 1,len(s)):
        if s[i] == current:
            r += 1
        else:
            return (current,r,i)
    return (current,r,len(s))

def getNSeriesSum(n:int):
    return n*(n-1)//2

def solve(S: str):
    currentIndex = 0
    csum = 0
    while True:
        next = nextSpan(S,currentIndex)
        currentIndex = next[2]
        if currentIndex == len(S):
            csum += getNSeriesSum(next[1]+1)
            break
        if next[0] == ">":
            csum += getNSeriesSum(next[1] + 1)
        else:
            nextNext = nextSpan(S,currentIndex)
            if nextNext[1] > next[1]:
                csum += getNSeriesSum(nextNext[1] + 1) + getNSeriesSum(next[1])
            else:
                csum += getNSeriesSum(nextNext[1]) + getNSeriesSum(next[1]+1)
            currentIndex = nextNext[2]
        if currentIndex == len(S):
            break
    print(csum)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  
    solve(S)

if __name__ == '__main__':
    main()

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()
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):
def main():
    string = input()
    length = len(string) + 1
    answer = [0] * length
    for i in range(length - 1):
        if string[i] == "<":
            answer[i + 1] = answer[i] + 1
    for i in range(length - 2, -1, -1):
        if string[i] == ">":
            answer[i] = max(answer[i], answer[i + 1] + 1)
    print(sum(answer))


if __name__ == '__main__':
    main()

Solution (Python):
s = input()

def comb(x):
    return x * (x-1) // 2

left, right = 0, 0
ans = 0
pre = '<'
for c in s:
    if pre == '>' and c == '<':
        ans += comb(min(left, right)) + comb(max(left, right)+1)
        left, right = 1, 0
    elif c == '<':
        left += 1
    else:
        right += 1
    pre = c
ans += comb(min(left, right)) + comb(max(left, right) + 1)
print(ans)