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 = input()
b = s[0]
cou = 0


lis = []
for i in s:
    if b ==i:
        if i=='<':
            cou-=1
        else:
            cou+=1
    else:
        lis.append(cou)
        b = i
        if b=='<':
            cou =-1
        else:
            cou = 1
lis.append(cou)
l = len(lis)
sum = 0
if s[0]=='<':
    for i in range(0,l,2):
        if i+1 == l and (i+1)%2==1:
            a = abs(lis[i])
            sum += a*(a+1)//2
            break
        a = abs(lis[i])
        b = abs(lis[i+1])

        if a < b:
            sum += b*(b+1)//2
            sum += (a-1)*a//2
        else:
            sum += a*(a+1)//2
            sum += (b-1)*b//2
else:
    a = abs(lis[0])
    sum += a*(a+1)//2
    for i in range(1,l,2):
        if i+1 == l and (i+1)%2==0:
            a = abs(lis[i])
            sum += a*(a+1)//2
            break
        a = abs(lis[i])
        b = abs(lis[i+1])

        if a < b:
            sum += b*(b+1)//2
            sum += (a-1)*a//2
        else:
            sum += a*(a+1)//2
            sum += (b-1)*b//2

print(sum)

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

for i in range(1,n):
  if s[i-1]=="<":
    x[i]=x[i-1]+1
  else:
    x[i]=0
    
for j in range(n-2,-1,-1):
  if s[j]==">":
    y[j]=y[j+1]+1
  else:
    y[j]=0

for k in range(0,n):
  a[k]=max(x[k],y[k])
  
print(sum(a))

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

i=1
ans=0
mode=2
con=1
anslist=[]
if s[0]==">":
  mode=0
else:
  mode=1


while i!=len(s):

  if s[i]==">":
    if mode==0:
      con+=1
    else:
      anslist.append([con,"<"])



      mode=0
      con=1
  else:
    if mode==1:
      con+=1
    else:
      anslist.append([con,">"])

      mode=1
      con=1
  i += 1

if s[-1]=="<":
  anslist.append([con, "<"])

else:
  anslist.append([con, ">"])

i=0
while i!=len(anslist):
  try:
    if anslist[i][1]=="<":
      if anslist[i][0]<=anslist[i+1][0]:
        anslist[i][0]=anslist[i][0]-1
    else:
      if anslist[i][0]<=anslist[i-1][0] and i!=0:
        anslist[i][0]=anslist[i][0]-1

  except:
    pass
  i+=1



i=0
ans=0
while i!=len(anslist):
  ans+=anslist[i][0]*(anslist[i][0]+1)/2
  i+=1

print(int(ans))

Solution (Python):
from itertools import groupby
def sum_until_n(n): return (n+1)*n//2

S = groupby(input())
ans = 0
prv_r_val = 0
for key, value in S:
  value = list(value)
  len_value = len(value)
  if key == '<':
    ans += sum_until_n(prv_r_val+len_value) - sum_until_n(prv_r_val)
    prv_r_val += len_value
  else:
    if prv_r_val-len_value < 0:
      ans +=  abs(prv_r_val-len_value)     
      
    ans += sum_until_n(len_value-1)
    prv_r_val = 0      
print(ans)

Solution (Python):
s = input()


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

n = len(s)+1


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

tani = []
yama = []

if s[0] =='<':
  tani.append(0)
elif s[0] =='>':
  yama.append(0)


for i in range(n-1):
  if s[i:i+2] =='><':
    tani.append(i+1)
  elif s[i:i+2] =='<>':
    yama.append(i+1)
    
if s[-1] =='>':
  tani.append(n-1)
elif s[-1] =='<':
  yama.append(n-1) 


count = 0
for i in range(len(yama)):
  d1 = yama[i]-tani[i]
  d2 = tani[i+1]- yama[i]
  count += rui(max(d1,d2)) + rui(min(d1,d2)-1)
  
print(count)

Solution (Python):
S = input()


if len(S) == 1:
    print("1")
    exit()

s_list = []
head_num = 10**6 if S[0] == ">" else 0
s_list.append(head_num)
for i in range(len(S)-1):
    if S[i] == ">" and S[i+1] == "<":
        s_list.append(0)
    elif S[i] == "<":
        s_list.append(s_list[i]+1)
    else:
        s_list.append(s_list[i]-1)
