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

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

from_left = [0] * N
from_right = [0] * N

for i in range(N-1):
  s = S[i]
  if s == '<':
    from_left[i+1] = from_left[i] + 1

for i in range(N-2,-1,-1):
  s = S[i]
  if s == '>':
    from_right[i] = from_right[i+1] + 1
    
ans = 0
for i in range(N):
  ans += max(from_left[i],from_right[i])
  
print(ans)

Solution (Python):
s=input()
a=[0]*(len(s)+1)
b=[0]*(len(s)+1)
flag=0
for i in range(len(s)):
    if s[i]=="<" and flag==0:
        flag=1
        a[i+1]=1
    elif s[i]=="<" and flag==1:
        a[i+1]=a[i]+1
    else:
        flag=0
flag=0
for i in range(len(s)-1,-1,-1):
    if s[i]==">" and flag==0:
        flag=1
        b[i]=1
    elif s[i]==">" and flag==1:
        b[i]=b[i+1]+1
    else:
        flag=0
c=[]
for i in range(len(s)+1):
    c.append(max(a[i],b[i]))
print(sum(c))

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

Solution (Python):
S = input()
N = len(S)
a = [0] * (N+1)
index = 0
while index < N:
  tmp = S[index]
  count = 1
  if index < N-1:
    while S[index+count] == tmp:
      count += 1
      if index+count == N:
        break
  if tmp == '<':
    for j in range(count+1):
      a[index+j] = max(a[index+j],j)
  else:
    for j in range(count+1):
      a[index+count-j] = max(a[index+count-j],j)
  index += count
print(sum(a))

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

Solution (Python):

def modelAnswer(S:list) -> int:
   l = [0 for i in range(len(S)+1)]
   for n,s in enumerate(S):
      if(s == "<"):
         l[n+1] = l[n] + 1
   for n,s in enumerate(S[::-1]):
      if(s == ">"):
         tmp = l[len(S) - n] + 1
         if (tmp > l[len(S) - n - 1]):
            l[len(S) -n - 1] = tmp
   return sum(l)
def main():
   S = list(input())
   print(modelAnswer(S[:]))
if __name__ == '__main__':
   main()

Solution (Python):
from itertools import*
a = b = 0
for k, n in groupby(input()):
  n = len(list(n))
  a -= n*~n//2 + min(n, b)*(k==">")
  b = n
print(a)

Solution (Python):

