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:
s=input()
n=len(s)+1
dp=[-1]*n
count=0
for i in range(n-1):
    if s[i]=='>':
        count+=1
    else:
        break
dp[0]=count
buf=dp[0]
for i in range(n-2):
    if s[i]=='>' and s[i+1]=='<':
        dp[i+1]=0
        continue
    if s[i]=='<' and s[i+1]=='<':
        dp[i+1]=dp[i]+1
        continue
    if s[i]=='<' and s[i+1]=='>':
        count=0
        for j in range(i+1,n-1):
            if s[j]=='>':
                count+=1
            else:
                break
        dp[i+1]=max(dp[i]+1,count)
        buf=count
        continue
    if s[i]=='>' and s[i+1]=='>':
        dp[i+1]=buf-1
        buf-=1
        continue
if s[n-2]=='>':
    dp[n-1]=dp[n-2]-1
else:
    dp[n-1]=dp[n-2]+1
print(sum(dp))

Submission status: Accepted

Solution code:
n = list(input())

def check_list(li):
    count_big = 0
    count_small = 0
    for i in li:
        if i == '>':
            count_small += 1
        elif i == '<':
            count_big += 1
    a = list(range(max(count_small, count_big)+1))
    b = list(range(min(count_small, count_big)))
    return sum(a) + sum(b)

point_list = []
count = 0
for i in range(len(n)-1):
    if n[i] == '>' and n[i+1] == '<':
        point_list.append(i)

if point_list == []:
    print(check_list(n))
    exit()

point_list.insert(0,0)
point_list.insert(len(n), len(n)-1)

for i in range(len(point_list)-1):
    if i == 0:
        a = n[:point_list[i+1]+1]
    else:
        a = n[point_list[i]+1:point_list[i+1]+1]
    b = check_list(a)
    count += b

print(count)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s=input().rstrip()
ls=len(s)
L=[0]*(ls+1)

pre,n='<',0
for i,c in enumerate(s):
    if c=='<':
        if pre == '<':
            n+=1
            L[i+1]=n
        else:
            n=1
            L[i+1]=1
            pre='<'
    else:
        pre='>'

pre,n='>',0
for i,c in enumerate(s[::-1]):
    if c=='>':
        if pre == '>':
            n+=1
            L[ls-1-i]=max(n,L[ls-1-i])
        else:
            n=1
            L[ls-1-i]=max(n,L[ls-1-i])
            pre='>'
    else:
        pre='<'
print(sum(L))

Submission status: Accepted

Solution code:
def perm_cul(N):
    return N * (N + 1) // 2
S = input()
N = len(S)
cnt_list = []
cnt = 1
ans = 0
if N == 1:
    print(1)
    exit()
for i in range(N-1):
    if S[i] == S[i+1]:
        cnt += 1
    elif S[i] != S[i+1]:
        cnt_list.append(cnt)
        cnt = 1
    if i == N-2:
        cnt_list.append(cnt)
##print(cnt_list)
if S[0] == '<' and S[N-1] == '<':
    for i in range(len(cnt_list) - 1):
        ans += perm_cul(cnt_list[i]-1)
        if i % 2 == 1:
            ans += max(cnt_list[i-1], cnt_list[i])
    ans += perm_cul(cnt_list[len(cnt_list) - 1])

elif S[0] == '<' and S[N-1] == '>':
    for i in range(len(cnt_list)):
        ans += perm_cul(cnt_list[i]-1)
        if i % 2 == 1:
            ans += max(cnt_list[i-1], cnt_list[i])

elif S[0] == '>' and S[N-1] == '>':
    ans += perm_cul(cnt_list[0])
    for i in range(1, len(cnt_list)):
        ans += perm_cul(cnt_list[i] - 1)
        if i % 2 == 0:
            ans += max(cnt_list[i-1], cnt_list[i])

else:
    ans += perm_cul(cnt_list[0])
    for i in range(1, len(cnt_list) - 1):
        ans += perm_cul(cnt_list[i]-1)
        if i % 2 == 0:
            ans += max(cnt_list[i-1], cnt_list[i])
    ans += perm_cul(cnt_list[len(cnt_list) - 1])

print(ans)

Submission status: Accepted

Solution code:
import itertools
import math

S= input()
sg = [[s, len(list(g))] for s ,g in itertools.groupby(S)]
a= [0]* (len(S)+1)
ans =0