if S[len(S)-1] == "<":
    s_list.append(s_list[len(S)-1] +1)
else:
    s_list.append(s_list[len(S)-1] -1)


count = 1
s_list[len(s_list)-1] = 0 if s_list[len(s_list)-1] < 0 else s_list[len(s_list)-1] 

for i in range(len(S)-1,0,-1):
    if S[i] == ">" and S[i-1] == ">":
    
        s_list[i] = count
        count += 1
    elif S[i] == ">" and S[i-1] == "<":
        s_list[i] = max(s_list[i-1], s_list[i+1]) + 1
    else:
        count = 1

if S[0] == ">":
    s_list[0] = s_list[1] + 1
if S[len(S)-1] == ">":
    s_list[len(s_list)-1] =  0




sum = 0
for i in range(len(s_list)):
    sum += s_list[i]

print(sum)

Solution (Python):
S = input()

N = len(S) + 1
L = []
counter = 0

for n in range(N-2):
    counter += 1
    if S[n]!=S[n+1]:
        L.append(counter)
        counter = 0
            
L.append(counter+1)

if S[0]=='<':
    K = len(L)//2
    for k in range(K):
        if L[2*k] <= L[2*k+1]:
            L[2*k] -= 1
        else:
            L[2*k+1] -= 1

else:
    K = (len(L)-1)//2
    for k in range(K):
        if L[2*k+1] <= L[2*k+2]:
            L[2*k+1] -= 1
        else:
            L[2*k+2] -= 1
        
