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

# now = 0
left = 0
right = 0
ans = []
for i in range(len(s) + 1):
    if left == 0:
        # 左側
        for j in range(i - 1, -1, -1):
            if s[j] != '<':
                break
            else:
                left += 1
    else:
        if s[i - 1] == '<':
            left += 1
        else:
            left = 0
    # 右側
    if right == 0:
        for j in range(i, len(s)):
            if s[j] != '>':
                break
            else:
                right += 1
    else:
        if i == len(s):
            right = 0
        elif s[i] == '>':
            right -= 1
        else:
            right = 0
    ans.append(max(left, right))
# print(ans)
print(sum(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_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

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

S = S()

data = []

prev = ">"
count = 0
for s in S:
  if s == prev:
    count += 1
  else:
    data.append(count)
    count = 1
  prev = s
data.append(count)
if S[-1] == ">":
  data.append(0)
  
ans = sum(d*(d+1)//2 for d in data)

N = (len(data)-2)//2
gosa = sum(min(data[i*2+1],data[i*2+2]) for i in range(N))

print(ans-gosa)

Submission status: Accepted

Solution code:
s=str(input())
s=list(s)
temp=[]
cnt=0
ans=0
for i in range(len(s)):
  if s[i]=="<":
    if i!=0 and s[i-1]==">":
      temp.append(cnt)
      cnt=0
    cnt=cnt+1
  else:
    if i!=0 and s[i-1]=="<":
      temp.append(cnt)
      cnt=0
    cnt=cnt+1
temp.append(cnt)
if s[0]=="<":
  for i in range(0,len(temp)-1,2):
    tempmin=min(temp[i],temp[i+1])-1
    tempmax=max(temp[i],temp[i+1])
    temp[i]=tempmin
    temp[i+1]=tempmax
else:
  for i in range(1,len(temp)-1,2):
    tempmin=min(temp[i],temp[i+1])-1
    tempmax=max(temp[i],temp[i+1])
    temp[i]=tempmin
    temp[i+1]=tempmax
for i in range(len(temp)):
  ans=ans+temp[i]*(temp[i]+1)//2
print(ans)

Submission status: Accepted

Solution code:
s = list(input())
num = 0
n = len(s)
l = 0
i = 0
while i < n:
  if s[i] == '<':
    l+=num
    num+=1
    i+=1
    if i==n:
      l+=num
  else:
    cur = 0
    while i < n and s[i]=='>':
      i+=1
      cur+=1
    if cur <= num:
      l+=num
      cur-=1
    l+=(cur*(cur+1))//2
    num = 0
print(l)

Submission status: Accepted

Solution code:
s = list(input())
num = 0
n = len(s)
l = []
i = 0
while i < n:
  if s[i] == '<':
    l.append(num)
    num+=1
    i+=1
    if i==n:
      l.append(num)
  else:
    cur = 0
    while i < n and s[i]=='>':
      i+=1
      cur+=1
    if cur <= num:
      l.append(num)
      cur-=1
    l.append((cur*(cur+1))//2)
    num = 0
print(sum(l))

Submission status: Accepted

Solution code:
from math import *
from collections import *
from itertools import *
from bisect import *
from heapq import *
from operator import *
from sys import *
setrecursionlimit(100000000)


import os
import sys
from sys import *
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()



sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
z = lambda: sys.stdin.readline().rstrip("\r\n")



def op():
    return list(map(int,z().split()))
def o():
    return int(z())
def r(x):
    if type(x)==int:
        return range(x)
    else:return range(len(x))
def kl(con,x=0):
    if x==0:print('Yes') if con else print('No')
    elif x==1:print('yes') if con else print('no')
    elif x==2:print('YES') if con else print('NO')
MOD = 1000000007
MAX=float('inf')
MIN=-float('inf')
x=z()
c=0
f=0
l1,l2=[],[]
for i in x:
    if i=='<':
        c+=1
        l1.append(c)
    else:
        c=0
        l1.append(c)
for i in x[::-1]:
    if i=='>':
        c+=1
        l2.append(c)
    else:
        c=0
        l2.append(c)
l2=l2[::-1]
ans=[]
for i in r(len(x)-1):
      ans.append(max(l1[i],l2[i+1]))
ans.insert(0,l2[0])
ans.append(l1[-1])
print(sum(ans))

Submission status: Accepted

Solution code:
s=input()
ans=0
up=0
down=0
if(s[0]=='>'):
    down+=1
else:
    up+=1


for i in range(1,len(s)):
    if(s[i]=='>'):
        down+=1
    else:
        if(s[i-1]=='>'):
            high=max(up,down)
            low=min(up,down)
            ans+=(high+1)*(0+high)//2
            low-=1
            ans+=(low+1)*(0+low)//2
            up=1
            down=0
        else:
            up+=1
else:
    high=max(up,down)
    low=min(up,down)
    ans+=(high+1)*(0+high)//2
    low-=1
    ans+=(low+1)*(0+low)//2
print(ans)

Submission status: Accepted

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

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

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

print(sum(res))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
k = len(s)
a = [0]*(k+1)
for i in range(k):
  if s[i] == '<':
    a[i+1] = max(a[i+1],a[i]+1)
for j in range(k-1,-1,-1):
  if s[j] == '>':
    a[j] = max(a[j],a[j+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,-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 for _ in range(len(S) + 1)]

for idx in range(len(S)):
    if S[idx] == "<":
        A[idx + 1] = max(A[idx + 1], A[idx] + 1)

for idx in reversed(range(len(S))):
    if S[idx] == ">":
        A[idx] = max(A[idx], A[idx + 1] + 1)

print(sum(A))

Submission status: Accepted

Solution code:
string = input()

lt = True
ans = 0
l_cnt = 0
m_cnt = 0
if string[0] == ">":
    lt = False

for s in string:
    if s == "<":
        if not lt:
            a, b = max(l_cnt, m_cnt), min(l_cnt, m_cnt)
            ans += a * (a + 1) // 2 + b * (b - 1) // 2
            l_cnt = m_cnt = 0
        l_cnt += 1
        lt = True
    else:
        m_cnt += 1
        lt = False
a, b = max(l_cnt, m_cnt), min(l_cnt, m_cnt)
ans += a * (a + 1) // 2 + b * (b - 1) // 2
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
S = input()
left = deque([0])
right = deque([0])
cnt = 0
for s in S:
    if s == '<':
        cnt += 1
    else:
        cnt = 0
    left.append(cnt)
cnt = 0
for s in S[::-1]:
    if s == '>':
        cnt += 1
    else:
        cnt = 0
    right.appendleft(cnt)
ans = 0
for l, r in zip(left, right):
    ans += max(l, r)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


a = input()
n = len(a)
coutn1 = [0] * (n+1)
coutn2 = [0] * (n+1)

for i in range(n):
    if a[i] == "<":
        coutn1[i+1] = coutn1[i] + 1
for i in range(n-1, -1, -1):
    if a[i] == ">":
        coutn2[i] = coutn2[i+1] + 1

total = 0

for i in range(n+1):
    total += max(coutn1[i], coutn2[i])
print(total)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    S = gete()

    p = []
    nl, ng = 0, 0  # <, >

    for i, c in enumerate(S):
        if c == "<":
            nl += 1
        else:
            ng += 1

        if c == "<" and i < len(S) - 1 and S[i + 1] == ">":
            p.append((ng, nl))
            nl, ng = 0, 0

    p.append((ng, nl))

    ans = 0
    for i, q in enumerate(p):

        if i == 0 or p[i - 1][1] < q[0]:
            ans += q[0] * (q[0] + 1) // 2
        else:
            ans += q[0] * (q[0] - 1) // 2

        if i == len(p) - 1 or q[1] >= p[i + 1][0]:
            ans += q[1] * (q[1] + 1) // 2
        else:
            ans += q[1] * (q[1] - 1) // 2


    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s=input()
sr=s[::-1]
cntl=0
cntr=0
ll=[0]
rl=[0]

for i in range(len(s)):
    if s[i]=="<":
        cntl+=1
    else:
        cntl=0
    
    if sr[i]==">":
        cntr+=1
    else:
        cntr=0
    ll.append(cntl)
    rl.append(cntr)
    
rrl=rl[::-1]
ans=[]
for i in range(len(s)+1):
    ans.append(max(rrl[i],ll[i]))

print(sum(ans))

Submission status: Accepted

Solution code:
from itertools import groupby
S=input()
T=groupby(S)
s=0
total=0
keys=[]
groups=[]
for key,group in T:
    keys.append(key)
    groups.append(len(list(group)))

if keys[0]==">":
    total+=sum([i for i in range(groups[0]+1)])
if keys[-1]=="<":
    total+=sum([i for i in range(groups[-1]+1)])
for i in range(len(keys)-1):
    if keys[i]=="<":
        if groups[i]<=groups[i+1]:
            total+=sum([j for j in range(groups[i])])
            total+=sum([j for j in range(groups[i+1]+1)])
        else:
            total+=sum([k for k in range(groups[i]+1)])
            total+=sum([k for k in range(groups[i+1])])
print(total)

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:
S=input()
l=len(S)
A=[0]*(l+1)
B=[0]*(l+1)
for i in range(l):
  if S[i]=='<':
    A[i+1]=A[i]+1
  if S[l-i-1]=='>':
    B[l-i-1]=B[l-i]+1
print(sum([max(a,b) for a,b in zip(A,B)]))

Submission status: Accepted

Solution code:
# A - ><
S = input()
N = len(S)+1
INF = 1000000
ans = [0]*N
tmp = 0
for i in range(N-1):
    if S[i]=='<':
        tmp += 1
    else:
        tmp = 0
    ans[i+1] = tmp
tmp = 0
for i in range(N-2,-1,-1):
    if S[i]=='>':
        tmp += 1
    else:
        tmp = 0
    ans[i] = max(ans[i],tmp)
print(sum(ans))

Submission status: Accepted

Solution code:
s = input()
de_num = 0
le_num = 0
ans = [0]*(len(s)+1)

for i in range(len(s)):
    if s[i] == "<":
        de_num += 1
    else:
        de_num = 0
    ans[i+1] = de_num

s = s[::-1]
ans.reverse()

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

print(sum(ans))

Submission status: Accepted

Solution code:
S = input()

bf = ''
idx = []
bdiff = 0
diff = 0
rlt = 0

for i in range(len(S)):
  if bf != S[i]:
    idx.append(i)
  bf = S[i]

idx.append(len(S))
for i in range(len(idx)-1): 
  diff = idx[i+1] - idx[i]
  rlt += diff*(diff+1)//2
  if S[idx[i]] == '>':
    if bdiff < diff:
      rlt -= bdiff
    else:
      rlt -= diff
  bdiff = diff

print(rlt)

Submission status: Accepted

Solution code:
def main():
    s = input()
    n = len(s) + 1
    ans = [-1] * (n)
    def right(i, ans):
        j = 1
        while True:
            ans[i + j] = max(ans[i + j], j)
            if i + j == n - 1:
                break
            if s[i + j] == '<':
                j += 1
            else:
                break
        return ans
    def left(i, ans):
        j = 1
        while True:
            ans[i - j] = max(ans[i - j], j)
            if i - j == 0:
                break
            if s[i - j - 1] == '>':
                j += 1
            else:
                break
        return ans
    for i in range(n):
        if i == 0:
            if s[i] == '<':
                ans[0] = 0
                ans = right(i, ans)
            else:
                pass
        elif i == n - 1:
            if s[i - 1] == '>':
                ans[n - 1] = 0
                ans = left(i, ans)
            else:
                pass
        else:
            if s[i] == '<' and s[i - 1] == '>':
                ans[i] = 0
                ans = right(i, ans)
                ans = left(i, ans)
            else:
                pass
    print(sum(ans))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
S = list(input())
lis = [0] * (len(S)+1)
 
if len(S) == 1:
    print(1)
    sys.exit()
 
 
#最初は < を処理する
for i in range(len(S)):
    if S[i] == "<":
        lis[i+1] = lis[i] + 1
 
 
 
 
for j in range(len(S)-1,-1,-1):
    if S[j] == ">":
        lis[j] = max(lis[j],lis[j+1] + 1)
 
 
 
print(sum(lis))

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

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

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]:
    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)
a=[0]*(n+1)
for i in range(n):
    if s[i]=="<":
        a[i+1]=a[i]+1
for i in reversed(range(n)):
    if s[i]==">":
        a[i]=max(a[i+1]+1,a[i])
print(sum(a))

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    S = input()
    count_right = 0
    count_left = 0
    prev = ""
    a = []

    current = 0
    for i, s in enumerate(S):
        if prev == ">" and s == "<":
            a.append((count_left, count_right))
            count_left = 0
            count_right = 0
        if s == ">":
            count_right += 1
            prev = ">"
            # a.append((count_left)
        else:
            count_left += 1
            prev = "<"
    a.append((count_left, count_right))
    s = 0
    for x in a:
        large = max(x[0], x[1])
        small = min(x[0], x[1])
        s += sum(range(large + 1)) + sum(range(small))
    print(s)

Submission status: Accepted

Solution code:
S = input()
prev = ">"
terrain = []
curr = 0
for c in S:
    if c == prev:
        curr += 1
    else:
        prev = c
        terrain.append(curr)
        curr = 1
terrain += [curr]
ans = (terrain[0] * (terrain[0] + 1)) // 2
for up, down in zip(terrain[1::2], terrain[2::2]):
    if up < down:
        up, down = down, up
    down -= 1
    ans += (up * (up + 1)) // 2
    ans += (down * (down + 1)) // 2
if len(terrain) % 2 == 0:
    ans += terrain[-1] * (terrain[-1] + 1) // 2
print(ans)

Submission status: Accepted

Solution code:
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div
# endregion
S = list(rs())
ans = 0
tmp = 0
cnt = 0
f = 1
for i in range(len(S)):
    if S[i] == '<':
        if f:
            cnt += 1
        else:
            ans += cnt * (cnt - 1) // 2
            ans += max(tmp, cnt)
            cnt = 1
            f = 1
    else:
        if f:
            ans += cnt * (cnt - 1) // 2
            tmp = cnt
            cnt = 1
            f = 0
        else:
            cnt += 1
ans += cnt * (cnt - 1) // 2
if f:
    ans += cnt
else:
    ans += max(tmp, cnt)
print(ans)

Submission status: Accepted

Solution code:
s = input()
cut = [0]
for i in range(len(s)-1):
    if(s[i:i+2] == '><'):
        cut.append(i+1)
cut.append(len(s)+1)

ans = 0
for i in range(len(cut)-1):
    ss = s[cut[i]:cut[i+1]]
    left = ss.count('<')
    right = ss.count('>')
    ans += left*(left+1)//2 + right*(right+1)//2 - min(left,right)

print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
tmpl = 0
tmpr = 0
for i in range(len(S) - 1):
  if S[i] == '<':
    tmpl += 1
  else:
    tmpr += 1
    if S[i + 1] == '<':
      x = max(tmpl, tmpr)
      y = min(tmpl, tmpr)
      ans += (1 + x) * x // 2 + y * (y - 1) // 2
      tmpl = 0
      tmpr = 0

if S[-1] == '<':
  tmpl += 1
else:
  tmpr += 1
x = max(tmpl, tmpr)
y = min(tmpl, tmpr)
ans += (1 + x) * x // 2 + y * (y - 1) // 2
print(ans)

Submission status: Accepted

Solution code:
S = input()
l = len(S)
A = [0 for i in range(l+1)]
for i in range(l):
    if S[i] == '<':
        A[i+1] = max(A[i+1],A[i]+1)
for i in range(l-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()
INC = '<'
DEC = '>'
icnt = 0
dcnt = 0
mode = DEC
ans = 0
for c in S:
  if mode == DEC:
    if c == DEC:
      dcnt += 1
    elif c == INC:
      if icnt <= dcnt:
        ans += (dcnt + 1) * dcnt // 2
      else:
        ans += icnt + dcnt * (dcnt - 1) // 2
      icnt = 1
      mode = INC
  elif mode == INC:
    if c == INC:
      icnt += 1
    elif c == DEC:
      ans += icnt * (icnt - 1) // 2
      dcnt = 1
      mode = DEC
if mode == INC:
  ans += (icnt + 1) * icnt // 2
elif mode == DEC:
  if icnt <= dcnt:
    ans += (dcnt + 1) * dcnt // 2
  else:
    ans += icnt + dcnt * (dcnt - 1) // 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
A = [0] * (len(s) + 1)
for i, c in enumerate(s):
	if c == '<':
		A[i+1] = A[i] + 1
for i, c in enumerate(s[::-1]):
	if c == '>':
		x = len(s) - i
		A[x-1] = max(A[x-1], A[x] + 1)
print(sum(A))

Submission status: Accepted

Solution code:
S = input()
l = len(S)
A = [0 for i in range(l+1)]
for i in range(l):
    if S[i] == '<':
        A[i+1] = max(A[i+1],A[i]+1)
for i in range(l-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().strip()

buf = s[0]
count = 0
popa  = []
suma = 0
for i in s:
  if i=="<":
    count+=1
    suma += count
  elif i==">" and buf=="<":
    popa.append(count)
    suma -= count
    count = 0
  buf = i
buf = s[-1]
count = 0
dupa  = []
for i in s[::-1]:
  if i==">":
    count+=1
    suma += count
  elif i=="<" and buf==">":
    dupa.append(count)
    suma -= count
    count = 0
  buf = i

for i,j in zip(dupa[::-1],popa):
  suma+=max(i,j)
print(suma)
# print(sum(map(int,"0 3 2 1 0 1 2 0 1 2 3 4 5 2 1 0 1".split())))

Submission status: Accepted

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

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

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

print(sum(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def rle(t):
    tmp2, count_, ans_ = t[0], 1, []
    for i_ in range(1, len(t)):
        if tmp2 == t[i_]:
            count_ += 1
        else:
            ans_.append([tmp2, count_])
            tmp2 = t[i_]
            count_ = 1
    ans_.append([tmp2, count_])
    return ans_


S = list(input())

l = rle(S)
ans = [0] * (len(S) + 1)
count = 0
for i in range(len(l)):
    if l[i][0] == '<':
        for j in range(l[i][1] + 1):
            ans[count + j] = max(ans[count + j], j)
    elif l[i][0] == '>':
        for k in range(l[i][1] + 1):
            ans[count + k] = max(ans[count + k], l[i][1] - k)
    count += l[i][1]
print(sum(ans))

Submission status: Accepted

Solution code:
s=raw_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:
# <>>><<><<<<<>>><
# >< is 0
S = input()
part = S.replace('><','> <').split(' ')

ans=0
for p in part:
    left  = p.count('<')
    right = p.count('>')
    ans += sum(range(1, max(left, right) + 1))
    ans += sum(range(1, min(left, right)))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
partition = s.replace('><','>|<').split('|')
ans=0

for sub in partition:
    left = sub.count('<')
    right = sub.count('>')
    ans += sum(range(1, max(left, right) + 1))
    ans += sum(range(1, min(left, right)))

print(ans)

Submission status: Accepted

Solution code:
S = list(input())
L = len(S)
count = 0
count_minus = [0] * L
for i in range(L):
    if S[i] == ">":
        count = 0
    else:
        count += 1
    count_minus[i] = count

count = 0
count_plus = [0] * L
for i in reversed(range(L)):
    if S[i] == "<":
        count = 0
    else:
        count += 1
    count_plus[i] = count

result_list = [0] * (L-1)
for i in range(len(result_list)):
    result_list[i] = max(count_minus[i], count_plus[i+1])

result = sum(result_list) + count_minus[L-1] + count_plus[0] 
print(result)

Submission status: Accepted

Solution code:
s = input()
s_len = len(s)
li = [0]*(s_len+1)
for i in range(0,s_len):
    if s[i] == "<":
        if li[i] >= li[i+1]:
            li[i+1] = li[i] + 1
for i in range(s_len-1,-1,-1):
    if s[i] == ">":
        if li[i] <= li[i+1]:
            li[i] = li[i+1]+1
print(sum(li))

Submission status: Accepted

Solution code:
A=list(input())
right_cnt=[0]
left_cnt=[0]
cnt=0
for i in range(len(A)):
   if A[i] == "<":
      right_cnt.append(right_cnt[-1]+1)
   else:
      right_cnt.append(0)
   if A[-i-1] == ">":
      left_cnt.append(left_cnt[-1]+1)
   else:
      left_cnt.append(0)
left_cnt=left_cnt[::-1]
for i in range(len(A)+1):
   cnt+=max(left_cnt[i],right_cnt[i])
print(cnt)

Submission status: Accepted

Solution code:
S = list(input())
n = len(S)+1
a = [0 for _ in range(n)]

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

# print(S)
# print(a)
S = S[::-1]
a = a[::-1]
for i in range(n-1):
    if S[i] == "<":
        S[i] = ">"
    else:
        S[i] = "<"

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

Submission status: Accepted

Solution code:

S = input()
N = len(S)+1
l = [0]
r = [0]

for i in range(N-1):
    if S[i] == '<':
        l.append(l[-1]+1)
    else:
        l.append(0)
    if S[-1-i] == '>':
        r.append(r[-1]+1)
    else:
        r.append(0)

r = r[::-1]
ans = [max(l[i], r[i]) for i in range(N)]
print(sum(ans))

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)+1
lc=[0]
rc=[0]
for i in range(n-1):
    if s[i]=='<':
        lc.append(lc[-1]+1)
    else:
        lc.append(0)
    if s[-1-i]=='>':
        rc.append(rc[-1]+1)
    else:
        rc.append(0)
rc=rc[::-1]
ans=[max(lc[i], rc[i]) for i in range(n)]
print(sum(ans))

Submission status: Accepted

Solution code:
s=input()
ans=0
if s[0]==">":
    s="<"+s
if s[-1]=="<":
    s=s+">"
s=list(s)
ls=len(s)

st=ct=gl=0
ans=0
for i in range(ls-1):
    if s[i]=="<" and s[i+1]==">":
        ct=i
    elif s[i]==">" and s[i+1]=="<":
        gl=i
    if i==ls-2:
        gl=ls-1
    if gl!=0:
        pre=((ct-st)+1)*(ct-st)/2
        pos=((gl-ct-1)+1)*(gl-ct-1)/2
        intra=max(ct-st+1, gl-ct)
        ans+=pre+pos+intra
        # 更新
        st=gl+1
        ct=gl=0

print(int(ans))

Submission status: Accepted

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

s = input()
n = len(s)+1
a = [0 for _  in range(n)]

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

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

ans = sum(a)

#print('a = ', a)
print(ans)

Submission status: Accepted

Solution code:
import re
a=0
for m in re.findall('(<*)(>*)',input()):u,v=map(len,m);a-=(u*~u+v*~v)//2+min(u,v)
print(a)