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:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

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

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

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

  _s=s[::-1]

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

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

  # print(l1)
  # print(l2)

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

  return sm

# main()
print(main())

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
S=list(input())

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

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

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

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

print(ans)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
S=input()
N=[[0,0] for i in range(len(S)+1)]

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

print(sum(ans))

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

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

print(sum(ans))

Submission status: Accepted

Solution code:
S=input()
import itertools
A=[]
for key,g in itertools.groupby(S):
  A.append([key,len(list(g))])
ans=0
open=True
cur=0
for i in range(len(A)):
  key=A[i][0]
  n=A[i][1]
  if (i==0 and key==">") or (i==len(A)-1 and key=="<"):
    ans+=n*(n+1)//2
  else:
    if open:
      cur=n
      open=False
    else:
      if n>cur:
        cur-=1
      else:
        n-=1
      ans+=cur*(cur+1)//2+n*(n+1)//2
      open=True
print(ans)

Submission status: Accepted

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

A = [0 for _ in range(N)]

for i, s in enumerate(S):
    if i + 1 < N and s == '<':
        A[i + 1] = max(A[i + 1], A[i] + 1)

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

print(sum(A))

Submission status: Accepted

Solution code:
S=input()
N=len(S)+1
L=[0 for i in range(N)]
R=[0 for i in range(N)]
for i in range(1,N):
    if S[i-1]==">":
        L[i]=0
    else:
        L[i]=L[i-1]+1
for i in range(N-2,-1,-1):
    if S[i]=="<":
        R[i]=0
    else:
        R[i]=R[i+1]+1
#print(L)
#print(R)
X=[max(L[i],R[i]) for i in range(N)]
print(sum(X))

Submission status: Accepted

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

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

Submission status: Accepted

Solution code:
import math
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return math.gcd #最大公約数
def lcm(a,b):return (a*b) // math.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

S=input()

l = len(S)
l_cnt = [0] * (l+1)
r_cnt = [0] * (l+1)
cnt = [0] * (l+1)
for i in range(l):
    if S[i] == '<':
        l_cnt[i+1] = l_cnt[i]+1
for i in range(l-1, -1, -1):
    if S[i] == '>':
        r_cnt[i] = r_cnt[i+1]+1
for i in range(l+1):
    cnt[i] = max(l_cnt[i], r_cnt[i])
print(sum(cnt))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
A = [0] * (N + 1)
B = [0] * (N + 1)
for i in range(N):
    if S[i] == "<":
        A[i+1] = A[i] + 1
    else:
        A[i+1] = 0

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

print(sum([max(A[i], B[i]) for i in range(N + 1)]))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

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

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    s = S()
    l = len(s)
    if l == 2:
        if s == ">>" or s == "<<":
            return 3
        if s == "><":
            return 2
        return 1

    a = [-1] * (l+1)
    q = []
    v = [False] * (l+1)
    if s[0] == "<":
        q.append(0)
        v[0] = True
    if s[l-1] == ">":
        q.append(l)
        v[l] = True
    for i in range(1,l):
        if s[i-1:i+1] == "><":
            q.append(i)
            v[i] = True

    for qi in range(l+1):
        t = q[qi]
        if t == 0:
            a[t] = a[t+1] + 1
            if not v[t+1] and (v[t+2] or s[t+1] == "<"):
                q.append(t+1)
                v[t+1] = True
        elif t == l:
            a[t] = a[t-1] + 1
            if not v[t-1] and (v[t-2] or s[t-2] == ">"):
                q.append(t-1)
                v[t-1] = True
        else:
            a[t] = max(a[t+1], a[t-1]) + 1
            if not v[t+1] and (t == l-1 or v[t+2] or s[t+1] == "<"):
                q.append(t+1)
                v[t+1] = True
            if not v[t-1] and (t == 1 or v[t-2] or s[t-2] == ">"):
                q.append(t-1)
                v[t-1] = True

    # k = []
    # for ai,c in zip(a,s+" "):
    #     k.append(ai)
    #     k.append(c)
    # print(k)
    return sum(a)


