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



Sample input:
<>>


Sample output:
3

Submission status: Accepted

Solution code:
import re
a=0
for m in re.findall('(<*)(>*)',input()):u,v=map(len,m);a+=(u*u-u+v*v-v)//2+max(u,v)
print(a)

Submission status: Accepted

Solution code:
import re
print(sum(sum(i * (i - 1) // 2 for i in p) + max(p) for p in (tuple(map(len, m)) for m in re.findall(r"(<*)(>*)", input()))))

Submission status: Accepted

Solution code:
s = input()
partition = s.replace('><','>|<').split('|')
ans=0
for sub in partition:
    left = sub.count('<')
    right = sub.count('>')
    ans += sum(range(1, max(left, right)+1))+sum(range(1, min(left, right)))
    
print(ans)

Submission status: Accepted

Solution code:
s = input()
inc = 0
dec = 0
increasing = True
ans = 0
for c in s:
    if increasing:
        if c == '<':
            inc += 1
        else:
            increasing = False
            dec += 1
    else:
        if  c == '>':
            dec += 1
        else:
            if inc > dec:
                inc, dec = dec, inc
            ans += inc * (inc - 1) // 2 + dec * (dec + 1) // 2
            increasing = True
            inc = 1
            dec = 0
else:
    if increasing:
        ans += inc * (inc + 1) // 2
    else:
        if inc > dec:
            inc, dec = dec, inc
        ans += inc * (inc - 1) // 2 + dec * (dec + 1) // 2
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
Ans = [0] * (n + 1)

top = set()
bottom = set()
if s[0] == ">":
    top.add(0)
else:
    bottom.add(0)

for i in range(len(s)-1):
    left = s[i]
    right = s[i+1]
    if left == "<" and right == ">":
        top.add(i+1)
    elif left == ">" and right == "<":
        bottom.add(i+1)

if s[n-1] == ">":
    bottom.add(n)
else:
    top.add(n)

for b in list(bottom):
    counter = 0
    for i in range(b, n+1):
        if i in top:
            break
        else:
            Ans[i] = counter
            counter += 1

    counter = 0
    for i in range(b-1, -1, -1):
        if i in top:
            break
        else:
            Ans[i] = counter + 1
            counter += 1
#print(Ans)

for t in list(top):
    if t == 0:
        Ans[0] = Ans[1] + 1
    if t == n:
        Ans[n] = Ans[n-1] + 1
    else:
        Ans[t] = max(Ans[t-1] + 1, Ans[t+1] + 1)

#print(top)
#print(bottom)
print(sum(Ans))

Submission status: Accepted

Solution code:
S=input()
N=len(S)+1
LEFT=[0]
RIGHT=[0]
left=0
right=0
for i in range(N-1):
  if S[i]==">":
    left=0
  else:
    left+=1
  LEFT+=[left]
for i in range(N-2,-1,-1):
  if S[i]=="<":
    right=0
  else:
    right+=1
  RIGHT+=[right]
ans=0  
for i in range(N):  
  ans+=max(LEFT[i],RIGHT[N-1-i])
print(ans)

Submission status: Accepted

Solution code:
import itertools
S=input()
N=len(S)+1
ans=0
KEY=[]
gr=itertools.groupby(list(S))
i=0
for key,group in gr:
  n=len(list(group))
  ans+=n*(n+1)//2
  KEY+=[n]
  if key==">" and i!=0:
    ans-=min(KEY[i-1],KEY[i])
  i+=1
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)+1
A = [0]*n

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

for i in reversed(range(n-1)):
    if s[i] == '>':
        A[i] = max(A[i], A[i+1] + 1)

print(sum(A))

Submission status: Accepted

Solution code:
from itertools import groupby

s = input()
A = [(key, sum(1 for _ in group)) for key, group in groupby(s)]
tmp = 0
ans = 0
for key, count in A:
    if key == '<':
        ans += count*(count+1)//2
        tmp = count
    else:
        if tmp < count:
            ans -= tmp
            ans += count
        ans += (count-1)*count//2
        tmp = 0
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement, groupby
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())
def TI(): return tuple(Is())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(S())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

s = S()
A = [(key, sum(1 for _ in group)) for key, group in groupby(s)]
tmp = 0
ans = 0
for key, count in A:
    if key == '<':
        ans += count*(count+1)//2
        tmp = count
    else:
        if tmp < count:
            ans -= tmp
            ans += count*(count+1)//2
        else:
            ans += (count-1)*count//2
        tmp = 0
print(ans)

Submission status: Accepted

Solution code:
s = input()
big = 0
small = 0
n = 0
big2 =0
for i in range(len(s)):
  if s[i]=='<':
    big += 1
    n += big
    small =0
    big2 = big
  else:
    small += 1
    n += small
    if small<=big2:
      n-=1
      big =0
print(n)

Submission status: Accepted

Solution code:
import re
s = input()
ans = [-1] * (len(s) + 1)
if s[0] == '<':
    ans[0] = 0
    diff = 1
    while (0 <= diff -1 < len(s)):
        if (s[diff - 1] == '>'):
            break
        ans[diff] = max(ans[diff], ans[diff - 1] + 1)
        diff += 1
        
if s[len(s) - 1] == '>':
    t = len(s)
    ans[t] = 0
    diff = -1
    while (0 <= t + diff < len(s)) & (s[t + diff] == '>'):
        ans[t + diff] = max(ans[t + diff], ans[t + diff + 1] + 1)
        diff -= 1

match = []
for i in range(len(s)):
    if s[i:i+2] == '><':
        match.append(i)

for i in match:
    ans[i + 1] = 0
    diff = 1
    while (0 <= i + 1 - diff < len(s)):
        if s[i - diff + 1] == '<':
            break
        ans[i + 1 - diff] = max(ans[i + 1 - diff], ans[i - diff + 2] + 1)
        diff += 1
    diff = 1
    while (0 <= i + diff < len(s)):
        if s[i + diff] == '>':
            break
        ans[i + 1 + diff] = max(ans[i + 1 + diff], ans[i + diff] + 1)
        diff += 1
print(sum(ans))

Submission status: Accepted

Solution code:
s = input()

a = 0
l = []

for i in s:
    if a == 0:
        if i == "<":
            a = 1
        else:
            a = -1
    elif ((a > 0) and i == "<"):
        a += 1
    elif ((a < 0) and i == ">"):
        a -= 1
    elif i == "<":
        l.append(a)
        a = 1
    else:
        l.append(a)
        a = -1
l.append(a)

m=[]

for j in l:
    if m:
        if j > 0:
            m.pop()
            for k in range(0, abs(j) + 1, 1):
                m.append(k)
        else:
            b = m.pop()
            if b > abs(j) - 1:
                m.append(b)
                for k in range(abs(j) -1, -1, -1):
                    m.append(k)
            else:
                for k in range(abs(j), -1, -1):
                    m.append(k)
    else:
        if j > 0:
            for k in range(0, abs(j) + 1, 1):
                m.append(k)
        else:
            for k in range(abs(j), -1, -1):
                m.append(k)
            
print(sum(m))

Submission status: Accepted

Solution code:
s = input() 
ans = 0
flag = False
s += "|"
if s[0] == ">": 
    cntl = 1
    flag = True
    need = 0
else:
    cntr = 1
for i in range(1,len(s)):
    if flag:
        if s[i] == ">":
            ans += cntl
            cntl += 1
        else:
            ans += cntl if cntl >= need else need
            flag = False
            cntr = 1
    else:
        if s[i] == "<":
            ans += cntr
            cntr += 1
        else:
            need = cntr
            flag = True
            cntl = 1
            if i == len(s)-1:
                ans += need
print(ans)

Submission status: Accepted

Solution code:
s = input()
now = s[0]
c = []
count = 1
for i in range(1,len(s)):
    if (now == s[i]):
        count += 1
    else:
        c.append(count)
        now = s[i]
        count = 1
c.append(count)
#print(c)

def ta(n):
    ans = 0
    for i in range(1,n+1):
        ans += i
    return ans

if (s[0] == "<"):
    a = []
    for i in range(len(c)//2):
        a.append(max(c[2*i],c[2*i+1]))
        a.append(min(c[2*i],c[2*i+1])-1)
    if (len(c)%2==1):
        a.append(c[-1])
    #print(a)
    ans = 0
    for i in a:
        ans += ta(i)
    print(ans)
else:
    a = []
    a.append(c[0])
    for i in range((len(c)-1)//2):
        a.append(max(c[2*i+1],c[2*i+2]))
        a.append(min(c[2*i+1],c[2*i+2])-1)
    if (len(c)%2==0):
        a.append(c[-1])
    ans = 0
    for i in a:
        ans += ta(i)
    print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
a1 = [0] * (n+1) # 左側に連続する<の個数
a2 = [0] * (n+1) # 右側に連続する>の個数
tmp1 = 0
tmp2 = 0
for i in range(n):
    if s[i] == "<": tmp1 += 1
    else: tmp1 = 0
    if s[n-i-1] == ">": tmp2 += 1
    else: tmp2 = 0
    a1[i+1] = tmp1
    a2[n-i-1] = tmp2
ans = 0
for i in range(n+1):
    ans += max(a1[i], a2[i])
print(ans)

Submission status: Accepted

Solution code:
s = input()

a1 = [0] * (len(s) + 1)
for i in range(len(s)):
    if s[i] == '<':
        a1[i + 1] = a1[i] + 1
a2 = [0] * (len(s) + 1)
for i in reversed(range(len(s))):
    if s[i] == '>':
        a2[i] = a2[i + 1] + 1

ans = 0
for i in range(len(a1)):
    ans += max(a1[i], a2[i])
print(ans)

Submission status: Accepted

Solution code:
s = input()
x = s.replace('<>', '<|>').split('|')


def func(t):
    c1 = t.count('>')
    c2 = len(t) - c1
    return list(reversed(range(1, c1 + 1))) + list(range(c2 + 1))


a = func(x[0])
for i in range(1, len(x)):
    ai = func(x[i])
    a[-1] = max(a[-1], ai[0])
    a.extend(ai[1:])

# print(a)
ans = sum(a)
print(ans)

Submission status: Accepted

Solution code:
def main():
    S = input()
    N = len(S)

    ret = [0] * (N + 1)

    for i, c in enumerate(S, start=1):
        if c == '<':
            ret[i] = max(
                ret[i],
                ret[i - 1] + 1
            )

    for i, c in enumerate(reversed(S), start=1):
        i = N - i
        if c == '>':
            ret[i] = max(
                ret[i],
                ret[i + 1] + 1
            )

    print(sum(ret))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = input()
N = len(S)
A = [0]*(N+1)

i = 0
ind = 0
flag = 0
if S[0] == '>':
    while S[ind] == '>':
        ind += 1
        if ind >= N:
            flag = 1
            break
    num = ind
    for i in range(ind+1):
        A[i] = num
        num -= 1
i = ind

if flag:
    print(sum(A))
    exit()
if S.count('<') == N:
    print(N*(N+1)//2)
    exit()
if S == '><' or (len(S) == ind+1 and S[i-1:i+1] == '><'):
    print(2)
    exit()
while True:
    if S[i] == '<' and S[i+1] == '>':
        cnt = 0
        while True:
            cnt += 1
            if i+1+cnt > N-1 or S[i+1+cnt] == '<':
                break
        #print(i, cnt)
        if i+1-ind >= cnt+1:
            num = 1
            for j in range(ind+1, i+2):
                A[j] = num
                num += 1
            num = 0
            for j in reversed(range(i+2, i+cnt+2)):
                A[j] = num
                num += 1
        else:
            num = 1
            for j in range(ind+1, i+1):
                A[j] = num
                num += 1
            num = 0
            for j in reversed(range(i+1, i+cnt+2)):
                A[j] = num
                num += 1
        ind = i+cnt+1
        i += cnt
        #print(A)
    else:
        A[i+1] = A[i] + 1
    i += 1
    if i >= N-1:
        if i == N-1:
            A[i+1] = A[i] + 1
        break

#print(A)
print(sum(A))

Submission status: Accepted

Solution code:
s=input()
cnt=0
if s[0]=="<":
    cnt=1
else:
    cnt=-1
l=[]
for i in range(len(s)-1):
    if s[i]=="<":
        if s[i+1]=="<":
            cnt+=1
        else:
            l.append(cnt)
            cnt=-1
    else:
        if s[i+1]==">":
            cnt-=1
        else:
            l.append(cnt)
            cnt=1
l.append(cnt)
ans=0
for i in range(len(l)-1):
    if l[i]>0 and l[i+1]<0:
        a=abs(l[i])
        b=abs(l[i+1])
        ans+=max(a,b)
        ans+=(a-1)*a//2+(b-1)*b//2

if l[0]<0:
    ans+=(abs(l[0])+1)*abs(l[0])//2

if l[-1]>0:
    ans+=(l[-1]+1)*l[-1]//2
print(ans)

Submission status: Accepted

Solution code:
S = input()
n = len(S) + 1
A = []
mini = 0

for i in range(n-1):
  if i==0:
    if S[i]=="<":
      A.append([1,0])
    else:
      A.append([0,1])
  else:
    if S[i]=="<" and S[i-1]==">":
      A.append([1,0])
    elif S[i]=="<":
      A[-1][0] += 1
    else:
      A[-1][1] += 1

summ = 0
for x in A:
  ma = max(x)
  mi = min(x)
  summ += (ma+1)*ma//2
  summ += (mi-1)*mi//2
print(summ)

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
#print('S',S)

dammy1=[0]*(N+1)
A=0
for i in range(1,N+1):
    if S[i-1]=='<':
        A+=1
        dammy1[i]=A
    elif S[i-1]=='>':
        A=0
        dammy1[i]=A

dammy2=[0]*(N+1)
B=0
for i in range(1,N+1):
    if S[-i]=='>':
        B+=1
        dammy2[-(i+1)]=B
    elif S[-i]=='<':
        B=0
        dammy2[-(i+1)]=B

#print('dammy1', dammy1)
#print('dammy2', dammy2)

out=[0]*(N+1)
for i in range(N+1):
    out[i] = max(dammy1[i], dammy2[i])

#print('out', out)
print(sum(out))

Submission status: Accepted

Solution code:
s=input()
s_l=len(s)

left=[0 for i in range(s_l+1)]
right=[0 for i in range(s_l+1)]

for i in range(s_l):
  if s[i]=='<':
    left[i+1]=left[i]+1
for i in range(s_l-1,-1,-1):
  if s[i]=='>':
    right[i]=right[i+1]+1

ans=0
for i,j in zip(left,right):
  ans+=max(i,j)
print(ans)

Submission status: Accepted

Solution code:
S = input()
# N, K = [int(_) for _ in input().split()]
count = 1
S2 = []
for i in range(len(S)):
    if i < len(S)-1 and S[i] == S[i+1]:
        count += 1
    else:
        if S[i] == '<':
            S2.append(['<', count])
        else:
            S2.append(['>', count])
        count = 1
ans = 0
for i in range(len(S2)):
    if S2[i][0] == '<':
        if i < len(S2)-1:
            if S2[i][1] < S2[i+1][1]:
                ans += (S2[i][1] - 1) * (S2[i][1] - 0) // 2
            else:
                ans += S2[i][1] * (S2[i][1] + 1) // 2
        else:
            ans += S2[i][1] * (S2[i][1] + 1) // 2
    else:
        if i > 0:
            if S2[i-1][1] >= S2[i][1]:
                ans += (S2[i][1] - 1) * (S2[i][1] - 0) // 2
            else:
                ans += S2[i][1] * (S2[i][1] + 1) // 2
        else:
            ans += S2[i][1] * (S2[i][1] + 1) // 2
print(ans)

Submission status: Accepted

Solution code:
S=input()
num=0
ans=0
con=0
upcon=0
before="<"
for s in S:
  if s==before and s=="<":
    upcon+=1
    num+=1
    ans+=num
  if s==">":
    con+=1
    num-=1
    ans+=num
  if s=="<" and before==">":
    ans+=(-num)*(con+(con>upcon))
    con=0
    upcon=1
    num=1
    ans+=num
  before=s
if con!=0:
  ans+=(-num)*(con+(con>upcon))
print(ans)

Submission status: Accepted

Solution code:
s = input()
a = [-1] * (len(s) + 1)

if s[0] == "<":
    a[0] = 0
if s[-1] == ">":
    a[-1] = 0
    
for i in range(len(s) - 1):
    if s[i] == ">" and s[i + 1] == "<":
        a[i + 1] = 0 

for i in range(len(a)):
    if a[i] == 0:
        l = i - 1
        while 0 <= l - 1:
            if s[l] == ">" and s[l - 1] == ">":
                a[l] = a[l + 1] + 1
            else:
                break
            l -= 1
        r = i + 1
        while r + 1< len(a):
            if s[r - 1] == "<" and s[r] == "<":
                a[r] = a[r - 1] + 1
            else:
                break
            r += 1

for i in range(len(a)):
    if a[i] == -1:
        if i == 0:
            a[i] = a[i + 1] + 1
        elif i == len(a) - 1:
            a[i] = a[i - 1] + 1
        else:
            a[i] = max(a[i - 1], a[i + 1]) + 1
            
ans = sum(a)
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
left = [0 for _ in range(n+1)]
right = [0 for _ in range(n+1)]

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

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

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

print(ans)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
ans=0
currentstreak=0
numberbefore=0
legacy=0
for i in range(n):
  if s[i]=='<':
    numberbefore+=1
    ans+=numberbefore
    currentstreak=0
    legacy=numberbefore
  else:
    currentstreak+=1
    ans+=currentstreak
    if currentstreak<=legacy:
      ans-=1
    numberbefore=0
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = list(str(input()))

n = len(s)+1


from_left = [0 for _ in range(n)]
from_right = [0 for _ in range(n)]

for i, sym in enumerate(s, 1):
    if sym == ">":
        from_left[i] = 0
    else:
        from_left[i] = from_left[i-1]+1

for i, sym in enumerate(s[::-1]):
    i = n-2-i
    if sym == "<":
        from_right[i] = 0
    else:
        from_right[i] = from_right[i+1]+1

seq = [max(x, y) for x, y in zip(from_left, from_right)]

print(sum(seq))

Submission status: Accepted

Solution code:
s = input()
a = 0
ans = 0
b = 0
d = [0]
e = []
now = 0

for i in range(len(s)):
    if s[i] == '<':
        
        if a != 0:
            if a > now:
                ans = ans - d[-1] + a
                
            for j in range(a):
                ans = ans + j
                d.append(a - j)
                e.append(">")
            now = 0
            a = 0
        
        ans = ans + now + 1
        now = now + 1
        d.append(now)
        
    else:
        a = a + 1
        b = 0
    
if a != 0:
    if a > now:
        ans = ans - d[-1] + a
                
    for j in range(a):
        ans = ans + j
        d.append(a - j)
        e.append(">")
    
print(ans)

Submission status: Accepted

Solution code:
S = input()
a = [0 for i in range(len(S)+1)]
for i, x in enumerate(S):
    if x == '<':
        a[i+1] = max(a[i+1], a[i]+1)
for i in range(len(S)):
    if S[-i-1] == '>':
        a[-i-2] = max(a[-i-2], a[-i-1]+1)
print(sum(a))

Submission status: Accepted

Solution code:
s=input()

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


for index,ss in enumerate(s):
    if ss=="<":
        result[index+1]=result[index]+1
#print(result)
for i in range(len(s)):
    index=len(s)-i-1
    if s[index]==">":
        result[index]=max(result[index],result[index+1]+1)
print(sum(result))




#1 0 -1
#2 1 0

Submission status: Accepted

Solution code:
S = input()
a = [0 for i in range(len(S)+1)]
for i, x in enumerate(S):
    if x == '<':
        a[i+1] = max(a[i+1], a[i]+1)
for i in range(len(S)):
    if S[-i-1] == '>':
        a[-i-2] = max(a[-i-2], a[-i-1]+1)
print(sum(a))

Submission status: Accepted

Solution code:
s=input()
#左に>が続く個数、右に<が続く個数
l=[0]
r=[0]
l_,r_=0,0
for i in range(len(s)):
    if s[i]=='<':
        l_+=1
    else:
        l_=0
    l.append(l_)
    if s[-1-i]=='>':
        r_+=1
    else:
        r_=0
    r.append(r_)
r.reverse()
ans=0
for i in range(len(s)+1):
    ans+=max(l[i],r[i])
print(ans)

Submission status: Accepted

Solution code:
s = input()
d = [[0]*2 for _ in range(len(s)+1)]
count_r = 0
count_l = 0
ans = 0
for i in range(len(s)):
    if s[i] == "<":
        d[i+1][0] = d[i][0]+1
    else:
        d[i+1][0] = 0
for i in range(len(s)-1, -1, -1):
    if s[i] == ">":
        d[i][1] = d[i+1][1]+1
    else:
        d[i][1] = 0
for i in range(len(s)+1):
    ans += max(d[i])
print(ans)

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	#b , c = tin()
	s = input()
	if s[0] == '>':
		s = '<' + s
		
	if s[-1] == '<':
		s = s + '>_'
	else:
		s = s + '_'
		
	dd = []
	pre = '<'
	count = [1,0]
	for c in s[1:]:
		if c == '<' and pre == '<':
			count[0] += 1
		elif c == '>' and pre == '>':
			count[1] += 1
		elif c == '>' and pre == '<':
			pre = '>'
			count[1] = 1
		elif c == '<' and pre == '>':
			pre = '<'
			dd.append(count)
			count=[1,0]
		else:
			dd.append(count)
	
	ret_sum = 0
	for l, r in dd:
		ret_sum += (r*(r+1)//2) + (l*(l+1)//2) - min(r,l)
	print(ret_sum)
		
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=SI()
if s[0]!="<":
    s="<"+s
if s[-1]!=">":
    s=s+">"
#print(s)
state="<"
strs=[]
count=0
for i in range(len(s)):
    if state=="<":
        if s[i]=="<":
            count+=1
        else:
            strs.append(count)
            count=1
            state=">"
    else:
        if s[i]==">":
            count+=1
        else:
            strs.append(count)
            count=1
            state="<"
strs.append(count)
#print(strs)
ans=0
for i in range(len(strs)//2):
    u=min(strs[2*i],strs[2*i+1])
    v=max(strs[2*i],strs[2*i+1])
    ans+=(u-1)*u//2+v*(v+1)//2
print(ans)

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)+1
cnt = [0] * N
j = 0
k = 0

for i in range(N-2):
    if S[i] == S[i+1]:
        k += 1
    
    else:
        k += 1
        cnt[j] = k
        j += 1
        k = 0

if S[N-2] == S[N-3]:
    cnt[j] = k + 1
else:
    cnt[j] = 1

ans = 0
if S[0] == "<":
    st = 0
else:
    ans += cnt[0]*(cnt[0]+1)//2
    st = 1

for k in range(st,N,2):
    if cnt[k] != 0:
        m = min(cnt[k],cnt[k+1])
        M = max(cnt[k],cnt[k+1])
        ans += m*(m-1)//2 + M*(M+1)//2 
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s) + 1
alist = [0]*n
slist = []
k = 0
for i in range(1,n-1):
    if s[i-1] == '>' and s[i] == '<':
        slist.append(s[k:i])
        k = i
slist.append(s[k:])

ans = 0

for s in slist:
    left = 0
    right = 0
    p = [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] == '>':
            p[i] = p[i+1] + 1 if p[i] == 0 else max(p[i],p[i+1] + 1)
    ans += sum(p)
print(ans)

Submission status: Accepted

Solution code:
s = input()
left = 0
cou = 0
k = 0
l = [0 for i in range(len(s)+1)]
for i in range(len(s)):
  s1 = s[i]
  a1 = l[i]
#  print(s1,l,left,cou,k)
  if s1=='<':
    l[i+1] = l[i]+1
    left = 0
    k = l[i+1]
  else:
    l[i+1] = l[i]-1
    left += 1
    if l[i+1]>=0:
      l[i+1] = 0
    else:
      l[i+1] =0
      if k>=left:
        cou += left-1
      else:
        cou += left
print(cou+sum(l))

Submission status: Accepted

Solution code:
import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

ans = []
s = ns()
n = len(s) + 1
now = 0
min_now = 0

ri = deque()
le = deque()

now = 0
for i in range(n-1):
    if s[i] == '<':
        now += 1
    else:
        now = 0
    le.append(now)
now = 0
for i in range(n-1):
    if s[(n-2)-i] == '>':
        now += 1
    else:
        now = 0
    ri.appendleft(now)
le.appendleft(0)
ri.append(0)

for i in range(n):
    ans.append(max(le.popleft(), ri.popleft()))

print(sum(ans))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = list(input())
data = [0] * (len(s) + 1)
for i in range(len(s)):
    if s[i] == "<":
        data[i + 1] = data[i] + 1

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

Submission status: Accepted

Solution code:
s = input()
right_cnt = 0
left_cnt = 0
total = 0
for i in range(len(s)):
  if s[i] == '<' and left_cnt == 0:
    right_cnt += 1
  elif s[i] == '<' and left_cnt > 0:
    k = max(right_cnt, left_cnt)
    l = min(right_cnt, left_cnt)
    total += (((k+1)*k) + (l*(l-1)))//2
    right_cnt = 1
    left_cnt = 0
  elif s[i] == '>':
    left_cnt += 1
k = max(right_cnt, left_cnt)
l = min(right_cnt, left_cnt)
total += (((k+1)*k) + (l*(l-1)))//2
print(total)

Submission status: Accepted

Solution code:
s = input()
prev = s[0]
n = len(s)
cnt= 0
L = [0]*(n+1)
R = [0]*(n+1)
for i in range(n):
    if s[i] =="<":
        cnt+=1
    else:
        cnt=0
    L[i+1] = cnt
s= s[::-1]
for i in range(n):
    if s[i] ==">":
        cnt+=1
    else:
        cnt=0
    R[i+1] = cnt
ans = 0
for i in range(n+1):
    ans+=max(L[i],R[-i-1])
print(ans)

Submission status: Accepted

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
S = S()
seq = [0]*(len(S)+1)
for i in range(len(S)):
    if S[i]=='<':
        seq[i+1] = seq[i]+1
for j in range(len(S)-1,-1,-1):
    if S[j]=='>':
        seq[j] = max(seq[j],seq[j+1]+1)
print(sum(seq))

Submission status: Accepted

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
S = S()
seq = [0]*(len(S)+1)
for i in range(len(S)):
    if S[i]=='<':
        seq[i+1] = seq[i]+1
for j in range(len(S))[::-1]:
    if S[j]=='>':
        seq[j] = max(seq[j],seq[j+1]+1)
print(sum(seq))

Submission status: Accepted

Solution code:
import itertools,sys
def S(): return sys.stdin.readline().rstrip()
S = S()
groupby_S = itertools.groupby(S)
ans = 0
rangeN = [i for i in range(len(S)+1)]
rangeN_accumulate = list(itertools.accumulate(rangeN))
group = []
temp = []
for k,g in groupby_S:
    if k=='<':
        temp.append(len(list(g)))
    else:
        temp.append(len(list(g)))
        group.append(temp)
        temp = []
group.append(temp)
for x in group:
    if len(x)==0:
        continue
    elif len(x)==1:
        ans += rangeN_accumulate[x[0]]
    else:
        a,b = max(x),min(x)-1
        ans += rangeN_accumulate[a]
        ans += rangeN_accumulate[b]
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    s=input()
    ls=len(s)
    a=[0]*(ls+1)
    for i in range(ls):
        if s[i]=='<':
            a[i+1]=a[i]+1
    for j in reversed(range(ls)):
        if s[j]=='>':
            a[j]=max(a[j+1]+1,a[j])
    print(sum(a))
resolve()

Submission status: Accepted

Solution code:
def main():
    S = input()
    smaller_cnt = [0]  # <
    seq_cnt = 0
    for c in S:
        if c != '<':
            seq_cnt = 0
        else:
            seq_cnt += 1
        smaller_cnt.append(seq_cnt)
    larger_cnt = [0]  # >
    for c in S[::-1]:
        if c != '>':
            seq_cnt = 0
        else:
            seq_cnt += 1
        larger_cnt.append(seq_cnt)
    larger_cnt.reverse()
    ans = 0
    for x, y in zip(smaller_cnt, larger_cnt):
        ans += max([x, y])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

import math

def main():
    s = str(input())
    first = s[0]
    cnt_l = []
    tmp_cnt = 1
    prev_s = first
    for curr_s in s[1:]:
        if prev_s != curr_s:
            cnt_l.append(tmp_cnt)
            tmp_cnt = 1
        else:
            tmp_cnt+=1
        prev_s = curr_s
    cnt_l.append(tmp_cnt)

    ans_l = []
    last_num = 0
    if first == '>':
        down_cnt = cnt_l[0]
        for d in range(down_cnt):
            ans_l.append(down_cnt-d)
        cnt_l = cnt_l[1:]

    # if first == '<':
    # print(cnt_l)
    ans_l.append(0)
    last_num = 0
    for i in range(math.ceil(len(cnt_l)/2)):
        # print('i',i)
        up_cnt = cnt_l[i*2]
        if i*2+1 >= len(cnt_l):
            down_cnt = 0
        else:
            down_cnt = cnt_l[i*2+1]
        # print(up_cnt,down_cnt)
        # print()
        for u in range(up_cnt):
            if u != up_cnt-1:
                last_num+=1
                ans_l.append(last_num)
            else:
                last_num = max(last_num+1, down_cnt)
                ans_l.append(last_num)
        for d in range(down_cnt):
            if d==0:
                if last_num > down_cnt:
                    last_num = down_cnt-1
                else:
                    last_num-=1
                ans_l.append(last_num)
            else:
                last_num-=1
                ans_l.append(last_num)

    # print(ans_l)
    print(sum(ans_l))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

S = input()
List=[0]*(len(S)+1)
i=0
while i<len(S):
    if S[i]=="<":
        List[i+1]=List[i]+1
    i+=1
j=1
while j<=len(S):
    if S[-j]==">":
        List[-(j+1)]=max(List[-j]+1,List[-(j+1)])
    j+=1
print(sum(List))