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

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, -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*;r=p=0
for k,g in groupby(input()):x=len(list(g));r=r+x*(x+1)//2-min(x,p)*(k=='>');p=x
print(r)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
#coding: utf-8

S = input()
ret = 0

# 山を下る
i = 0
while i < len(S) and S[i] == ">":
    i += 1
    ret += i

# 山を登って降りる
n_up = 0
n_down = 0
while i < len(S):
    n_up = 0
    n_down = 0
    while i < len(S) and S[i] == "<":
        n_up += 1
        i += 1
        if i >= len(S):
            break
    while i < len(S) and S[i] == ">":
        n_down += 1
        i += 1
        if i >= len(S):
            break
    if n_up < n_down:
        n_up, n_down = n_down, n_up

    ret += ((n_up+1) * n_up) // 2
    ret += (n_down * (n_down-1)) // 2
    
print(ret)

Submission status: Accepted

Solution code:
s = input()

up = 0
down = 0
prev_x = ''
up_cnt = 0
down_cnt = 0
ans = 0

for i in range(len(s)):
    if (prev_x =='<'or prev_x ==''):
        if s[i] == '<':
            up_cnt += 1
        else: # s[i] == '>' at top
            up = up_cnt
            up_cnt = 0
            down_cnt =+1
            
    else: # prev_x = '>'
        if s[i] == '>':
            down_cnt += 1
        else: # s[i] ='<' at bottom
            down = down_cnt
            down_cnt =0
            up_cnt += 1
            if up == 0:
                ans += (down*(down+1))/2
            else:
                if up > down:
                    ans += (up*(up+1))/2 + (down*(down-1))/2
                else:
                    ans += (up*(up-1))/2 + (down*(down+1))/2
    prev_x = s[i]

if up_cnt > 0 and down_cnt == 0:
    ans += (up_cnt*(up_cnt+1))/2
elif down_cnt > 0 and up_cnt == 0:
    if up > down_cnt:
        ans += (up*(up+1))/2 + (down_cnt*(down_cnt-1))/2
    else:
        ans += (up*(up-1))/2 + (down_cnt*(down_cnt+1))/2

print(int(ans))

Submission status: Accepted

Solution code:
S = input()

N = len(S)
num = 0
L = [0]
R = [0]
cnt = 0

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

ans = 0
S = S[::-1]
cnt = 0

for i in range(N):
    if S[i] == ">":
        cnt += 1
    else:
        cnt = 0
    R.append(cnt)

R = R[::-1]

for i in range(N+1):
    ans += max(L[i], R[i])

print(ans)

Submission status: Accepted

Solution code:
def resolve():
    S = list(input())
    ans = [0 for _ in range(len(S) + 1)]
    cnt = 0
    for i in range(len(S)):
        if S[i] == "<":
            cnt += 1
            ans[i + 1] = max(cnt, ans[i + 1])
        else:
            cnt = 0
    cnt = 0
    for i in range(len(S), 0, -1):
        if S[i - 1] == ">":
            cnt += 1
            ans[i - 1] = max(cnt, ans[i - 1])
        else:
            cnt = 0
    print(sum(ans))


resolve()

Submission status: Accepted

Solution code:
import sys
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush

sys.setrecursionlimit(10**6)
INF = 10**20

def mint():
    return map(int,input().split())
def lint():
    return map(int,input().split())
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])

S = input()
N = len(S)+1
L = [0]*N
R = [0]*N
for i in range(N-1):
    L[i+1] = L[i]+1 if S[i]=='<' else 0
for i in range(N-2,-1,-1):
    R[i] = R[i+1]+1 if S[i]=='>' else 0
ans = [max(l,r) for l,r in zip(L,R)]
print(sum(ans))

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,-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())

#不等号の向きを記録する
memo = ""

#不等号の連続した個数を記録する
cnt = 0

#1つ前に数えた不等号の連続した個数を記録する
before_cnt = 0

