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

Solution (Python):


import sys
from operator import itemgetter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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

A = []
s = 0
for i in range(N-2):
    if S[i] != S[i+1]:
        A.append((i+1-s, S[i], s, i+1))
        s = i + 1
A.append((N-1-s, S[-1], s, N-1))

A.sort(key=itemgetter(0), reverse=True)

B = [-1] * N
for n, s, l, r in A:
    cnt = 0
    if s == '<':
        for i in range(l, r+1):
            if B[i] == -1:
                B[i] = cnt
            cnt += 1
    else:
        for i in range(r, l-1, -1):
            if B[i] == -1:
                B[i] = cnt
            cnt += 1
print(sum(B))

Solution (Python):
from itertools import groupby

S = input()

p = 0
s = 0
for key, values in groupby(S):
    l = len(list(values))
    s = s + (l * (l+1))//2
    if key == '>':
        s = s - min(l, p)
    if key == '<':
        p = l

print(s)

Solution (Python):
func = list(input())
mont = []
num=1
if len(func)==1 and func[0]==">":
  print(1)
else:
  for i in range(len(func)):
    if i == len(func)-1:
      if func[i]=="<":
        mont.append(num)
        mont.append(0)
      else:
        
        mont.append(num)
    elif i==0 and func[0] ==">":
      mont.append(0)
      num=1
    elif func[i] == "<" and func[i+1]==">":
      mont.append(num)
      num=0
    elif func[i] == ">" and func[i+1]=="<":
      mont.append(num)
      num=0
    else:
      pass
    num += 1

  count=0
  for i in range(0,len(mont),2):
    if mont[i] >= mont[i+1]:
      count+= mont[i]*(mont[i]+1)//2 + mont[i+1]*(mont[i+1]-1)//2
    else:
      count+= mont[i]*(mont[i]-1)//2 + mont[i+1]*(mont[i+1]+1)//2
  print(count)

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

ans = 0
last_s = s[0]
if last_s == '<':
    l, r = 1, 0
else:
    l, r = 0, 1
for i in range(1, n):
    if last_s == '<':
        if s[i] == '<':
            l += 1
        else:
            r += 1
            last_s = '>'
    else:
        if s[i] == '>':
            r += 1
        else:
            M = max(l, r)
            m = min(l, r)
            ans += M*(M+1)//2 + m*(m-1)//2
            l, r = 1, 0
            last_s = '<'

if last_s == '<':
    ans += l*(l+1)//2
else:
    M = max(l, r)
    m = min(l, r)
    ans += M*(M+1)//2 + m*(m-1)//2

print(ans)

Solution (Python):
def wa(nature):
    nature_i = len(nature)
    return nature_i*(nature_i+1)//2
in_str = input()
moji_ls = []
i = 1
taiki = in_str[0]
len_in_str =len(in_str)
while i < len_in_str:
    if taiki[0] == in_str[i]:
        taiki += in_str[i]
        i += 1
    else:
        moji_ls.append(taiki)
        taiki = in_str[i]
        i += 1
moji_ls.append(taiki)


sub = 0
moji_ls_len = len(moji_ls)
i = 0
while i < moji_ls_len:
    if moji_ls[i][0] == '<':
        if i == moji_ls_len-1:
            sub += wa(moji_ls[i])
        else:
            sub += wa(moji_ls[i]) - min(len(moji_ls[i]),len(moji_ls[i+1]))
    else:
        sub += wa(moji_ls[i])
    i += 1
print(sub)

Solution (Python):

import itertools

total = 0
last_l = 0
s = [c for c in input()]
for k,g in itertools.groupby(s):
    l = len(list(g))
    
    total += (l+1)*l//2
    if(k=='>'):
        if(last_l <= l):
            total -= last_l
            
        else:
            total -= l
            
    last_l = l
print(total)

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

Solution (Python):
s = input()
n = len(s) + 1
lis = [0] * n
if s[0] == "<":
  lis[0] = 0
