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):
from itertools import groupby
s=input()
n=len(s)
s=list(s)
gr=groupby(s)
cnt=[]
for k,g in gr:
    cnt.append(len(list(g)))

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

print(ans)

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

cnt1 = 0
cnt2 = 0
for i in range(N-1):
    if S[i]=="<":
        cnt1 += 1
        cnt2 = 0
    elif S[i] ==">":
        cnt1 = 0
        cnt2 += 1
    X[i+1] = cnt1

cnt1 = 0
cnt2 = 0
for i in range(N-1):
    if S[-i-1]=="<":
        cnt1 += 1
        cnt2 = 0
    elif S[-i-1] ==">":
        cnt1 = 0
        cnt2 += 1
    Y[-i-2] = cnt2

A = [0]*N
for i in range(N):
    A[i] = max(X[i],Y[i])
print(sum(A))

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

r = [0]*(n+1)
temp = 0
for i in reversed(range(n)):
  if s[i] == '>':
    temp += 1
    r[i] = temp
  else:
    temp = 0
    r[i] = temp


ans = [0]*(n+1)
for i in range(n+1):
  ans[i] = max(l[i], r[i])

print(sum(ans))

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

r = [0]*(n+1)
temp = 0
for i in reversed(range(n)):
  if s[i] == '>':
    temp += 1
    r[i] = temp
  else:
    temp = 0
    r[i] = temp


ans = [0]*(n+1)
for i in range(n+1):
  ans[i] = max(l[i], r[i])

print(sum(ans))

Solution (Python):
s = str(input())
n = len(s)+1
a = [0]*n
a_2 = [0]*n
tmp = 1
ems = list(enumerate(s))
for i,c in ems:
    if c == "<":
        a[i+1] = tmp
        tmp += 1
    else:
        tmp = 1

for i,c in reversed(ems):
    if c == ">":
        a[i] = max(a[i],tmp)
        tmp += 1
    else:
        tmp = 1

print(sum(a))

Solution (Python):
def calcsum(n):
    return n * (n + 1) // 2

s = str(input())
n = len(s) + 1
arrk = []
arrg = []
tmp = s[0]
cnt = 1
for i in range(1, n-1):
    if s[i] == tmp:
        cnt += 1
    elif s[i] != tmp:
        if tmp == '<':
            arrk.append(cnt)
        else:
            arrg.append(cnt)
        cnt = 1
        tmp = s[i]
if tmp == '<':
    arrk.append(cnt)
else:
    arrg.append(cnt)

ans = 0
for i in range(len(arrk)):
    
    ans += calcsum(arrk[i]-1)
for i in range(len(arrg)):
    
    ans += calcsum(arrg[i]-1)

l = min(len(arrg), len(arrk))
m = max(len(arrg), len(arrk))

if s[0] == '<':
    for i in range(l):
        ans += max(arrg[i], arrk[i])
    if l < len(arrk):
        ans += arrk[len(arrk) - 1]
elif s[0] == '>':
    ans += arrg[0]
    
    if l != m:
        for i in range(l):
            
            ans += max(arrg[i+1], arrk[i])
    else:
        for i in range(l-1):
            
            ans += max(arrg[i+1], arrk[i])
    if s[n-2] == '<':
        ans += arrk[len(arrk) - 1]
    if l < len(arrk):
        ans += arrk[len(arrk) - 1]
print(ans)

Solution (Python):
import sys