s = list(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 j in range(len(s)-1,-1,-1):
    if s[j] == '>':
        tmp = ans[j+1] + 1
        if tmp > ans[j]:
            ans[j] = tmp
                
print(sum(ans))

Solution (Python):


from collections import deque,Counter













S = input()
Slist = S.replace("><",">,<").split(",")
ans = 0
for s in Slist:
    cnt = Counter(s)
    num = max(cnt["<"],cnt[">"])
    ans += (num+1)*num//2
    num = min(cnt["<"],cnt[">"]) - 1
    ans += (num+1)*num//2

print(ans)

Solution (Python):

s = list(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 j in range(len(s)-1,-1,-1):
    if s[j] == '>':
        tmp = ans[j+1] + 1
        if tmp > ans[j]:
            ans[j] = tmp
                
print(sum(ans))

Solution (Python):
def GetPoint(U,D):
    N = 0
    if U >= D:
        N += D*(D-1)/2 + U*(U+1)/2
    else:
        N += D*(D+1)/2 + U*(U-1)/2
    return N
S = input()
N = 0
U = 0
D = 0
for i in range(len(S)):
    if S[i] == "<":
        U += 1
    elif S[i] == ">":
        D += 1
    if i<len(S)-1:
        if (S[i]==">" and S[i+1]=="<"):
            N += GetPoint(U,D)
            U=0
            D = 0
N += GetPoint(U, D)
    

print(int(N))

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

print(sum(l))

Solution (Python):
s = input()

left, right = [0],[0]
tmp=0
for itr,eq in enumerate(s):
    if eq == "<":
        tmp+=1
    else:
        tmp = 0
    left.append(tmp)
tmp = 0
for itr in range(len(s)):
    if s[len(s)-itr -1] == ">":
        tmp+=1
    else:
        tmp =0
    right.append(tmp)
right.reverse()

ans = 0
for i in range(len(s) +1) :
    ans +=max(right[i], left[i])

print(ans)

Solution (Python):





s=input()
n=len(s)

a=[0]
tmp=0
for i in range(n):
    if s[i]=='<':
        tmp+=1
    else:
        tmp=0
    a.append(tmp)

arev=[0]
for i in range(n):
    if s[n-i-1]=='>':
        tmp+=1
    else:
        tmp=0
    arev.append(tmp)
arev.reverse()

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

print(ans)

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

for i in range(N-2,-1,-1):
    if S[i] == ">":
        ary[i] = max(ary[i], ary[i+1] + 1)

print(sum(ary))

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

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

Solution (Python):

s = input()
A = [0] * (len(s) + 1)
B = [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]:
    if s[i] == '>':
        B[i] = B[i + 1] + 1

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

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

for i in range(len(S)):
    if S[i] == ">":
        a[i+1] = a[i] - 1
    elif S[i] == "<":
        a[i+1] = a[i] + 1
    if i > 0:
        if S[i-1] == "<" and S[i] == ">":
            yama = i
        if S[i-1] == ">" and S[i] == "<":
            tani = i
            val = a[tani]
        if a[tani] < 0:

            for j in range(yama, tani+2):
                a[j] = a[j] - val

        elif a[tani] > 0:
            for j in range(yama+1, tani+2):
                a[j] = a[j] - val
last = len(a) -1
val = a[last]
if a[last] < 0:

    for j in range(yama, last+1):
        a[j] = a[j] - val



print(sum(a))

Solution (Python):
s=list(input())
n=len(s)
l=[0] 
r=[0] 
l_num=0
r_num=0
for i in range(n):
    if s[i]=="<":
        l_num+=1
    else:
        l_num=0
    if s[-(i+1)]==">":
        r_num+=1
    else:
        r_num=0
    l.append(l_num)
    r.append(r_num)
ans=0
for i in range(n+1):
    ans+=max(l[i],r[-(i+1)])
print(ans)

Solution (Python):
s_l = list(input())
n = len(s_l)+1
num_l = [0] * n

for i in range(n-1):
    if s_l[i] == '<':
        num_l[i+1] = num_l[i] + 1

for j in range(n-1):
    if s_l[n-2-j] == '>':
        num_l[n-2-j] = max(num_l[n-2-j], num_l[n-2-j+1]+1)

total = 0
for k in num_l:
    total += k

print(total)

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

num=[]
def search(now,kigo): 
    global s,n
    count=0
    while s[now]==kigo:
        now+=1
        count+=1
        if now==n:
            break
    return count
where=0
left=0
if s[0]=="<":
    a=search(0,"<")
    nn=0
    for i in range(a):
        num.append(nn)
        if i==a-1:
            break
        nn+=1
    left=nn
else:
    a=search(0,">")
    nn=a
    for i in range(a):
        num.append(nn)
        nn-=1
    left=1
where=a 
while where<=n-1:
    if s[where]=="<":
        a=search(where,"<")
        nn=0
        for i in range(a):
            num.append(nn)
            if i==a-1:
                break
            nn+=1
        left=nn
    else:
        a=search(where,">")
        if left<a:
            nn=a
        else:
            nn=left+1
        num.append(nn)
        nnn=a-1
        for i in range(a-1):
            num.append(nnn)
            nnn-=1
        left=1
    where+=a
    
if s[-1]=="<":
    num.append(left+1)
else:
    num.append(left-1)

print(sum(num))

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

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

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

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

print(sum(ans))

Solution (Python):

"""
@author: H_Hoshigi
31min 41sec
"""
"""
<がn個連続するとき、0からnまでの自然数を並べればよい。
>がn個連続するとき、nから0までの自然数を並べればよい。
これらのときの和は、n*(n+1)//2。
><と並んだときは、間に0が挟まれるので考えなくいていい。
<>と並んだときは、連続する数が小さいほうから1個取り除くことにする。
"""
def main():
    S = input()
    N = len(S)
    compressed_list = []
    now_direction = S[0]
    now_counter = 0
    for i in range(N):
        if S[i] == now_direction:
            now_counter += 1
        else:
            compressed_list.append([now_direction, now_counter])
            now_direction = S[i]
            now_counter = 1
    compressed_list.append([now_direction, now_counter])
    answer = 0
    for i in range(len(compressed_list)):
        n = compressed_list[i][1]
        if compressed_list[i][0] == "<":
            if i <= len(compressed_list)-2 and \
                compressed_list[i][1] <= compressed_list[i+1][1]:
                n -= 1
        else:
            if i >= 1 and \
                compressed_list[i-1][1] > compressed_list[i][1]:
                n -= 1
        answer += n*(n+1)//2
    print(answer)
    return

if __name__ == "__main__":
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    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):
        if s[n-i-1]==">":
            A[n-i-1]=max(A[n-i-1],A[n-i]+1)
    print(sum(A))

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    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):
        if s[n-i-1]==">":
            A[n-i-1]=max(A[n-i-1],A[n-i]+1)
    print(sum(A))

