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)
a = [0]
for i in range(n):
    if s[i] == ">":
        temp = a[-1] - 1
        a.append(temp)
        if i == n - 1 or s[i + 1] == "<":
            a[i + 1] = 0
            for j in range(i, -1, -1):
                if s[j] == ">":
                    if s[j - 1] == "<":
                        a[j] = max(a[j], a[j + 1] + 1)
                    else:
                        a[j] = a[j + 1] + 1
                else:
                    break
    else:
        a.append(a[-1] + 1)
print(sum(a))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def left(N, S, a, i):
    a[i + 1] = 0
    v = 0
    while True:
        if i == 0:
            a[i] = v + 1
            break
        if S[i - 1] == ">":
            v += 1
            a[i] = v
            i -= 1
        else:
            a[i] = max(a[i], v + 1)
            break


def right(N, S, a, i):
    a[i] = 0
    v = 0
    while True:
        if i == N - 1:
            a[i + 1] = v + 1
            break
        if S[i + 1] == "<":
            i += 1
            v += 1
            a[i] = v
        else:
            a[i + 1] = max(a[i + 1], v + 1)
            break


def main():
    S = input().rstrip()
    N = len(S)

    a = [0] * (N + 1)
    if S[0] == "<":
        right(N, S, a, 0)
    if S[-1] == ">":
        left(N, S, a, N - 1)
    for i in range(N - 1):
        if S[i:i + 2] == "><":
            left(N, S, a, i)
            right(N, S, a, i + 1)
    
    ans = sum(a)
    print(ans)


if __name__ == "__main__":
    main()

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] = 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:
s = input()
n = len(s) + 1

a = [-1] * n
tmp = 0

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

for i in range(1,n-2):
    if s[i] == '>' and s[i+1] == '<':
        a[i+1] = 0

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

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

print(sum(a))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
A = [-1 for i in range(N+1)]
if S[0] == "<":
  A[0] = 0
if S[-1] == ">":
  A[-1] = 0
  
for i in range(N):
  if S[i:i+2] == "><":
    A[i+1] = 0

#print(A)

for i in range(N):
  if S[i] == "<":
    A[i+1] = max(A[i]+1, A[i+1])
    
for i in range(N):
  if S[N-i-1] == ">":
    A[N-i-1] = max(A[N-i]+1, A[N-i-1])
    
#print(A)
print(sum(A))

Submission status: Accepted

Solution code:
def r(i):
    indr = s.find('<', i)
    return indr - i if indr != -1 else n - i - 1
def l(i):
    indl = s.rfind('>', 0, i)
    return i - indl -1 if indl != -1 else i 
s = input()
n = len(s) + 1
print(sum([max(r(i), l(i)) for i in range(n)]))

Submission status: Accepted

Solution code:
S = list(input())
ls = len(S)

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


for i in range(ls):
    if S[i] == "<":
        a[i + 1] = max(a[i + 1], a[i] + 1)
        
for i in range(ls - 1, -1, -1):
    if S[i] == ">":
        a[i] = max(a[i], a[i + 1] + 1)
        
print(sum(a))

Submission status: Accepted

Solution code:
S = list(input())
ls = len(S)

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


for i in range(ls):
    if S[i] == "<":
        a[i + 1] = max(a[i + 1], a[i] + 1)
        
for i in range(ls - 1, -1, -1):
    if S[i] == ">":
        a[i] = max(a[i], a[i + 1] + 1)
        
print(sum(a))

Submission status: Accepted

Solution code:
S = list(input())

#  ><は0でいいのか
#  同様に S[0]==<とS[-1]==>も0でいい
#  制約的にNlogNくらいまでは十分許容範囲だし><は0で埋めてindex保持、そこから単調増加で組むのが良さそう？

#  3回ループさせる形で実装してみる

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

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

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

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

print(sum(tmp))

Submission status: Accepted

