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

Solution (Python):



import math


def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True


def main():

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

    a[0] = 0
    temp = 0
    for i in range(len(s)):
        if s[i] == "<":
            a[i + 1] = a[i]+ 1
            if temp>0:
                for j in range(temp+1):
                    a[i - j] = max(0 + j,a[i-j])
            temp = 0
        elif s[i] == ">" and i < len(s)-1:
            temp += 1
        else:
            temp+=1
            for j in range(temp):
                a[i - j] = 0 + j + 1

    b = 0
    for i in range(len(a)):
        b += a[i]

    print(b)




if __name__ == "__main__":
    main()

Solution (Python):
s = input().strip()
import re
r = 0
for mch in re.findall("((<+)(>+)|^>+|<+$)", s):
    n, m = sorted([len(mch[1]),len(mch[2])])
    if m == 0:
        x = len(mch[0])
        r += x*(x+1)//2
    else:
        r += m*(m+1)//2 + n*(n-1)//2
print(r)

Solution (Python):
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 range(n - 2, - 1, -1):
    if s[i] == '>':
        if a[i] <= a[i + 1] + 1:
            a[i] = a[i + 1] + 1

print(sum(a))

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

s = s.split("><")
for t in s:
    t = "<"+t+">"
    t = t.split("<>")
    
    M = int(max(len(t[0]),len(t[1])))
    m = int(min(len(t[0]),len(t[1])))
    ans += (m*(m+1) + (M+2)*(M+1))/2
print(int(ans))

Solution (Python):
def main():

    S = input()
    left = [0]
    c = 0
    for i in range(len(S)):
        if S[i] == "<":
            c += 1
        else:
            c = 0
        left.append(c)
    right = [0]
    for i in range(len(S)-1, -1, -1):
        if S[i] == ">":
            c += 1
        else:
            c = 0
        right.append(c)
    right = right[::-1]

    
    
    

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

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

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

L1 = np.zeros(len(S)+1)
for i in range(len(S)):
  L1[i+1] = L1[i] + 1 if S[i] == '<' else 0

L2 = np.zeros(len(S)+1)
for i in range(len(S), 0, -1):
  L2[i-1] = L2[i] + 1 if S[i-1] == '>' else 0

print(int(sum(np.max([L1, L2], axis=0))))

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
S = input()

S = S + 'g'
memo = [0]*len(S)
last = 's'
cnt_r = 0
cnt_l = 0
res = 0
for s in S:
    if last == 's':
        if s == '<':
            cnt_l = 1
        else:
            cnt_r = 1
    elif last == '<':
        if s == '<':
            cnt_l += 1
        elif s == '>':
            cnt_r = 1
        else:
            res += cnt_l * (cnt_l + 1) // 2
    else:
        if s == '<':
            maxv = max(cnt_l, cnt_r)
            minv = min(cnt_l, cnt_r)
            res += maxv * (maxv+1) // 2
            if minv != 0:
                res += (minv-1) * minv // 2
            cnt_l = 1
            cnt_r = 0
        elif s == '>':
            cnt_r += 1
        else:
            maxv = max(cnt_l, cnt_r)
            minv = min(cnt_l, cnt_r)
            res += maxv * (maxv+1) // 2
            if minv != 0:
                res += (minv-1) * minv // 2


    last = s


print(res)

Solution (Python):


S = list(input())
S.append("end")

def count(r, l):
    part_sum = ((r-1)*r + (l-1)*l)/2 
    part_max = max(r, l) 
    return(part_sum + part_max)

ans = 0
r = l = 0
for i in range(len(S)-1):
    if S[i+1] != S[i] and S[i] == ">": 
        r += 1
        ans += count(r, l)
        r = l = 0
    elif S[i] == "<":
        l += 1
    elif S[i] == ">":
        r += 1
ans += count(r, l) 
print(int(ans))

Solution (Python):





"""
GC040 A-2
"""

ali = list(input())

tmp = 0
b = [0]
for L in ali:
    if L == '<':
        tmp += 1
    else:
        tmp = 0
    b.append(tmp)