def solve():
    S = input()
    N = len(S)
    A = [0] * (N + 1)
    init = []
    for i in range(N - 1):
        if  S[i] == ">" and S[i + 1] == "<": init.append(i + 1)
    

    if S[0] == "<":
        d = 1
        A[d] = A[d - 1] + 1
        while d <= N - 1:
            if S[d] == ">": break
            d += 1
            A[d] = A[d-1] + 1

    for s in init:
        d = s + 1
        A[d] = A[d - 1] + 1
        while d <= N - 1:
            if S[d] == ">": break
            d += 1
            A[d] = A[d-1] + 1

    
    if S[N - 1] == ">":
        d = N - 1
        while d >= 0:
            if S[d] == "<": break
            A[d] = max(A[d], A[d+1] + 1)
            d -= 1
            
    for s in init:
        d = s - 1
        while d >= 0:
            if S[d] == "<": break
            A[d] = max(A[d], A[d+1] + 1)
            d -= 1

    print(sum(A))
    

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
def solve():
    S = input()
    lenS = len(S)
    sumS = 0
    N = [0] * (lenS + 1)
    zero = set()
    if S[0] == "<": zero |= {0}
    for i in range(lenS - 1):
        if S[i] == ">" and S[i+1] == "<": zero |= {i+1}
    if S[lenS-1] == ">": zero |= {lenS}

    for start in zero:
        pointer = start
        while pointer <= lenS - 1:
            if S[pointer] == "<":N[pointer + 1] = max(N[pointer] + 1, N[pointer + 1])
            else: break
            pointer += 1
        
        pointer = start - 1
        while pointer >= 0:
            if S[pointer] == ">": N[pointer] = max(N[pointer + 1] + 1, N[pointer])
            else: break
            pointer -= 1

    
    print(sum(N))

    return 0

if __name__ == "__main__": solve()

Solution (Python):


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

num_list = [0]*N
ans_sum = 0


for i in range(len(S)):
    s = S[i]
    if s=="<":
        num_list[i+1] = num_list[i] + 1


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


for i in range(N):
    ans_sum = ans_sum + num_list[i]

print(ans_sum)

Solution (Python):
def main():
    S = input()
    from itertools import groupby
    ans = 0
    SL = [(k, len(list(v))) for k, v in groupby(S)]
    if SL[0][0] == ">":
        ans += (SL[0][1])*(SL[0][1] + 1)//2
        pre_v = SL[0][1]
        for k, v in SL[1:]:
            if k == "<":
                pre_v = v
                continue
            else:
                if pre_v > v:
                    ans += pre_v*(pre_v+1)//2
                    ans += v*(v-1)//2
                else:
                    ans += (pre_v-1)*pre_v//2
                    ans += v*(v+1)//2
            
            pre_v = v
    else:
        pre_v = 0
        for k, v in SL:
            if k == "<":
                pre_v = v
                continue
            else:
                if pre_v > v:
                    ans += pre_v*(pre_v+1)//2
                    ans += v*(v-1)//2
                else:
                    ans += (pre_v-1)*pre_v//2
                    ans += v*(v+1)//2
            
            pre_v = v
    if SL[-1][0] == "<":
        ans += (SL[-1][1])*(SL[-1][1] + 1)//2
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin
def main():
	readline=stdin.readline
	S=readline().strip()
	if S[0]=="<":
		l_flag=True
		l_count=1
		r_count=0
	else:
		l_flag=False
		l_count=0
		r_count=1

	res=0
	for i in range(1,len(S)+1):
		if i==len(S):
			res+=max(l_count,r_count)*(max(l_count,r_count)+1)//2
			res+=(min(l_count,r_count)-1)*min(l_count,r_count)//2
			break
		if S[i]=="<" and l_flag:
			l_count+=1
		elif S[i]==">" and l_flag:
			l_flag=False
			r_count+=1
		elif S[i]==">" and l_flag==False:
			r_count+=1
		elif S[i]=="<" and l_flag==False:
			res+=max(l_count,r_count)*(max(l_count,r_count)+1)//2
			res+=(min(l_count,r_count)-1)*min(l_count,r_count)//2
			l_flag=True
			l_count=1
			r_count=0
	print(res)
if __name__=="__main__":
	main()

Solution (Python):
s = input()
a = []
prev = cnt = 0
for i in s:
        if i==prev: cnt+=1
        else:
                if prev: a.append([prev,cnt])
                cnt = 1
        prev = i
a.append([prev, cnt])

ans = [0] * (len(s)+1)
idx = 0
for t, c in a:
        for j in range(c+1):
                if t=='<': ans[idx+j] = max(ans[idx+j], j)
                else: ans[idx+j] = max(ans[idx+j], c-j)
        idx += j
