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
s = tuple(map(str, input().split("><")))
n = len(s)
ans = 0
def calc(x, y):
    return (x*(x-1) + y*(y-1))/2 + max(x, y)
if n == 1:
    a = s[0].count("<")
    b = s[0].count(">")
    print(int(calc(a, b)))
    sys.exit()
for i in range(n):
    if i == 0:
        a = s[i].count("<")
        b = s[i].count(">") + 1
    elif i == n - 1:
        a = s[i].count("<") + 1
        b = s[i].count(">")
    else:
        a = s[i].count("<") + 1
        b = s[i].count(">") + 1
    ans += calc(a, b)

print(int(ans))

Submission status: Accepted

Solution code:
moji=input()
s=[]

for c in moji:
    if(c=="<"):
        s.append(1)
    else:
        s.append(-1)

#print(s)

temp=0

yama=[]


n=len(s)+1
a=[-1]*(n)
#print(len(a))

for i in range(n-1):
    temp+=s[i]
    if(i==n-2):
        yama.append(temp)
    else:
        if(s[i]*s[i+1]==-1):
            yama.append(temp)
            temp=0

#print(yama)

l=len(yama)
ans=0
for i in range(l):
    if(i==0 and yama[i]<0):
        tasu=-yama[i]
        ans+=(tasu+1)*tasu//2
        continue
    if(i==l-1 and yama[i]>0):
        tasu=yama[i]
        ans+=(tasu+1)*tasu//2
        continue
    if(i==l-1):
        continue
    if(yama[i]<0 or yama[i+1]>0):
        continue
    dai=max(yama[i],-yama[i+1])
    sho=min(yama[i],-yama[i+1])
    ans+=(dai+1)*dai//2
    ans+=sho*(sho-1)//2

print(ans)

Submission status: Accepted

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

vA = [0,] * N
vZ = []
p = ">"
for i,s in enumerate(S):
    if p+s == "><":
        vZ.append(i)
    p = s
if S[-1] == ">":
    vZ.append(N-1)

# print(vZ)##
####
for z in vZ:
    if z == N-1:
        break
    t = z
    while t<N-1 and S[t] == "<":
        vA[t+1] = vA[t] + 1
        t += 1

# print(vA)##

for z in vZ:
    if z == 0:
        continue
    t = z
    while t>0 and S[t-1] == ">":
        vA[t-1] = max(vA[t] + 1, vA[t-1])
        t -= 1

# print(vA)###
print(sum(vA))

Submission status: Accepted

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


def solve(S: str):
    ## ><を探す。閉じたところのindex(<)
    S = ">"+S+"<"
    answer = [0]*(len(S)+1)
    between_index = []
    prev = ">"
    for i in range(len(S)):
        if prev == ">" and S[i]=="<":
            between_index.append(i)
        
        prev = S[i]
    if prev == ">":
        between_index.append(len(S))

    for index in between_index:
        for left in range(index-2,-1,-1):
            if S[left]=="<":
                answer[left+1] = max(answer[left+1],answer[left+2]+1)
                break
            else:
                answer[left+1]=answer[left+2]+1
        for right in range(index+1,len(S)):
            if S[right]==">":
                answer[right] = max(answer[right],answer[right-1]+1)
                break
            else:
                answer[right]=answer[right-1]+1
            
    answer = answer[1:len(answer)-1]
    print(sum(answer))
    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()
lens1 = False
snum = [0]
st = 0
end = 0
count = 1
result = 0

if len(S) == 1:
    result = 1
    lens1 = True
else:
    for i, s in enumerate(S):
        if i == 0:
            if s == '>':
                st = 1
        elif i == len(S) - 1 :
            if s == '<':
                end = 1
            if s != S[i-1]:
                snum.append(count)
                snum.append(1)
            else:
                snum.append(count+1)
        elif s != S[i-1]:
            snum.append(count)
            count = 1
        else:
            count += 1

snum.append(0)

if not lens1:
    for i in range(1, len(snum)-1):
        n = snum[i]
        if st:
            if i % 2 == 0 and n <= snum[i+1]:
                result += int(n * (n - 1) / 2)
            elif i % 2 != 0 and n < snum[i-1]:
                result += int(n * (n - 1) / 2)
            else:
                result += int(n * (n + 1) / 2)
        else:
            if i % 2 == 1 and n <= snum[i+1]:
                result += int(n * (n - 1) / 2)
            elif i % 2 == 0 and n < snum[i-1]:
                result += int(n * (n - 1) / 2)
            else:
                result += int(n * (n + 1) / 2)