print(main())

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    S = rs()
    N = len(S)
    a = [0] * (N + 1)
    for i in range(N):
        if S[i] == '<':
            a[i + 1] = a[i] + 1
        else:
            a[i + 1] = a[i] - 1
    
    b = min(a)
    for i in range(N + 1): a[i] -= b
    l = []
    for i in range(N + 1):
        l.append((a[i],i))
    
    def cmp(_p, _q):
        if(_p[0] < _q[0]): return -1
        if(_p[0] > _q[0]): return 1
        return 0
    l = sorted(l, key=cmp_to_key(cmp))

    for dep, pos in l:
        if pos == 0:
            if S[pos] == '<':
                a[pos] = 0
            else:
                a[pos] = a[pos + 1] + 1
        elif pos == N:
            if S[pos - 1] == '>':
                a[pos] = 0
            else:
                a[pos] = a[pos - 1] + 1
        else:
            if S[pos - 1] == '<' and S[pos] == '<':
                a[pos] = a[pos - 1] + 1
            elif S[pos - 1] == '<' and S[pos] == '>':
                a[pos] = max(a[pos - 1], a[pos + 1]) + 1
            elif S[pos - 1] == '>' and S[pos] == '<':
                a[pos] = 0
            elif S[pos - 1] == '>' and S[pos] == '>':
                a[pos] = a[pos + 1] + 1
    
    print(sum(a))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

    #print(N)
    print(sum(N))

    return 0

if __name__ == "__main__": solve()

Submission status: Accepted

Solution code:
S = input().strip()
N = len(S)+1
A = [0 for _ in range(N)]
B = []
for i in range(N):
    if i==0 and S[i]=="<":
        B.append(0)
    elif i<N-2 and S[i]==">" and S[i+1]=="<":
        B.append(i+1)
    elif i==N-2 and S[i]==">":
        B.append(i+1)
for j in range(len(B)-1):
    ind0 = B[j]
    ind1 = B[j+1]
    c = ind0
    while S[c]=="<":
        A[c+1] = max(A[c+1],A[c]+1)
        c += 1
    c = ind1
    while S[c-1]==">":
        A[c-1] = max(A[c-1],A[c]+1)
        c -= 1
c = B[0]
if c>0:
    for i in range(c-1,-1,-1):
        A[i] = A[i+1]+1
c = B[-1]
if c<N-1:
    for i in range(c+1,N):
        A[i] = A[i-1]+1
print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)
forward = [0]*(n+1)
backward = [0]*(n+1)
for i in range(n):
    if s[i] == "<":
        forward[i+1] = forward[i] + 1

for i in range(n-1,-1,-1):
    if s[i] == ">":
        backward[i] = backward[i+1] + 1


ans = sum([max(x,y) for x,y in zip(forward,backward)])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

inf = float("inf")
tmp = ""
for i in range(l):
	if i == 0:
		if s[i] == ">":
			A[i] = inf
		else:
			A[i] = 0

		tmp = s[i]

	if s[i] == tmp:
		continue
	elif s[i] == ">" and tmp == "<":
		A[i] = inf
		tmp = ">"
	elif s[i] == "<" and tmp == ">":
		A[i] = 0
		tmp = "<"

if s[i] == ">":
	A[-1] = 0
else:
	A[-1] = inf

ans = 0
flg = 0
cnt = 0
pool = 0
for i in range(l+1):
	if A[i] == inf:
		flg = 1
		pool = cnt
		cnt = 0
		continue
	if A[i] == 0:
		if flg == 1:
			ans += max(pool, cnt) + 1
		flg = 0
		cnt = 0
		pool = 0
		continue
	
	cnt += 1
	ans += cnt

if flg == 1:
	ans += pool + 1


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

Submission status: Accepted

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


def countConsecutive(s, ch):
    consecutive = [0] * N
    for i in range(1, N):
        if s[i - 1] == ch:
            consecutive[i] = consecutive[i - 1] + 1
    return consecutive


# Longest trail of < to the left of an index
consecutiveLeft = countConsecutive(s, "<")
# Longest trail of > to the right of an index
consecutiveRight = countConsecutive(s[::-1], ">")[::-1]

# Value at each index is longest consecutive trail of inequalities to left or right
nums = [max(consecutiveLeft[i], consecutiveRight[i]) for i in range(N)]

print(sum(nums))

Submission status: Accepted

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

x=[0]*N
y=0

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

Submission status: Accepted

Solution code:
s=input()
l=len(s)
c=0
m=0
s1=0
cc=0
k=0
for i in range(l):
    if s[i]=="<":
        c+=1
        s1+=c
        k=0
        cc=0
        m=0
    elif c==0:
        k-=1
        if k<0 and m==0:
            s1+=cc-k
            m=1
            cc+=1
        else:
            s1+=cc
        cc+=1
    else:
        k=c-1
        c=0
        cc+=1