print(sum(ans))

Solution (Python):
s = input()
if s[0] == ">":
    s="<"+s
if s[-1] == ">":
    s=s+"<"
elif s[-1] == "<":
    s=s+"><"

cc = 0
r = []
for b, c in zip(s, s[1:]):
    cc += 1

    if b == "<" and c == ">":
        d = cc
        cc = 0
    if b == ">" and c == "<":
        r.append((d, cc))
        cc = 0
R = 0
for x, y in r:

    R += (x-1)*x//2+(y-1)*y//2+max(x,y)

print(R)

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

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

Solution (Python):
s=input()
n=len(s)
l=[]
i = 0
cnt = 0
while i<n:
  if (len(l)%2) ^ (s[i]=='>'):
    l.append(cnt)
    cnt = 1
  else:
    cnt += 1
  i += 1
l.append(cnt)
if len(l)%2:
  l.append(0)
ans=0
for i in range(0,len(l),2):
  ans += l[i] * (l[i] - 1) // 2
  ans += l[i+1]*(l[i+1]-1) // 2
  ans += max(l[i],l[i+1])
print(ans)

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

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

print(sum(ans_list))

Solution (Python):
S = [False if s == "<" else True for s in input()]

N = len(S)

a = [0] * (N+1)

for i in range(N):
    if not S[i]:
        a[i+1] = max(a[i+1], a[i] + 1)

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

print(sum(a))

Solution (Python):
s=input()
N=len(s)+1
up=[0]*N
down=[0]*N
for i in range(N-1):
    if s[i]=='<':
        up[i+1]=up[i]+1
for i in range(N-2,-1,-1):
    if s[i]=='>':
        down[i]=down[i+1]+1


res=[max(u,d) for u,d in zip(up,down)]

print(sum(res))

Solution (Python):
S = input()

les = len(S)

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

R = [0] + R

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

print(sum([max(R[x],L[x]) for x in range(les+1)]))

Solution (Python):

s=input()
n=len(s)+1
a=[-1]*n
INF = 10**6

indecies=set()

for i in range(1,n-1):
    if(s[i-1:i+1]=="><"):
        a[i]=0
        indecies.add(i)
    elif(s[i-1:i+1]=="<>"):
        a[i] = INF

if s[0]=="<":
    a[0] = 0
    indecies.add(0)
else:
    a[0] = INF

if s[n-2]==">":
    a[n-1] = 0
    indecies.add(n-1)
else:
    a[n-1] = INF
    
for ind in indecies:
    l=ind-1
    now = 1
    while(0<=l):
        if(a[l]<0):
            a[l]=now
            l -= 1
            now += 1
        else:
            if(a[l]==INF):
                a[l] = now
            else:
                a[l]=max(now, a[l])
            break
            
    r=ind+1
    now = 1
    while(r<n):
        if(a[r]<0):
            a[r]=now
            r += 1
            now += 1
        else:
            if(a[r]==INF):
                a[r] = now
            else:
                a[r]=max(now, a[r])
            break
            
print(sum(a))

Solution (Python):
s=input()
ans=0
cnt=1
res=[]
s+="X"
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        cnt+=1
    elif s[0]==">" and ans==0:
        ans+=cnt*(cnt+1)//2
        cnt=1
    else:
        res.append(cnt)
        cnt=1