if __name__=='__main__':
    main()

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


print(sum(ans))

Solution (Python):
S = input()
nums = [0] * (len(S)+1)
pos = 0
count = 0
pre_count = 0
now = '>'
for (i, s) in enumerate(S):
  if s != now:
    if s == '<':
      nums[pos] = max(pre_count, count)
      while pos != i:
        pos += 1
        count -= 1
        nums[pos] = count
    else:
      pos = i
      pre_count = count+1
      count = 1
    now = s
  else:
    count += 1
    if s == '<':
      nums[i] = count
if now == '<':
  nums[i+1] = count+1

if s == '>':
  nums[pos] = max(pre_count, count)
  while pos != i+1:
    pos += 1
    count -= 1
    nums[pos] = count

print(sum(nums))

Solution (Python):
si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
smii = lambda: sorted(map(int, input().split()))



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

print(sum(a))

Solution (Python):
def resolve():
    '''
    code here
    '''

    S = input()
    N = len(S)

    a_list = [ 0 for _ in range(N+1)]


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

    
    
    print(sum(a_list))


if __name__ == "__main__":
    resolve()

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

s = read().rstrip().decode()
cnt = [[0, 0] for i in range(len(s) + 1)]
ans = 0
for i in range(len(s)):
    if s[i] == '<':
        cnt[i + 1][0] += 1
    else:
        cnt[i][1] += 1
for i in range(1, len(s) + 1):
    if cnt[i - 1][1] == 0:
        cnt[i][0] += cnt[i - 1][0]
    if cnt[len(s) - i + 1][0] == 0:
        cnt[len(s) - i][1] += cnt[len(s) - i + 1][1]
for i in range(len(s) + 1):
    ans += max(cnt[i])
print(ans)

Solution (Python):
INT_MAX=10**18+7
x=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]

s=input()
prev=0
sum=0
i=0
while(i<len(s)):
    if s[i]=="<":
        count1=0
        while(i<len(s) and s[i]=="<" ):
            count1+=1
            i+=1
        sum=sum+(count1*(2*prev+1+count1))//2
        prev=prev+count1
    else:
        count=0
        while(i<len(s) and s[i]==">"):
            count+=1
            i+=1
        if count>prev:
            sum-=prev
            prev=count
            sum+=((count)*(count+1))//2
            prev=0
        else:
            sum+=(count*(count-1))//2
            prev=0
print(sum)

Solution (Python):
S = input()

left_counter = 0
right_counter = 0
before = 0
answer = 0

for i,s in enumerate(S):
    if s == "<":
        left_counter += 1
        if i == len(S)-1:
            answer += ((1+left_counter)*left_counter)/2
            break
    else:
        right_counter += 1
        if i == len(S)-1:
            answer += ((1+max(left_counter, right_counter))*max(left_counter, right_counter))/2
            answer += (min(left_counter, right_counter)*(min(left_counter, right_counter)-1))/2
            break
        elif S[i+1] == "<":
            answer += ((1+max(left_counter, right_counter))*max(left_counter, right_counter))/2
            answer += (min(left_counter, right_counter)*(min(left_counter, right_counter)-1))/2
            left_counter = 0
            right_counter = 0