tmp = 0
c = [0]
ali.reverse()
for L in ali:
    if L == '>':
        tmp += 1
    else:
        tmp = 0
    c.append(tmp)
c.reverse()

numlist = [max(a, b) for (a, b) in zip(b, c)]
print(sum(numlist))

Solution (Python):
import sys
from collections import deque
s = deque(s for s in sys.stdin.readline().rstrip())

s.append(None)
ans = 0
while s[0] != None:
    l_c = 0
    while s[0] == '<':
        l_c += 1
        s.popleft()
    
    r_c = 0
    while s[0] == '>':
        r_c += 1
        s.popleft()

    if l_c >= r_c:
        ans += (1 + l_c) * l_c // 2 + r_c * (r_c - 1) // 2
    else:
        ans += l_c * (l_c - 1) // 2 + (1 + r_c) * r_c // 2

print(ans)

Solution (Python):
S = list ( input("") )
sum_list = [-100 for _ in range( len(S) + 1 )]
if S[0] == "<":
    sum_list[0] = 0
if S[len(S) - 1] == ">":
    sum_list[len(S)] = 0
for i in range( 1, len(S) ):
    before_check = i - 1
    after_check = i
    if S[before_check] == ">" and S[after_check] == "<":
        sum_list[i] = 0

a = list(sum_list)      
for i in range( 1, len(S) + 1 ):
    before_check = i - 1
    if a[i] == -100:
        if S[before_check] == "<":
            a[i] = a[i-1] + 1
            
b = list(sum_list)
for j in range( len(S)-1,-1,-1  ):
    after_check = j
    if b[j] == -100:
        if S[after_check] == ">":
            b[j] = b[j+1] + 1 

answer = list()
for i in range(len(a)):
    answer.append(max(a[i],b[i]))
        
print(sum(answer))

Solution (Python):
s = input()

r = 0
l = 0
max_num = 0
min_num = 0
ans = 0

for i in range(len(s)):
  if s[i] == "<":
    r += 1
  if s[i] == ">":
    l += 1
  if i < (len(s)-1):
    if s[i] == ">" and s[i+1] == "<":
      max_num = max(r, l)
      min_num = min(r, l)
      ans += (max_num*(max_num+1))/2
      ans += ((min_num-1)*min_num)/2
      r = l = 0

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

print(int(ans))

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


def calc(a, b):
    if a > b:
        return acc(a) + acc(max(b - 1, 0))
    else:
        return acc(b) + acc(max(a - 1, 0))


s = input()
lc = 0
hc = 0
pre = None
ans = 0
for si in s:
    if pre == '>' and si == '<':
        ans += calc(hc, lc)
        lc, hc = 0, 0
    if si == '<':
        lc += 1
    else:
        hc += 1
    pre = si
ans += calc(hc, lc)

print(ans)

Solution (Python):
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 range(N-2, -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
from_left = [0]*N
from_right = [0]*N
ii = [0]*N

for i, s in enumerate(S, 1):
  if s == '>':
    from_left[i] = 0
  else:
    from_left[i] = from_left[i-1]+1
    
for i,s in enumerate(S[::-1]):
  i = N-2-i
  if s == '<':
    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)]    
answer = sum(seq)
print(answer)

Solution (Python):

from itertools import groupby


def main():
    S = input().rstrip()
    ans, prev = 0, 0
    for sign, g in groupby(S):
        cnt = len(tuple(g))
        ans += cnt * (cnt + 1) // 2
        if sign == ">":
            ans -= min(cnt, prev)
        prev = cnt
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
s = str(input())
m = len(s)
c = 0
r = 0
prevr = -1
s += "a"
if s[0] == "<":
  state = 1
else:
  state = -1
for i in range(1,m+1):
  if s[i] == s[i-1]:
    r += 1
  else:
    if state == 1:
      prevr = r
      c += ((r+2)*(r+1))//2
      state = -1
      r = 0
    else:
      c += ((r+2)*(r+1))//2
      if prevr >= r:
        c -= (r+1)
      else:
        c -= (prevr+1)
      state = 1
      r = 0
print(c)

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

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