for i in range(len(res)//2):
    r1=max(res[2*i],res[2*i+1])
    r2=min(res[2*i],res[2*i+1])
    ans+=(r1*(r1+1)+r2*(r2-1))//2
if len(res)%2==1:
    ans+=res[-1]*(res[-1]+1)//2
print(ans)

Solution (Python):
S=input()
smallcount=0    
smallflag=0     
bigcount=0      
bigflag=1       
endflag=0
event=0
count=0

def renzokusum(n):
    return int((n*(n+1))/2)

for i in range(len(S)):
    
    if (S[i]=="<"):
        bigflag=1
    if (S[i]==">"):
        smallflag=1
    if (S[i]=="<")and(bigflag==1)and(smallflag==1):
        count=count+renzokusum(max(smallcount,bigcount))+renzokusum(min(smallcount,bigcount)-1)
        smallflag=0
        bigcount=0
        smallcount=0
    if (S[i] == "<"):
        bigcount = bigcount + 1
    if (S[i]==">"):
        smallcount = smallcount + 1

count=count+renzokusum(max(smallcount,bigcount))+renzokusum(min(smallcount,bigcount)-1)

print(count)

Solution (Python):
from itertools import *
s = input()
g = [[k,len(list(v))] for k,v in groupby(s)]
ans = 0
for command,length in g:
    ans += length*(length+1)//2
for i in range(len(g)-1):
    if g[i][0] == "<":
        ans -= min(g[i][1],g[i+1][1])
print(ans)

Solution (Python):
S = input()
n = len(S)
l1 = [0] * (n+1)
l2 = [0] * (n+1)

v = 0
for i in range(1, n+1):
    if S[i-1] == "<":
        v += 1
        l1[i] = v
    else:
        v = 0

v = 0
for i in range(n)[::-1]:
    if S[i] == ">":
        v += 1
        l2[i] = v
    else:
        v = 0

ans = 0
for i, j in zip(l1, l2):
    ans += max(i, j)

print(ans)

Solution (Python):
S = input()
N = len(S)
cnts = []
now = "<"
if S[0] == ">":
    cnts.append(0)
    now = ">"
cnt = 0
for i in range(N):
    if S[i] == now:
        cnt += 1
    else:
        cnts.append(cnt)
        cnt = 1
        now = ">" if now == "<" else "<"

if cnt > 0:
    cnts.append(cnt)

if len(cnts) % 2 != 0:
    cnts.append(0)

ans = 0
for i in range(0, len(cnts), 2):
    if cnts[i] < cnts[i+1]:
        ans += sum([x for x in range(cnts[i])])
        ans += sum([x for x in range(cnts[i+1] + 1)])
    else:
        ans += sum([x for x in range(cnts[i] + 1)])
        ans += sum([x for x in range(cnts[i + 1])])
print(ans)

Solution (Python):
s = input()

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

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

s = s[::-1]

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


print(sum(a))

Solution (Python):
s = input()
a = [0 for _ in range(len(s) + 1)]
for i in range(len(s)):
    if s[i] == "<": a[i+1] = a[i] + 1
for i in reversed(range(len(s))):
    if s[i] == ">" and a[i+1] >= a[i]: a[i] = a[i+1] + 1
print(sum(a))

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

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

Solution (Python):
s = input()

if s[0] == ">": s = "<" + s
if s[-1] == "<": s = s + "><"
if s[-1] == ">": s = s + "<"
lens = len(s)

a = []
c = 1
for i in range(1, lens):
    if s[i] == s[i-1]:
        c += 1
    else:
        a.append(c)
        c = 1

ans = 0
for i in range(0, len(a), 2):
    ans += a[i+1] * (a[i+1]-1) // 2
    ans += a[i] * (a[i]-1) // 2
    ans += max(a[i], a[i+1])

print(ans)

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

dat = [0] * n
c = 0
for i in range(len(s)):
    if s[i] == "<":
        c += 1
        dat[i + 1] = c
    else:
        c = 0

dat2 = [0] * n
for i in range(len(s)-1, -1, -1):
    if s[i] == ">":
        c += 1
        dat2[i] = c
    else:
        c = 0








res = []
for i in range(len(dat)):
    res.append(int(max(dat[i], dat2[i])))




print(sum(res))

Solution (Python):
S = input()

n = len(S)
s_0 = S[0]
s_sum = 0
left = 0
right = 0
for s in S:
    if '>' == s:
        right += 1
    else:
        break

for i in range(n+1):
    
    if right >= left:
        s_sum += right
    else:
        s_sum += left
    if right == 0:
        left += 1
        while right + i + 1 < n:
            if '>' == S[right + i + 1]:
                right += 1
            else:
                break
    else:
        right -= 1
        left = 0
print(s_sum)

Solution (Python):
S = input()
A = []
A.append(0)

for i in range(len(S)):
    if S[i] == "<":
        A.append(A[i] + 1)
    else:
        A.append(0)

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


print(sum(A))

Solution (Python):
def main():
    from itertools import groupby
    r = p = 0
    for k,g in groupby(input()):
        l = sum([1 for _ in g])
        r += l*(l+1)//2
        if k == ">":
            r -= min(l,p)
        p = l
    print(r)

if __name__ == '__main__':
    main()

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

A = [0] * (N+1)

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

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

print(sum(A))

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

A = [0] * N

c = 0
for i, si in enumerate(S):
    if si == '<':
        c += 1
    else:
        c = 0
    A[i+1] = c

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


print(sum(A))

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


dai = [None] * N
dai[0] = 0

c = 0
for i, si in enumerate(S):
    if si == '<':
        c += 1
    else:
        c = 0
    dai[i+1] = c



S = S[::-1]
sho = [None] * N
sho[0] = 0  

c = 0
for i, si in enumerate(S):
    if si == '>':
        c += 1
    else:
        c = 0
    sho[i+1] = c

sho = sho[::-1]  




a = [None] * (N)
for i in range(N):
    a[i] = max(dai[i], sho[i])


ans = sum(a)
print(ans)

Solution (Python):
def total(num):
    return (1+num) * num // 2

s = input()
length = len(s)

ans = 0
cnt = 0
a = []
bef = ''

for c in enumerate(s):
    if c[0] == 0:
        cnt += 1
        bef = c[1]
        continue

    if c[1] == bef:
        cnt += 1
    else:
        a.append(cnt)
        bef = c[1]
        cnt = 1
a.append(cnt)

aa = [total(i) for i in a]


if s[0] == '<':
    for i in range(0, len(a)-1, 2):
        if a[i] <= a[i+1]:
            aa[i] -= a[i]
        else:
            aa[i+1] -= a[i+1]
else:
    for i in range(1, len(a)-1, 2):
        if a[i] <= a[i+1]:
            aa[i] -= a[i]
        else:
            aa[i+1] -= a[i+1]



print(sum(aa))

Solution (Python):
s = input()
l = []
cnt = 0
flg = 0
for c in s:
    if (c == '<') ^ flg:
        cnt += 1
    else:
        l.append(cnt)
        flg ^= 1
        cnt = 1
l.append(cnt)
if len(l) % 2:
    l.append(0)
ans = 0
for i in range(len(l) // 2):
    x = l[i * 2]
    y = l[i * 2 + 1]
    ans += x * (x - 1) // 2 + y * (y - 1) // 2 + max(x, y)
print(ans)

Solution (Python):
def solve(s):
    ret = [0] * (len(s) + 1)
    size = 0
    tmp = 0
    for i in range(len(s)):
        if s[i] == '>':
            size += 1
            ret[i] = tmp
            tmp = 0
        if s[i] == '<':
            ret[i] = tmp
            tmp += 1
            if size > 0:
                for j in range(size + 1):
                    if ret[i - j] < j:
                        ret[i - j] = j
                tmp = 1
            size = 0

    if size > 0:
        for j in range(size + 1):
            if ret[len(s) - j] < j:
                ret[len(s) - j] = j
    else:
        size += 1
        ret[len(s)] = tmp

    return sum(ret)

_s = input()
print(solve(_s))

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

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

Solution (Python):
def main():
  import sys

  f = "" 
  ans = 0 
  count = 0 
  continuous = 0 
  
  for m in sys.stdin.readline().strip("\n"):
    if m=="<":
      if f==">" and count>0:
        
        ans-=count*continuous
        count=0
      count+=1
        
    else:
      if f=="<":
        
        continuous=0
      count-=1
      continuous+=1
      if count==-1:
        ans+=continuous
        count=0
        continue

    ans+=count
    f=m

  print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
def main():
  import sys

  f = "" 
  ans = 0 
  count = 0 
  continuous = 0 
  
  for m in sys.stdin.readline().strip("\n"):
    if m=="<":
      if f==">" and count>0:
        
        ans-=count*continuous
        count=0
      count+=1
        
    else:
      if f=="<":
        
        continuous=0
      count-=1
      continuous+=1
      if count==-1:
        ans+=continuous
        count=0
        continue

    ans+=count
    f=m

  print(ans)
    
if __name__ == '__main__':
    main()

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

f = "" 
ans = 0 
count = 0 
continuous = 0 

for m in s:
  if m=="<":
    if f==">" and count>0:
      
      ans-=count*continuous
      count=0
    count+=1

  else:
    if f=="<":
      
      continuous=0
    count-=1
    continuous+=1
    if count==-1:
      ans+=continuous
      count=0
      continue

  ans+=count
  f=m

print(ans)

Solution (Python):
def main():
  
  f = "" 
  ans = 0 
  count = 0 
  continuous = 0 
  
  for m in input():
    if m=="<":
      if f==">" and count>0:
        
        ans-=count*continuous
        count=0
      count+=1
        
    else:
      if f=="<":
        
        continuous=0
      count-=1
      continuous+=1
      if count==-1:
        ans+=continuous
        count=0
        continue

    ans+=count
    f=m

  print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
def main():
  s = str(input())
  
  f = "" 
  ans = 0 
  count = 0 
  continuous = 0 
  
  for m in s:
    if m=="<":
      if f==">" and count>0:
        
        ans-=count*continuous
        count=0
      count+=1
        
    else:
      if f=="<":
        
        continuous=0
      count-=1
      continuous+=1
      if count==-1:
        ans+=continuous
        count=0
        continue

    ans+=count
    f=m

  print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
def main():
  s = str(input())
  
  f = "" 
  ans = 0 
  count = 0 
  continuous = 0 
  
  for m in s:
    if m=="<":
      if f==">" and count>0:
        
        ans-=count*continuous
        count=0
      count+=1
        
    else:
      if f=="<":
        
        continuous=0
      count-=1
      continuous+=1

    if count>=0:
      ans+=count
    else:
      ans+=continuous
      count=0
    
    f=m

  print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
def main():
  s = tuple(input())
  
  f = "" 
  ans = 0 
  count = 0 
  continuous = 0 
  
  for m in s:
    if m=="<":
      if f==">" and count>0:
        
        ans-=count*continuous
        count=0
      count+=1
        
    else:
      if f=="<":
        
        continuous=0
      count-=1
      continuous+=1

    if count>=0:
      ans+=count
    else:
      ans+=continuous
      count=0
    
    f=m

  print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):

def main():
  from itertools import groupby

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

  for k,v in groupby(s):
    d = len(tuple(v))
    left = d if k==">" else 0
    right = d if k=="<" else 0
    if f>left:
      ans += d*(d+1)//2 - left
    else:
      ans += -1*f + d*(d+1)//2  
    f = right 

  print(ans) 

if __name__ == '__main__':
    main()

Solution (Python):
from itertools import groupby

s = list(input())
f = 0
ans = 0
for k,v in groupby(s):
  d = len(list(v))
  left = d if k==">" else 0
  right = d if k=="<" else 0
  if f>left:
    ans += d*(d+1)//2 - left
  else:
    ans += -1*f + d*(d+1)//2  
  f = right 
print(ans)

Solution (Python):
arr = input()
l = len(arr)

ans_arr = [0] * (l+1)
for i in range(l):
    if arr[i] == '<':
        ans_arr[i+1] = ans_arr[i] + 1

for i in range(l-1, -1, -1):
    if arr[i] == '>':
        ans_arr[i] = max(ans_arr[i], ans_arr[i+1] + 1)


print(sum(ans_arr))

Solution (Python):
def main():
    S = input()
    N = len(S)
    A = [ 0 for _ in range(N+1)]

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

    for i in reversed(range(N)):
        if S[i] == '>':
            A[i] = max(A[i+1]+1, A[i])

    print(sum(A))


if __name__ == '__main__':
    main()

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def calc(N):
    return sum(int(x) for x in str(N))


def main():
    
    S = Scanner.string()
    ans = 0
    i = 0
    A = [0] * (len(S) + 1)
    B = [0] * (len(S) + 1)
    i = len(S) - 1
    while i >= 0:
        if S[i] == ">":
            A[i] = 0
            while i >= 0 and S[i] == ">":
                A[i] = A[i+1] + 1
                i -= 1
        i -= 1
    i = 0
    while i < len(S):
        if S[i] == "<":
            B[i] = 0
            while i < len(S) and S[i] == "<":
                i += 1
                B[i] = B[i-1] + 1
        i += 1
    ans = 0
    for i in range(len(S) + 1):
        ans += max(A[i], B[i])
    print(ans)

    return


if __name__ == "__main__":
    main()

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

for i in reversed(range(n)):
	if s[i] == ">":
		ans[i] = max(ans[i+1]+1, ans[i])
	
print(sum(ans))

Solution (Python):
A = list(input())
n = len(A)
l = [0] * (n+1)
count = 0

for i in range(n):
    if A[i] == '<':
        count += 1
        l[i+1] = count
    else:
        count = 0

A.reverse()
l.reverse()
count = 0

for i in range(n):
    if A[i] == '>':
        count += 1
        l[i+1] = max(count, l[i+1])
    else:
        count = 0

print(sum(l))

Solution (Python):
import sys


def main():
    s = str(input())
    N = len(s)
    pl = [0 for _ in range(N+1)]
    ml = [0 for _ in range(N+1)]
    for i in range(N):
        if s[i] == "<":
            pl[i+1] = pl[i]+1
        if s[-i-1] == ">":
            ml[-i-2] = ml[-i-1]+1

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

if __name__ == "__main__":
    main()

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

for i in l:
  if i[0] == "<":
    for j in range(i[2]+1):
      a[i[1]+j] = max(a[i[1]+j], j)
  else:
    for j in range(i[2]+1):
      a[i[1]+j] = max(a[i[1]+j], i[2]-j)
      
print(sum(a))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=list(S())
  
  l1=[]
  l2=[]

  _s=s[::-1]

  st=0
  l1.append(st)
  a=0
  for x in s:
    if x=='<':
      a+=1
    else:
      a=0
    l1.append(a)

  st=0
  l2.append(st)
  a=0
  for x in _s:
    if x=='>':
      a+=1
    else:
      a=0
    l2.append(a)
  l2.reverse()

  
  

  sm=0
  for i in range(len(s)+1):
    sm+=max(l1[i],l2[i])

  return sm


print(main())

Solution (Python):


S=list(input())

nums=[1 if S[0]=="<" else -1]
for i in range(len(S)-1):
    if S[i+1]==S[i]:
        if S[i+1]=="<":
            nums[-1]+=1
        else:
            nums[-1]-=1
    else:
        if S[i+1]=="<":
            nums.append(1)
        else:
            nums.append(-1)

ans=0
if nums[0]<0:
    are=-nums.pop(0)
    ans+=are*(are+1)//2
    if nums:
        pass
    else:
        print(ans)
        exit()
if nums[-1]>0:
    are=nums.pop(-1)
    ans+=are*(are+1)//2
    if nums:
        pass
    else:
        print(ans)
        exit()

temp=list(map(lambda x:abs(x)-1,nums))
temp=list(map(lambda x:x*(x+1)//2,temp))


ans+=sum(temp)

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

print(ans)

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

for i in range(0, l  + 1):
    if S[i] == ">":
        ans_list[i] = 0
    else:
        ans_list[i] = ans_list[i - 1] + 1
ans_list2 =  [0]  * (l + 1)

for i in range(l + 1,0,-1 ):
    if S[i] == "<":
        ans_list2[i - 1] =max( 0 ,ans_list2[i - 1])
    else:
        ans_list2[i - 1] = max( ans_list2[i - 1], ans_list2[i] + 1)



final_ans = []
for a,b in zip(ans_list,ans_list2):
    final_ans.append(max(a,b))

print(sum(final_ans))