#出力する答え
ans = 0

#文字列Sの連続した不等号の向きを数える
for x in s:
    #初めはmemoが空白なので,memoに不等号の向きを記録
    if memo == "":
        memo = x
    
    #不等号の向きが同じ場合は、数を1カウントしてループに戻る
    if memo == x:
        cnt += 1
        
    #不等号の向きが異なる場合
    else:
        #ansに和を加算する
        ans += cnt * (cnt+1) // 2
        
        #不等号の向きの変化が処理が必要な場合
        if memo == ">":
            if before_cnt < cnt:
                ans -= before_cnt
            else:
                ans -= cnt

        before_cnt = cnt
        cnt = 1
        memo = x
else:
    ans += cnt * (cnt+1) // 2
    if before_cnt < cnt:
        if memo == ">":
            ans -= before_cnt
    else:
        if memo == ">":
            ans -= cnt
    before_cnt = cnt
    cnt = 0
 
print(ans)

Submission status: Accepted

Solution code:
s=input()

sl=len(s)+1
l=[0]*sl

for i in range(sl-1):
  if s[i]=="<":
    l[i+1]=l[i]+1
    
for i in range(sl-2,-1,-1):
  if s[i]==">":
    l[i]=max(l[i+1]+1, l[i])
    
print(sum(l))

Submission status: Accepted

Solution code:
S = list(input())
 
left = [0]*(len(S)+1)
 
right = [0]*(len(S)+1)
 
for i in range(len(S)):
    if S[i] == '<':
        left[i+1] += 1+left[i]
 
for i in range(len(S)-1,-1,-1):
    if S[i] == '>':
        right[i] = right[i+1]+1
 
ans = [0]*(len(S)+1)
for i in range(len(S)+1):
    ans[i] = max(left[i],right[i])
print(sum(ans))

Submission status: Accepted

Solution code:
def main():
    S = input()
    N = len(S)+1
    a = [0]*(N)
    #右側からみていく
    for i in range(N-1):
        if S[i] == '<':
            a[i+1] = max(a[i]+1,a[i+1])
    #print(a)
    #左側から見ていく
    for i in range(N-2,-1,-1):
        #print(i)
        if S[i] == '>':
            a[i] = max(a[i+1]+1,a[i])
    ans = 0
    #print(a)
    for i in range(N):
        ans += a[i]
    return ans

print(main())

Submission status: Accepted