print(s1)

Submission status: Accepted

Solution code:
L = input()
L = list(L.split('><'))
if len(L) == 1:
    a = [L[0].count('<'),L[0].count('>')]
    a_max = max(a)
    ans = a_max*(a_max+1)/2
else:
    ans = 0
    for i in range(len(L)):
        if i == 0:
            a = [L[i].count('<'),L[i].count('>')+1]
        elif i == len(L)-1:
            a = [L[i].count('<')+1,L[i].count('>')]
        else:
            a = [L[i].count('<')+1,L[i].count('>')+1]
        a_max = max(a)
        a_min = min(a)

        ans += a_max*(a_max+1)/2
        ans += a_min*(a_min-1)/2

print(int(ans))

Submission status: Accepted

Solution code:
#bfs

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

ans = 0
a = [None]*N

prev = ">"
q=[]

#確定0を埋める．
for i in range(N-1):
    if prev==">" and S[i] == "<":
        a[i]=0
        q.append(i)
    prev = S[i]

if S[-1]==">":
    a[-1]=0
    q.append(N-1)

while len(q)!=0:
    i = q.pop()
    if i+1 < N:
        if S[i]=="<":
            if a[i+1]==None:
                a[i+1]=a[i]+1
                q.append(i+1)
            else:
                a[i+1]=max(a[i]+1,a[i+1])
    if i-1>=0:
        if S[i-1]==">":
            if a[i-1]==None:
                a[i-1]=a[i]+1
                q.append(i-1)
            else:
                a[i-1]=max(a[i]+1,a[i-1])

print(sum(a))

Submission status: Accepted

Solution code:
s = input()
a = []
for i in range(len(s)+1):a.append(0)
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:
import sys
s=input()
if s=='<':
  print(1)
  sys.exit()
if s[0]=='<':
  s=s[1:]
if s[-1]=='>':
  s=s[:-1]
s=list(s.split('><'))

ans=0
for i in s:
  a=[i.count('<'),i.count('>')]
  a_max=max(a)
  a_min=min(a)
  ans+=(a_max+1)*(a_max+2)//2
  ans+=a_min*(a_min+1)//2
print(ans)

Submission status: Accepted

Solution code:
S = input()

def g(X, s):
    res = 0
    yield 0
    for x in X:
        res = res + 1 if x == s else 0
        yield res

print(sum(map(max, g(S, "<"), list(g(S[::-1], ">"))[::-1])))

Submission status: Accepted

Solution code:
S = input().rstrip("\n")
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:
import re

def cha(s):
    s_ = []
    for i in s:
        s_.append(len(i))
    return s_
def sum_all(n):
    return n*(n-1)//2

if __name__=="__main__":
    s = input()
    top = s[0]
    c = 0
    if top == "<":
        s = re.split('(>+)',s)
        if s[-1] == "":
            s = s[:-1]
    else:
        s = re.split('(<+)',s)
        if s[-1] == "":
            s = s[:-1]
    s = cha(s)
    sum_top = 0
    sum_end = 0
    if top == ">":
        sum_top = sum_all(s[0]) + s[0]
        s = s[1:]
    if len(s)%2 == 1:
        sum_end = sum_all(s[-1])+s[-1]
        s = s[:-1]
    for i in range(0,len(s),2):
        c += sum_all(s[i])
        if s[i] >= s[i+1]:
            c += s[i] + sum_all(s[i+1])
        else:
            c += s[i+1]+sum_all(s[i+1])
    c += sum_end + sum_top

    print(c)

Submission status: Accepted

Solution code:
s=input()
s_l=[s[_] for _ in range(len(s))]
a_l=[0]*(len(s)+1)
for i in range(len(s)):
	if s[i]=='<':
		a_l[i+1]=a_l[i]+1
a_l.reverse()
s_l.reverse()
for j in range(len(s)):
	if s_l[j]=='>':
		a_l[j+1]=max(a_l[j]+1,a_l[j+1])
print(sum(a_l))

Submission status: Accepted

Solution code:
s = input().split('><')
if len(s) > 1:
  l = [s[0]+'>'] + list(map(lambda x: '<'+x+'>', s[1:-1])) + ['<'+s[-1]]
else:
  l = s