Solution (Python):
r = l = p = lp = 0
for c in input():
    if c != p:
        if c == '<':
            r -= min(l, lp)
        p = c
        lp = l
        l = 0
    l += 1
    r += l
if p == '>':
    r -= min(l, lp)   
print(r)

Solution (Python):

import sys
from collections import deque
INF = float("inf")


def runlength(S):
    ans = [0]
    newS = [S[0]]
    pos = [0]
    for i, (pre, curr) in enumerate(zip(S[0]+S, S)):
        if pre == curr:
            ans[-1] += 1
        else:
            ans.append(1)
            newS.append(curr)
            pos.append(i)
    return [(n, a, i) for (n, a, i) in zip(ans, newS, pos)]


def solve(S: str):
    N = len(S)
    RL = deque(sorted(runlength(S)))
    ans = [-1]*(N+1)
    while RL:
        n, a, i = RL.popleft()
        
        if a == ">":
            for j in range(n+1):
                ans[i+j] = n-j
        else:
            for j in range(n+1):
                ans[i+j] = j
        
    print(sum(ans))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  
    solve(S)


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import groupby

ans = premax = 0

for k, g in groupby(input()):
    
    for c, _ in enumerate(g, 1):
        ans += c
    
    if k == '>':
        ans -= min(c, premax)
    premax = c
print(ans)

Solution (Python):
from heapq import heappush, heappop
from collections import deque
import re
import math
import functools

def sRaw():
    return input().rstrip("\r")

def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29


def make1d_arr(n, val=INF):
    return [val for i in range(n)]


def make2d_arr(h, w, val=INF):
    return [[val for i in range(w)]for i in range(h)]


def gcd(a, b):
    if(b == 0):
        return a
    return gcd(b, a % b)


def BFord(n,es):
    v_cost = [INF]*n
    v_cost[0] = 0
    for v in range(n*2):
        for e in es:
            frm = e[0]
            to = e[1]
            if v_cost[to] > v_cost[frm]+e[2]:
                v_cost[to] = v_cost[frm]+e[2]
                if v >= n:
                    v_cost[to] = -INF
        if v == n-1:
            prev = v_cost[:]
    v_cost = [-INF if prev[idx]!=v_cost[idx] else v_cost[idx] for idx in range(n)]
    return v_cost
    
def ZAlgo(s):
    l = len(s)
    A = [0]*l
    i =1
    j =0
    A[0]=l
    while i<l:
        while i+j<l and s[j] == s[i+j]:
            j+=1
        if j==0:
            i+=1
            continue
        A[i]=j
        k=1
        while (i+k<l) and (k+A[k]<j):
            A[i+k] =A[k]
            k+=1
        i+=k
        j-=k
    return A


def main():
    S = sRaw()
    nLs = [0]*(len(S)+1)
    for idx,c in enumerate(S):
        if c=="<":
            nLs[idx+1] = nLs[idx]+1
    nRs = [0]*(len(S)+1)
    for idx, c in enumerate(S[::-1]):
        if c==">":
            nRs[len(nRs)-idx-2] = nRs[len(nRs)-idx-1]+1
    mas = [max(nLs[idx],nRs[idx]) for idx in range(len(nLs))]
    return sum(mas)

if __name__ == "__main__":
    print(main())

Solution (Python):
r = p = 0
l = [0, 0]
for c in input():
    f = c == '<'
    if c != p:
        p = c
        if f:
            r -= min(l)
            l = [0, 0]
    l[f] += 1
    r += l[f]
if not f:
    r -= min(l)
print(r)

Solution (Python):
s = input()
n = len(s)
m = n + 1
a1, a2 = [0] * m, [0] * m
cnt = 0
for i in range(n-1, -1, -1):
    if s[i] == ">":
        a2[i+1] = cnt
        cnt += 1
    else:
        a2[i+1] = cnt
        cnt = 0
a2[0] = cnt

cnt = 0
for i in range(n):
    if s[i] == "<":
        a1[i] = cnt
        cnt += 1
    else:
        a1[i] = cnt
        cnt = 0
a1[-1] = cnt