Solution code:
s = input()
ans = [0 for i in range(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:
import itertools as it

S = input()
R = [(k,len(list(g))) for k,g in it.groupby(S)]
#print(R)

tot = 0
n = 0
for k,val in R:
  if k == "<":
    n = val
    tot += n*(n+1)/2
  elif k == ">":
    tot += max(0,val-n)
    tot += val*(val-1)/2
    n = 0
  
print(int(tot))

Submission status: Accepted

Solution code:
S = input()
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:
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


S = LS2()
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-2,-1,-1):
    if S[i] == '>':
        ANS[i] = max(ANS[i],ANS[i+1]+1)

print(sum(ANS))

Submission status: Accepted

Solution code:
S = input()
L = len(S)
if S[0] == ">":
    S = "<"+S
else:
    S = ">"+S
if S[L] == ">":
    S = S+"<"
else:
    S = S+">"
count = 0
ans = 0
kari = 0
for i in range(L+1):
    if S[i] == "<" and S[i+1] == ">":
        kari = count
        count = 1
    elif S[i] == ">" and S[i+1] == "<":
        ans += max(kari, count)
        count = 1
    else:
        ans += count
        count += 1

if S[L] == "<" and S[L+1] == ">":
    ans += kari
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    examA()

def examA():
    S = SI()
    S = ">" + S + "<"
    N = len(S)
    A = [0]*(N)
    i = 0
    while(i<N-1):
        r = i + 1
        if S[i]==">" and S[i+1]=="<":
            A[i+1] = 0
            l = i-1
            cur = 0
            while(0<=l):
                cur += 1
                A[l] = max(A[l], cur)
                l -= 1
                if S[l+1]=="<":
                    #print("break",l,A)
                    break
            r = i+1
            cur = 0
            while(r<N):
                cur += 1
                A[r] = max(A[r], cur)
                r += 1
                if r==N or S[r]==">":
                    break
        #print(i,A)
        i = r
    #print(A)
    A[-1] = 0
    ans = sum(A)
    print(ans)
    return

def examB():
    H, W = LI()
    A = [SI()for _ in range(H)]
    C = defaultdict(int)
    for a in A:
        for s in a:
            C[s] += 1
    B = sorted(C.items())
    # print(B)
    flag_odd = not (H%2==1 and W%2==1)
    upper_2 = (H%2==1) * (W//2) + (W%2==1) * (H//2)
    for s,c in B:
        if c%2==1:
            if flag_odd:
                print("No")
                return
            flag_odd = True
        elif c%4==2:
            upper_2 -= 1
            if upper_2<0:
                print("No")
                return
    print("Yes")
    return

def examC():
    N, K = LI()
    P = LI()
    C = LI()

    if max(C)<0:
        print(max(C))
        return

    loop = [[0,0]for _ in range(N)]

    for i in range(N):
        checked = set()
        now = i
        score = 0
        while(now not in checked):
            checked.add(now)
            now = P[now]-1
            score += C[now]
        n = len(checked)
        for j in checked:
            loop[j] = [n,score]
    # print(loop)
    ans = 0
    for i in range(N):
        n,s = loop[i]
        score = 0
        if s>0:
            score += (K//n - 1) * s
        ans = max(ans,score)
        now = i
        for j in range(n + K%n):
            now = P[now] - 1
            score += C[now]
            ans = max(ans,score)

    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

def test():
    i = I()
    li = LI()
    lsi = LSI()
    si = LS()
    print(i)
    print(li)
    print(lsi)
    print(si)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,alphabet_convert,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 1<<31
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    main()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


S = LS2()
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-2,-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)
ans=[0]*(n+1)
  
for i in range(0,n):
  if s[i]=='<':
    ans[i+1]=ans[i]+1
for i in range(n-1,-1,-1):
  if s[i]=='>':
    ans[i]=max(ans[i+1]+1,ans[i])
print(sum(ans))

Submission status: Accepted

Solution code:
S = list(input())

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

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

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

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

ans = [0]*(len(S)+1)
for i in range(len(S)+1):
    ans[i] = max(left[i],right[i])
print(sum(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:
s = input()
s += 'a'
cnts = []
prev = s[0]
cnt = 1
for i,si in enumerate(s[1:]):
    if prev == si:
        cnt += 1
    else:
        cnts.append(cnt)
        cnt = 1
    prev = si


ans = 0
c_num = 0
if s[0] == '<':
    for i,c in enumerate(cnts):
        if i%2 == 0:
            ans += c*(c-1)//2
            c_num = c-1
        else:
            ans += c*(c-1)//2
            ans += max(c,c_num+1)
    if s[-2] == '<':
        ans += cnts[-1]
        # print(cnts[-1])
    print(ans)

if s[0] == '>':
    ans = cnts[0]*(cnts[0]+1)//2
    for i,c in enumerate(cnts[1:]):
        if i%2 == 0:
            ans += c*(c-1)//2
            c_num = c-1
        else:
            ans += c*(c-1)//2
            ans += max(c,c_num+1)
        
    if s[-2] == '<':
        ans += cnts[-1]
    print(ans)

# print(cnts)

Submission status: Accepted

Solution code:
from collections import deque
S=input()
N=len(S)+1
X=[-1 for i in range(N)]
'''
 < > >
0 2 1 0
'''
q=deque([])
for i in range(N-2):
    if S[i]==">" and S[i+1]=="<":
        X[i+1]=0
        q.append(i+1)
if S[0]=="<":
    q.append(0)
    X[0]=0
if S[N-2]==">":
    q.append(N-1)
    X[N-1]=0

while(len(q)>0):
    r=q.popleft()
    for p in [r-1,r+1]:
        if not(0<=p<N):
            continue
        if (p<r and S[p]==">") or (p>r and S[r]=="<"):
            if X[p]<=X[r]:
                X[p]=X[r]+1
                q.append(p)
#print(X)
print(sum(X))

Submission status: Accepted

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

ans = 0
i = 0
while i < N and S[i]=='>':
    i += 1
ans += i*(i+1)//2

arr = [i]
while i < N:
    while i < N and S[i]=='<':
        i += 1
    arr.append(i)
    if i==N: break
    while i < N and S[i]=='>':
        i += 1
    arr.append(i)

arr = [b-a for a,b in zip(arr,arr[1:])]
for a,b in zip(arr[::2],arr[1::2]):
    if a<b: a,b = b,a
    ans += a*(a+1)//2
    ans += b*(b-1)//2
if len(arr)%2:
    ans += arr[-1]*(arr[-1]+1)//2

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

S = list(map(str, input().rstrip()))

ans = np.zeros(len(S) + 1, dtype=np.int64)

# 左から、右から流す
for i, s in enumerate(S):
    if s == "<":
        ans[i+1] = max(ans[i+1], ans[i]+1)

ans = ans[::-1]

for i, s in enumerate(S[::-1]):
    if s == ">":
        ans[i+1] = max(ans[i+1], ans[i]+1)

print(ans.sum())

Submission status: Accepted

Solution code:
def main():
    s = input()
    arr = [0]*(len(s)+1)
    for i in range(len(s)):
        c = s[i]
        if c == "<":
            arr[i+1] = arr[i]+1
    for i in reversed(range(len(s))):
        c = s[i]
        if c == ">":
            arr[i] = max(arr[i], arr[i+1]+1)
    print(sum(arr))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

print(sum(A))

Submission status: Accepted

Solution code:
s=input()
sl=len(s)
a=[]
count=1
for i in range(sl-1):
    if s[i+1]==s[i]:
        count+=1
    else:
        a.append(count)
        count=1
a.append(count)
ans=0
al=len(a)
if s[0]=="<":
    for i in range(0,al-1,2):
        m,n=max(a[i],a[i+1]),min(a[i],a[i+1])
        ans+=(m*(m+1)+n*(n-1))/2
    if al%2==1:
        ans+=a[-1]*(a[-1]+1)/2
elif s[0]==">":
    ans+=a[0]*(a[0]+1)/2
    for i in range(1,al-1,2):
        m,n=max(a[i],a[i+1]),min(a[i],a[i+1])
        ans+=(m*(m+1)+n*(n-1))/2
    if al%2==0:
        ans+=a[-1]*(a[-1]+1)/2
print(int(ans))

Submission status: Accepted

Solution code:
a=list(input())
count=1
ans = 0
temp = 0
for i in range(len(a)-1):
  if a[i] ==a[i+1]:
    count+=1
  else:
    if a[i]=='<':
      ans += count*(count+1)//2
      temp = count
      #print('<', count, ans)
      count = 1
      
    else:
      ans += count*(count+1)//2
      ans -= min(count, temp)
      #print('>', count, ans)
      count =1
else:
  if a[-1]=='<':
    ans += count*(count+1)//2
  else:
    ans += count*(count+1)//2
    ans -= min(count, temp)
print(ans)

Submission status: Accepted

Solution code:
a = input()
N = len(a)
c = []
temp = int(1)
ans = int(0)
for i in range(N):
    if i != N-1:
      if a[i] == a[i+1]:
        temp += 1
      else:
        c.append(temp)
        temp = 1
    else:
      if a[i-1] == a[i]:
        c.append(temp)
      else:
        c.append(1)

clen = len(c)

if a[0] == "<" and clen % 2 == 1:
    c.append(0)
elif a[0] == ">" and clen % 2 == 0:
    c.append(0)

if a[0] == "<":
    for i in range(0,clen,2):
        maxi = max([c[i],c[i+1]])
        mini = min([c[i],c[i+1]])
        ans += maxi*(maxi+1)/2
        ans += mini*(mini-1)/2
else:
    ans += c[0]*(c[0]+1)/2
    for i in range(1,clen,2):
        maxi = max([c[i],c[i+1]])
        mini = min([c[i],c[i+1]])
        ans += maxi*(maxi+1)/2
        ans += mini*(mini-1)/2
    
print(int(ans))

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc040/tasks/agc040_a
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    ans = 0
    left = 0
    right = 0
    for i in range(len(S) - 1):
        if S[i] + S[i + 1] == "><":
            right += 1
            tmp = max(left, right)
            ans += tmp
            ans += sum([i for i in range(left)])
            ans += sum([i for i in range(right)])
            right = 0
            left = 0
        else:
            if S[i] == ">":
                right += 1
            elif S[i] == "<":
                left += 1
    else:
        if S[-1] == "<":
            left += 1
        else:
            right += 1
        tmp = max(left, right)
        ans += tmp
        ans += sum([i for i in range(left)])
        ans += sum([i for i in range(right)])
    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input().rstrip() + "#"
s0 = S[0]
A, cnt = [], 1
for s in S[1:]:
    if s==s0: cnt+=1
    else: A.append(cnt); cnt=1
    s0 = s
res, st = 0, 0
if S[0]==">":
    res += A[0]*(A[0]+1)//2
    st=1
for i in range(st,len(A),2):
    if i+1==len(A): res += A[i]*(A[i]+1)//2; break
    p, q = A[i], A[i+1]
    if p < q:
        res += q*(q+1)//2 + p*(p-1)//2
    else:
        res += q*(q-1)//2 + p*(p+1)//2
print(res)

Submission status: Accepted

Solution code:

S = input()
N = len(S)

increasing = S[0] == '<'
A = [] if increasing else [1]
cnt = 0
for c in S:
    f = c == '<'
    if f == increasing:
        cnt += 1
    else:
        A.append(cnt*(increasing*2-1))
        increasing = not increasing
        cnt = 1
A.append(cnt*(increasing*2-1))

if A[-1] > 0:
    A.append(-1)

m = iter(A)
res = 0

for a,b in zip(m,m):
    b = -b
    if a > b:
        a,b = b,a
    res += ((a-1)*a+(b+1)*b)

print(res//2)

Submission status: Accepted

Solution code:
s = input()
l = [0]
m = [0]
a = 0
b = 0
arr = []
for i in range(len(s)):
  if s[i] == '<':
    a += 1
  else:
    a = 0
  l.append(a)

  if s[len(s) - i - 1] == '>':
    b += 1
  else:
    b = 0
  m.append(b)
m = m[::-1]

for i in range(len(l)):
  arr.append(max(l[i], m[i]))
ans = sum(arr)
print(ans)

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, -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 = [0]*N

cnt = 0
for i in range(N):
    A[i] = cnt
    if i == N-1:
        break
    if S[i] == "<":
        cnt += 1
    else:
        cnt = 0

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

print(sum(A))

Submission status: Accepted

Solution code:
s = list(input())

#不等号の向きを記録する
memo = ""

#不等号の連続した個数を記録する
cnt = 0

#1つ前に数えた不等号の連続した個数を記録する
before_cnt = 0

#出力する答え
ans = 0

#文字列Sの連続した不等号の向きを数える
for x in s:
    #初めはmemoが空白なので,memoに不等号の向きを記録
    if memo == "":
        memo = x
    
    #不等号の向きが同じ場合は、数を1カウントしてループに戻る
    if memo == x:
        cnt += 1
        
    #不等号の向きが異なる場合
    else:
        #ansに和を加算する
        ans += cnt * (cnt+1) // 2
        
        #不等号の向きの変化が処理が必要な場合
        if memo == ">":
            if before_cnt < cnt:
                ans -= before_cnt
            else:
                ans -= cnt

        before_cnt = cnt
        cnt = 1
        memo = x
else:
    ans += cnt * (cnt+1) // 2
    if before_cnt < cnt:
        if memo == ">":
            ans -= before_cnt
    else:
        if memo == ">":
            ans -= cnt
    before_cnt = cnt
    cnt = 0
 
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


S = S()

lis = [0] * (len(S) + 1)  # 左に連続する'<' の数、右に連続する'<'の数の大きい方
left = [0] * (len(S) + 1)
right = [0] * (len(S) + 1)
left_count = 0
for i, s in enumerate(S):
    if (s == '<'):
        left_count += 1
        left[i+1] = left_count
    else:
        left_count = 0

right_count = 0
i = len(S)
for s in reversed(S):
    if (s == '>'):
        right_count += 1
        right[i-1] = right_count
    else:
        right_count = 0
    i -= 1


ans = 0
for l, r in zip(left, right):
    ans += max(l, r)
print(ans)

Submission status: Accepted

Solution code:
s = input()
count = 1; memo = 0; x = 0
for i in range(1, len(s)):
    if s[i-1] == "<" and s[i] == ">":
        x += count*(count-1)//2
        memo = count
        count = 1
    elif s[i-1] == ">" and s[i] == "<":
        x += count*(count-1)//2+max(count, memo)
        memo = 0
        count = 1
    else:
        count += 1
else:
    if s[-1] == "<":
        x += count*(count+1)//2
    else:
        x += count*(count-1)//2+max(count, memo)
print(x)

Submission status: Accepted

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

l = 0
r = 0
ans = 0
for i in range(n):
    if '<' == s[i]:
        if r != 0:
            M = max(l,r)
            m = min(l,r)
            ans += M*(M+1)//2 + m*(m-1)//2
            r = 0
            l = 0
        l += 1
    if '>' == s[i]:
        r += 1

M = max(l,r)
m = min(l,r)
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
R=[0]*N
ans=[0]*N
for i in range(1,N):
    if S[i-1]=='<':
        L[i]=L[i-1]+1
    if S[N-i-1]=='>':
        R[N-i-1]=R[N-i]+1
for i in range(N):
    ans[i]=max(L[i], R[i])
print(sum(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = list(map(str,input()))
# s = "><<<<><<"
# S = list(map(str,s))
num = [-1]*(len(S)+1)
index0 = list()
than = 0# 0 == >, 1 == <
#----------------------------------------
for i in range(len(S)):
    if(S[i] == '<'):
        if(than == 0):
            num[i] = 0
            index0.append(i)
        than = 1
    else:
        than = 0
if(S[-1] == '>'):
    num[-1] = 0
    index0.append(len(S)+1)
#--------------------------------------
if(index0[0] == 0):
    i = 1
    while(True):
        num[i] = num[i-1]+1
        if(i >= len(S)):break
        if(S[i] == '>'):
            break
        i+=1
    index0.pop(0)
if(len(index0)>0):
    if(index0[-1] == len(S)+1):
        i = len(S)-1
        while(True):
            num[i] = num[i+1]+1
            i-=1
            if(i < 0):break
            if(S[i] == '<'):break
        index0.pop(-1)

while(len(index0)>0):
        for i in reversed(range(0,index0[0])):
            if(S[i] == '<'):
                break
            num[i] = max(num[i],num[i+1]+1)
        for i in range(index0[0]+1,len(S)+1):
            num[i] = max(num[i],num[i-1]+1)
            if(i >= len(S)):break
            if(S[i]== '>'):break
        index0.pop(0)

ans = 0
for i in range(len(num)):
    ans += num[i]
print(ans)

Submission status: Accepted

Solution code:
S=list(str(input()))
ans=0
sofar=0
j=1
nax=0
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        ans+=j
        j+=1
    elif S[i]=='<' and S[i+1]=='>':
        ans+=j
        nax=j
        j=1    
    else:
        ans+=j
        if nax!=0:
            ans-=j
        j=1
        nax=0
    if j>nax:
        ans-=nax
        nax=0
if j>nax:
    ans+=j
    ans-=nax
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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()
num = [0] * (len(S) + 1)
min_cnt = 0
plu_cnt = 0
flag = 0
ans = 0
if S[0] == ">":
    flag = 1
for i in range(len(S)):
    if flag == 1:
        if S[i] == "<":
            flag = 0
            plu_cnt = 0
        else:
            plu_cnt += 1
            ans += plu_cnt
    if S[i] == "<":
        if min_cnt == 0:
            plu_cnt += 1
        else: #ansに精算する
            M = max(plu_cnt, min_cnt)
            m = min(plu_cnt, min_cnt)
           # ans += ((plu_cnt+1)*plu_cnt)/2
           # ans += (min_cnt*(min_cnt-1))/2
            ans += ((M + 1) * M) // 2
            ans += (m*(m-1))//2
            plu_cnt, min_cnt = 0, 0
            plu_cnt += 1
    elif S[i] == ">" and flag == 0:
        min_cnt += 1
if flag == 1:
    plu_cnt, min_cnt = 0, 0
M = max(plu_cnt, min_cnt)
m = min(plu_cnt, min_cnt)
ans += ((M + 1) * M)//2
ans += (m*(m-1))//2
print(ans)

Submission status: Accepted

Solution code:
S = list(input())
value = [0] * (len(S) + 1)
  
for i in range(len(S)):
  if S[i] == '<':
    if value[i] == 0:
      value[i+1] = 1
    else:
      value[i+1] = value[i] + 1

for i in reversed(range(len(S))):
  if S[i] == '>':
    if value[i+1] == 0 and value[i] == 0:
      value[i] = 1
    elif value[i] <= value[i+1]:
      value[i] = value[i+1] + 1
print(sum(value))

Submission status: Accepted

Solution code:
S = input()
l = [0] * (len(S)+1)
r = [0] * (len(S)+1)
for i in range(len(S)):
    if S[i] == '<':
        l[i+1] = l[i] + 1
for i in range(len(S)-1,-1,-1):
    if S[i] == '>':
        r[i] = r[i+1] + 1
print(sum([max(l[i],r[i]) for i in range(len(S)+1)]))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
down = 0
up = 0
ans = 0
uA = [0]*(N+1)
dA = [0]*(N+1)
for i in range(N+1):
    uA[i] = up
    if i < N:
        if S[i] == "<":
            up += 1
        else:
            up = 0
for i in range(N, -1, -1):
    dA[i] = down
    if i > 0:
        if S[i-1] == ">":
            down += 1
        else:
            down = 0
for i in range(N+1):
    ans += max(uA[i], dA[i])
print(ans)

Submission status: Accepted

Solution code:

s = input()
data = []
cnt = 0
for i in range(len(s)-1):
    cnt += 1
    if s[i] != s[i+1]:
        if s[i] == "<" and s[i+1] == ">":
            data.append(cnt)
            data.append(-1)
        else:
            data.append(cnt)
        cnt = 0
data.append(cnt+1)

for i in range(len(data)-1):
    if data[i] == -1:
        if data[i-1] < data[i+1]:
            data[i-1] -= 1
        else:
            data[i-1] > data[i+1]
            data[i+1] -= 1

ans = 0
for i in range(len(data)):
    if data[i] != -1:
        for j in range(1, data[i]+1):
            ans += j

# print(data)
print(ans)