p = 1
while p < n - 1:
  if s[p - 1] == ">" and s[p] == "<":
    lis[p] = 0
  elif s[p - 1] == "<" and s[p] == "<":
    lis[p] = max(lis[p - 1] + 1, lis[p])
  elif s[p] == ">":
    pass
  p += 1
    
if s[-1] == ">":
  lis[-2] = 1
  lis[-1] = 0
  
p = n - 3
while p >= 0:
  if s[p] == ">" and s[p + 1] == "<":
    if p - 1 >= 0:
      lis[p] = max(lis[p + 1] + 1, lis[p], lis[p - 1] + 1)
    else:
      lis[p] = 1
  elif s[p] == ">" and s[p + 1] == ">":
    if p - 1 >= 0:
      lis[p] = max(lis[p + 1] + 1, lis[p], lis[p - 1] + 1)
    else:
      lis[p] = max(lis[p + 1] + 1, lis[p])
  elif s[p] == "<":
    pass
  p -= 1

if s[-1] == "<":
  lis[-1] = lis[-2] + 1
  
print(sum(lis))

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

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

n = [0]
for i in range(1, N + 1):
  n.append(n[-1] + i)

ans = 0
cnt_L = 0
cnt_R = 0
for i in range(N - 1):
  if i == 0:
    if S[i] == "<":
      cnt_L += 1
    else:
      cnt_R += 1
  elif S[i] != S[i - 1] and S[i] == "<":
    if cnt_L > 0:
      ans += n[max(cnt_L, cnt_R)] + n[min(cnt_L, cnt_R) - 1]
    else:
      ans += n[cnt_R]

    cnt_L = 1
    cnt_R = 0
  else:
    if S[i] == "<":
      cnt_L += 1
    else:
      cnt_R += 1
if S[-1] == "<":
  ans += n[cnt_L]
else:
  if cnt_L > 0:
    ans += n[max(cnt_L, cnt_R)] + n[min(cnt_L, cnt_R) - 1]
  else:
    ans += n[cnt_R]
print(ans)

Solution (Python):
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = str(input().rstrip('\n'))
    s = list(map(str, s.replace("><", ">_<").split("_")))
    cnt = 0
    for v in s:
        a = 0
        b = 0
        for i in range(len(v)):
            if v[i] == "<":
                a += 1
            else:
                b += 1
        if a != 0 and b != 0:
            cnt += (a - 1) * (1 + a - 1) // 2 + (b - 1) * (1 + b - 1) // 2
            cnt += max(a, b)
        elif b != 0:
            cnt += b * (1 + b) // 2
        elif a != 0:
            cnt += a * (1 + a) // 2
    print(cnt)


if __name__ == '__main__':
    solve()

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

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

A=[0]*(N+1)
L=[]
if S[0]=="<":
  r=1
  l=0
else:
  l=1
  r=0

for i in range(1,N):
  if S[i]=="<":
    r+=1
    if S[i]!=S[i-1]:
      L.append(-l)
      l=0
  else:
    l+=1
    if S[i]!=S[i-1]:
      L.append(r)
      r=0
if r>0:
  L.append(r)
elif l>0:
  L.append(-l)
      