if sg[0][0]=='>':
    ans += (sg[0][1] + 1 ) * sg[0][1] //2

if sg[-1][0]=='<':
    ans += (sg[-1][1] + 1 ) * sg[-1][1] //2

for i in range(len(sg)-1):
    if sg[i][0]=='<' and sg[i+1][0]=='>':
        maxsg =max(sg[i][1] , sg[i+1][1])
        ans += (maxsg + 1 ) * maxsg //2
        minsg = min(sg[i][1] , sg[i+1][1])-1
        ans += ( minsg + 1 ) * minsg //2

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] == '<'):
		if(a[i+1] < a[i]+1):
			a[i+1] = a[i]+1
for i in reversed(range(n-1)):
	if(S[i] == '>'):
		if(a[i] < a[i+1]+1):
			a[i] = a[i+1]+1
print(sum(a))

Submission status: Accepted

Solution code:
S = input()
l = len(S)
A = [0] * (l+1)

count = 0
for i, s in enumerate(S):
    if s == '>':
        count = 0
    else:
        count += 1
        A[i+1] = count

count = 0
for i in range(l-1, -1, -1):
    s = S[i]
    if s == '<':
        count = 0
    else:
        count += 1
        A[i] = max(A[i], count)

print(sum(A))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

S = input().strip()
N = len(S) + 1
incre = [0] * N
decre = [0] * N
sum_a = 0

t = 0
for i, s in enumerate(S):
    if s == '<':
        t += 1
        incre[i + 1] = t
    else:
        t = 0

t = 0
for i, s in enumerate(S[::-1]):
    if s == '>':
        t += 1
        decre[-(i + 2)] = t
    else:
        t = 0

for i, (inc, dec) in enumerate(zip(incre, decre)):
    if inc < dec:
        incre[i] = dec

print(sum(incre))

Submission status: Accepted

Solution code:
S = input()

a = [-1] * (len(S) + 1)

# find zero positions
if S[0] == "<":
    a[0] = 0

if S[-1] == ">":
    a[-1] = 0

for i in range(len(S)):
    if S[i:i+2] == "><":
        a[i + 1] = 0

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] >= 0:
        a[i] = max(a[i], a[i + 1] + 1)

print(sum(a))

Submission status: Accepted

Solution code:
S=input()

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

if S[0]=="<":
    x[0]=0

if S[-1]==">":
    x[-1]=0


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

        
print(sum(x))

Submission status: Accepted

Solution code:
#import sys

#input = sys.stdin.readline
import math
#import bisect

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


def main():
#    h,w,a,b = map(int, input().split())
    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()

Submission status: Accepted

Solution code:
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)

#m = False
#cd = 0
#for c in s:
#    for b != c:
#        print(cd)

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

print(sum(a))

Submission status: Accepted

Solution code:
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("<>")
    #print(t)
    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))

Submission status: Accepted

Solution code:
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]

    # print(S)
    # print(left)
    # print(right)

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

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

Submission status: Accepted

Solution code:
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))))

Submission status: Accepted

Solution code:
import sys
#input = sys.stdin.readline
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)

Submission status: Accepted

Solution code:
# coding: utf-8

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) #"<"終わりの時は、その分がカウントされないので足す(ただしl = 0)
print(int(ans))

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

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 range(N-2, -1, -1):
  if S[i] == '>':
    A[i] = max(A[i], A[i+1]+1)
    
print(sum(A))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# AGC040A - ><
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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()
        # print((n, a, i))
        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(ans)
    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)  # type: str
    solve(S)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import groupby

ans = premax = 0
# 文字列を連続した < か > のグループに分ける
for k, g in groupby(input()):
    # 連続している数分1ずつ増やして足していく
    for c, _ in enumerate(g, 1):
        ans += c
    # >の連続なら前回の<の最大値（最後の値）と今回の>の最後の値で小さい方を引く
    if k == '>':
        ans -= min(c, premax)
    premax = c
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)]))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=list(input())
#print(S)
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(A)
#print(len(A))
print(sum(A))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

# 1回目のループ: 凹凸↗︎↘︎を判定する
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)

# 2回目のループ: 凹と↗︎部分の値を確定させる
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)

# 3回目のループ: 末尾から見ていって、凸と↘︎部分を確定させる
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
s = input()
N = len(s) + 1
l = [0]*N #からのリスト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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))