ans = 0
for block in l:
  left = block.count('<')
  right = block.count('>')
  m = max(left, right)
  ans += left * (left-1) // 2 + right * (right-1) // 2 + m
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = read().rstrip().decode('utf-8')

S = S.replace('><','>,<').split(',')

answer = 0
for T in S:
    # <<<< >>>> の形
    a = T.count('<')
    b = T.count('>')
    x = a * (a-1) // 2 + b * (b-1) // 2 + max(a,b)
    answer += x

print(answer)

Submission status: Accepted

Solution code:

s = input()
n = len(s)

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

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

res = 0
#print(" ".join(str(l) for l in L))
for l in L :
    res += l
print(res)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(S: str):
    N = len(S)
    l = [0] * (N+1)

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

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

    print(sum(l))

    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:
S = input()
N = len(S)
l = [0] * (N + 1)

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

print(sum(l))
# print(l)

Submission status: Accepted

Solution code:
s=input()
cnt1=0
cnt2=1
ans=0
for i in range(len(s)-1):
    if s[i]==">" and s[i+1]=="<":
        a=max(cnt1,cnt2)
        b=max(min(cnt1,cnt2)-1,0)
        #print(cnt1,cnt2)
        ans+=(a*(a+1)+b*(b+1))//2
        cnt1=0
        cnt2=1
    elif s[i]=="<":
        cnt1+=1
    else:
        cnt2+=1
if s[len(s)-1]=="<" and s[len(s)-2]=="<":
    cnt1+=1
#print(cnt1,cnt2)
a=max(cnt1,cnt2)
b=max(min(cnt1,cnt2)-1,0)
ans+=(a*(a+1)+b*(b+1))//2
print(ans)

Submission status: Accepted

Solution code:
Ss = '>' + input() + '<'

N = len(Ss) - 1

A1s = [0] * N
for i in range(N):
    if Ss[i:i+2] == '><':
        A1s[i] = 0
    elif Ss[i:i+2] != '>>':
        A1s[i] = A1s[i-1] + 1

A2s = [0] * N
for i in reversed(range(N)):
    if Ss[i:i+2] == '><':
        A2s[i] = 0
    elif Ss[i:i+2] != '<<':
        A2s[i] = A2s[i+1] + 1

As = [A1 if A1 >= A2 else A2 for A1, A2 in zip(A1s, A2s)]
print(sum(As))

Submission status: Accepted

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

if S[-1] == '>':
    A[-1] = 0

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

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

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

print(sum(A))

Submission status: Accepted

Solution code:
#!python3

def resolve():
    S = input().rstrip()

    N = len(S)

    a, i, aa = "<", 0, []
    for c in S:
        if c == a:
            i += 1
        else:
            aa.append((a, i))
            i = 1
            a = c
    aa.append((a, i))

    if S[-1] == "<":
        aa.append((">", 0))

    pt = 0
    aaa = iter(aa)
    n = 0
    for a, b in zip(aaa, aaa):
        x, y = a
        n += y * (y - 1) // 2

        pt = y

        x, y = b

        if y > pt:
            pass
        else:
            n += pt
            y -= 1

        n += y * (y + 1) // 2

    print(n)




if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
s = input()
length = len(s)
sum = 0
right = [0]
left = [0]
r = 0
for i in range(length):
  if s[i] == "<":
    r += 1
    right.append(r)
  else:
    r = 0
    right.append(r)
l = 0    
for i in range(length-1,-1,-1):
  if s[i] == ">":
    l += 1
    left.append(l)
  else:
    l = 0
    left.append(l)
left.reverse()

for i in range(length+1):
  sum += max(right[i],left[i])

print(sum)

Submission status: Accepted

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

A = [-1] * N

if S[0] == '<':
  A[0] = 0

if S[-1] == '>':
  A[-1] = 0

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

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

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

print(sum(A))

Submission status: Accepted

Solution code:
w1 = input()
length = len(w1)
num_list = [-1]*(length+1)
c1 = 0
c2 = 0
for i in range(length):
    if i==0 and w1[i] == "<":
        num_list[0] = 0
    if i==(length-1) and w1[i] == ">":
        num_list[length] = 0
    if not i==length-1:
        if w1[i] == ">" and w1[i+1] =="<":
            num_list[i+1] = 0

    if(w1[i] == "<"):
        num_list[i+1] = num_list[i] + 1