Solution code:
s = list(input())
l2r = [0]
r2l = [0]
n = len(s)
for i in range(n):
  if s[i] == '<':
    l = l2r[i]
    l2r.append(l+1)
  else:
    l2r.append(0)

for j in range(n):
  if s[n-1-j] == '>':
    r2l.append(r2l[j]+1)
  else:
    r2l.append(0)
invr2l = r2l[::-1]
ans = []
for i in range(n+1):
  m = max(l2r[i],invr2l[i])
  ans.append(m)

print(sum(ans))

Submission status: Accepted

Solution code:
s=input()
n=len(s)+1
mountain=[0,0]
count=[0,0]
sum=0
for i in range(n-1):
    if s[i]=="<":
        mountain[1]+=1
    else:
        if mountain[1]>0:
            sum+=(mountain[0]*(mountain[0]-1)+mountain[1]*(mountain[1]+1))//2+max([0,mountain[0]-count[1]])
            count=mountain
            mountain=[1,0]
        else:
            mountain[0]+=1

sum+=(mountain[0]*(mountain[0]-1)+mountain[1]*(mountain[1]+1))//2+max([0,mountain[0]-count[1]])

print(sum)

Submission status: Accepted

Solution code:
s = input()
n = len(s)+1
ans = 0
ls = [0 for _ in range(n)]
rs = [0 for _ in range(n)]
for i in range(n-1):
    if s[i] == '<':
        ls[i+1] = ls[i]+1
for i in range(n-1):
    if s[-1-i] == '>':
        rs[-2-i] = rs[-1-i]+1
for i,j in zip(ls,rs):
    ans += max(i,j)
print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    S = input()
    n = len(S)
    l_res = [0]
    r_res = [0]
    for i in range(n):
        if S[i] == '<':
            l_res.append(l_res[i] + 1)
        else:
            l_res.append(0)
    inv_S = S[::-1]

    for i in range(n):
        if inv_S[i] == '>':
            r_res.append(r_res[i] + 1)
        else:
            r_res.append(0)
    res = 0
    for l_cnt, r_cnt in zip(l_res, r_res[::-1]):
        res += max(l_cnt, r_cnt)
    print(res)

Submission status: Accepted

Solution code:
s = input()
n = len(s)+1
ls = [0]*n
rs = [0]*n
for i in range(n-1):
    if s[i] == "<":
        ls[i+1] = ls[i]+1
for i in range(n-1):
    if s[-1-i] == ">":
        rs[-2-i] = rs[-1-i]+1
ans = 0
for i,j in zip(ls,rs):
    ans += max(i,j)
print(ans)

Submission status: Accepted

Solution code:
s = input() + "."
comp = []

cur = s[0]
streak = 0
count = 0

for i in range(len(s)):
    if s[i] == cur:
        streak += 1
    else:
        if (len(comp) == 0):
            if cur == ">":
                count += streak*(streak+1)//2
            elif i == (len(s) - 1):
                count += streak*(streak+1)//2
        elif cur == ">":
            prevStreak = comp[-1][1]
            count += (prevStreak*(prevStreak+1) + streak*(streak+1)) // 2
            count -= min(streak, prevStreak)
        elif i == (len(s) - 1):
            if cur == "<":
                count += streak*(streak+1)//2

        comp.append((cur, streak))
        streak = 1
        cur = s[i]

print(count)

Submission status: Accepted

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

for i in range(len(S)):
    if S[i] is '<':
        a[i+1] = max(a[i+1], a[i]+1)
        

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

Submission status: Accepted

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