print(sum([max(a1[i], a2[i]) for i in range(m)]))

Solution (Python):
from itertools import groupby
 
r = p = 0
for k, g in groupby(input()):
    i = 0
    for _ in g:
        i += 1
        r += i
    if k == '>':
        r -= min(i, p)
    p = i
print(r)

Solution (Python):
from itertools import groupby
 
r = p = 0
for k, g in groupby(input()):
    for i, _ in enumerate(g, 1):
        r += i
    if k == '>':
        r -= min(i, p)
    p = i
print(r)

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

A = []
c = 0
pre = '<'
for s in S:
    if pre == s:
        c += 1
    else:
        A.append(c)
        c = 1
    pre = s
A.append(c)

ans = 0
if A[0] != 0:
    l = len(A)
    for i in range(l):
        if i%2 == 0:
            if i != l-1:
                ans += max(A[i], A[i+1])
            else:
                ans += A[i]
    for a in A:
        ans += a*(a-1)//2
else:
    l = len(A)
    for i in range(l):
        if i % 2 == 0:
            if i != l-1:
                ans += max(A[i], A[i+1])
            else:
                ans += A[i]
    for a in A:
        ans += a*(a-1)//2
print(ans)

Solution (Python):
from itertools import groupby
 
r = p = 0
for k, g in groupby(input()):
    i = 0
    for _ in g:
        i += 1
        r += i
    if k == '>':
        r -= min(i, p)
    p = i
print(r)

Solution (Python):
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)

Solution (Python):
from itertools import groupby

r = p = 0
for k, g in groupby(input()):
    for i, _ in enumerate(g, 1):
        r += i
    if k == '>':
        r -= min(i, p)
    p = i
print(r)

Solution (Python):
def calc(a, b):
    a, b = min(a, b), max(a, b)
    return (a * a - a + b * b + b) // 2

s = input()
ls = s.split('><')
if len(ls) == 1:
    g = ls[0].count('<')
    l = len(ls[0]) - g
    print(calc(l, g))
else:
    ans = 0
    g = ls[0].count('<')
    l = len(ls[0]) - g
    ans += calc(l + 1, g)
    for t in ls[1:-1]:
        g = t.count('<')
        l = len(t) - g
        ans += calc(l + 1, g + 1)
    g = ls[-1].count('<')
    l = len(ls[-1]) - g
    ans += calc(l, g + 1)
    print(ans)

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


dp=[0]*(len(s)+1)
count=0
x=0
for i in range(len(s)):
    if s[i]=='<':
        dp[i+1]=dp[i]+1

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

print(sum(dp))

Solution (Python):
def solve():
    s_arr = input().replace('><', '> <').split()
    ans = 0
    
    for s in s_arr:
        left = s.count('<')
        right = len(s) - left
        if left < right:
            left -= 1
            ans += left * (left + 1) // 2 + right * (right + 1) // 2
        else:
            right -= 1
            ans += left * (left + 1) // 2 + right * (right + 1) // 2
    
    print(ans)

if __name__ == '__main__':
    solve()

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

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


print(sum(A))

Solution (Python):


S = input()
s_list = list(S)
s_l = len(s_list)
N = s_l + 1
t_list = ["ou"] if s_list[0] == "<" else ["totsu"]


for i, char in enumerate(s_list):
    
    is_ou = False
    is_totsu = False
    if i == s_l - 1:
        if char == ">":
            is_ou = True
        else:
            is_totsu = True
    else:
        if s_list[i] == "<" and s_list[i + 1] == ">":
            is_totsu = True
        elif s_list[i] == ">" and s_list[i + 1] == "<":
            is_ou = True

    if is_ou:
        t = "ou"
    elif is_totsu:
        t = "totsu"
    elif char == "<":
        t = "up"
    else:
        t = "down"
    t_list.append(t)


x_list = []
for i, t in enumerate(t_list):
    if t == "ou":
        x = 0
    elif t == "up" or i == N - 1:
        x = x_list[i - 1] + 1
    else:
        x = None
    x_list.append(x)


total = 0