for i in range(length-1,-1,-1):
    if (w1[i] == ">"):
        if(num_list[i] < num_list[i+1] + 1):
            num_list[i] = num_list[i+1] + 1


print(sum(num_list))

#0<3>2>1>0<1<2>0<1<2<3<4<5>2>1>0<1

#0<>>>0<<>0<<<<<>>>0<

Submission status: Accepted

Solution code:
s = input()

leng = len(s) + 1

lr = [0] * leng
rl = [0] * leng

for i in range(1, leng):
    if s[i - 1] == '<':
        lr[i] = lr[i - 1] + 1

for i in range(leng - 1, 0, -1):
    if s[i - 1] == '>':
        rl[i - 1] = rl[i] + 1

ans_list = [max(rl[i], lr[i]) for i in range(leng)]

print(sum(ans_list))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = input()
i = 0
c = 0
res = 0
while i<len(s):
    j = i
    while j<len(s) and s[i]==s[j]:
        j += 1
    if s[i]=="<":
        res += (j-i)*(j-i+1)//2
        c = j-i
    else:
        res += (j-i)*(j-i+1)//2
        if c>j-i:
            res -= j-i
        else:
            res -= c

    i = j

print(res)

Submission status: Accepted

Solution code:
import re
from collections import Counter
s = input()
res = re.finditer(r"(<+>+)|(^>+)|(<+$)", s)

def calc(string):
    ct = Counter(string)
    cnt_d = ct[">"]
    cnt_s = ct["<"]
    if cnt_s > cnt_d:
        return (cnt_s * (cnt_s + 1) + (cnt_d - 1) * cnt_d) // 2
    elif cnt_s == cnt_d:
        return cnt_s * cnt_s
    else:
        return ((cnt_d + 1) * cnt_d + (cnt_s - 1) * cnt_s) // 2
score = 0
for r in res:
    score += calc(r.group())
print(score)

Submission status: Accepted

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

ret = [0] * N
now = 0
for i in range(1, N) :
  if S[i - 1] == '<' :
    now += 1
    ret[i] = now
  else :
    now = 0

now = 0
for i in range(N - 2, -1, -1) :
  if S[i] == '>' :
    now += 1
    ret[i] = max(ret[i], now)
  else :
    now = 0
    
print(sum(ret))

Submission status: Accepted

Solution code:
S = input()

n = len(S)
N = n + 1

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

Submission status: Accepted

Solution code:
S=input()
x=len(S)
temp=ans=check=0
for i in range(x):
  if S[i]=="<":
    if temp>0 and S[i-1]==">":
      ans=ans-(temp*check)
      temp=0    
    check=0
    temp+=1
    ans+=temp
  else:
    check+=1
    temp-=1
    if temp<0:
      temp=0
      ans+=check
    else:
      ans+=temp
print(ans)

Submission status: Accepted

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

for i in range(n):
  if s[i] == "<":
    v[i+1] = v[i] + 1

for j in range(n):
  if s[-j-1] == ">":
    if v[-j-2] <= v[-j-1]:
      v[-j-2] = v[-j-1] + 1

print(sum(v))

Submission status: Accepted

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

for i in range(n-1):
    if s[i] == "<":
        v[i+1] = v[i] + 1

for j in range(n-1):
    if s[-j-1] == ">":
        if v[-j-2] <= v[-j-1]:
            v[-j-2] = v[-j-1] + 1

print(sum(v))

Submission status: Accepted

Solution code:
import unittest
import itertools
import sys

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

def solve(problem):
    rl = [(k, len(list(g))) for (k, g) in itertools.groupby(problem)]
    print(rl, file=sys.stderr)

    result = 0
    pos = 0
    while pos < len(rl):
        if rl[pos][0] == '>':
            assert pos == 0
            result += triangle(rl[pos][1])
            pos += 1
        elif pos + 1 < len(rl): # < then >
            result += triangle(max(rl[pos][1], rl[pos+1][1]))
            result += triangle(min(rl[pos][1], rl[pos+1][1]) - 1)
            pos += 2
        else: # last <
            result += triangle(rl[pos][1])
            pos += 1
    return result

class Tests(unittest.TestCase):
    def test_1(self):
        self.assertEqual(solve('<>>'), 3)

    def test_2(self):
        self.assertEqual(solve('<>>><<><<<<<>>><'), 28)

if __name__ == '__main__':
    print(solve(input().strip()))