print(int(answer))

Solution (Python):
s = input()
n = len(s) + 1
ans = 0
l = 0
r = 0
if s[0] == ">":
    p = 0
elif s[0] == "<":
    p = 1
for i in range(n-1):
    if p == 0:
        if s[i] == ">":
            l += 1
        elif s[i] == "<":
            p = 1
            ans += l*(l+1)//2
            if l < r:
                ans -= l
            elif l >= r:
                ans -= r 
            l = 0
            r = 1
    elif p == 1:
        if s[i] == "<":
            r += 1
        elif s[i] == ">":
            l += 1
            p = 0
            ans += r*(r+1)//2
if p == 0:
    ans += l*(l+1)//2
    if l < r:
        ans -= l
    elif l >= r:
        ans -= r
elif p == 1:
    ans += r*(r+1)//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()

A = [-1, ] * (len(S) + 1)
cnt = 0
for i in range(0, len(S)):
    if S[i] == '<':
        A[i] = cnt
        cnt += 1
        A[i + 1] = cnt
    else:
        cnt = 0

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

print(sum(A))

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

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

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

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

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

Solution (Python):
S = input().replace("><", "> <").split()
ans = 0
for s in S:
    up = s.count("<")
    down = len(s) - up
    if up < down: 
        up -= 1
        ans += up * (up+1) // 2 + down * (down+1) // 2
    else:
        down -= 1
        ans += up * (up+1) // 2 + down * (down+1) // 2
print(ans)

Solution (Python):
s=input()
flag=2
cnt=0
p=[]

for i in range(len(s)):
  if s[i]==">":
    if flag==0 or flag==2:
      cnt+=1
    elif flag==1:
      p.append(cnt)
      cnt=1
    flag=0
  
  elif s[i]=="<":
    if flag==1 or flag==2:
      cnt+=1
    elif flag==0:
      p.append(cnt)
      cnt=1
    flag=1
p.append(len(s)-sum(p))
n=len(p)
ans=0