for i in range(N):
    idx = N - (i + 1)
    t = t_list[idx]
    if t == "down":
        x_list[idx] = x_list[idx + 1] + 1
    elif t == "ou" or t == "down":
        pass
    elif t == "totsu":
        if idx == 0:
            x_list[0] = x_list[1] + 1
        elif idx == N - 1:
            x_list[idx] = x_list[idx - 1] + 1
        else:
            a = x_list[idx - 1]
            b = x_list[idx + 1]
            x_list[idx] = max(a, b) + 1
    total += x_list[idx]

ans = total
print(ans)

Solution (Python):
S = input() + "_"
i = 0
d = 0
ans = 0
for k in range(len(S)):
    if S[k] == "<":
        i += 1
    elif S[k] == ">":
        d += 1
    if S[k] == ">" and S[k+1] == "<":
        m = min(i,d)
        M = max(i,d)
        ans += M*(M+1)//2 + m*(m-1)//2
        i = 0
        d = 0
m = min(i,d)
M = max(i,d)
ans += M*(M+1)//2 + m*(m-1)//2
print(ans)

Solution (Python):
s = input()
N = len(s) + 1
l = [0]*N 
for i in range(N-1):
  if s[i] == '<':
    l[i+1] = l[i] + 1
for k in range(N-2,-1,-1):
  if s[k] == '>':
    l[k] = max(l[k], l[k+1] + 1)
print(sum(l))

Solution (Python):
def main():
    s=list(input())
    n=len(s)+1
    ans=[0 for _ in range(n)]
    for i in range(n-1):
        if s[i]=="<":
            ans[i+1]=ans[i]+1
    s.reverse()
    ans.reverse()
    for i in range(n-1):
        if s[i]==">":
            ans[i+1]=max(ans[i]+1,ans[i+1])
    print(sum(ans))    
if __name__ == "__main__":
    main()

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

A = [0] * (N + 1)
left = 0

while left < N and S[left] == '<':
    A[left + 1] = A[left] + 1
    left += 1

while left < N:
    mid = left + 1
    while mid < N and S[mid] == '>':
        mid += 1

    right = mid
    while right < N and S[right] == '<':
        right += 1

    for l in range(left, mid)[:: -1]:
        A[l] = max(A[l], A[l + 1] + 1)
    for r in range(mid + 1, right + 1):
        A[r] = max(A[r], A[r - 1] + 1)
    left = right

ans = sum(A)
print(ans)

Solution (Python):
import numpy as np

S = list(input())
l = len(S) + 1
A = [0] * l
B = [0] * l

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

for i in range(len(S)-1, -1, -1):
    if S[i] == '>':
        B[i] = B[i+1] + 1
answer = 0
for i in range(l):
    answer += max(A[i], B[i])
print(answer)

Solution (Python):
def gauss(n):
    ans = int (n * (n + 1) / 2)
    return(ans) 

s = input().replace("><", "> <")
new_s = s.split(" ")

a = [0] * len(new_s)

for i in range(len(new_s)):
    if new_s[i].count("<") >= new_s[i].count(">"):
        a[i] = gauss(new_s[i].count("<"))
        a[i] += gauss(new_s[i].count(">") - 1)
    else:
        a[i] = gauss(new_s[i].count(">"))
        a[i] += gauss(new_s[i].count("<") - 1)

print(sum(a))

Solution (Python):

from itertools import groupby

S = input()

L = [[k, len(list(g))] for k, g in groupby(S)]

ans = 0
i = 0
while i != len(L):
    if i == 0 and L[i][0] == ">":
        ans += ((L[i][1] * (L[i][1] + 1)) / 2)
        i += 1
    elif i == len(L) - 1:
        ans += ((L[i][1] * (L[i][1] + 1)) / 2)
        i += 1
    else:
        if L[i][1] > L[i+1][1]:
            ans += ((L[i][1] * (L[i][1] + 1)) / 2) + (((L[i+1][1] - 1) * (L[i+1][1])) / 2)
        else:
            ans += ((L[i+1][1] * (L[i+1][1] + 1)) / 2) + (((L[i][1] - 1) * (L[i][1]) / 2))
        i += 2