def main():
  S = input()[:-1]

  N = len(S)+1

  from_left = [0]*N
  from_right = [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 = [x if x>y else y for x, y in zip(from_left, from_right)]

  answer = sum(seq)
  print(answer)


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
l, count = [], 0
for i in s:
    if i=='>': count+=1
    else:
        if count: l.append(count)
        count = 0
if count: l.append(count); count = 0
j = 0
ans = []
if s[0]=='<': ans.append(0)
else:
    ans.append(l[0])
    l[0]-=1

for i in range(len(s)):
    if s[i]=='<': ans.append(ans[-1]+1)
    else:
        if i==0: ans.append(ans[-1]-1); continue
        if l[j]==0: j+=1
        if ans[-1]>=l[j]:
            l[j]-=1
            ans.append(l[j])
                
        else:
            ans[-1]=l[j]
            l[j]-=1
            ans.append(l[j])
print(sum(ans))

Submission status: Accepted

Solution code:
s = input()

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

left = [0]*(len(s)+1)
for i in range(len(s)-1, -1, -1):
    if s[i] == '>':
        left[i] = left[i+1] + 1

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

print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    s = input().rstrip('\n')
    n = len(s)
    ansl = [0]*(n+1)
    for i in range(n):
        if s[i] == '<':
            ansl[i+1] = ansl[i]+1
    for i in reversed(range(n)):
        if s[i] == '>':
            ansl[i] = max(ansl[i+1]+1,ansl[i])
    print(sum(ansl))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S=input()
a=[0]*(len(S)+1)
for i in range(len(S)):
    if S[i]=="<":
        # a[i+1]=max(a[i+1],a[i]+1)
        a[i+1]=a[i]+1
for i in range(len(S)-1,-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)
shift_max = [0]*(n+1)

big_run = 0
for i in range(n):
    if S[i] == '<':
        big_run += 1
    else:
        big_run = 0
    shift_max[i+1] = big_run
small_run = 0
for i in reversed(range(n)):
    if S[i] == '>':
        small_run += 1
    else:
        small_run = 0
    shift_max[i] = max(shift_max[i],small_run)

print(sum(shift_max))

Submission status: Accepted

Solution code:
S = input()
n = len(S)
shift_max = [0]*(n+1)

big_run = 0
for i in range(n):
    if S[i] == '<':
        big_run += 1
    else:
        big_run = 0
    shift_max[i+1] = big_run
small_run = 0
for i in reversed(range(n)):
    if S[i] == '>':
        small_run += 1
    else:
        small_run = 0
    shift_max[i] = max(shift_max[i],small_run)


print(sum(shift_max))

Submission status: Accepted

Solution code:
S = input()

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

print(sum(A))

Submission status: Accepted

Solution code:
s = input()

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

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

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

print(sum(a))

Submission status: Accepted

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

for i in range(num):
    if s[i] is '<':
        a[i+1] = max(a[i+1], a[i]+1)

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

Submission status: Accepted

Solution code:
S = input()
s_Count = 0
b_Count = 0
ans = 0

for i in range(len(S)):
  if S[i] == "<":
    s_Count += 1
    if i == len(S)-1:
      max_sb = max(s_Count,b_Count)
      min_sb = min(s_Count,b_Count) - 1
      ans += max_sb * (max_sb+1) / 2 + min_sb * (min_sb+1) / 2
      s_Count = 0
      b_Count = 0
  elif S[i] == ">":
    b_Count += 1
    if i == len(S)-1 or S[i+1] == "<":
      max_sb = max(s_Count,b_Count)
      min_sb = min(s_Count,b_Count) - 1
      ans += max_sb * (max_sb+1) / 2 + min_sb * (min_sb+1) / 2
      s_Count = 0
      b_Count = 0
print(int(ans))

Submission status: Accepted

Solution code:
s = input()
left, right = [0,], [0,]
a, b = 0, 0
for i in range(len(s)):
    a = a+1 if s[i] == '<' else 0
    left.append(a)
    b = b+1 if s[-1*(i+1)] == '>' else 0
    right.append(b)

right.reverse()
ans = sum(max(x, y) for x, y in zip(left, right))
print(ans)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
lst = [0] * (l+1)

for idx in range(l):
    if s[idx] is '<':
        lst[idx+1] = max(lst[idx+1], lst[idx]+1)

for inv in range(1, l+1):
    if s[-inv] is '>':
        lst[-(inv+1)] = max(lst[-(inv+1)], lst[-inv]+1)


print(sum(lst))

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
s.append('<')
mini = 0
maxi = 0
p = 0

for i in range(n):
    if s[i] == '<':
        mini += 1
    else:
        maxi += 1
        if s[i+1] == '<':
            m = max(mini,maxi)
            p += (1 + m) * m // 2
            m = min(mini,maxi) - 1
            p += (1 + m) * m // 2
            mini = 0
            maxi = 0

if mini != 0:
    print(p + ((1+mini) * mini // 2))
else:
    print(p)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    s = input()
    ans, i, j = 0, 0, 0
    while i < len(s):
        if s[i] == '<':
            j = 0
            while i<len(s) and s[i] == '<':
                ans += j
                j += 1
                i += 1
        else:
            k = 1
            while i<len(s) and s[i] == '>':
                ans += k
                k += 1
                i += 1
            if j > k - 1:
                ans = ans - (k - 1) + j
    if s[-1] == '<':
        ans += j
    print(ans)
                
            
if __name__ == '__main__':
    main()

Submission status: Accepted

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

S = input()

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

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

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

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

ans = 0
for a in A:
    ans += a
print(ans)

Submission status: Accepted

Solution code:
S = input()
arr = [0]*(len(S) + 1)
cn = 0
for i in range(len(S)):
    if S[i] == "<":
        cn += 1
    else:
        cn = 0
    arr[i+1] = cn
cn = 0
for i in range(len(S)-1, -1, -1):
    if S[i] == ">":
        cn += 1
    else:
        cn = 0
    arr[i] = max(arr[i], cn)
# print(arr)
print(sum(arr))

Submission status: Accepted

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

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

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

print(sum(A))

Submission status: Accepted

Solution code:
s=input()
n=len(s)+1
a,b=[0]*n,[0]*n
temp=0
for i,val in enumerate(s):
    if val=="<": temp+=1
    else: temp=0
    a[i+1]=temp
temp=0
for i,val in enumerate(s[::-1]):
    if val==">": temp+=1
    else: temp=0
    b[n-i-2]=temp
ans=0
for i,j in zip(a,b): ans+=max(i,j)
print(ans)

Submission status: Accepted

Solution code:
s = input()
s_l = [0] * (len(s) + 1)
s_r = [0] * (len(s) + 1)
for i in range(len(s)):
    if s[i] == '<':
        s_l[i + 1] = s_l[i] + 1
for i in range(len(s)):
    if s[- i - 1] == '>':
        s_r[- i - 2] = s_r[- i - 1] + 1
        
ans = 0
for i, j in zip(s_l, s_r):
    ans += max(i, j)
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] = a[i] + 1
for i in range(N - 1, -1, -1):
    if S[i] == '>' and a[i] <= a[i+1]:
        a[i] = a[i+1] + 1
print(sum(a))

Submission status: Accepted

Solution code:
S = list(input().strip())
ans = [0] * (len(S)+1)

for i in range(len(S)):
    if S[i] == "<":
        ans[i+1] = max(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))

Submission status: Accepted

Solution code:
s = input()

n = len(s)+1
L = [0]*(n)

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

for i in range(n-2,-1,-1):
  if s[i]=='>':
    L[i] = max(L[i],L[i+1]+1)
    
print(sum(L))

Submission status: Accepted

Solution code:
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    def n2(x):
        return x*(x+1)//2

    s = input()
    s +='.'
    ans = 0
    p = 0
    n = 0
    prev_p= 0
    for i in range(len(s)-1):
        if s[i] == '>':
            n += 1
            if s[i+1] == '<' or s[i+1] == '.':
                ans += n2(n)
                ans -= min(n, prev_p)
                n = 0
        else:
            p += 1
            if s[i+1] == '>':
                ans += n2(p)
                prev_p = p
                p = 0
            elif s[i+1] == '.':
                ans += n2(p)
                p = 0
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
n = len(s)+1
v1 = [None]*n
v2 = [None]*n
v1[0] = 0
v2[-1] = 0
v = 0
for i,c in enumerate(s):
    if c=="<":
        v += 1
    else:
        v = 0
    v1[i+1] = v
v = 0
for i,c in enumerate(s[::-1]):
    if c==">":
        v += 1
    else:
        v = 0
    v2[n-2-i] = v
ans = [max(v1[i], v2[i]) for i in range(n)]
print(sum(ans))

Submission status: Accepted

Solution code:
s=input()
ans=0
a=[0]
for i in s:
  if i=='<':
    if a[-1]>=0:a[-1]+=1
    else:a+=[1]
  else:
    if a[-1]<0:a[-1]-=1
    else:a+=[-1]
n=len(a)
for i in range(n//2):
  i*=2
  j=i+1
  if a[i]<abs(a[j]):
    x=abs(a[j])
    y=a[i]-1
  else:
    x=abs(a[j])-1
    y=a[i]
  ans+=x*(x+1)//2+y*(y+1)//2
ans+=n%2*a[-1]*(a[-1]+1)//2
print(ans)

Submission status: Accepted

Solution code:
s=list(input())
ans=0
i=0
comp_s=[]
while i<len(s):
    if s[i]=='<':
        comp_s.append('<')
        tmp=0
        while i<len(s) and s[i]=='<':
            i+=1
            tmp+=1
        comp_s.append(tmp)
    elif s[i]=='>':
        comp_s.append('>')
        tmp=0
        while i<len(s) and s[i]=='>':
            i+=1
            tmp+=1
        comp_s.append(tmp)
#print(comp_s)
    
j=1
sdata=[]
if comp_s[0]=='>':
    sdata.append((0,comp_s[1]))
    j+=2
for i in range(j,len(comp_s)-2,4):
    sdata.append((comp_s[i],comp_s[i+2]))
if comp_s[-2]=='<':
    sdata.append((comp_s[-1],0))
#print(sdata)

for l,r in sdata:
    ans+=l*(l-1)//2+r*(r-1)//2+max(l,r)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
c = 0
a = 0
p = ""
n = 0
for i in s:
    if i != p:
        if i == "<":
            if c < 0:
                a -= c * n
            else:
                a -= c * (n - 1)
            n = 2
            c = 1
        else:
            n = 2
            c -= 1
    else:
        if i == "<":
            c += 1
            n += 1
        else:
            c -= 1
            n += 1
    a += c
    p = i
if p == ">":
    if c < 0:
        a -= c * n
    else:
        a -= c * (n - 1)
print(a)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import groupby
    s = input()
    ans = 0
    prev = 0

    for k, g in groupby(s):
        l = len(list(g))
        if k == "<":
            ans += l * (l + 1) // 2
            prev = l
        else:
            ans += l * (l + 1) // 2
            ans -= min(l, prev)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

A=[0]*N
B=[0]*N

for k in range(N-1):
    if S[k]=="<":
        A[k+1]=A[k]+1

for k in range((N-1)-1,-1,-1):
    if S[k]==">":
        B[k]=B[k+1]+1
        
print(sum(map(lambda x:max(A[x],B[x]),range(N))))

Submission status: Accepted

Solution code:
s = input()

cnt_l = [0]*(len(s)+1)
cnt_r = [0]*(len(s)+1)

for i in range(1, len(s)+1):
    if s[i-1] == "<":
        cnt_l[i] = cnt_l[i-1] + 1
    else:
        cnt_l[i] = 0

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

ans = 0
for l, r in zip(cnt_l, cnt_r):
    ans += max(l, r)
print(ans)

Submission status: Accepted

Solution code:
def r(i):
    indr = s.find('<', i)
    return indr - i if indr != -1 else n - i - 1
def l(i):
    indl = s.rfind('>', 0, i)
    return i - indl -1 if indl != -1 else i 

s = input()
n = len(s) + 1
print(sum([max(r(i), l(i)) for i in range(n)]))

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

Submission status: Accepted

Solution code:
S = input()
N=len(S)+1
SS = '>'+S+'<'
a = [-1]*(N+2)
for i in range(N+1):
    if SS[i] == '>' and SS[i+1]=='<':
        a[i+1]=0
b = a[1:-1]
c = a[1:-1]

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


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

ans = 0
for bb,cc in zip(b,c):
    ans += max(bb,cc) 

print(ans)

Submission status: Accepted

Solution code:
S = input()

r = 0
l = 0
ans = 0
val = 0
for i in range(len(S)):
    if(S[i] == "<"):
        if(l == 1):
            r = 1
            if(val > l):
                ans += val
                val = 0
                l = 0
            else:
                ans += l
                l = 0
        elif(l > 1):
            if(val > l):
                ans += (l*(l+1))//2+(val-l)
                l = 0
                r = 1
                val = 0
            else:
                ans += (l*(l+1))//2
                l = 0
                r = 1
                val = 0
        else:
            r += 1
    else:
        if(r):
            ans += (r*(r-1))//2
            val = r
            l = 1
            r = 0
        else:
            l += 1
if(l):
    if(l == 1):
        if(val > l):
            ans += val
        else:
            ans += l
    else:
        if(val > l):
            ans += (l*(l+1))//2+(val-l)
        else:
            ans += (l*(l+1))//2
else:
    ans += (r*(r+1))//2
print(ans)

Submission status: Accepted

Solution code:
S = input()
lst = []
cnt = 0
if S[0] == '<':
    flg = 0
else:
    flg = 1
for i in range(len(S)):
    if flg == 0:
        if S[i] == '<':
            cnt += 1
        elif S[i] == '>':
            lst.append(['<',cnt])
            cnt = 1
            flg = 1
    elif flg == 1:
        if S[i] == '<':
            lst.append(['>', cnt])
            cnt = 1
            flg = 0
        elif S[i] == '>':
            cnt += 1
if flg == 0:
    lst.append(['<',cnt])
else:
    lst.append(['>', cnt])
#print(lst)

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

if lst[0][0] == '>':
    n3 = lst[0][1]
    ans += n3 * (n3 + 1) / 2
if lst[-1][0] == '<':
    n4 = lst[-1][1]
    ans += n4 * (n4+1) /2
print(int(ans))

Submission status: Accepted

Solution code:
S = input()
N = len(S)+1
x = [0 for _ in range(N)]
l = 0
while(l<N-1):
    r = l+1
    while(r<N-1 and S[r]==S[l]):
        r += 1
    if S[l]=='<':
        x[l] = 0
        for i in range(l+1, r+1):
            x[i] = max(x[i], x[i-1]+1)
    else:
        x[r] = 0
        for i in range(r-1, l-1, -1):
            x[i] = max(x[i], x[i+1]+1)
    l = r
print(sum(x))

Submission status: Accepted

Solution code:
s=list(input())
num=[]
str1="<"
if s[0]=="<":
    num1=1
else:
    num.append(0)
    str1=">"
    num1=1
for i in range(len(s)-1):
    if str1==s[i+1]:
        num1+=1
    else:
        if str1=="<":
            str1=">"
        else:
            str1="<"
        num.append(num1)
        num1=1
num.append(num1)
ans=0
if str1=="<":
    num.append(0)
for i in range(len(num)//2):
    ans+=((num[i*2]+1)*num[i*2])//2
    ans+=((num[i*2+1]+1)*num[i*2+1])//2
    ans-=min(num[i*2],num[i*2+1])
print(ans)

Submission status: Accepted

Solution code:
S = input()
S = S.replace('><','> <').split()

ans = 0
for i in S:
    j = max(i.count('>'),i.count('<'))
    k = min(i.count('>'),i.count('<'))-1
    for a in range(1,j+1):
        ans += a
    for b in range(1,k+1):
        ans += b

print(ans)

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


s = S()
n = len(s)
a = [0] * (n + 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]:
        a[i] = max(a[i], a[i + 1] + 1)
print(sum(a))

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


s = S()
n = len(s)
ans = 0
cnt = 0
before_cnt = 0
now = s[0]
for x in s:
    if now == x:  # 同じ不等号が連続しているとき
        cnt += 1
    else:  # 不等号が変わるとき
        ans += cnt * (cnt + 1) // 2
        if now == '>':  # > から < に変わるとき
            if before_cnt < cnt:
                ans -= before_cnt
            else:
                ans -= cnt

        before_cnt = cnt
        cnt = 1
        now = x

ans += cnt * (cnt + 1) // 2
if now == '>':
    if before_cnt < cnt:
        ans -= before_cnt
    else:
        ans -= cnt
print(ans)

Submission status: Accepted

Solution code:
s=list(input())
l=len(s)
ans=0

if len(set(s))==1:
    for i in range(1,l+1):
        ans+=i
    print(ans)
    exit()

for i in range(l-1):
    if s[i]=="<" and s[i+1]==">":
        left=1
        right=1
        for j in range(i):
            if s[i-j-1]=="<":
                left+=1
            else:
                break
        for j in range(l-i-2):
            if s[i+j+2]==">":
                right+=1
            else:
                break
        p=max(left,right)
        q=min(left,right)
        for j in range(p):
            ans+=(j+1)
        for j in range(q-1):
            ans+=(j+1)
if s[0]==">":
    ans+=1
    for i in range(1,l):
        if s[i]==">":
            ans+=(i+1)
        else:
            break
if s[-1]=="<":
    ans+=1
    for i in range(2,l+1):
        if s[-i]=="<":
            ans+=i
        else:
            break
print(ans)

Submission status: Accepted

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

import sys
import numpy as np
from itertools import groupby
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = readline().decode().rstrip()
cnt = [0] * (len(S) + 1)

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

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

print(sum(cnt))

Submission status: Accepted

Solution code:
S = input()
ans = 0
S = S.replace("><", ">,<").split(",")
for s in S:
  a = s.count(">")
  b = s.count("<")
  ans += a * (a - 1) // 2 + b * (b - 1) // 2 + max(a, b)
print(ans)

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
s = list(input())
l = [-1]
i = 0

while i < len(s):
    if s[i] == "<":
        l.append(l[i] + 1)
    if s[i] == ">":
        cnt = 0
        while s[i + cnt] == ">":
            if i + cnt == len(s) -1:
                cnt += 1
                break
            cnt += 1
        if l[i] < cnt:
            l.append(cnt)
        else:
            l.append(l[i] + 1)
        i += cnt
        cnt -= 1
        while cnt != -1:
            l.append(cnt)
            cnt -= 1
    i += 1
if s[len(s) -1] == "<":
    l.append(l[i] + 1)
del l[0]
ans = sum(l)
print(ans)

Submission status: Accepted

Solution code:
s=list(input())
m=len(s)
a=[0]*(m+1)
add=1
for i in range(m):
    if s[i]=="<":
        a[i+1]+=add
        add+=1
    else:
        add=1
for i in range(m-1,-1,-1):
    if s[i]==">" and a[i]<=a[i+1]:
        a[i]+=a[i+1]-a[i]+1
print(sum(a))

Submission status: Accepted

Solution code:
S = input()
count_more = 0
count_less = 0
ans = 0
pre_si = '>'
for i, si in enumerate(S):
    if pre_si == '>' and si == '<':
        max_n = max(count_more, count_less)
        min_n = min(count_more, count_less)
        ans += (max_n+1)*(max_n)//2
        # print(i, ans)
        ans += (min_n)*(min_n-1)//2
        count_more = 0
        count_less = 0
        # print(i, ans)
    if si == '<':
        count_more += 1
    elif si == '>':
        count_less += 1
    pre_si = si
max_n = max(count_more, count_less)
min_n = min(count_more, count_less)
ans += (max_n+1)*(max_n)//2
ans += (min_n)*(min_n-1)//2
print(ans)