if n%2==0 and s[0]=="<":
  for i in range(0,n,2):
    x=max(p[i],p[i+1])
    y=min(p[i],p[i+1])
    ans+=(x*(x+1)//2)+(y*(y-1)//2)

if n%2==0 and s[0]==">":
  ans+=p[0]*(p[0]+1)//2+p[n-1]*(p[n-1]+1)//2
  for i in range(1,n-1,2):
    x=max(p[i],p[i+1])
    y=min(p[i],p[i+1])
    ans+=(x*(x+1)//2)+(y*(y-1)//2) 

if n%2==1 and s[0]=="<":
  ans+=p[n-1]*(p[n-1]+1)//2
  for i in range(0,n-1,2):
    x=max(p[i],p[i+1])
    y=min(p[i],p[i+1])
    ans+=(x*(x+1)//2)+(y*(y-1)//2)
    
if n%2==1 and s[0]==">":
  ans+=p[0]*(p[0]+1)//2
  for i in range(1,n,2):
    x=max(p[i],p[i+1])
    y=min(p[i],p[i+1])
    ans+=(x*(x+1)//2)+(y*(y-1)//2)

print(ans)

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

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

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

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

c = 0
for j in range(1,n):
    if s[-j] == '>':
        c+=1
        a[-j-1] = max(a[-j-1],c)
    else:
        c = 0

print(sum(a))

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

Solution (Python):
s = input()
li = list(s)


tmp = [] 
last_str = ''
memo = []
for i,l in enumerate(li):
    if i == 0:
        tmp.append(l)
        last_str = l
        continue
    if l != last_str:
        memo.append(tmp)
        tmp = [l]
        last_str = l
    else:
        tmp.append(l)
if len(tmp)>0:
    memo.append(tmp)

all_count = 0
muki = memo[0][0]
last_len = 0
for mi,m in enumerate(memo):
    all_count += (1+len(m))*len(m)//2
    
    if muki == '<' and m[0] == '>':
        
        all_count -= (min(last_len,len(m)))
    muki = m[0]
    last_len = len(m)
print(all_count)

Solution (Python):
S = input().replace('><','> <').split()
ans = 0
for s in S:
    up = s.count('<')
    down = len(s)-up
    if up < down:
        up -= 1
        ans += up*(up+1)//2 + down*(down+1)//2
    else:
        down -= 1
        ans += up*(up+1)//2 + down*(down+1)//2        
print(ans)

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

s = 0
cl = 0
cc = S[0]
ccc = 0

def kaidan(k):
    return k * (k + 1) / 2

for i in range(len(S)):
    if S[i] == cc:
        ccc += 1
    else:
        if cc == '<':
            s += kaidan(ccc) + cl * ccc
            cl = ccc
        else:
            s += kaidan(ccc) - min(cl, ccc)
            cl = 0
        cc = S[i]
        ccc = 1

if cc == '<':
    s += kaidan(ccc) + cl * ccc
else:
    s += kaidan(ccc) - cl

print(int(s))

Solution (Python):
S = input()
ans = 0
a = []
up = True
count = 0
for i in S:
    if up:
        if i == '>':
            a.append(count)
            count = 1
            up = False
        else:
            count += 1
    else:
        if i == '<':
            a.append(count)
            count = 1
            up = True
        else:
            count += 1
a.append(count)
if len(a)%2 == 1:
    a.append(0)
for i in range(0,len(a),2):
    u,d = max(a[i],a[i+1]), min(a[i],a[i+1])-1
    ans += u*(u+1)//2 + d*(d+1)//2
print(ans)

Solution (Python):
S = input()
gt = [0]
for i in range(len(S)):
    if S[i] == '<':
        gt.append(gt[i] + 1)
    else:
        gt.append(0)

lt = [0] * (len(S)+1)
for i in range(len(S)-1, -1, -1):
    if S[i] == '>':
        lt[i] = lt[i+1] + 1
    else:
        lt[i] = 0



print(sum([max(g, l) for g, l in zip(gt, lt)]))

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

Solution (Python):
S = input()

left_count = [0] * (len(S) + 1)
right_count = [0] * (len(S) + 1)

S = "*" + S + "*"
cur_left_count = 0
cur_right_count = 0
for i in range(len(left_count)):
    if S[i] == "<":
        cur_left_count += 1
    else:
        cur_left_count = 0

    if S[-i-1] == ">":
        cur_right_count += 1
    else:
        cur_right_count = 0
    
    left_count[i] = cur_left_count
    right_count[-i-1] = cur_right_count

a =  [max(l, r) for l, r in zip(left_count, right_count)]

print(sum(a))

Solution (Python):
S = input()

left_count = [0] * (len(S) + 1)
right_count = [0] * (len(S) + 1)

S = "*" + S + "*"
cur_left_count = 0
cur_right_count = 0
for i in range(len(left_count)):
    if S[i] == "<":
        cur_left_count += 1
    else:
        cur_left_count = 0

    if S[-i-1] == ">":
        cur_right_count += 1
    else:
        cur_right_count = 0
    
    left_count[i] = cur_left_count
    right_count[-i-1] = cur_right_count

a =  [max(l, r) for l, r in zip(left_count, right_count)]

print(sum(a))

Solution (Python):
S = str(input())
S += '/'
l = [0]*len(S)

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

print(sum(l))

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


small_left=[1 if S[0]=="<" else 0]

large_right=[1 if S[-1]==">" else 0]

for i in range(1,len(S)):
  if S[i]=="<":
    small_left.append(small_left[-1]+1) 
  else:
    small_left.append(0) 
    
for i in range(len(S)-2,-1,-1):
  if S[i]==">":
    large_right.append(large_right[-1]+1) 
  else:
    large_right.append(0) 
large_right = large_right[::-1]


cnt += large_right[0]
for i in range(1,N-1):
  cnt += max(large_right[i], small_left[i-1])
cnt += small_left[-1]

print(cnt)

Solution (Python):



S = input()


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


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

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


ans = sum(num_list)
print(ans)

Solution (Python):
S = input()

i = 0
h = 0
c = 0

while i < len(S):
  hx = 0
  while i < len(S) and S[i] == '<':
    i += 1
    hx += 1
  c += hx * (hx + 1) // 2
  h = hx
  
  hx = 0
  while i < len(S) and S[i] == '>':
    i += 1
    hx += 1
  c += hx * (hx + 1) // 2
  c -= h if hx > h else hx
  h = hx

print(c)

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

print(sum(A))

Solution (Python):
s = input()
L = [0]*(len(s)+1)
R = [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] == '>':
        R[i] = R[i+1]+1

print(sum(max(x, y) for x, y in zip(L, R)))

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

s = readline().rstrip().decode('utf-8')
n = len(s)
count = 0
lst1 = [0]*(n+1)
lst2 = [0]*(n+1)

for i in range(n):
	if s[i] == "<":
		lst1[i+1] = lst1[i]+1
for i in range(n-1,-1,-1):
	if s[i] == ">":
		lst2[i] = lst2[i+1]+1

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

print(ans)

Solution (Python):
s = input()
n = len(s)
l = [0]*(n+1)
r = [0]*(n+1)
for i in range(n):
    if s[i] == "<":
        l[i+1] = l[i] + 1
    if s[~i] == ">":
        r[~(i+1)] = r[~i] + 1
ans = 0
for j in range(n+1):
    ans += max(l[j],r[j])
print(ans)

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

A = [0] * (N + 1)
now = 0
for i, s in enumerate(S, start=1):
    if s == '<':
        now += 1
    else:
        now = 0
    A[i] = now

B = [0] * (N + 1)
now = 0
for i, s in enumerate(S[::-1], start=1):
    if s == '>':
        now += 1
    else:
        now = 0
    B[i] = now
B = B[::-1]

ans = [10**18] * (N + 1)
for i in range(N + 1):
    ans[i] = max(A[i], B[i])
print(sum(ans))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()


def resolve():
    S = list(input())
    ls = len(S)

    rr = [0] * (ls + 1)
    ll = [0] * (ls + 1)

    for i in range(ls):
        if S[i] == '<':
            ll[i+1]=ll[i]+1
    for i in reversed(range(ls)):
        if S[i] == '>':
            rr[i]=rr[i+1]+1


    ans = 0
    for i in range(ls + 1):
        ans += max(ll[i], rr[i])
    print(ans)


resolve()

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

left = [0]*(n+1)
right = [0]*(n+1)

for i in range(n):
    if S[i] == '<':
        left[i+1] = left[i] + 1
for i in range(n):
    if S[n-i-1] == '>':
        right[n-i-1] = right[n-i] + 1

answer = 0
for l, r in zip(left, right):
    answer += max(l, r)

print(answer)

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

l = [0] * n
r = [0] * n

for i, c in enumerate(s, 1):
    if c == '>':
        l[i] = 0
    else:
        l[i] = l[i - 1] + 1

for i, c in enumerate(s[::-1]):
    i = n - 2 - i
    if c == '<':
        r[i] = 0
    else:
        r[i] = r[i + 1] + 1

seq = [x if x > y else y for x, y in zip(l, r)]

ans = sum(seq)
print(ans)

Solution (Python):
S = input()

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


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

print(sum(a))

Solution (Python):
s = str(input())
n = len(s)
cnt = 0
l = []
for i in range(n):
    l.append(cnt)
    if s[i] == '<':
        cnt += 1
    else:
        cnt = 0
else:
    l.append(cnt)


r = []
cnt = 0
for i in reversed(range(n)):
    r.append(cnt)
    if s[i] == '>':
        cnt += 1
    else:
        cnt = 0
else:
    r.append(cnt)
r.reverse()


A = [0]*len(l)
for i in range(len(A)):
    A[i] = max(l[i], r[i])
print(sum(A))

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()

over_count_in_my_left = [0] * (len(S)+1)
over_count_in_my_right = [0] * (len(S)+1)

over = 0
for idx, s in enumerate(S):
    over_count_in_my_left[idx] = over
    if s == '<':
        over += 1
    else:
        over = 0
over_count_in_my_left[-1] = over

over = 0
for idx, s in enumerate(S[::-1], 1):
    over_count_in_my_right[-idx] = over
    if s == '>':
        over += 1
    else:
        over = 0
over_count_in_my_right[0] = over

ans = 0
for a, b in zip(over_count_in_my_left, over_count_in_my_right):
    ans += max(a, b)

print(ans)

Solution (Python):
from itertools import groupby
s=input()
n=len(s)
s=list(s)
gr=groupby(s)
a=[]
for k,g in gr:
    a.append(len(list(g)))

ans=0
nn=len(a)
if s[0]=='<':
    for i in range(nn):
        if i%2==0:
            if i==nn-1:
                if nn%2==1:
                    ans+=a[i]*(a[i]+1)//2
                else:
                    t_max=max(a[i],a[i+1])
                    t_min=min(a[i],a[i+1])
                    t_min-=1
                    ans+=t_max*(t_max+1)//2
                    ans+=t_min*(t_min+1)//2
            else:
                t_max=max(a[i],a[i+1])
                t_min=min(a[i],a[i+1])
                t_min-=1
                ans+=t_max*(t_max+1)//2
                ans+=t_min*(t_min+1)//2                
else:
    for i in range(nn):
        if i==0:
            t_max=a[i]
            ans+=t_max*(t_max+1)//2
            continue
        if i%2==1:
            if i==nn-1:
                if nn%2==0:
                    ans+=a[i]*(a[i]+1)//2
                else:
                    t_max=max(a[i],a[i+1])
                    t_min=min(a[i],a[i+1])
                    t_min-=1
                    ans+=t_max*(t_max+1)//2
                    ans+=t_min*(t_min+1)//2
            else:
                t_max=max(a[i],a[i+1])
                t_min=min(a[i],a[i+1])
                t_min-=1
                ans+=t_max*(t_max+1)//2
                ans+=t_min*(t_min+1)//2 

print(ans)

Solution (Python):
S = input()
ls = []
rs = []
if S[0] == '>':
    ls.append(0)
pre = None
seq = 0
for c in S:
    if c == pre:
        seq += 1
    else:
        if pre:
            if pre=='<':
                ls.append(seq)
            else:
                rs.append(seq)
        seq = 1
        pre = c
if pre=='<':
    ls.append(seq)
else:
    rs.append(seq)
if len(ls) > len(rs):
    rs.append(0)

ans = 0
for l,r in zip(ls,rs):
    if l<r: l,r = r,l
    ans += l*(l+1)//2 + r*(r-1)//2
print(ans)

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


x=[len(list(v)) for k,v in groupby(s)]

n=len(x)

ans=0
if s[0]==">":
    ans+=(x[0]+1)*x[0]//2
    n-=1
    del x[0]
if s[-1]=="<":
    ans+=(x[-1]+1)*x[-1]//2
    n-=1
for i in range(0,n,2):
    ma=max(x[i],x[i+1])
    mi=min(x[i],x[i+1])
    ans+=ma*(ma+1)//2
    ans+=(mi-1)*mi//2
print(ans)

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    S = input().strip("\n")
    N = len(S)
    A = [0] * (N + 1)
    Start = []
    if S[0] == "<": Start.append(0)
    for i in range(N - 1):
        if S[i] == ">" and S[i+1] == "<": Start.append(i + 1)
    if S[N-1] == ">": Start.append(N)
    for s in Start:
        if s < N:
            for r in range(s, N):
                if S[r] == ">": break
                else: A[r + 1] = max(A[r + 1], A[r] + 1)
    for s in Start:
        if s > 0:
            for r in reversed(range(1, s + 1)):
                if S[r - 1] == "<": break
                else: A[r - 1] = max(A[r - 1], A[r] + 1)
    
    print(sum(A))
    

    
    
    return 0

if __name__ == "__main__":
    solve()