print(int(ans))

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

from collections import deque

ans = []
_x = s[0]
l = 1
for x in s[1:]:
    if x == _x:
        l += 1
    else:
        ans.append(l)
        _x = x
        l = 1
ans.append(l)
ans = deque(ans)

_ans = 0

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

if s[0] == '>':
    d = ans.popleft()
    _ans += partsum(d)

while len(ans)>1:
    a = ans.popleft()
    b = ans.popleft()
    _ans += partsum(max(a,b)) + partsum(min(a,b)-1)
if len(ans)==1:
    c = ans.popleft()
    _ans += partsum(c)

print(_ans)

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

Solution (Python):
from itertools import groupby

s = input()
if s[-1] == '<':
    s += '>' 
r = p = 0
for k, g in groupby(s):
    s = sum(1 for _ in g)
    if k == '>':
        r += (p * p  + s * s - p - s) // 2 + max(p, s)
    p = s
print(r)

Solution (Python):
from itertools import groupby, chain, islice
 
def pairs(t):
    a = True
    while a:
        a =[sum(1 for _ in g) for k, g in islice(t, 2)]
        if a:
            yield sum(x * (x - 1) // 2 for x in a) + max(a)
 
s = input()
t = groupby(s)
if s[0] == '>':
    t = chain([(0, ())], t)
print(sum(pairs(t)))

Solution (Python):
S=input()
Clusters=S.replace("><","> <").split(" ")
ans=0
for c in Clusters:
  r=c.count('>')
  l=c.count('<')
  M=max(r,l)
  m=min(r,l)
  ans+=max(0,M*(M+1)//2)+max(0,(m)*(m-1)//2)
print(ans)

Solution (Python):
from itertools import groupby, chain, islice
 
def pairs(t):
    a = True
    while a:
        a =[sum(1 for _ in g) for k, g in islice(t, 2)]
        if a:
            yield sum(x * (x - 1) // 2 for x in a) + max(a)
 
s = input()
t = groupby(s)
d = [(0, ())]
if s[0] == '>':
    t = chain(d, t)
if s[-1] == '<':
    t = chain(t, d)
print(sum(pairs(t)))

Solution (Python):
S = input()
N = len(S) + 1
Ans = [0]
a = 0
for c in S:
    if c=="<":
        a += 1
    else:
        a = 0
    Ans.append(a)

a = 0
for c, i in zip(S[::-1], range(N-2, -1, -1)):
    if c==">":
        a += 1
    else:
        a = 0
    Ans[i] = max(Ans[i], a)

print(sum(Ans))

Solution (Python):
s=input()
d=[0]*(len(s)+1)
Z=[]
scount=0
ans=0

if s[0]=="<":
  d[1]=d[0]+1
for i in range(1,len(s)-1):
  if s[i]==">":
    d[i+1]=0
    scount+=1
    Q=scount
    X=i
    if s[i-1]=="<":
      Z.append(i)
  elif s[i]=="<":
    d[i+1]=d[i]+1
    for j in range(scount):
      d[i-scount+j]=(scount-j)
    scount=0

if s[-1]==">":
  d[-1]=0
  scount+=1
  Q=scount
  X=len(s)-1    
if scount>0:
  for j in range(scount):
    d[X-scount+j+1]=Q
    Q-=1
for i in Z:
  d[i]=max(d[i+1]+1,d[i-1]+1)
  if i==0 and s[0]=="<":
    d[i]=0
if s[-1]=="<":
  d[-1]=d[-2]+1
if s[0]==">":
  d[0]=d[1]+1

print(sum(d))

Solution (Python):
from sys import stdin
S = (stdin.readline().rstrip())
ans1 = [0] * (len(S)+1)

cnt = 0
for j in range(len(S)):
    if S[j] == "<":
        cnt += 1
        ans1[j+1] = cnt

    else:
        cnt = 0

ans2 = [0]*(len(S)+1)
cnt = 0
for j in range(len(S)-1, -1, -1):
    if S[j] == ">":
        cnt += 1
        ans2[j] = cnt

    else:
        cnt = 0

ans = 0
for i,j in zip(ans1,ans2):
    ans += max(i,j)
print(ans)

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

Solution (Python):
S = input()
slst = [[] for _ in range(len(S) + 1)]
tmp = S[0]
cnt = 0
index = 0
for i in range(len(S)):
    if tmp == S[i]:
        cnt += 1
    else:
        slst[index].append(tmp)
        slst[index].append(cnt)
        index += 1
        tmp = S[i]
        cnt = 1

slst[index].append(tmp)
slst[index].append(cnt)

dp = [0] * (len(S) + 1)
if slst[0][0] == '<':
    dp[0] = 0
else:
    dp[0] = slst[0][1]

index = 1
for i in range(len(S)):
    if slst[i] == []:
        break

    if slst[i][0] == '>':
        dp[index] = dp[index - 1] + ((slst[i][1]) * ((slst[i][1] - 1))) // 2
        index += 1
    else:
        if slst[i + 1] == []:
            dp[index] = dp[index - 1] + ((slst[i][1] + 1) * ((slst[i][1]))) // 2
            index += 1
        else:
            if slst[i][1] < slst[i + 1][1]:
                tdp = slst[i + 1][1]
                for k in range(1, slst[i][1]):
                    tdp += k
                dp[index] = dp[index - 1] + tdp
                index += 1

            else:
                dp[index] = dp[index - 1] + ((slst[i][1] + 1) * ((slst[i][1]))) // 2
                index += 1


print(dp[index - 1])

Solution (Python):
S = input()

N = len(S) + 1
t = [0] * N
for i in range(N - 1):
    if S[i] == '<':
        t[i + 1] = t[i] + 1
for i in range(N - 2, -1, -1):
    if S[i] == '>':
        t[i] = max(t[i], t[i + 1] + 1)
print(sum(t))

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


def solve():
    s = list(input())
    res = find_sum(s)
    print(res)


def find_sum(S):
    prev = S[0]
    series = 1
    l = []
    for i in range(1, len(S)):
        if prev == S[i]:
            series += 1
        else:
            l.append((prev, series))
            prev = S[i]
            series = 1
    l.append((prev, series))
    prev_max = l[0][1]
    prev = calc(prev_max)
    res = prev
    for s, n in l[1::]:
        if s == '<':
            prev = calc(n)
            prev_max = n
            res += prev
        else:
            if n >= prev_max:
                res -= prev_max
                prev = calc(n)
                res += prev
            else:
                prev = calc(n - 1)
                res += prev

    return res


if __name__ == "__main__":
    solve()

Solution (Python):
S = input()
def rle_encode(data):
    encoding = []
    prev_char = ''
    count = 1

    if not data: return ''

    for char in data:
        
        
        if char != prev_char:
            
            
            if prev_char:
                encoding.append([int(count), prev_char])
            count = 1
            prev_char = char
        else:
            
            
            count += 1
    else:
        
        encoding.append([int(count), prev_char])
        return encoding

S_rle = list(rle_encode(S))
if len(S_rle) == 1:
  print(sum(range(S_rle[0][0]+1)))
  exit()
total = 0
if S_rle[0][1] == '>':
  head = S_rle[0]
  S_rle.pop(0)
  total += sum(range(head[0]+1))
else:
  head = []
if S_rle[-1][1] == '<':
  tail = S_rle[-1]
  S_rle.pop(-1)
  total += sum(range(tail[0]+1))
else:
  tail = []
body = S_rle[:]
for i in range(len(body)//2):
  num1, num2 = body[2*i][0], body[2*i+1][0]
  total += sum(range(max(num1, num2)+1)) + sum(range(min(num1, num2)))
print(total)

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

a = [0]*N

for i, s in enumerate(S):
  if s=="<":
    a[i+1]=a[i]+1

S_ = list(reversed(S))
j=0
for s in S_:
  if s==">":
    if a[N-1-(j+1)]<=a[N-1-j]:
      a[N-1-(j+1)]=a[N-1-j]+1
  j+=1
print(sum(a))

Solution (Python):
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

s = input()
n = len(s)

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

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

print(sum(l))

Solution (Python):
S=input()

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

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

ans = [0] * N
for i in range(N - 1):
    if S[i] == '<':
        ans[i + 1] = ans[i] + 1
for i in range(N - 1):
    if S[N - i - 2] == '>' and ans[N - i - 2] <= ans[N - i - 1]:
        ans[N - i - 2] = ans[N - i - 1] + 1

print(sum(ans))

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

po=[]
ne=[]
li = [m.span()[0] for m in re.finditer('><', S)]
result = []
n = 0
for i in S:
    if i == "<":
        n += 1
    else:
        break
po.append(n)
for i in li:
    s = "<"
    n = 0
    while s == S[i+1]:
        n += 1
        i += 1
        if i+1 >= len(S):
            break
    po.append(n)
for i in li:
    s = ">"
    n = 0
    while s == S[i]:
        n += 1
        i -= 1
        if i < 0:
            break
    ne.append(n)
n = 0
for i in S[::-1]:
    if i == ">":
        n += 1
    else:
        break
ne.append(n)
for i,l in enumerate(po):
    if l < ne[i]:
        if l > 0:
            result.append((1/2)*(l-1)*l)
        if ne[i] > 0:
            result.append((1/2)*ne[i]*(ne[i]+1))
    else:
        if l > 0:
            result.append((1/2)*l*(l+1))
        if ne[i] > 0:
            result.append((1/2)*ne[i]*(ne[i]-1))
print(int(sum(result)))

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

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

Solution (Python):



def solve(*args: str) -> str:
    S = args[0]
    A = [0 for _ in range(len(S)+1)]

    m = 0
    for n in range(1, len(S)+1):
        if 0 < m:
            A[n] = m
            m -= 1
        elif S[n-1] == '<':
            A[n] = A[n-1]+1
        else:
            m = 0
            while n+m < len(S) and S[n+m] == '>':
                m += 1

            A[n-1] = max(m+1, A[n-1])
            A[n] = m
            m -= 1

    
    
    

    return str(sum(A))


if __name__ == "__main__":
    print(solve(*[input() for _ in range(1)]))

Solution (Python):
S = input()
N = len(S)+1
k = 0
score= 0
countup = 0
countdown = 0
final = None
for i in range(N-1):
  if S[i] == "<":
    if final == ">":
      score += int(countdown*(countdown-1)/2)
      if countup <= countdown:
        score += countdown - countup
      countup = 0
    countdown = 0
    final = "<"
    countup += 1
    score += countup
  elif S[i] == ">":
    final = ">"
    countdown += 1
if final == ">":
  score += int(countdown*(countdown-1)/2)
  if countup <= countdown:
    score += countdown - countup
print(score)

Solution (Python):
S = input()
dp = []
cnt = 1
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 1
    else:
        dp.append(cnt)
        cnt = 1
dp.append(cnt)
ans = 0
if S[0] == '<':
    for i in range(0, len(dp)-1, 2):
        N = max(dp[i], dp[i+1])
        n = min(dp[i], dp[i+1])
        ans += sum(range(N+1)) + sum(range(n))
    if len(dp)%2 == 1:
        ans += sum(range(dp[-1]+1))
else:
    ans += sum(range(dp[0]+1))
    for i in range(1, len(dp)-1, 2):
        N = max(dp[i], dp[i+1])
        n = min(dp[i], dp[i+1])
        ans += sum(range(N+1)) + sum(range(n))
    if len(dp)%2 == 0:
        ans += sum(range(dp[-1]+1))
print(ans)

Solution (Python):
s=input()+"1"
a=0
b=[]
i=0
l=len(s)
e=0
while True:
    if s[i]==s[i+1]:
        a+=1
    else:
        b.append(a+1)
        a=0
    i+=1
    if i+1>=l:
        break
if s[-2]=='<':
    b.append(0)
if s[0]=='>':
    b.insert(0,0)
for i in range(len(b)//2):
    c,d=max(b[i*2],b[i*2+1]),min(b[i*2],b[i*2+1])
    e+=(c*(c+1)//2)+(d*(d-1)//2)
print(e)