print(sum([l*(l+1)//2 for l in L]))

Solution (Python):
S = list(input())
ans = 0
now = 0
count = 0
a = 0
for i in S:
  if i == "<":
    if count > 0:
      if count == 1:
        now = 0
        count = 0
      else:
        if count > now:
          ans = ans +  sum(range(1, count+1)) - now
          now = 0
          count = 0
        else:
          ans = ans + sum(range(1, count))
          now = 0
          count = 0
    now += 1
    a = 1
  else:
    if a == 1:
      ans += sum(range(1, now+1))
      a = 0
    count += 1
if a == 1:
  ans += sum(range(1, now+1))
elif count > 0:
  if count == 1:
    if now == 0:
      ans += 1
      now = 0
      count = 0
    else:
      now = 0
      count = 0
  else:
    if count > now:
      ans = ans +  sum(range(1, count+1)) - now
      now = 0
      count = 0
    else:
      ans = ans + sum(range(1, count))
      now = 0
      count = 0
  
print(ans)

Solution (Python):
s=input()
n=len(s)
lst=[]
cnt=1

if n==2:
  print(1)
  
for i in range(n-1):
  if s[i]==s[i+1]:
    cnt+=1
  else:
    lst.append(cnt)
    cnt-=(cnt-1)

if s[n-2]!=s[n-1]:
  lst.append(1)
else:
  lst.append(cnt)
    
totl=0
l=len(lst)
if s[0]=='<':
  for j in range(l):
    if j%2==0:
      totl+=(lst[j]*(lst[j]-1))//2
      totl+=max(lst[j],lst[min(j+1,l-1)])
    else:
      totl+=(lst[j]*(lst[j]-1))//2
  print(totl)
else:
  totl+=lst[0]
  for j in range(len(lst)):
    if j%2==1:
      totl+=(lst[j]*(lst[j]-1))//2
      totl+=max(lst[j],lst[min(j+1,l-1)])
    else:
      totl+=(lst[j]*(lst[j]-1))//2
  print(totl)

Solution (Python):
s = input()
t = s.split(">")
t2 = s.split("<")
a = []
b = []
for i in t:
    if i != '':
        a.append(i)

for i in t2:
    if i != '':
        b.append(i)
n = len(a)
n2 = len(b)
if len(b) == 1 and len(a) == 1:
    if s[0] == '>':
        y = len(b[0])
        x = len(a[0])
        sums = 0
        sums += (x * (x + 1)) / 2
        sums += (y * (y + 1)) / 2
        print(int(sums))
        exit()

tmp = min(n, n2)
sums = 0
if s[0] == '>' and s[len(s)-1] == '<':
    x = len(a[n-1])
    sums += (x * (x + 1)) / 2
    x = len(b[0])
    sums += (x * (x + 1)) / 2
    for i in range(tmp-1):
        x = len(a[i])
        y = len(b[i+1])
        if x > y:
            sums += (x * (x + 1)) / 2
            sums += (y * (y - 1)) / 2
        else:
            sums += (x * (x - 1)) / 2
            sums += (y * (y + 1)) / 2
    print(int(sums))
    exit()

if n2 > n:
    for i in range(tmp):
        x = len(a[i])
        y = len(b[i+1])
        if x > y:
            sums += (x * (x + 1)) / 2
            sums += (y * (y - 1)) / 2
        else:
            sums += (x * (x - 1)) / 2
            sums += (y * (y + 1)) / 2
elif n > n2:
    for i in range(tmp):
        x = len(a[i])
        y = len(b[i])
        if x > y:
            sums += (x * (x + 1)) / 2
            sums += (y * (y - 1)) / 2
        else:
            sums += (x * (x - 1)) / 2
            sums += (y * (y + 1)) / 2
elif n == n2:
    for i in range(tmp):
        x = len(a[i])
        y = len(b[i])
        if x > y:
            sums += (x * (x + 1)) / 2
            sums += (y * (y - 1)) / 2
        else:
            sums += (x * (x - 1)) / 2
            sums += (y * (y + 1)) / 2
if n > n2:
    x = len(a[n-1])
    sums += (x * (x + 1)) / 2
elif n2 > n:
    x = len(b[0])
    sums += (x * (x + 1)) / 2

print(int(sums))

Solution (Python):


import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    S = i2s()
    sum_r = 0
    ls_max = 0
    i = 0
    while i < len(S):
        if S[i] == '<':
            next_lg = S.find('>', i + 1)
            if next_lg == -1:
                next_lg = len(S)
            ls_len = next_lg - i
            ls_max = ls_len - 1
            sum_r += ls_len * (ls_len - 1) / 2
            i = next_lg
        else:
            next_ls = S.find('<', i + 1)
            if next_ls == -1:
                next_ls = len(S)
            lg_len = next_ls - i
            lg_max = lg_len
            sum_r += lg_len * (lg_len + 1) / 2
            if ls_max >= lg_max:
                sum_r += ls_max + 1 - lg_max
            i = next_ls
    if S[-1] == '<':
        sum_r += ls_max + 1
    print(int(sum_r))
    return

main()

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

if S[0] == '<':
    pm = 1
else:
    pm = 0

inlist = [1]
for i in range(N - 2):
    if S[i] != S[i+1]:
        inlist.append(1)
    else:
        inlist[-1] += 1
if pm == 0:
    inlist.insert(0,1)
if len(inlist)%2 == 1:
    inlist.append(1)

for j in range(int(len(inlist)/2)):
    p = max(inlist[2*j], inlist[2*j+1])
    ans += ((p + 1) * p / 2)
    p = min(inlist[2*j], inlist[2*j+1]) - 1
    ans += ((p + 1) * p / 2)

print (int(ans))

Solution (Python):
S = input()
n = len(S)
S = S + " "
ans = 0
l = 0
r = 0
temp = 0

if S[0] == '<':
    temp = 0
else:
    for i in range(n):
        if S[i] == '>' and S[i + 1] == ('<'):
            temp = i+1
            break
        if i == n - 1:
            print((n + 1) * n // 2)
            exit()
ans += (temp) * (temp + 1) // 2
i = max(temp, 0)

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

l, r = min(l, r), max(l, r)
ans += l * (l - 1) // 2 + r * (r + 1) // 2
print(ans)

Solution (Python):


b=input()

i=0
left=0
right=0
previous=0
minleft=0
ans=0 

def process_peak(): 
    global left
    global minleft
    global right
    global ans
    if minleft > left:
        ans = ans + minleft
        ans = ans + left * (left -1) // 2
    else:
        ans = ans + left * (left +1) //2

    ans = ans + right * (right - 1 )//2
    
    minleft = right
    right = 0


for c in b:
    
    if c == ">": 
        if previous == 0: 
            left = 1
        elif previous == 1: 
            
            process_peak()
            left = 1 
        else: 
            left = left + 1
        previous = -1 
    else: 
        if previous == 0: 
            right  = 1
        elif previous == 1: 
            right = right + 1 
        else: 
            
            right = 1
        previous = 1
    


process_peak()
ans += minleft 
    
print(ans)

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

ans = 0

con = 0
x = S[0]
i = 0
while x != "<":
  con += 1
  x = S[i]
  if x == ">":
    i += 1
  if i == N-1:
    x = "<"
ans += con * (con - 1) / 2


if i == N-1:
  ans += con
  print(int(ans))
  quit()
  

mae = 0
con = 1
x = "<"
i += 1

while i < N - 1:
  if S[i] == x:
    
    con += 1
  else:
    ans += con * (con-1)/2
    if S[i] == ">":
      mae = con
    else:
      ans += max(con, mae)
      mae = 0
    con = 1
    x = S[i]
    
  i += 1

ans += con * (con-1)/2 

ans += max(con, mae)

print(int(ans))

Solution (Python):
s = input()

i = 0
li = list()
while i < len(s):
    lc = 0
    while i < len(s) and s[i] == '<':
        lc += 1
        i += 1
    gc = 0
    while i < len(s) and s[i] == '>':
        gc += 1
        i += 1
    li.append((lc, gc))

ans = 0
for e in li:
    g = max(e)
    l = min(e)
    l = l - 1 if l > 0 else 0
    ans += int(g * (g + 1) / 2 + l * (l + 1) / 2)
print(ans)

Solution (Python):
import numpy as np
S = input()

p = [0] * (len(S) + 1)
m = [0] * (len(S) + 1)

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

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

p = np.array(p, np.int64)
m = np.array(m, np.int64) * (-1)
answer = np.maximum(p, m)
print(answer.sum())

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

tmp_list = [0]
bigger = True
for i in range(len(S)):
    if (bigger and S[i] == '<') or (not bigger and S[i] == '>'):
        tmp_list[-1] += 1
    else:
        tmp_list.append(1)
        bigger = not bigger

if len(tmp_list) % 2 == 1:
    tmp_list.append(0)

def func(x):
    return x * (x + 1) // 2

ans = 0
for i in range(len(tmp_list) // 2):
    a = tmp_list[i * 2]
    b = tmp_list[i * 2 + 1]
    if a > b:
        a, b = b, a
    ans += func(a - 1)
    ans += func(b)

print(ans)

Solution (Python):
import math
def till_sum(n):
    return((n) * (n - 1) / 2)
s = list(input())
count = 0
ls = []
for i in range(len(s)):
    count += 1
    if len(s) - 1 == i:
        break
    else:
        if s[i] != s[i+1]:
            ls.append(count)
            count = 0
ls.append(count)
result = sum(map(till_sum, ls))
if s[0] == "<":
    for i in range(math.ceil(len(ls)/2)):
        if len(ls) - 1 == 2*i:
            result += ls[2*i]
        else:
            if ls[2*i] < ls[2*i + 1]:
                result += ls[2*i + 1]
            if ls[2*i] >= ls[2*i + 1]:
                result += ls[2*i]
else:
    result += ls[0]
    ls = ls[1:]
    for i in range(math.ceil(len(ls)/2)):
        if len(ls) - 1 == 2*i:
            result += ls[2*i]
        else:
            if ls[2*i] < ls[2*i + 1]:
                result += ls[2*i + 1]
            if ls[2*i] >= ls[2*i + 1]:
                result += ls[2*i]
print(int(result))

Solution (Python):
import sys
from itertools import groupby
inputs = sys.stdin.readlines()
s = inputs[0].strip()

p = [len(list(t[1])) for t in groupby(s)]
p_ = []
if s[0] == '<':
    for i in range(0, len(p), 2):
        try:
            p_.append((p[i], p[i+1]))
        except IndexError:
            p_.append((p[i], 0))
else:
    p_.append((0, p[0]))
    for i in range(1, len(p), 2):
        try:
            p_.append((p[i], p[i+1]))
        except IndexError:
            p_.append((p[i], 0))

ans = 0
for r1, r2 in p_:
    if r1 > r2:
        ans += (r1+1)*r1 // 2 + r2*(r2-1) // 2
    else:
        ans += (r2+1)*r2 // 2 + r1*(r1-1) // 2
        
print(ans)

Solution (Python):
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = list(input().rstrip())

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

        if len(S2) == 1:
            print((S2[0][1] * (S2[0][1] + 1)) // 2)
            exit()

        ans = 0
        for i in range(len(S2)):
            ans += (S2[i][1] * (S2[i][1] + 1)) // 2

        for i in range(len(S2) - 1):
            if S2[i][0] == '>' and S2[i + 1][0] == '<':
                continue
            else:
                ans -= min(S2[i][1], S2[i + 1][1])
        print(ans)



if __name__ == '__main__':
    AtCoder().main()

Solution (Python):
s = input()
s += '!'

sn = 0

pvl = 0
psl = 1

ch = 0
if(s[0]=='>'):
    ch = 0
else:
    ch = 1

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

        else:
            sn += psl*(psl-1)//2
            pvl = psl
            psl = 1
            ch = 1

    
    if(s[i]=='>'):
        if(s[i]==s[i+1]):
            psl += 1

        else:

            sn += psl*(psl+1)//2
            if(psl>=pvl):
                sn = sn
            else:
                sn += pvl-psl
            pvl = psl 
            psl = 1
            ch = 0
    
if(ch):
    sn += pvl

         
print(sn)

Solution (Python):
slist=list(input())
kosu=[]
n=len(slist)
counter=1
for i in range(n-1):
	if slist[i]==slist[i+1]:
		counter+=1
	else:
		kosu.append(counter)
		counter=1
kosu.append(counter)

nagasa=len(kosu)
kotae=0
if nagasa==1:
	kotae=kosu[0]*(kosu[0]+1)/2
else:
	if slist[0]=="<":
		if nagasa%2==0:
			for i in range(0,nagasa,2):
				kotae+=(kosu[i]*(kosu[i]+1)+kosu[i+1]*(kosu[i+1]+1))/2-min(kosu[i],kosu[i+1])
		else:
			for i in range(0,nagasa-1,2):
				kotae+=(kosu[i]*(kosu[i]+1)+kosu[i+1]*(kosu[i+1]+1))/2-min(kosu[i],kosu[i+1])
			kotae+=kosu[-1]*(kosu[-1]+1)/2
	else:
		if nagasa%2!=0:
			for i in range(1,nagasa,2):
				kotae+=(kosu[i]*(kosu[i]+1)+kosu[i+1]*(kosu[i+1]+1))/2-min(kosu[i],kosu[i+1])
			kotae+=kosu[0]*(kosu[0]+1)/2
		else:
			for i in range(1,nagasa-1,2):
				kotae+=(kosu[i]*(kosu[i]+1)+kosu[i+1]*(kosu[i+1]+1))/2-min(kosu[i],kosu[i+1])
			kotae+=kosu[0]*(kosu[0]+1)/2
			kotae+=kosu[-1]*(kosu[-1]+1)/2
kotae=int(kotae)
print(kotae)

Solution (Python):

import sys
from collections import Counter
import string


sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

def divisor(n):
    """
    n の約数をリストで返す
    :param int n:
    :rtype: list of int
    """
    ret = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ret.append(i)
            if n // i != i:
                ret.append(n // i)
    return ret


def factorization(n):
    """
    素因数分解
    :param int n:
    :rtype: list of int
    """
    if n <= 1:
        return []

    ret = []
    while n > 2 and n % 2 == 0:
        ret.append(2)
        n //= 2
    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            ret.append(i)
            n //= i
        else:
            i += 2
    ret.append(n)
    return ret


def is_prime(n):
    """
    nの素数判定
    :param int n:
    :rtype: Bool
    """
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


def coprime(a, b):
    return gcd(a, b) == 1


def main():
    S = input()
    ans = 0
    cur = 0
    stack_initial = 0
    stack_count = 0
    

    for i in range(len(S)):
        if i == 0 and S[i] == '<':
            cur = 0
            ans = 0
            cur = 1
        elif i == 0 and S[i] == '>':
            stack_count = 1
        elif S[i-1] == '<' and S[i] == '<':
            ans += cur
            cur += 1
        elif S[i-1] == '<' and S[i] == '>':
            
            stack_initial = cur
            
            stack_count = 1
            cur = 0
        elif S[i-1] == '>' and S[i] == '>':
            stack_count += 1
        elif S[i-1] == '>' and S[i] == '<':
            stack_count += 1
            
            
            if stack_count > stack_initial:
                ans += (stack_count * (0 + (stack_count - 1)) // 2)
            else:
                ans += stack_initial + ((stack_count - 1) * (0 + ((stack_count - 1) - 1)) // 2)
            stack_initial = 0
            stack_count = 0
            cur = 1
        

    if S[len(S)-1] == '<':
        ans += cur
        
    elif S[len(S)-1] == '>':
        stack_count += 1
        
        if stack_count > stack_initial:
            ans += (stack_count * (0 + (stack_count - 1)) // 2)
        else:
            ans += stack_initial + ((stack_count - 1) * (0 + ((stack_count - 1) - 1)) // 2)
        
        stack_count = 0
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):





"""
GC040 A
"""

ali = list(input())

zeroflag = False
lastflag = False

if ali[0] == '<':
    ali.insert(0, '>')
    zeroflag = True
if ali[-1] == '>':
    ali.append('<')
    lastflag = True

itop = []
ibtm = []


for (i, x) in enumerate(ali[:-1]):
    
    if x == '>' and ali[i+1] == '<':
        ibtm.append(i+1)
    if x == '<' and ali[i+1] == '>':
        itop.append(i+1)
itop.append(len(ali))




s = 0
nowtop = 0
toplheight = [-10]
toprheight = []

for l in range(len(itop)):
    nexttop = itop[l]
    nowbtm = ibtm[l]
    lint = nowbtm - nowtop - 1
    rint = nexttop - nowbtm - 1
    s += (lint)*(lint+1)//2
    s += (rint)*(rint+1)//2
    toprheight.append(lint)
    toplheight.append(rint)
    
    
    nowtop = nexttop

toprheight.append(-10)

if zeroflag:
    del toplheight[0]
    del toprheight[0]
if lastflag:
    toplheight.pop()
    toprheight.pop()

while toplheight:
    left = toplheight.pop()
    right = toprheight.pop()
    s += max(left, right)+1

print(s)

Solution (Python):
S = list(input())
if S[-1] == '<':
  S.append('>')
else:
  S.append('<')
output = 0
count = 0
num_list = []

if S[0] == '>':
  model = 0
else:
  model = 1
s_pre = S[0]
for i in range(len(S)):
  s = S[i]
  if s != s_pre or i == len(S)-1:
    num_list.append(count)
    count = 1
    s_pre = s
  else: 
    count += 1
if model == 0:
  output += num_list[0]*(num_list[0]+1)/2
  num_list = num_list[1:]

for i in range(len(num_list)//2):
  n_max = max(num_list[2*i], num_list[2*i+1]) 
  n_min = min(num_list[2*i], num_list[2*i+1])
  output += n_max*(n_max+1)/2
  output += (n_min-1)*n_min/2
if len(num_list)%2 == 1:
  output += num_list[-1]*(num_list[-1]+1)/2
print(int(output))

Solution (Python):
s=input()
a=[]
su=0
k=0
def wa(x):
  j=0
  t=0
  for i in range(x):
    j+=1
    t+=j
  return t
def unkosumaho(x):
  b=0
  c=0
  for i in range(len(x)):
    if x[i]=='<':
      b+=1
    else:
      c+=1
  return wa(max(b,c))+wa(min(b,c)-1)
for i in range(len(s)-1):
  if s[i]=='>':
    if s[i+1]=='<':
      a.append(s[k:i+1])
      k=i+1
  if i==len(s)-2:
      a.append(s[k:])
for i in a:
  su+=unkosumaho(i)
if (len(s))==1:
  print(1)
else:
  print(su)

Solution (Python):
s = input()
tmp1 = 1
tmp2 = 1
yet = 0
ans = 0
for i in range(len(s)-1):
    if s[i] == '<' and s[i+1] == '<':
        tmp1 += 1
    elif s[i] == '>' and s[i+1] == '>':
        tmp2 += 1
    elif s[i] == '>' and s[i+1] == '<':
        if tmp1 >= tmp2:
            ans += (tmp1*(tmp1+1))//2 + ((tmp2-1)*tmp2)//2
        else:
            ans += (tmp2*(tmp2+1))//2 + ((tmp1-1)*tmp1)//2
        tmp1 = 1
        tmp2 = 1
        yet = i + 1
        if i+1 == len(s)-1:
            ans += 1
if yet != len(s)-1:
    if s[-1] == '>':
        if tmp1 >= tmp2:
            ans += (tmp1*(tmp1+1))//2 + ((tmp2-1)*tmp2)//2
        else:
            ans += (tmp2*(tmp2+1))//2 + ((tmp1-1)*tmp1)//2
    else:
        ans += (tmp1*(tmp1+1))//2
if len(s) == 1:
    ans = 1
print(ans)

Solution (Python):
S = input()

def count(up, down):
    max_count = max(up, down)
    return (up * (up - 1)) / 2 + (
                down * (down - 1)) / 2 + max_count

up = 0
down = 0
answer = 0

for i in range(len(S)):
    if i == len(S) - 1:
        if S[i] == ">":
            down += 1
        elif S[i] == "<":
            up += 1
        answer += count(up, down)
        up = 0
        down = 0
    elif S[i] == ">" and S[i + 1] == "<":
        if S[i] == ">":
            down += 1
        elif S[i] == "<":
            up += 1
        answer += count(up, down)
        up = 0
        down = 0
    else:
        if S[i] == ">":
            down += 1
        elif S[i] == "<":
            up += 1
print(int(answer))

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


s = input()

d = '<'
r = '>'

prev = r
count = 0
array = []

for i in s:
    if i == prev:
        count += 1
    else:
        array.append([prev, count])
        count = 1
        prev = i

array.append([prev, count])

for i in range(len(array)-1):
    if array[i][0] == d and array[i+1][0] == r:
        if array[i][1] <  array[i+1][1]:
            array[i][1] -= 1
        else:
            array[i+1][1] -= 1

ans = 0
for i in array:
    ans += wa(i[1])

print(int(ans))

Solution (Python):
from collections import deque
MAX = float('inf')
S = input()
points = [MAX] * (len(S) + 1)
idxs = []
comp = [[] for _ in range(len(S) + 1)]
if S[0] == '<':
    points[0] = 0
    idxs.append(0)
if S[-1] == '>':
    points[-1] = 0
    idxs.append(len(S))
for idx, s in enumerate(S):
    if s == '<': comp[idx].append(idx + 1)
    else: comp[idx + 1].append(idx)
    if idx == 0 or idx == len(S): continue
    if S[idx - 1] == '>' and s == '<':
        points[idx] = 0
        idxs.append(idx)
stack = deque(idxs)
while stack:
    idx = stack.pop()
    for i in comp[idx]:
        points[i] = max(points[i], points[idx] + 1) if points[i] != MAX else points[idx] + 1
        stack.append(i)
print(sum(points))

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

Solution (Python):

import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

S=input()
S=">"+S
n=len(S)
data=[0]*n
start=0
minv=0
for i in range(1,n):
    if S[i]=='<':
        data[i]=data[i-1]+1
    if S[i]=='>':
        if S[i-1]=='<':
            
            for k in range(start+1,i):
                data[k]-=minv
            data[start]=max(data[start],data[start+1]+1)
            
            data[i]=0
            minv=0
            start=i-1
        else:
            data[i]=data[i-1]-1
            minv=min(minv,data[i])


for i in range(start+1,n):
    data[i]-=minv
data[start]=max(data[start],data[start+1]+1)
if S[1]=='<':
    data[0]=0
print(sum(data))

Solution (Python):
S = input()
ans = 0


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



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

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

lefts = 0
rights = 0

for i in range(len(S)):
    if S[i]=='<':
        lefts += 1
    if S[i]=='>':
        rights += 1
    if S[i]=='>' and S[i+1]=='<': 
        M = max(lefts,rights)
        m = min(lefts,rights)
        ans += M*(M+1)/2 + m*(m+1)/2 - m
        lefts = 0
        rights = 0
        
print(int(ans))

Solution (Python):
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    S = input()

    arr = []
    S = S.replace('><', '>,<')
    S = S.replace('<>', '<,>')
    S = S.split(',')
    for s in S:
        a = []
        if s[0] == '<':
            for i in range(len(s) + 1):
                a.append(i)
        else:
            for i in range(len(s), -1, -1):
                a.append(i)
        arr.append(a)
    ans, prev = 0, 0
    for i, a in enumerate(arr):
        ans += sum(a[1:])
        if arr[i][0] > prev:
            ans += arr[i][0] - prev
        prev = arr[i][-1]
    print(ans)


main()

Solution (Python):
s=input()

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

m=[]
now=1
tmp=s[0]
for i in range(1,len(s)):
  if s[i]==tmp:
    now += 1
  elif tmp == "<" and s[i] == ">":
    m.append("
  if tmp != s[i]:
    m.append(now)
    now = 1
    tmp = s[i]
m.append(now)

ans=0
for j in range(len(m)):
  if m[j] == "
    ans -= min(m[j+1],m[j+2])
  else:
  	ans += sum_li(m[j])
print(ans)

Solution (Python):



s = input()

ans = 0
point = 0
for i in s:
    if i == ">":
        point += 1
        ans += point
    else:
        break

point2 = 0
for i in s[::-1]:
    if i == "<":
        point2 += 1
        ans += point2
    else:
        break

if point2:
    s = s[point: -point2]
else:
    s = s[point:]

l_p = 0
r_p = 0
for i in s:
    if i == "<":
        if l_p:
            ans -= min(l_p, r_p)
            r_p = 0
            l_p = 0
        r_p += 1
        ans += r_p
    else:
        l_p += 1
        ans += l_p
ans -= min(l_p, r_p)
print(ans)

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

def parse(S):
    N = len(S)
    i = 0
    array = []

    n = 0
    array.append(n)
    while i < N:
        while i < N and S[i] == '<':
            n += 1
            array.append(n)
            i += 1

        while i < N and S[i] == '>':
            array.append(0)
            i += 1

        j = i - 1
        m = 1
        while j >= 0 and S[j] == '>':
            array[j] = max(array[j], m)
            m += 1
            j -= 1
        n = 0
    return array

array = parse(S)
total = 0
for n in array:
    total += n

print(total)

Solution (Python):
s = input()

def calc_sum(n):
    if n <= 0:
        return 0
    return (n+1)*n/2

length = len(s)

num_g = 0
num_l = 0

prev = 1
cur = -1

out = 0

for i in range(length):
    if s[i] == '<':
        cur = 1
    else:
        cur = 0
        
    if prev == 1 and cur == 1:
        num_g += 1
    elif prev == 1 and cur == 0:
        num_l += 1
    elif prev == 0 and cur == 0:
        num_l += 1
    elif prev == 0 and cur == 1:
        out += calc_sum(max(num_g, num_l)) + calc_sum(min(num_g, num_l)-1)
        
        num_g = 1
        num_l = 0
    
    prev = cur
    
if cur == 1:
    out += calc_sum(num_g)
else:
    out += calc_sum(max(num_g, num_l)) + calc_sum(min(num_g, num_l)-1)
    
print(str(int(out)))

Solution (Python):
s = list(str(input()))
ans = 0
l = []
p = 0
m = 0
n = len(s)
if n == 1:
  if s[0] == "<":
    l = [1]
  else:
    l = [-1]
for i in range(n):
  if i == 0:
    if s[i] == "<":
      p += 1
    else:
      m -= 1
  else:
    if s[i] == s[i-1]:
      if s[i] == "<":
        p += 1
        if i == n-1:
          l.append(p)
      else:
        m -= 1
        if i == n-1:
          l.append(m)
    else:
      if s[i] == "<":
        l.append(m)
        m = 0
        p = 1
        if i == n-1:
          l.append(p)
      else:
        l.append(p)
        p = 0
        m = -1
        if i == n-1:
          l.append(m)

l.append(0)
for i in range(len(l)-1):
  if l[i] > 0:
    ans += l[i]*(l[i]-1)//2
    ans += max(l[i],-(l[i+1]))
  else:
    ans += (l[i])*(l[i]+1)//2
    if i == 0:
      ans += -(l[i])
print(ans)

Solution (Python):
import sys
from collections import Counter, deque, defaultdict
from math import factorial
from fractions import Fraction
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
MOD = 10**9 + 7
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()))

s = input()
n = len(s) + 1
s = list(s)
a = []
temp = 0
for i in range(n-1):
    if i == n-2:
        a.append(n-1-temp)
    else:
        if s[i] != s[i+1]:
            a.append(i+1-temp)
            temp = i+1

if s[0] == '>':
    a.insert(0, 0)
if s[-1] == '<':
    a.append(0)
res = 0
for i in range(len(a)//2):
    h = max(a[2*i], a[2*i + 1])
    l = min(a[2*i], a[2*i + 1])
    ans = l*(l-1)//2 + h + h*(h-1)//2
    res += ans

print(res)