print(result)

Submission status: Accepted

Solution code:
S = list(input())
if S == ['>'] or S == ['<']:
    print(1)
    exit()
m = 0
n = 0
s = 0
l = []
if S[0] == '>':
    l.append(0)
    p = '>'
else:
    p = '<'
c = 1
for i in range(1, len(S)):
    if S[i] == p:
        c += 1
    else:
        l.append(c)
        c = 1
        p = S[i]
if c != 0:
    l.append(c)
if S[-1] == '<':
    l.append(0)
# print(l)
ans = 0

def calc(x):
    if x == 0:
        return 0
    elif x == 1:
        return 1
    else:
        return (1 + x) * x // 2

for i in range(0, len(l), 2):
    # print(l[i], l[i+1])
    ans += calc(l[i]) + calc(l[i + 1]) - min(l[i], l[i + 1])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

S = input()
pad = []

if S[0] == "<":
    left_flag = True
    count = 0
    for k in S:
        if left_flag and k == "<":
            count += 1
        elif left_flag and k == ">":
            pad.append(count)
            left_flag ^= 1
            count = 1
        elif (not left_flag) and k == ">":
            count += 1
        else:
            pad.append(-count)
            left_flag ^= 1
            count = 1
    if left_flag:
        pad.append(count)
    else:
        pad.append(-count)


    result = 0
    for i, j in zip(pad[0::2], pad[1::2]):
        if i > abs(j):
            result += sum(range(i + 1)) + sum(range(abs(j)))
        else:
            result += sum(range(i)) + sum(range(abs(j) + 1))
    if len(pad) % 2 == 1:
        result += sum(range(abs(pad[-1] + 1)))
    print(result)

else:
    left_flag = False
    count = 0
    for k in S:
        if left_flag and k == "<":
            count += 1
        elif left_flag and k == ">":
            pad.append(count)
            left_flag ^= 1
            count = 1
        elif (not left_flag) and k == ">":
            count += 1
        else:
            pad.append(-count)
            left_flag ^= 1
            count = 1
    if left_flag:
        pad.append(count)
    else:
        pad.append(-count)

    result = sum(range(abs(pad[0]) + 1))
    for i, j in zip(pad[1::2], pad[2::2]):
        if i > abs(j):
            result += sum(range(i + 1)) + sum(range(abs(j)))
        else:
            result += sum(range(i)) + sum(range(abs(j) + 1))
    if len(pad) % 2 == 0:
        result += sum(range(abs(pad[-1] + 1)))
    print(result)

Submission status: Accepted

Solution code:
s = list(input())

memo = ""
cnt = 0
before_cnt = 0
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
S = input()
if S[0] == '>':
    S = '<' + S
if S[- 1] == '<':
    S = S + '>'
    
N = len(S)
res = 0
    
i = 0
while i < N and S:
    a = 1
    while i + a < N and S[i + a] == '<':
        a += 1
    i += a
    d = 1
    while i + d < N and S[i + d] == '>':
        d += 1
    i += d
    x = max(a, d)
    y = min(a, d)
    res += x*(x + 1)//2 + y*(y - 1)//2
print(res)

Submission status: Accepted

