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 sys
from collections import Counter
import string

# input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

def divisor(n):
    """
    n の約数をリストで返す
    :param int n:
    :rtype: list of int
    """
    ret = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ret.append(i)
            if n // i != i:
                ret.append(n // i)
    return ret


def factorization(n):
    """
    素因数分解
    :param int n:
    :rtype: list of int
    """
    if n <= 1:
        return []

    ret = []
    while n > 2 and n % 2 == 0:
        ret.append(2)
        n //= 2
    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            ret.append(i)
            n //= i
        else:
            i += 2
    ret.append(n)
    return ret


def is_prime(n):
    """
    nの素数判定
    :param int n:
    :rtype: Bool
    """
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


def coprime(a, b):
    return gcd(a, b) == 1


def main():
    S = input()
    ans = 0
    cur = 0
    stack_initial = 0
    stack_count = 0
    # arr = []

    for i in range(len(S)):
        if i == 0 and S[i] == '<':
            cur = 0
            ans = 0
            cur = 1
        elif i == 0 and S[i] == '>':
            stack_count = 1
        elif S[i-1] == '<' and S[i] == '<':
            ans += cur
            cur += 1
        elif S[i-1] == '<' and S[i] == '>':
            # ans += cur
            stack_initial = cur
            # print('stack_initial', i, stack_initial)
            stack_count = 1
            cur = 0
        elif S[i-1] == '>' and S[i] == '>':
            stack_count += 1
        elif S[i-1] == '>' and S[i] == '<':
            stack_count += 1
            # ans += (stack_count * (0 + (stack_count)) // 2)
            # print(i, stack_initial, stack_count)
            if stack_count > stack_initial:
                ans += (stack_count * (0 + (stack_count - 1)) // 2)
            else:
                ans += stack_initial + ((stack_count - 1) * (0 + ((stack_count - 1) - 1)) // 2)
            stack_initial = 0
            stack_count = 0
            cur = 1
        # print(i, ans)

    if S[len(S)-1] == '<':
        ans += cur
        # print(cur)
    elif S[len(S)-1] == '>':
        stack_count += 1
        #
        if stack_count > stack_initial:
            ans += (stack_count * (0 + (stack_count - 1)) // 2)
        else:
            ans += stack_initial + ((stack_count - 1) * (0 + ((stack_count - 1) - 1)) // 2)
        # print(stack_count, ans)
        stack_count = 0
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

"""
GC040 A
"""

ali = list(input())

zeroflag = False
lastflag = False

if ali[0] == '<':
    ali.insert(0, '>')
    zeroflag = True
if ali[-1] == '>':
    ali.append('<')
    lastflag = True

itop = []
ibtm = []
# print(ali)

for (i, x) in enumerate(ali[:-1]):
    # print(i)
    if x == '>' and ali[i+1] == '<':
        ibtm.append(i+1)
    if x == '<' and ali[i+1] == '>':
        itop.append(i+1)
itop.append(len(ali))

# print(itop)
# print(ibtm)

s = 0
nowtop = 0
toplheight = [-10]
toprheight = []

for l in range(len(itop)):
    nexttop = itop[l]
    nowbtm = ibtm[l]
    lint = nowbtm - nowtop - 1
    rint = nexttop - nowbtm - 1
    s += (lint)*(lint+1)//2
    s += (rint)*(rint+1)//2
    toprheight.append(lint)
    toplheight.append(rint)
    # print('l',l)
    # print('s',s)
    nowtop = nexttop

toprheight.append(-10)

if zeroflag:
    del toplheight[0]
    del toprheight[0]
if lastflag:
    toplheight.pop()
    toprheight.pop()

while toplheight:
    left = toplheight.pop()
    right = toprheight.pop()
    s += max(left, right)+1

print(s)

Submission status: Accepted

Solution code:
S = list(input())
if S[-1] == '<':
  S.append('>')
else:
  S.append('<')
output = 0
count = 0
num_list = []

if S[0] == '>':
  model = 0
else:
  model = 1
s_pre = S[0]
for i in range(len(S)):
  s = S[i]
  if s != s_pre or i == len(S)-1:
    num_list.append(count)
    count = 1
    s_pre = s
  else: 
    count += 1
if model == 0:
  output += num_list[0]*(num_list[0]+1)/2
  num_list = num_list[1:]

for i in range(len(num_list)//2):
  n_max = max(num_list[2*i], num_list[2*i+1]) #同じ場合考える
  n_min = min(num_list[2*i], num_list[2*i+1])
  output += n_max*(n_max+1)/2
  output += (n_min-1)*n_min/2
if len(num_list)%2 == 1:
  output += num_list[-1]*(num_list[-1]+1)/2
print(int(output))

Submission status: Accepted

Solution code:
s=input()
a=[]
su=0
k=0
def wa(x):
  j=0
  t=0
  for i in range(x):
    j+=1
    t+=j
  return t
def unkosumaho(x):
  b=0
  c=0
  for i in range(len(x)):
    if x[i]=='<':
      b+=1
    else:
      c+=1
  return wa(max(b,c))+wa(min(b,c)-1)
for i in range(len(s)-1):
  if s[i]=='>':
    if s[i+1]=='<':
      a.append(s[k:i+1])
      k=i+1
  if i==len(s)-2:
      a.append(s[k:])
for i in a:
  su+=unkosumaho(i)
if (len(s))==1:
  print(1)
else:
  print(su)

Submission status: Accepted

Solution code:
s = input()
tmp1 = 1
tmp2 = 1
yet = 0
ans = 0
for i in range(len(s)-1):
    if s[i] == '<' and s[i+1] == '<':
        tmp1 += 1
    elif s[i] == '>' and s[i+1] == '>':
        tmp2 += 1
    elif s[i] == '>' and s[i+1] == '<':
        if tmp1 >= tmp2:
            ans += (tmp1*(tmp1+1))//2 + ((tmp2-1)*tmp2)//2
        else:
            ans += (tmp2*(tmp2+1))//2 + ((tmp1-1)*tmp1)//2
        tmp1 = 1
        tmp2 = 1
        yet = i + 1
        if i+1 == len(s)-1:
            ans += 1
if yet != len(s)-1:
    if s[-1] == '>':
        if tmp1 >= tmp2:
            ans += (tmp1*(tmp1+1))//2 + ((tmp2-1)*tmp2)//2
        else:
            ans += (tmp2*(tmp2+1))//2 + ((tmp1-1)*tmp1)//2
    else:
        ans += (tmp1*(tmp1+1))//2
if len(s) == 1:
    ans = 1
print(ans)

Submission status: Accepted

Solution code:
S = input()

def count(up, down):
    max_count = max(up, down)
    return (up * (up - 1)) / 2 + (
                down * (down - 1)) / 2 + max_count

up = 0
down = 0
answer = 0

for i in range(len(S)):
    if i == len(S) - 1:
        if S[i] == ">":
            down += 1
        elif S[i] == "<":
            up += 1
        answer += count(up, down)
        up = 0
        down = 0
    elif S[i] == ">" and S[i + 1] == "<":
        if S[i] == ">":
            down += 1
        elif S[i] == "<":
            up += 1
        answer += count(up, down)
        up = 0
        down = 0
    else:
        if S[i] == ">":
            down += 1
        elif S[i] == "<":
            up += 1
print(int(answer))

Submission status: Accepted

Solution code:
def wa(x):
    return ((x+1)*x)/2


s = input()

d = '<'
r = '>'

prev = r
count = 0
array = []

for i in s:
    if i == prev:
        count += 1
    else:
        array.append([prev, count])
        count = 1
        prev = i

array.append([prev, count])

for i in range(len(array)-1):
    if array[i][0] == d and array[i+1][0] == r:
        if array[i][1] <  array[i+1][1]:
            array[i][1] -= 1
        else:
            array[i+1][1] -= 1

ans = 0
for i in array:
    ans += wa(i[1])

print(int(ans))

Submission status: Accepted

Solution code:
from collections import deque
MAX = float('inf')
S = input()
points = [MAX] * (len(S) + 1)
idxs = []
comp = [[] for _ in range(len(S) + 1)]
if S[0] == '<':
    points[0] = 0
    idxs.append(0)
if S[-1] == '>':
    points[-1] = 0
    idxs.append(len(S))
for idx, s in enumerate(S):
    if s == '<': comp[idx].append(idx + 1)
    else: comp[idx + 1].append(idx)
    if idx == 0 or idx == len(S): continue
    if S[idx - 1] == '>' and s == '<':
        points[idx] = 0
        idxs.append(idx)
stack = deque(idxs)
while stack:
    idx = stack.pop()
    for i in comp[idx]:
        points[i] = max(points[i], points[idx] + 1) if points[i] != MAX else points[idx] + 1
        stack.append(i)
print(sum(points))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

S=input()
S=">"+S
n=len(S)
data=[0]*n
start=0
minv=0
for i in range(1,n):
    if S[i]=='<':
        data[i]=data[i-1]+1
    if S[i]=='>':
        if S[i-1]=='<':
            # print(minv)
            for k in range(start+1,i):
                data[k]-=minv
            data[start]=max(data[start],data[start+1]+1)
            # print(data,i,minv)
            data[i]=0
            minv=0
            start=i-1
        else:
            data[i]=data[i-1]-1
            minv=min(minv,data[i])
# print(data)
# print(minv,start)
for i in range(start+1,n):
    data[i]-=minv
data[start]=max(data[start],data[start+1]+1)
if S[1]=='<':
    data[0]=0
print(sum(data))
# print(data)

Submission status: Accepted

Solution code:
S = input()
ans = 0

#左端が>のときはその左に<を増やす
if S[0]=='>':
    S = '<' + S

#終端処理
#右端が<のときはその右に><を増やす
if S[len(S)-1]=='<':
    S = S + '><'
#右端が>のときはその右に<を増やす
if S[len(S)-1]=='>':
    S = S + '<'

lefts = 0
rights = 0

for i in range(len(S)):
    if S[i]=='<':
        lefts += 1
    if S[i]=='>':
        rights += 1
    if S[i]=='>' and S[i+1]=='<': #ここは絶対0になる
        M = max(lefts,rights)
        m = min(lefts,rights)
        ans += M*(M+1)/2 + m*(m+1)/2 - m
        lefts = 0
        rights = 0
        
print(int(ans))

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    S = input()

    arr = []
    S = S.replace('><', '>,<')
    S = S.replace('<>', '<,>')
    S = S.split(',')
    for s in S:
        a = []
        if s[0] == '<':
            for i in range(len(s) + 1):
                a.append(i)
        else:
            for i in range(len(s), -1, -1):
                a.append(i)
        arr.append(a)
    ans, prev = 0, 0
    for i, a in enumerate(arr):
        ans += sum(a[1:])
        if arr[i][0] > prev:
            ans += arr[i][0] - prev
        prev = arr[i][-1]
    print(ans)


main()

Submission status: Accepted

Solution code:
s=input()

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

m=[]
now=1
tmp=s[0]
for i in range(1,len(s)):
  if s[i]==tmp:
    now += 1
  elif tmp == "<" and s[i] == ">":
    m.append("#")
  if tmp != s[i]:
    m.append(now)
    now = 1
    tmp = s[i]
m.append(now)

ans=0
for j in range(len(m)):
  if m[j] == "#":
    ans -= min(m[j+1],m[j+2])
  else:
  	ans += sum_li(m[j])
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

s = input()

ans = 0
point = 0
for i in s:
    if i == ">":
        point += 1
        ans += point
    else:
        break

point2 = 0
for i in s[::-1]:
    if i == "<":
        point2 += 1
        ans += point2
    else:
        break

if point2:
    s = s[point: -point2]
else:
    s = s[point:]

l_p = 0
r_p = 0
for i in s:
    if i == "<":
        if l_p:
            ans -= min(l_p, r_p)
            r_p = 0
            l_p = 0
        r_p += 1
        ans += r_p
    else:
        l_p += 1
        ans += l_p
ans -= min(l_p, r_p)
print(ans)

Submission status: Accepted

Solution code:
S = list(input())

def parse(S):
    N = len(S)
    i = 0
    array = []

    n = 0
    array.append(n)
    while i < N:
        while i < N and S[i] == '<':
            n += 1
            array.append(n)
            i += 1

        while i < N and S[i] == '>':
            array.append(0)
            i += 1

        j = i - 1
        m = 1
        while j >= 0 and S[j] == '>':
            array[j] = max(array[j], m)
            m += 1
            j -= 1
        n = 0
    return array

array = parse(S)
total = 0
for n in array:
    total += n

print(total)

Submission status: Accepted

Solution code:
s = input()

def calc_sum(n):
    if n <= 0:
        return 0
    return (n+1)*n/2

length = len(s)

num_g = 0
num_l = 0

prev = 1
cur = -1

out = 0

for i in range(length):
    if s[i] == '<':
        cur = 1
    else:
        cur = 0
        
    if prev == 1 and cur == 1:
        num_g += 1
    elif prev == 1 and cur == 0:
        num_l += 1
    elif prev == 0 and cur == 0:
        num_l += 1
    elif prev == 0 and cur == 1:
        out += calc_sum(max(num_g, num_l)) + calc_sum(min(num_g, num_l)-1)
        
        num_g = 1
        num_l = 0
    
    prev = cur
    
if cur == 1:
    out += calc_sum(num_g)
else:
    out += calc_sum(max(num_g, num_l)) + calc_sum(min(num_g, num_l)-1)
    
print(str(int(out)))

Submission status: Accepted

Solution code:
s = list(str(input()))
ans = 0
l = []
p = 0
m = 0
n = len(s)
if n == 1:
  if s[0] == "<":
    l = [1]
  else:
    l = [-1]
for i in range(n):
  if i == 0:
    if s[i] == "<":
      p += 1
    else:
      m -= 1
  else:
    if s[i] == s[i-1]:
      if s[i] == "<":
        p += 1
        if i == n-1:
          l.append(p)
      else:
        m -= 1
        if i == n-1:
          l.append(m)
    else:
      if s[i] == "<":
        l.append(m)
        m = 0
        p = 1
        if i == n-1:
          l.append(p)
      else:
        l.append(p)
        p = 0
        m = -1
        if i == n-1:
          l.append(m)

l.append(0)
for i in range(len(l)-1):
  if l[i] > 0:
    ans += l[i]*(l[i]-1)//2
    ans += max(l[i],-(l[i+1]))
  else:
    ans += (l[i])*(l[i]+1)//2
    if i == 0:
      ans += -(l[i])
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter, deque, defaultdict
from math import factorial
from fractions import Fraction
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
MOD = 10**9 + 7
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

s = input()
n = len(s) + 1
s = list(s)
a = []
temp = 0
for i in range(n-1):
    if i == n-2:
        a.append(n-1-temp)
    else:
        if s[i] != s[i+1]:
            a.append(i+1-temp)
            temp = i+1

if s[0] == '>':
    a.insert(0, 0)
if s[-1] == '<':
    a.append(0)
res = 0
for i in range(len(a)//2):
    h = max(a[2*i], a[2*i + 1])
    l = min(a[2*i], a[2*i + 1])
    ans = l*(l-1)//2 + h + h*(h-1)//2
    res += ans

print(res)

Submission status: Accepted

Solution code:
import numpy as np
S=input();T=S[::-1];a=[];c=0
for t in T:
    if t==">":
        c+=1
    else:
        c=0
    a.append(c)
A=np.array(a[::-1]+[0])
b=[];c=0
for s in S:
    if s=="<":
        c+=1
    else:
        c=0
    b.append(c)
B=np.array([0]+b)
print(np.maximum(A,B).sum())

Submission status: Accepted

Solution code:
#
import sys
import math
import numpy as np
import itertools

# 文字列を一文字ずつのリストに代入 test は['t', 'e', 's', 't']
s = list(input())
t = [0]
now = 0
if s[0]=='<':
    now = 1
else:
    now = -1

for i in range(1,len(s)):
    if s[i]=='<' and now > 0:
        now += 1
    elif s[i]=='<' and now < 0:
        t.append(now)
        now = 1
    elif s[i]=='>' and now < 0:
        now -= 1
    elif s[i]=='>' and now > 0:
        t.append(now)
        now = -1
t.append(now)

answer=0
for i in range(1,len(t)):
    if t[i-1] > 0 and t[i] < 0:
        if t[i-1] < -t[i]:
            t[i-1] -= 1
        else:
            t[i] += 1
for i in range(len(t)):
    answer += abs(t[i]) * (abs(t[i]) + 1) // 2
#print(t)
print(answer)

Submission status: Accepted

Solution code:
s = input()
i = 0

l_count = 0
r_count = 0

check = 0

sum_value = 0

while i < len(s):
    if s[i] == '<':
        if r_count > 0:
            if check > r_count:
                sum_value += check
                n = r_count-1
                sum_value += n * (n + 1) // 2 
            else:
                n = r_count
                sum_value += n * (n + 1) // 2     
        l_count += 1
        r_count = 0
        
        
    elif s[i] == '>':
        if l_count > 0:
            check = l_count
            n = l_count-1
            sum_value += n * (n + 1) // 2
        l_count = 0
        r_count += 1
    i += 1
    
if l_count > 0:
    n = l_count
    sum_value += n * (n + 1) // 2  
if r_count > 0:
    n = r_count
    sum_value += n * (n + 1) // 2

print(sum_value)

Submission status: Accepted

Solution code:
S = input()
sign_list = []
count = 1


if S[0] == "<":
    flag = True
else:
    flag = False


S_dummy = S + "_"
for i in range(len(S_dummy) - 1):
    if S_dummy[i] == S_dummy[i + 1]:
        count += 1
    else:
        sign_list.append(count)
        count = 1


ans = 0
if flag:
    for i in range(len(sign_list) // 2):
        s_count = sign_list[i * 2]
        d_count = sign_list[i * 2 + 1]

        if s_count <= d_count:
            ans += d_count * (d_count + 1) / 2 + s_count * (s_count - 1) / 2
        else:
            ans += s_count * (s_count + 1) / 2 + d_count * (d_count - 1) / 2
    
    if len(sign_list) % 2 != 0:
        ans += sign_list[-1] * (sign_list[-1] + 1) / 2

else:
    ans += sign_list[0] * (sign_list[0] + 1) / 2

    for i in range((len(sign_list) - 1) // 2):
        s_count = sign_list[i * 2 + 1]
        d_count = sign_list[i * 2 + 2]

        if s_count <= d_count:
            ans += d_count * (d_count + 1) / 2 + s_count * (s_count - 1) / 2
        else:
            ans += s_count * (s_count + 1) / 2 + d_count * (d_count - 1) / 2
    
    if len(sign_list) % 2 == 0:
        ans += sign_list[-1] * (sign_list[-1] + 1) / 2


print(int(ans))

Submission status: Accepted

Solution code:
S=input()
N=len(S)
a = 0
b = 0
ans=0
for x in range(0,N-1):
    if S[x] == '<':
        a += 1
    else:
        b += 1
    if S[x] == '>' and S[x+1] == '<':
        if a > b:
            b -= 1
        else:
            a -= 1
        if a < 0:
            a = 0
        if b < 0:
            b = 0
        for y in range (0,a+1):
            ans += y
        for z in range (0,b+1):
            ans += z
        a = 0
        b = 0
if S[N-1] == '<':
        a += 1
else:
        b += 1
if a > b:
    b -= 1
else:
     a -= 1
for y in range (0,a+1):
    ans += y
for z in range (0,b+1):
    ans += z
print(ans)

Submission status: Accepted

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

S = list(input().strip())
S_count = []
len_S = len(S)

if S[0] == '>':
    S_count.append(0)

loc_index = 0
for i in range(len_S - 1):
    if S[i] != S[i+1]:
        S_count.append(i + 1 - loc_index)
        loc_index = i + 1

S_count.append(len_S - loc_index)

if len(S_count) % 2 != 0:
    S_count.append(0)


def value(x0, x1):
    v = 0
    x_max = max(x0, x1)
    x_min = min(x0, x1)
    for j in range(x_max):
        v += j+1
    for k in range(x_min):
        v += k
    return v


result = 0
left = 0
right = 1
for g in range(len(S_count) // 2):
    result += value(S_count[left], S_count[right])
    left += 2
    right += 2

print(result)

Submission status: Accepted

Solution code:
# for c in '03210120123452101':
# 3 2 5 2
s = input()
lst = []
tmp = ''
cnt = 1
for c in s:
    if tmp == c:
        cnt += 1
    else :
        lst.append(cnt)
        cnt = 1
    tmp = c
lst.append(cnt)

ans = 0

if s[0] == '<':
    idx = 1
else:
    idx = 0
if (len(lst) - idx ) % 2 == 1:
    lst.append(1)
for i in range(idx,len(lst),2):
    if lst[i] > 1:
        if lst[i] <= lst[i+1]:
            lst[i] -= 1
        ans += lst[i] * (lst[i]+1) // 2
    if lst[i+1] > 1:
        if lst[i] > lst[i+1]:
            lst[i+1] -= 1
        ans += lst[i+1] * (lst[i+1]+1) // 2
    if lst[i] == 1 and lst[i+1] == 1:
        ans += 1
    # print(lst[i], lst[i+1])
print(ans)
# print(lst, idx)

Submission status: Accepted

Solution code:
#0<3>2>1>0<1<2>0<1<2<3<4<5>2>1>0<1
import math
s = input()
bigger=0
smaller=0
count = 0
bigger=1 if s[0]=="<" else 0 
smaller=1 if s[0]==">" else 0 


for i in range(len(s)-1):
    if (s[i]==">" and s[i+1]=="<"):
        count += (max(bigger,smaller))*((max(bigger,smaller))+1)/2
        count += (min(bigger,smaller)-1)*(min(bigger,smaller))/2 if (min(bigger,smaller)-1)!=0 else 0
        bigger = 1
        smaller = 0
    elif (s[i]=="<" and s[i+1]=="<"):
        bigger += 1
    elif (s[i]=="<" and s[i+1]==">"):
        smaller += 1
    elif (s[i]==">" and s[i+1]==">"):
        smaller += 1
count += (max(bigger,smaller))*((max(bigger,smaller))+1)/2
count += (min(bigger,smaller)-1)*(min(bigger,smaller))/2 if (min(bigger,smaller)-1)!=0 else 0

print(int(count))

Submission status: Accepted

Solution code:
def solve_a(s):
    n = len(s) + 1
    # from left
    left = [0] * n
    for i in range(1, n):
        if s[i - 1] == "<":
            left[i] = left[i - 1] + 1
    # from right
    right = [0] * n
    for i in range(n - 2, -1, -1):
        if s[i] == ">":
            right[i] = right[i + 1] + 1
    return sum([max(left[i], right[i]) for i in range(n)])


def main():
    s = list(input())
    res = solve_a(s)
    print(res)


def test():
    assert solve_a(list("<>>")) == 3
    assert solve_a(list("<>>><<><<<<<>>><")) == 28


if __name__ == "__main__":
    test()
    main()

Submission status: Accepted

Solution code:
import itertools
s=input()
splitlist=[[k, len(list(g))] for k, g in itertools.groupby(s)]
n=len(splitlist)
#print(splitlist)

def total(lst):
	return lst[1]*(lst[1]+1)//2


ans=total(splitlist[0])
for i in range(1,n):
	ans+=total(splitlist[i])
	if splitlist[i][0]==">":
		ans-=min(splitlist[i-1][1],splitlist[i][1])
print(ans)

Submission status: Accepted

Solution code:
s = input()

ans = 0
l = 0
r = 0
p = 0
for i in range(len(s)):
    if s[i] == ">":
        l += 1
    else:
        r += 1

    if i == len(s) - 1:
        break
        
    if s[i] == ">" and s[i+1] == "<":
        x = max(l, r)
        y = min(l, r)
        ans += x * (x+1) / 2
        if y == 0:
            ans += 0
        else:
            ans += y * (y-1) / 2
        l = 0
        r = 0
        p = i+1

if p != len(s) + 1:
    x = max(l, r)
    y = min(l, r)
    ans += x * (x+1) / 2
    if y == 0:
        ans += 0
    else:
        ans += y * (y-1) / 2


print(int(ans))

Submission status: Accepted

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

for i in range(n-1):
    if s[i:i+2]==[">","<"]:
        l.append(i+1)

m=0
if l==[]:
        a=s.count("<")
        b=s.count(">")
        m=m+(max(a,b)+1)*max(a,b)//2+(min(a,b)+1)*min(a,b)//2-min(a,b)


else:
    l.insert(0,0)
    l.append(n)
    for i in range(len(l)-1):
        a=s[l[i]:l[i+1]].count("<")
        b=s[l[i]:l[i+1]].count(">")
        m=m+(max(a,b)+1)*max(a,b)//2+(min(a,b)+1)*min(a,b)//2-min(a,b)

print(m)

Submission status: Accepted

Solution code:
a=input()
#print(a)
lenS=len(a)
b1=list()
b2=list()
c=a[0]
b1.append(1)
b2.append(a[0])
max_count=1
for i in range(1,len(a)):
  if c!=a[i]:
    c=a[i]
    b1.append(1)
    b2.append(a[i])
  else:
    b1[-1]+=1
    #if b[-1]>max_count:
      #max_count=b[-1]
      #max_i=i
#print(b1)
#print(b2)
N=len(b1)
ans=list()
if a[0]=='<':
  ans+=list(range(b1[0]+1))
else:
  ans+=list(range(b1[0]+1))[::-1]
#print(ans)  
for i in range(1,N):
  if b2[i]=='<':
    ad=list(range(b1[i]+1))
  else:
    ad=list(range(b1[i]+1)[::-1])
  if ans[-1]<ad[0]:
    del ans[-1]
  else:
    del ad[0]
  ans+=ad
#print(ans)
print(sum(ans))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    s = input()

    g = []

    p = ' '
    o = 0
    for c in s:
        if p == c:
            o += 1 
        else:
            if p != ' ':
                g.append([p, o])
            o = 1
        p = c
    g.append([p, o])

    s = c = 0
    for i in g:
        if i[0] == '<':
            s += (i[1] * (2 * c + 1 + i[1])) // 2
            c += i[1]
        elif c < i[1]:
            s += (i[1] - c) + (i[1] * (i[1] - 1)) // 2
            c = 0
        else:
            s += (i[1] * (i[1] - 1)) // 2
            c = 0

    print(s)


# region fastio

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):
    """Prints the values to a stream, or to sys.stdout by default."""
    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()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
l = 0
b = 0
k = 0
sum = 0
for i in range(len(S)):
    k += 1
    if i == len(S)-1 or (S[i] != S[i+1]):
        sum += k * (k + 1) / 2
        if S[i] =="<":
            l = k
            k = 0
        if S[i] ==">":
            b = k
            k = 0
            sum -= min(l, b)

print(int(sum))

Submission status: Accepted

Solution code:
l = input()

n = [0  for i in range(len(l)+1)]
c = 1
i=1
for x in l:
    if x == '<':
        n[i] = c
        c+=1
    else:
        c=1
    i+=1
c=1
i=1
n_=[0 for i in range(len(l)+1)]
for x in reversed(l):
    if x == '>':
        n_[i] = c
        c+=1
    else:
        c=1
    i+=1

n_=list(reversed(n_))

ans = [max(n[i],n_[i]) for i in range(len(l)+1)]
print(sum(ans))

Submission status: Accepted

Solution code:
S=input()
S_rev=S[::-1]

import numpy as np

arr_rev=[]
cnt=0
for s_rev in S_rev:
    if s_rev==">":
        cnt+=1
    else:
        cnt=0
    arr_rev.append(cnt)

A=np.array(arr_rev[::-1]+[0])

arr=[]
cnt=0
for s in S:
    if s=="<":
        cnt+=1
    else:
        cnt=0
    arr.append(cnt)

B=np.array([0]+arr)

print(sum(np.maximum(A,B)))

Submission status: Accepted

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

i = 0
while i < len(s):
  char = s[i]
  
  # < or > がいくつ続くか数える
  count = 1
  for j in range(i+1, len(s)):
    if s[j] == char:
      count = count +1
    else:
      break
  if char == '<':
    tmp = 0
    for k in range(count+1):
      ans_array[i+k] = tmp
      tmp = tmp + 1
  else:
    tmp = count
    start = 0
    if ans_array[i] > count:
      tmp = tmp - 1
      start = 1
      

    for k in range(start, count+1): 
      ans_array[i+k] = tmp
      tmp = tmp - 1
      
  i = i + count

print(sum(ans_array))

Submission status: Accepted

Solution code:
import re

s = str(input())

s = re.sub('><', '>,0,<', s)

if s[0] == '<' :
  s = '0,' + str(s)
  
if s[-1] == '>' :
  s = str(s) + ',0'
  
s = re.sub('<>', '<,>', s) 

s = s.split('0')

sum = 0

for i in s:
  i = i.split(',')
  cnt = 0
  for j in range(len(i)):
    Len = int(len(i[j]))
    cnt = cnt + 1
    sum = sum + Len * (Len + 1) / 2
    if cnt > 3:
      des = min([len(i[1]),len(i[2])])
      sum = sum - des
    
print(int(sum))

Submission status: Accepted

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

calc = False
ans = 0
left = 0
right = 0
for i in range(n):
    if i == n-1:
        if s[i] == '<':
            left += 1
            calc = True
        else:
            right += 1
            calc = True
    else:
        if s[i] == '<':
            left += 1
        else:
            right += 1
            if s[i+1] == '<':
                calc = True
    if calc:
        if left >= right:
            ans += left*(left+1)//2
            ans += right*(right-1)//2
            calc = False
            left = 0
            right = 0
        else:
            ans += right*(right+1)//2
            ans += left*(left-1)//2
            calc = False
            left = 0
            right = 0

print(ans)

Submission status: Accepted

Solution code:
S = '>' + input() + '<='
l = len(S)
A = [0] * (l-2)
zero_posi = []
max_posi = []

for i in range(l-2):
    now = S[i]
    nex = S[i+1]
    if S[i] == '>' and S[i+1] =='<':
        A[i] = 0
        zero_posi.append(i)

while zero_posi:
    start = zero_posi.pop()
    count = 0
    for i in range(start, -1, -1):
        A[i] = max(A[i], count)
        count += 1
        if S[i-1] == '<':
            A[i-1] = max(A[i], count)
            break

    count = 0
    for i in range(start, l-2):
        A[i] = max(A[i], count)
        count += 1
        if S[i + 1] == '>':
            break

ans = sum(A)
print(ans)

Submission status: Accepted

Solution code:
# >0<
s = input()
if s[0] ==">":
    s = "<"+s
if s[-1]=="<":
    s = s +">"
#末端の処理
l=len(s)
upp = 0
dwn = 0
ans = 0
U = []
D = []
for i in range(l):
    if s[i] == "<":
        if dwn:
            D.append(dwn)
            ans += dwn*(dwn+1)//2
            dwn = 0
        upp+=1
    else:
        if upp:
            U.append(upp)
            ans += upp*(upp+1)//2
            upp=0
        dwn += 1
ans += dwn*(dwn+1)//2
for i in range(len(D)):
    ans -= min(U[i],D[i])
print(ans-1)