m=max(abs(max(L)),abs(min(L)))
ans=0
if S[0]=="<":
  if len(L)%2==0:
    for i in range(len(L)//2):
      ma=max(L[2*i],-L[2*i+1])
      mi=min(L[2*i],-L[2*i+1])
      ans+=ma*(ma+1)//2+(mi-1)*mi//2
  else:
    for i in range(len(L)//2):
      ma=max(L[2*i],-L[2*i+1])
      mi=min(L[2*i],-L[2*i+1])
      ans+=ma*(ma+1)//2+(mi-1)*mi//2
    ans+=L[-1]*(L[-1]+1)//2
    
if S[0]==">":
  ans+=(-L[0])*(-L[0]+1)//2
  if len(L)%2==0:
    for i in range(len(L)//2-1):
      ma=max(L[2*i+1],-L[2*i+2])
      mi=min(L[2*i+1],-L[2*i+2])
      ans+=ma*(ma+1)//2+(mi-1)*mi//2
    ans+=L[-1]*(L[-1]+1)//2
  else:
    for i in range(len(L)//2):
      ma=max(L[2*i+1],-L[2*i+2])
      mi=min(L[2*i+1],-L[2*i+2])
      ans+=ma*(ma+1)//2+(mi-1)*mi//2

print(ans)

Solution (Python):
S = input()

ans = 0
count_l = 0
count_u = 0

if S[0] == '<':
    count_u += 1
elif S[0] == '>':
    count_l += 1


for i in range(1, len(S)):
    if S[i] == '<' and S[i] != S[i-1]:
        if count_u < count_l:
            count_u -= 1
        else:
            count_l -= 1
        ans += count_u * (count_u+1) /2 + count_l * (count_l+1) /2
        count_u = 1
        count_l = 0
    elif S[i] == '<':
        count_u += 1
    elif S[i] == '>':
        count_l += 1

if count_u < count_l:
    count_u -= 1
else:
    count_l -= 1

ans += count_u * (count_u+1) /2 + count_l * (count_l+1) /2

print(int(ans))

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

for i in range(len(s)):
    if s[i] == '>': continue
    arr[i+1] = arr[i] + 1

for i in range(len(s))[::-1]:
    if s[i] == '<': continue
    
    if arr[i] > arr[i+1]+1:continue
    else: arr[i] = arr[i+1]+1
print(sum(arr))

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

S = list(input().strip())
S.append("<")

L = [0] * len(S)
tmp = ">"

for i in range(len(S)):
    if tmp == ">" and S[i] == "<":
        L[i] == 0
    elif tmp == ">" and S[i] == ">":
        pass
    elif tmp == "<" and S[i] == "<":
        L[i] = L[i-1] + 1
    elif tmp == "<" and S[i] == ">":
        L[i] = L[i-1] + 1
    tmp = S[i]

tmp = S[-1]
for i in range(len(S)-2, -1, -1):
    if tmp == ">" and S[i] == "<":
        L[i+1] = max(L[i+1], L[i+2] + 1)
    elif tmp == ">" and S[i] == ">":
        L[i+1] = L[i+2] + 1
    elif tmp == "<" and S[i] == "<":
        pass
    elif tmp == "<" and S[i] == ">":
        pass
    tmp = S[i]

if S[0] == ">" and S[1] == ">":
    L[0] = L[1] + 1
elif S[0] == ">" and S[1] == "<":
    L[0] = max(L[0], L[1] + 1)

print(sum(L))

Solution (Python):
s = input() + "<"

a = 0
b = 0
ans = 0
pre = s[0]

for i in s:
    if i == ">":
        a += 1
        if pre == "<":
            ans += ((1 + b - 1) * (b - 1)) // 2
        pre = i
    if i == "<":
        if pre == ">":
            if b <= a:
                ans += ((1 + a) * a) // 2
            else:
                ans += ((1 + a - 1) * (a - 1)) // 2 + b
            a = 0
            b = 0
        b += 1
        pre = i
if i == "<":
    ans += ((1 + b - 1) * (b - 1)) // 2
print(ans)

Solution (Python):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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



S=one_str()

temp = S.split("><")

sums=0
length=len(temp)

for ind, i in enumerate(temp):
    left=i.count(">")
    right=i.count("<")
    
    if len(i)==0:
        right+=1
    
    elif ind==0 and length!=1:
        left = i.count(">")+1
        right= i.count("<")
        
    elif ind==length-1 and length!=1:
        left = i.count(">")
        right= i.count("<")+1
        
    elif ind !=0 and ind != length-1:
        left = i.count(">")+1
        right= i.count("<")+1
    
    maxs = max(left,right)
    mins = min(left,right) 
    maxs_array=[value for value in range(maxs+1)]
    mins_array=[value for value in range(mins)]

    sums += sum(maxs_array)
    sums += sum(mins_array)

print(sums)

Solution (Python):
s = input()
l = len(s)
prev = s[0]
a = []
cnt = 0
for i in range(l):
    if s[i] != prev:
        a.append(cnt)
        prev = s[i]
        cnt = 0
    cnt += 1
a.append(cnt)
if s[0]=="<": a = [0]+a
for i in range(len(a)-1): a[i+1] += a[i]
a = a[::2]

b = [0] * (l+1)
s = "=" + s + "="
for i in a:
    bi = 0
    while s[i-bi]==">":
        b[i-bi-1] = max(b[i-bi-1], b[i-bi]+1)
        bi += 1
    bi = 0
    while s[i+bi+1]=="<":
        b[i+bi+1] = max(b[i+bi+1], b[i+bi]+1)
        bi += 1
print(sum(b))

Solution (Python):
s = input()
a = [-1 for i in range(len(s)+1)]
for i in range(len(s)-1):
    if s[i] == '>' and s[i+1] == "<":
        a[i+1] = 0
if s[0] == "<":
    a[0] = 0
if s[-1] == ">":
    a[-1] = 0
def plus(i):
    j = i -1
    while j >= 0 and s[j] == '>':
        a[j] = max(a[j+1] + 1, a[j])
        j -= 1
    j = i
    if j == len(a) -1:
        return
    while s[j] == '<':
        a[j+1] = max(a[j] + 1, a[j+1])
        j += 1
        if  j == len(a) - 1:
            break
for i in range(len(a)):
    if a[i] == 0:
        plus(i)
print(sum(a))

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

lp = [0] * n
rp = [0] * n

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

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

total = 0
for i in range(n):
  total += max(lp[i], rp[i])

print (total)

Solution (Python):
import itertools
S = input()
ans = 0
s = itertools.groupby(S)
b=0
for key,group in s:
  if key=="<":
    a = len(list(group))
    ans += ((b+b+a)*(a+1))/2
    b = a
  elif key==">":
    a = len(list(group))
    if b<=a:
      ans +=(b+abs(b-a)+0)*(a+1)/2-b
      b=0
    else:
      ans +=((a-1)*(a))/2
      b=0
    
print(int(ans))

Solution (Python):
s=input()
cnt1=0
cnt2=1
ans=0
for i in range(len(s)-1):
    if s[i]==">" and s[i+1]=="<":
        a=max(cnt1,cnt2)
        b=max(min(cnt1,cnt2)-1,0)
        
        ans+=(a*(a+1)+b*(b+1))//2
        cnt1=0
        cnt2=1
    elif s[i]=="<":
        cnt1+=1
    else:
        cnt2+=1
if s[len(s)-1]=="<" and s[len(s)-2]=="<":
    cnt1+=1

a=max(cnt1,cnt2)
b=max(min(cnt1,cnt2)-1,0)
ans+=(a*(a+1)+b*(b+1))//2
print(ans)

Solution (Python):
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    s = input()
    n = len(s)
    l = []
    a,b = 0,0
    for i in range(n):
        if s[i] == "<":
            if b > 0:
                l.append(b)
                b = 0
            a+=1
        else:
            if a > 0:
                l.append(a)
                a = 0
            b += 1
    if a > 0:
        l.append(a)
        a = 0
    if b > 0:
        l.append(b)
        b = 0
    ans = 0
    
    if s[0] == "<":
        for i in range(0, len(l) - len(l) % 2, 2):
            if l[i] == l[i + 1]:
                ans += l[i]*l[i]
            elif l[i] < l[i + 1]:
                ans += l[i] * (l[i] - 1) // 2
                ans += l[i + 1] * (l[i + 1] + 1) // 2
            else:
                ans += l[i] * (l[i] + 1) // 2
                ans += l[i + 1] * (l[i + 1] - 1) // 2
        if len(l) % 2 == 1:
            ans += l[len(l) - 1] * (l[len(l) - 1] + 1) // 2
    else:
        ans += l[0]*(l[0]+1)//2
        for i in range(1, (len(l)-1) - (len(l)-1) % 2, 2):
            if l[i] == l[i + 1]:
                ans += l[i]*l[i]
            elif l[i] < l[i + 1]:
                ans += l[i] * (l[i] - 1) // 2
                ans += l[i + 1] * (l[i + 1] + 1) // 2
            else:
                ans += l[i] * (l[i] + 1) // 2
                ans += l[i + 1] * (l[i + 1] - 1) // 2
        if (len(l)-1) % 2 == 1:
            ans += l[len(l) - 1] * (l[len(l) - 1] + 1) // 2

                

    print(ans)
             
        
        
            

    
   


if __name__ == '__main__':
    main()

Solution (Python):
import sys
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
N = len(s)

ans = [-1]*(N+1)
ans[0] = 0
ans[-1] = 0
tmp = 0
for i in range(N-1):
  if s[i] == "<":
    tmp += 1
    ans[i + 1] = tmp
  elif s[i] == ">" and s[i + 1] == "<":
    tmp = 0
    ans[i + 1] = tmp
else:
  if s[-1] == "<":
    ans[-1] = ans[-2] + 1

tmp = 0
for i in range(N-1,0,-1):
  if s[i] == ">":
    tmp += 1
    if s[i - 1] == "<":
      ans[i] = max(ans[i], tmp)
    else:
      ans[i] = tmp
  elif s[i] == "<" and s[i - 1] == ">":
    tmp = 0
    ans[i] = tmp
  
else:
  if s[0] == ">":
    ans[0] = ans[1] + 1

print(sum(ans))

Solution (Python):
s=str(input())
arr=[0]
sumx=0
i=0
while(i<len(s)):
	if(s[i]=='<'):
		arr.append(arr[-1]+1)
		i+=1
	else:
		countx=0
		j=i
		while(j<len(s) and s[j]=='>'):
			countx+=1
			j+=1
		if(arr[-1]<countx):
			arr[-1]=countx
		while(i<j):
			arr.append(countx-1)
			countx-=1
			i+=1

print(sum(arr))

Solution (Python):
S = input()
sep = [0]
i=0
for i in range(len(S)-1):
    if S[i]=='<' and S[i+1]=='>': sep.append(i+1)
sep.append(i+2)

S += 'X'
ans = 0
center = 0
for i in range(len(sep)-1):
    s = S[sep[i]: sep[i+1]]
    l_max = s.count('>')
    ans += max(center, l_max)
    ans += l_max*(l_max-1)//2

    r_max = s.count('<')
    ans += r_max*(r_max-1)//2
    center = r_max

ans += center
print(ans)

Solution (Python):
S=input()
V=[]
ans=0
num=[-1]*len(S)
for s in S:
	if len(V)==0 or V[-1][0]!=s:
		V.append([s,1])
	else:
		V[-1][1] += 1
if len(V)==1:print(V[0][1]*(V[0][1]+1)//2);exit()
c=len(V)
if V[0][0]==">":
  ans+=V[0][1]*(V[0][1]+1)//2
  del V[0]
  c-=1
if V[-1][0]=="<":
  ans+=V[-1][1]*(V[-1][1]+1)//2
  del V[-1]
  c-=1

for i in range(c//2):
  M=max(V[2*i][1],V[2*i+1][1])
  m=min(V[2*i][1],V[2*i+1][1])
  ans+=M*(M+1)//2+m*(m-1)//2
print(ans)

Solution (Python):
def answer():
    input_s = input()

    sign_list = [input_s[0]]
    n_list = [1]

    for sign in input_s[1:]:
        previous_sign = sign_list[-1]

        if sign == previous_sign:
            n_list[-1] += 1
        else:
            sign_list.append(sign)
            n_list.append(1)

    for i, sign in enumerate(sign_list[:-1]):
        if sign == '<':
            this_n = n_list[i]
            next_n = n_list[i+1]
            if this_n < next_n:
                n_list[i] -= 1
            else:
                n_list[i+1] -= 1

    total = 0
    for n in n_list:
        total += n*(n+1)//2

    print(total)


if __name__ == '__main__':
    answer()

Solution (Python):
import sys

s = list(input())
ans = 0
point = 0

if s[len(s)-1] == "<":
    s.append(">")

def walk(n):
    sum = 0
    i = n
    l = len(s)
    while True:
        sum += 1
        if i+1 < l:
            if s[i] != s[i+1]:
                break
        else:
            break
        i += 1
    return sum

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

if s[0] == ">":
    point = walk(0)
    ans += sigma(point)

if point == len(s):
    print(ans)
    sys.exit()

while True:
    d1 = walk(point)
    point += d1
    ans += sigma(d1-1)
    d2 = walk(point)
    point += d2
    ans += max(d1,d2)
    ans += sigma(d2-1)
    if point == len(s):
        break

print(ans)

Solution (Python):

"""
Created on Sun Nov  3 14:57:33 2019

@author: Tomomasa Takahashi
"""

S=input()
tot = 0
lcont=0
scont=0
for i in range(len(S)):
    if S[i]=='<':
        lcont += 1
    else:
        scont += 1
    if i < len(S)-1:
        if S[i]==">" and S[i+1]=='<':
            t = max(lcont, scont)
            s = min(lcont, scont)-1
            tot += t*(t+1)//2
            tot += s*(s+1)//2
            lcont=0
            scont=0
t = max(lcont, scont)
s = min(lcont, scont)-1
tot += t*(t+1)//2
tot += s*(s+1)//2
print(tot)

Solution (Python):
def calc_count(token):
    num_left = token.count('<')
    num_right = token.count('>')
    sum_left = sum(range(num_left))
    sum_right = sum(range(num_right))
    midle = max(num_left, num_right)
    return sum_left + sum_right + midle


def main(n):
    strings = n.replace('><', '>|<').split('|')
    return sum([calc_count(s) for s in strings])


if __name__ == '__main__':
    N = input().strip()
    print(main(n=N))

Solution (Python):
s = input()

li = []

tmp = s[0]

if tmp == '<':
    flag = 0
else:
    flag = 1

now = 1

for i in range(len(s)-1):
    if tmp == s[i+1]:
        now += 1
    else:
        tmp = s[i+1]
        li.append(now)
        now = 1

li.append(now)

ans = 0


if flag == 0:
    ans_li = [0]
    for i in range(len(li)):
        if i % 2 == 0:
            for j in range(li[i]):
                ans_li.append(j+1)
        else:
            if li[i] > ans_li[-1]:
                ans_li[-1] = li[i]
            for k in range(li[i]):
                ans_li.append(li[i]-k-1)
else:
    ans_li = [li[0]]
    for i in range(len(li)):
        if i % 2 == 1:
            for j in range(li[i]):
                ans_li.append(j+1)
        else:
            if i != 0 and li[i] > ans_li[-1]:
                ans_li[-1] = li[i]
            for k in range(li[i]):
                ans_li.append(li[i]-k-1)

print(sum(ans_li))

Solution (Python):
import collections
S = input()

s = list(S.split("><"))
ans = 0
for i in range(len(s)):
    table = collections.defaultdict(int)
    for y in s[i]:
        table[y] += 1

    if i == 0 and len(table) != 0:
        table["<"] -= 1
    if i == len(s)-1 and len(table) != 0:
        table[">"] -= 1
    table = list(table.values())
    if len(table) == 2:
        table.sort()
        ans += max((table[1]+1)*(table[1]+2) // 2, 0)
        ans += max((table[0]+1)*table[0] // 2, 0)

    elif len(table) == 1:
        ans += max((table[0]+1)*(table[0]+2) // 2, 0)
    else:
        ans += 1
print(ans)

Solution (Python):
s=input()
if s[0]==">":s="<"+s
if s[-1]=="<":s=s+">"
tmps="<"
tmp1,tmp2=0,0
ans=0
for i in s:
    if tmps=="<":
        if i=="<":
            tmp1+=1
        else:
            tmps=i
            tmp2+=1
    else:
        if i==">":
            tmp2+=1
        else:
            ans+=tmp1*(tmp1+1)//2+tmp2*(tmp2+1)//2-min(tmp1,tmp2)
            tmp1,tmp2=1,0
            tmps=i
ans+=tmp1*(tmp1+1)//2+tmp2*(tmp2+1)//2-min(tmp1,tmp2)
print(ans)

Solution (Python):
s = input()

ans = 0
f = 0
be = 0
for k in range(len(s)):
    if s[k] == '<':
        if f != 0 and be != 0:
            ans -= be * f
            be = 0
        ans += be + 1
        f = 0
        be += 1
    elif be ==0:
        f += 1
        ans += be + f
    else:
        f += 1
        ans += be - 1
        be = be - 1
print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 18
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


s = S()
ans = [0] * (len(s) + 1)
ret = 0
for j in range(len(s) - 1, -1, -1):
    if s[j] == '>':
        ret += 1
        ans[j] = ret
    else:
        ret = 0


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



print(sum(ans))

Solution (Python):
s = list(input())
pre_index = 0
split_s = []
for i in range(len(s) - 1):
    if s[i] == '>' and s[i + 1] == '<':
        split_s.append(s[pre_index:i+1])
        pre_index = i + 1
split_s.append(s[pre_index:])
ans = 0
for i in range(len(split_s)):
    l = split_s[i].count('<')
    r = split_s[i].count('>')
    if l > r:
        ans += sum(range(1,l+1))
        ans += sum(range(1,r))
    else:
        ans += sum(range(1,r+1))
        ans += sum(range(1,l))
print(ans)

Solution (Python):
S = input()

L = []
s = 0
u = 0

for i in range(len(S)-1):
  if S[i] != S[i+1]:
    L.append(i+1-u)
    u = i+1
L.append(len(S)-u)

if S[0] == '<':
  if len(L) % 2 == 1:
    L.append(0)
  for j in range(len(L) // 2):
    M = max(L[2*j], L[2*j+1])
    m = min(L[2*j], L[2*j+1])
    s += (M * (M + 1)) // 2 + (m * (m-1)) // 2
elif S[0] == '>':
  s += (L[0] * (L[0] + 1)) // 2
  del L[0]
  if len(L) % 2 == 1:
    L.append(0)
  for j in range(len(L) // 2):
    M = max(L[2*j], L[2*j+1])
    m = min(L[2*j], L[2*j+1])
    s += (M * (M + 1)) // 2 + (m * (m-1)) // 2
    
print(s)

Solution (Python):
s=input()
n=len(s)
l=[0]*(n+1)
ans=0
c=1
ll=[]
for i in range(1,n):
    if s[i]==s[i-1]:
        c+=1
    else:
        ll.append((c,i,s[i-1]))
        c=1


for x,y,h in ll:
    if h=="<":
        l[y]=max(l[y],x)
    else:
        l[y-x]=max(l[y-x],x)


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

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

print(sum(l))

Solution (Python):
s = list(input())
s.append(" ")
n = len(s)
i = 0
ans = []
j = 1
while i<n-1:
    if s[i]==s[i+1]:
        i+=1
        j+=1
    else:
        ans.append([s[i],j])
        i+=1
        j =1
m = len(ans)
answer = 0
i = 0
while i<m:
    if i==m-1:
        x = ans[i][1]*(ans[i][1]+1)
        x = x//2
        answer +=x
        break
    
    if ans[i][0]=="<" and ans[i][1]>=ans[i+1][1]:
        x = ans[i][1]*(ans[i][1]+1)
        x = x//2
        answer +=x 
        y = ans[i+1][1]*(ans[i+1][1]-1)
        y = y//2
        answer +=y
        i+=2
    elif ans[i][0]=="<" and ans[i][1]<ans[i+1][1]:
        x = ans[i][1]*(ans[i][1]-1)
        x = x//2
        answer+=x
        y = ans[i+1][1]*(ans[i+1][1]+1)
        y = y//2
        answer +=y
        i +=2
    else:
        x = ans[i][1]*(ans[i][1]+1)
        x = x//2
        answer +=x
        i+=1
print(answer)

Solution (Python):
import sys

input = sys.stdin.readline
s = input()
lft, rgt = 0, 0
cnt = 0
tmp = ""
for cur in s:
    if tmp == ">" and cur == "<":
        lar = max(lft, rgt)+1
        sma = min(lft, rgt)
        cnt += sum(range(lar)) + sum(range(sma))
        lft, rgt = 1, 0
    elif cur == ">":
        rgt += 1
    elif cur == "<":
        lft += 1
    tmp = cur

lar = max(lft, rgt)+1
sma = min(lft, rgt)
cnt += sum(range(lar)) + sum(range(sma))
print(cnt)

Solution (Python):
s = input()
n = len(s)+1
num = 0
ans = 0
con = 0


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

        num -= 1
        if num < 0:
            num = 0
            ans += con
    else:
        if not con == 0:
            ans = ans - num*(con)
            num = 0
        num += 1
        con = 0
    ans += num
print(ans)

Solution (Python):
s = input()
n = len(s)+1
a = [-1]*n
flag = False
for i in range(n-1):
    if s[i] == "<":
        if not flag: a[i] = 0
        a[i+1] = a[i]+1
        flag = True
    else: flag = False
flag = False
for i in range(n-1):
    j = n-2-i
    if s[j] == ">":
        if not flag: a[j+1] = 0
        a[j] = max(a[j], a[j+1]+1)
        flag = True
    else: flag = False
print(sum(a))

Solution (Python):
import sys

input = sys.stdin.readline

S = input().strip()


a = [0]*(5*10**5)

i = 0
while i<=len(S)-1:
	si = S[i]
	if si=='<':
		a[i+1] = a[i]+1 
		i += 1
	else:
		dec_num = 0
		j = i
		while S[j]=='>':
			dec_num += 1
			j += 1
			if j==len(S): break

		for n in range(dec_num):
			a[i+n] = max(dec_num,a[i+n])
			dec_num -= 1

		i = j

ans = sum(a)

print(ans)

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

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

mins = 0
sums = 0
starti = 0
inc = False
if s[0] == '<':
    inc = True
for i in range(1, n):
    if inc == True:
        sl[i] = sl[i-1]+1
        if i == n-1 or s[i] == '<':
            sums += sl[i]
        else:
            starti = i
            sl[i] = 0
            inc = False
    else:
        if i == n-1 or s[i] == '<':
            sl[i] = sl[i-1]-1
            nums = i - starti -1
            if starti != 0 and sl[starti-1]+1 > -1* sl[i]:
                sums += sl[starti-1]+1
                sl[starti-1] = sl[starti-1]+1
            else:
                nums += 1
            sums += -1 * sl[i] * nums
            sl[i] = 0
            inc = True
        else:
            sl[i] = sl[i-1] -1
            sums += sl[i]


print(sums)

Solution (Python):
s = input()
value = [-1] * (len(s) + 1)

count = 0

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

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

Solution (Python):
s = input()
s += "a"
n = len(s)
k = 1
lis = []
for i in range(n-1):
  if s[i] != s[i+1]:
    lis.append(k)
    k = 1
  else:
    k += 1
def fac(i):
  return i*(i+1)//2
lislis = []
num = len(lis)
for i in range(num):
  lislis.append(fac(lis[i]))
ans = sum(lislis)
if s[0] == "<":
  for i in range(0, num-1, 2):
    l = min(lis[i], lis[i+1])
    ans -= l
else:
  for i in range(1, num-1, 2):
    l = min(lis[i], lis[i+1])
    ans -= l
print(ans)

Solution (Python):

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


S = input()

if S[0] == '>':
    S = '<' + S
    

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



s_pre = '<'
sum_s_tmp = 0
rencho = []  
for s in S:
    if s_pre == s:
        sum_s_tmp += 1
    else:
        rencho.append(sum_s_tmp)
        sum_s_tmp = 1
        s_pre = s
rencho.append(sum_s_tmp)


ans = 0
for a_big, a_small in zip(rencho[0::2], rencho[1::2]):
    if a_big < a_small:
        a_big, a_small = a_small, a_big
    ans += sum(range(a_big + 1))
    ans += sum(range(a_small))


print(ans)