Solution code:
S = str(input())
N = len(S) + 1
a = [0]*N
if '>' not in S or '<' not in S:
    print(N*(N-1)//2)
    exit()
res = 0
st = 1
if S[0] == '>':
    st = S.index('<')
    res += st*(st+1)//2
ed = 0
a = 0
b = 0
for i in range(st, N-1):
    if S[i-1] == '>' and S[i] == '<':
        if i != st:
            res += max([a+1,b]) + a*(a+1)//2 + b*(b-1)//2
        if i==N-2:
            ed = -2
            break
        a = 0
        b = 0
        ed = i
    elif i==N-2 and S[i] == '>':
        res += max([a+1,b+1]) + a*(a+1)//2 + b*(b+1)//2
        ed = i
    elif S[i] == '<':
        a += 1
    elif S[i] == '>':
        b += 1
if ed == -2:
    res += 1
elif ed != N-2:
    res += (N-1-ed)*(N-ed)//2
print(res)

Submission status: Accepted

Solution code:
def f(n):
    return n*(n+1)//2

import re
S=input()
T = re.findall('<+|>+', S)
N=[len(i) for i in T]
sum_=0
A=[]
B=[]
if '<' in T[0]:
    A.append(0)
    B.append(len(T[0]))
    #print(0,len(T[0]))
for i,s in enumerate(T):
    if '>' in s:
        if i+1 < len(T):
            #print(len(T[i]),len(T[i+1]))
            A.append(len(T[i]))
            B.append(len(T[i+1]))
if '>' in T[-1]:
    #print(len(T[-1]),0)
    A.append(len(T[-1]))
    B.append(0)
sum_=0
for i in range(len(A)-1):
    if B[i] < A[i+1]:
        sum_ += f(A[i+1])
        sum_ += f(B[i]-1)
    else:
        sum_ += f(B[i])
        sum_ += f(A[i+1]-1)
sum_ += f(A[0])
sum_ += f(B[-1])
print(sum_)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
left = 0
right = 0
for i in range(len(S)):
  if S[i] == ">":
    left += 1
  else:
    break
for i in range(len(S)):
  if S[len(S)-i-1] == "<":
    right += 1
  else:
    break
# print(left)
# print(right)

if right != 0:
  S = S[left:-right]
else:
  S = S[left:]

ruiseki = [0] * len(S)
r, l = 0, 0

# for i in range(len(S)):
#   if S[i] == "<":
#     # l += 1
#     ruiseki[i+] = ruiseki[i]
#   elif S[i] == ">":
#     # r += 1
#     ruiseki[i] += 1
# print(ruiseki)

left_box = []
right_box = []
# left
count = 0
for i in range(len(S)):
  if S[i] == "<":
    count += 1
  else:
    if count != 0:
      left_box.append(count)
    count = 0
if count != 0:
  left_box.append(count)
      
# print(left_box)

for i in range(len(S)):
  if S[i] == ">":
    count += 1
  else:
    if count != 0:
      right_box.append(count)
    count = 0
if count != 0:
  right_box.append(count)


# print(right_box)
  
m = []
for i in range(len(right_box)):
  r = right_box[i]
  l = left_box[i]
  m.append(max(r, l))
# print(m)
count = 0

for i in range(len(m)):
  for j in range(1, m[i]+1):
    count += j
# print(count)

# for i in range(len(m))
ans = 0

def wa(num):
  wa = 0
  for i in range(1,num+1):
    wa += i
  return wa

def small_wa(num):
  wa = 0
  for i in range(0, num):
    wa += i
  return wa

for i in range(len(right_box)):
  r = right_box[i]
  l = left_box[i]
  b = max(r, l)
  s = min(r, l)
  a = small_wa(s) + wa(b)
  ans += a
  # print(a)


# nokori
ans += wa(left) + wa(right)
print(ans)

Submission status: Accepted

Solution code:
s=input()
n=len(s)+1
ans=[-1 for i in range(n)]
st=False
for i in range(1,n):
    if s[i-1]=="<":
        if st:
            st=False
            ans[i-1]=0
    else:
        st=True
if s[0]=="<":
    ans[0]=0
else:
    d=0
    for i in range(1,n):
        if s[i-1]==">":
            d+=1
        else:
            break
    ans[0]=d
#print(ans)
co=0
for i in range(n-1,0,-1):
    if s[i-1]==">":
        ans[i]=co
        co+=1
    else:
        if co>0:
            ans[i]=co
        co=0
#print(ans)
for i in range(1,n):
    if s[i-1]=="<" and ans[i]==-1:
        ans[i]=ans[i-1]+1
    elif s[i-1]=="<" and ans[i]!=-1:
        ans[i]=max(ans[i],ans[i-1]+1)
print(sum(ans))

Submission status: Accepted

Solution code:
# [int(j) for j in input().split()]
s = input()
n = len(s)+1
a = [[] for i in range(n)]
ch = [[] for i in range(n)]
b = [0 for i in range(n)]
for i in range(len(s)):
    if s[i]==">":
        a[i+1].append(i) 
        ch[i].append(i+1)    
    else:
        a[i].append(i+1)
        ch[i+1].append(i)
st = []
# print(a)

for i in range(n):
    if ch[i]==[]:
        st.append(i)
# print(st)
for vertex in st:
    q = [vertex]
    ct = 0
    while(q):
        curr = q.pop()
        for nb in a[curr]:
            b[nb] = max(b[nb], b[curr]+1)
            q.append(nb)
print(sum(b))

Submission status: Accepted

Solution code:
def f_a():
    s = input()
    c, l, ans = 0, [], 0
    for i in range(1, len(s)):
        c += 1
        if s[i-1]!=s[i]:
            l.append(c); c = 0
    l.append(c+1)

    if s[-1]=="<":
        ans += sum(range(l[-1]+1))
        l.pop()

    while len(l)>1:
        a, b = l[-1], l[-2]
        ans += sum(range(a)) + sum(range(b))
        ans += max(a, b)
        l.pop(); l.pop()

    if len(l)>0:
        ans += sum(range(l[-1]+1))

    print(ans)


if __name__ == "__main__":
    f_a()

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 j in range(N-2,-1,-1):
    if(s[j] == ">"):
        if(a[j] <= a[j+1]):
            a[j] = a[j+1]+1

print(sum(a))

Submission status: Accepted

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

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

    s = 0
    x = 0
    while x != n-1:
        if S[x] == ">":
            x+= 1
        else:
            break
    s += x*(x+1)//2

    if x == n-1:
        print(s)
        exit()


    a = 0
    b = 0
    f = 0
    for i in range(x, n-1):
        if S[i] == ">":
            f = 1
            b += 1
        elif f == 0:
            a += 1
        else:
            if a == b:
                s += a*a
            elif a > b:
                s += a*(a+1)//2 + b*(b-1)//2
            else:
                s += a*(a-1)//2 + b*(b+1)//2
            f = 0
            a = 1
            b = 0



    if S[n-2] == ">":
        if a == b:
            s += a*a
        elif a > b:
            s += a*(a+1)//2 + b*(b-1)//2
        else:
            s += a*(a-1)//2 + b*(b+1)//2
    else:
        s += a*(a+1)//2




    print(s)





if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
n = len(s)
list0 = list()
list2 = list()
ans = 0
for i in range(n-1):
    if s[i:i+2] == '><':
        list0.append(i+1)
    elif s[i:i+2] == '<>':
        list2.append(i+1)

if s[0] == '<':
    list0.insert(0, 0)
else:
    if len(list0):
        p1 = list0[0]
    else:
        p1 = n
    ans += 1/2 * p1 * (p1 + 1)



if s[-1] == '>':
    list0.append(n)
else:
    if len(list0):
        p1 = n - list0[-1]
    else:
        p1 = n
    ans += 1/2 * p1 * (p1 + 1)

for i in range(len(list2)):
    p1 = max(list2[i] - list0[i], list0[i+1] - list2[i])
    p2 = min(list2[i] - list0[i], list0[i+1] - list2[i])
    ans += 1/2 * p1 * (p1 + 1) + 1/2 * p2 * (p2 - 1)

print(int(ans))

Submission status: Accepted

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

import sys
from operator import itemgetter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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

A = []
s = 0
for i in range(N-2):
    if S[i] != S[i+1]:
        A.append((i+1-s, S[i], s, i+1))
        s = i + 1
A.append((N-1-s, S[-1], s, N-1))

A.sort(key=itemgetter(0), reverse=True)

B = [-1] * N
for n, s, l, r in A:
    cnt = 0
    if s == '<':
        for i in range(l, r+1):
            if B[i] == -1:
                B[i] = cnt
            cnt += 1
    else:
        for i in range(r, l-1, -1):
            if B[i] == -1:
                B[i] = cnt
            cnt += 1
print(sum(B))

Submission status: Accepted

Solution code:
from itertools import groupby

S = input()

p = 0
s = 0
for key, values in groupby(S):
    l = len(list(values))
    s = s + (l * (l+1))//2
    if key == '>':
        s = s - min(l, p)
    if key == '<':
        p = l

print(s)

Submission status: Accepted

Solution code:
func = list(input())
mont = []
num=1
if len(func)==1 and func[0]==">":
  print(1)
else:
  for i in range(len(func)):
    if i == len(func)-1:
      if func[i]=="<":
        mont.append(num)
        mont.append(0)
      else:
        
        mont.append(num)
    elif i==0 and func[0] ==">":
      mont.append(0)
      num=1
    elif func[i] == "<" and func[i+1]==">":
      mont.append(num)
      num=0
    elif func[i] == ">" and func[i+1]=="<":
      mont.append(num)
      num=0
    else:
      pass
    num += 1

  count=0
  for i in range(0,len(mont),2):
    if mont[i] >= mont[i+1]:
      count+= mont[i]*(mont[i]+1)//2 + mont[i+1]*(mont[i+1]-1)//2
    else:
      count+= mont[i]*(mont[i]-1)//2 + mont[i+1]*(mont[i+1]+1)//2
  print(count)

Submission status: Accepted

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

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

if last_s == '<':
    ans += l*(l+1)//2
else:
    M = max(l, r)
    m = min(l, r)
    ans += M*(M+1)//2 + m*(m-1)//2

print(ans)

Submission status: Accepted

Solution code:
def wa(nature):
    nature_i = len(nature)
    return nature_i*(nature_i+1)//2
in_str = input()
moji_ls = []
i = 1
taiki = in_str[0]
len_in_str =len(in_str)
while i < len_in_str:
    if taiki[0] == in_str[i]:
        taiki += in_str[i]
        i += 1
    else:
        moji_ls.append(taiki)
        taiki = in_str[i]
        i += 1
moji_ls.append(taiki)
#print(moji_ls)
#print(len(moji_ls))
sub = 0
moji_ls_len = len(moji_ls)
i = 0
while i < moji_ls_len:
    if moji_ls[i][0] == '<':
        if i == moji_ls_len-1:
            sub += wa(moji_ls[i])
        else:
            sub += wa(moji_ls[i]) - min(len(moji_ls[i]),len(moji_ls[i+1]))
    else:
        sub += wa(moji_ls[i])
    i += 1
print(sub)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import itertools
# 整数の入力
total = 0
last_l = 0
s = [c for c in input()]
for k,g in itertools.groupby(s):
    l = len(list(g))
    # print(k, l, (l+1)*l//2)
    total += (l+1)*l//2
    if(k=='>'):
        if(last_l <= l):
            total -= last_l
            # print(-last_l)
        else:
            total -= l
            # print(-l)
    last_l = l
print(total)
# 出力
# print("{} {}".format(a+b+c, s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s) + 1
lis = [0] * n
if s[0] == "<":
  lis[0] = 0
p = 1
while p < n - 1:
  if s[p - 1] == ">" and s[p] == "<":
    lis[p] = 0
  elif s[p - 1] == "<" and s[p] == "<":
    lis[p] = max(lis[p - 1] + 1, lis[p])
  elif s[p] == ">":
    pass
  p += 1
    
if s[-1] == ">":
  lis[-2] = 1
  lis[-1] = 0
  
p = n - 3
while p >= 0:
  if s[p] == ">" and s[p + 1] == "<":
    if p - 1 >= 0:
      lis[p] = max(lis[p + 1] + 1, lis[p], lis[p - 1] + 1)
    else:
      lis[p] = 1
  elif s[p] == ">" and s[p + 1] == ">":
    if p - 1 >= 0:
      lis[p] = max(lis[p + 1] + 1, lis[p], lis[p - 1] + 1)
    else:
      lis[p] = max(lis[p + 1] + 1, lis[p])
  elif s[p] == "<":
    pass
  p -= 1

if s[-1] == "<":
  lis[-1] = lis[-2] + 1
  
print(sum(lis))

Submission status: Accepted

Solution code:
s=input()+"1"
up=int(s[0]=="<")
do=1-up
ans=0
for i in range(1,len(s)):
  if s[i]=="1":
    ans += ((up*(up-1))>>1) + ((do*(do-1))>>1) + max(up,do)
  elif s[i-1]==">" and s[i]=="<":
    ans += ((up*(up-1))>>1) + ((do*(do-1))>>1) + max(up,do)
    up,do=1,0
  elif s[i]=="<":
    up+=1
  else:
    do+=1
print(ans)

Submission status: Accepted

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

n = [0]
for i in range(1, N + 1):
  n.append(n[-1] + i)

ans = 0
cnt_L = 0
cnt_R = 0
for i in range(N - 1):
  if i == 0:
    if S[i] == "<":
      cnt_L += 1
    else:
      cnt_R += 1
  elif S[i] != S[i - 1] and S[i] == "<":
    if cnt_L > 0:
      ans += n[max(cnt_L, cnt_R)] + n[min(cnt_L, cnt_R) - 1]
    else:
      ans += n[cnt_R]

    cnt_L = 1
    cnt_R = 0
  else:
    if S[i] == "<":
      cnt_L += 1
    else:
      cnt_R += 1
if S[-1] == "<":
  ans += n[cnt_L]
else:
  if cnt_L > 0:
    ans += n[max(cnt_L, cnt_R)] + n[min(cnt_L, cnt_R) - 1]
  else:
    ans += n[cnt_R]
print(ans)

Submission status: Accepted

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = str(input().rstrip('\n'))
    s = list(map(str, s.replace("><", ">_<").split("_")))
    cnt = 0
    for v in s:
        a = 0
        b = 0
        for i in range(len(v)):
            if v[i] == "<":
                a += 1
            else:
                b += 1
        if a != 0 and b != 0:
            cnt += (a - 1) * (1 + a - 1) // 2 + (b - 1) * (1 + b - 1) // 2
            cnt += max(a, b)
        elif b != 0:
            cnt += b * (1 + b) // 2
        elif a != 0:
            cnt += a * (1 + a) // 2
    print(cnt)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
s = input()
l = [0 for i in range(len(s)+1)]
if s[0] == '<':
  cnt = 1
  for i in range(0, len(s)):
    if s[i] == '<':
      l[i+1] = max(cnt, l[i+1])
      cnt += 1
    else:
      break
if s[-1] == '>':
  cnt = 1
  for i in range(len(s)-1, -1, -1):
    if s[i] == '>':
      l[i] = max(cnt, l[i])
      cnt += 1
    else:
      break
for i in range(1, len(s)):
  if s[i-1:i+1] == '><':
    #左側検索
    cnt = 1
    for j in range(i-1, -1, -1):
      if s[j] == '>':
        l[j] = max(cnt, l[j])
        cnt += 1
      else:
        break
    #右側検索
    cnt = 1
    for j in range(i, len(s)):
      if s[j] == '<':
        l[j+1] = max(cnt, l[j+1])
        cnt += 1
      else:
        break
ans = sum(l)
print(ans)

Submission status: Accepted

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

A=[0]*(N+1)
L=[]
if S[0]=="<":
  r=1
  l=0
else:
  l=1
  r=0

for i in range(1,N):
  if S[i]=="<":
    r+=1
    if S[i]!=S[i-1]:
      L.append(-l)
      l=0
  else:
    l+=1
    if S[i]!=S[i-1]:
      L.append(r)
      r=0
if r>0:
  L.append(r)
elif l>0:
  L.append(-l)
      
m=max(abs(max(L)),abs(min(L)))
ans=0
if S[0]=="<":
  if len(L)%2==0:
    for i in range(len(L)//2):
      ma=max(L[2*i],-L[2*i+1])
      mi=min(L[2*i],-L[2*i+1])
      ans+=ma*(ma+1)//2+(mi-1)*mi//2
  else:
    for i in range(len(L)//2):
      ma=max(L[2*i],-L[2*i+1])
      mi=min(L[2*i],-L[2*i+1])
      ans+=ma*(ma+1)//2+(mi-1)*mi//2
    ans+=L[-1]*(L[-1]+1)//2
    
if S[0]==">":
  ans+=(-L[0])*(-L[0]+1)//2
  if len(L)%2==0:
    for i in range(len(L)//2-1):
      ma=max(L[2*i+1],-L[2*i+2])
      mi=min(L[2*i+1],-L[2*i+2])
      ans+=ma*(ma+1)//2+(mi-1)*mi//2
    ans+=L[-1]*(L[-1]+1)//2
  else:
    for i in range(len(L)//2):
      ma=max(L[2*i+1],-L[2*i+2])
      mi=min(L[2*i+1],-L[2*i+2])
      ans+=ma*(ma+1)//2+(mi-1)*mi//2

print(ans)

Submission status: Accepted

Solution code:
S = input()

ans = 0
count_l = 0
count_u = 0

if S[0] == '<':
    count_u += 1
elif S[0] == '>':
    count_l += 1


for i in range(1, len(S)):
    if S[i] == '<' and S[i] != S[i-1]:
        if count_u < count_l:
            count_u -= 1
        else:
            count_l -= 1
        ans += count_u * (count_u+1) /2 + count_l * (count_l+1) /2
        count_u = 1
        count_l = 0
    elif S[i] == '<':
        count_u += 1
    elif S[i] == '>':
        count_l += 1

if count_u < count_l:
    count_u -= 1
else:
    count_l -= 1

ans += count_u * (count_u+1) /2 + count_l * (count_l+1) /2

print(int(ans))

Submission status: Accepted

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

for i in range(len(s)):
    if s[i] == '>': continue
    arr[i+1] = arr[i] + 1

for i in range(len(s))[::-1]:
    if s[i] == '<': continue
    
    if arr[i] > arr[i+1]+1:continue
    else: arr[i] = arr[i+1]+1
print(sum(arr))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

S = list(input().strip())
S.append("<")

L = [0] * len(S)
tmp = ">"

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

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

if S[0] == ">" and S[1] == ">":
    L[0] = L[1] + 1
elif S[0] == ">" and S[1] == "<":
    L[0] = max(L[0], L[1] + 1)

print(sum(L))

Submission status: Accepted

Solution code:
s = input() + "<"

a = 0
b = 0
ans = 0
pre = s[0]

for i in s:
    if i == ">":
        a += 1
        if pre == "<":
            ans += ((1 + b - 1) * (b - 1)) // 2
        pre = i
    if i == "<":
        if pre == ">":
            if b <= a:
                ans += ((1 + a) * a) // 2
            else:
                ans += ((1 + a - 1) * (a - 1)) // 2 + b
            a = 0
            b = 0
        b += 1
        pre = i
if i == "<":
    ans += ((1 + b - 1) * (b - 1)) // 2
print(ans)

Submission status: Accepted

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))



S=one_str()

temp = S.split("><")

sums=0
length=len(temp)

for ind, i in enumerate(temp):
    left=i.count(">")
    right=i.count("<")
    
    if len(i)==0:
        right+=1
    
    elif ind==0 and length!=1:
        left = i.count(">")+1
        right= i.count("<")
        
    elif ind==length-1 and length!=1:
        left = i.count(">")
        right= i.count("<")+1
        
    elif ind !=0 and ind != length-1:
        left = i.count(">")+1
        right= i.count("<")+1
    
    maxs = max(left,right)
    mins = min(left,right) 
    maxs_array=[value for value in range(maxs+1)]
    mins_array=[value for value in range(mins)]

    sums += sum(maxs_array)
    sums += sum(mins_array)

print(sums)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
prev = s[0]
a = []
cnt = 0
for i in range(l):
    if s[i] != prev:
        a.append(cnt)
        prev = s[i]
        cnt = 0
    cnt += 1
a.append(cnt)
if s[0]=="<": a = [0]+a
for i in range(len(a)-1): a[i+1] += a[i]
a = a[::2]

b = [0] * (l+1)
s = "=" + s + "="
for i in a:
    bi = 0
    while s[i-bi]==">":
        b[i-bi-1] = max(b[i-bi-1], b[i-bi]+1)
        bi += 1
    bi = 0
    while s[i+bi+1]=="<":
        b[i+bi+1] = max(b[i+bi+1], b[i+bi]+1)
        bi += 1
print(sum(b))

Submission status: Accepted

Solution code:
s = input()
a = [-1 for i in range(len(s)+1)]
for i in range(len(s)-1):
    if s[i] == '>' and s[i+1] == "<":
        a[i+1] = 0
if s[0] == "<":
    a[0] = 0
if s[-1] == ">":
    a[-1] = 0
def plus(i):
    j = i -1
    while j >= 0 and s[j] == '>':
        a[j] = max(a[j+1] + 1, a[j])
        j -= 1
    j = i
    if j == len(a) -1:
        return
    while s[j] == '<':
        a[j+1] = max(a[j] + 1, a[j+1])
        j += 1
        if  j == len(a) - 1:
            break
for i in range(len(a)):
    if a[i] == 0:
        plus(i)
print(sum(a))

Submission status: Accepted

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

lp = [0] * n
rp = [0] * n

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

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

total = 0
for i in range(n):
  total += max(lp[i], rp[i])

print (total)

Submission status: Accepted

Solution code:
import itertools
S = input()
ans = 0
s = itertools.groupby(S)
b=0
for key,group in s:
  if key=="<":
    a = len(list(group))
    ans += ((b+b+a)*(a+1))/2
    b = a
  elif key==">":
    a = len(list(group))
    if b<=a:
      ans +=(b+abs(b-a)+0)*(a+1)/2-b
      b=0
    else:
      ans +=((a-1)*(a))/2
      b=0
    #print(ans)
print(int(ans))
#print(len(list(s)))