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: Time Limit Exceeded

Solution code:
def main():
    s = input()
    l = [s[0]]
    lap = l.append
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            l[-1] = l[-1] + s[i]
        else:
            lap(s[i])
    dlist = []
    plist = []
    dap = dlist.append
    pap = plist.append
    if l[0][0] == "<":
        dap(0)
    for i in l:
        if i[0] == "<":
            pap(len(i))
        else:
            dap(len(i))
    if l[-1][0] == ">":
        pap(0)
    dm = max(dlist)
    pm = max(plist)
    sm = [i for i in range(0,max(dm,pm)+1)]
    for i in range(1,len(sm)):
        sm[i] = sm[i-1]+sm[i]
    for i in range(1,len(dlist)):
        x = dlist[i]
        y = plist[i-1]
        if y <= x:
            dlist[i] = sm[x]
            plist[i-1] = sm[max([0,y-1])]
        else:
          dlist[i] = sm[max([0,x-1])]
          plist[i-1] = sm[y]
    dlist[0] = sm[dlist[0]]
    plist[-1] = sm[plist[-1]]
    print(sum(dlist)+sum(plist))
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
n=len(s)+1
a=[0]*n
x=[0]*n
y=[0]*n

for i in range(0,n):
  c=i
  while i>0 and s[i-1]=="<":
    x[c]+=1
    i-=1
for j in range(0,n):
  d=j
  while j<n-1 and s[j]==">":
    y[d]+=1
    j+=1

for k in range(0,n):
  a[k]=max(x[k],y[k])
  
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    l = [s[0]]
    sm = [i for i in range(0,len(s)+1)]
    for i in range(1,len(sm)):
        sm[i] = sm[i-1]+sm[i]
    lap = l.append
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            l[-1] = l[-1] + s[i]
        else:
            lap(s[i])
    dlist = []
    plist = []
    dap = dlist.append
    pap = plist.append
    if l[0][0] == "<":
        dap(0)
    for i in l:
        if i[0] == "<":
            pap(len(i))
        else:
            dap(len(i))
    if l[-1][0] == ">":
        pap(0)
    for i in range(1,len(dlist)):
        x = dlist[i]
        y = plist[i-1]
        if y <= x:
            dlist[i] = sm[x]
            plist[i-1] = sm[max([0,y-1])]
        else:
          dlist[i] = sm[max([0,x-1])]
          plist[i-1] = sm[y]
    dlist[0] = sm[dlist[0]]
    plist[-1] = sm[plist[-1]]
    print(sum(dlist)+sum(plist))
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
n=len(s)+1
a=[0]*n
x=[0]*n
y=[0]*n
ans=0

for i in range(0,n):
  c=i
  while i>0 and s[i-1]=="<":
    x[c]+=1
    i-=1
for j in range(0,n):
  d=j
  while j<n-1 and s[j]==">":
    y[d]+=1
    j+=1

for k in range(0,n):
  a[k]=max(x[k],y[k])
  
for l in range(0,n):
  ans+=a[l]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
import re


def nchars(s, n):
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1)) 
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]
        
        
def n_sum(n):
  return n*(n+1)//2
        
s_l = list(nchars(S,1))
s_l_length = len(s_l)
answer=0
if s_l[0][0]=='<':
  if s_l_length%2==0:
    for i in range(0,s_l_length,2):
      s_1=s_l[i]
      s_2=s_l[i+1]
      s_1_l=len(s_1)
      s_2_l=len(s_2)
      if s_1_l<=s_2_l:
        answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
      else:
        answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
  else:
    for i in range(0,s_l_length,2):
      if i==s_l_length-1:
        answer+=n_sum(len(s_l[i]))
      else:
        s_1=s_l[i]
        s_2=s_l[i+1]
        s_1_l=len(s_1)
        s_2_l=len(s_2)
        if s_1_l<=s_2_l:
          answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
        else:
          answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
          
else:
  answer+=n_sum(len(s_l.pop(0)))
  s_l_length-=1
  if s_l_length%2==0:
    for i in range(0,s_l_length,2):
      s_1=s_l[i]
      s_2=s_l[i+1]
      s_1_l=len(s_1)
      s_2_l=len(s_2)
      if s_1_l<=s_2_l:
        answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
      else:
        answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
  else:
    for i in range(0,s_l_length,2):
      if i==s_l_length-1:
        answer+=n_sum(len(s_l[i]))
      else:
        s_1=s_l[i]
        s_2=s_l[i+1]
        s_1_l=len(s_1)
        s_2_l=len(s_2)
        if s_1_l<=s_2_l:
          answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
        else:
          answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
  
      
print(answer)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    flag = True
    l = [""]
    sm = [i for i in range(0,len(s)+1)]
    for i in range(1,len(sm)):
        sm[i] = sm[i-1]+sm[i]
    lap = l.append
    for i in range(len(s)):
        if flag:
            l[-1] = l[-1] + s[i]
        else:
            lap(s[i])
        if i < len(s)-1:
            if s[i] == "<" and s[i+1] == ">":
                flag = False
            else:
                flag = True
    xlist = []
    ylist = []
    xap = xlist.append
    yap = ylist.append
    for i in l:
        x = 0
        y = 0
        for j in list(i):
            if j == ">":
                x += 1
            else:
                y += 1
        xap(x)
        yap(y)
    for i in range(1,len(l)):
        x = xlist[i]
        y = ylist[i-1]
        if y <= x:
            xlist[i] = sm[x]
            ylist[i-1] = sm[max([0,y-1])]
        else:
          xlist[i] = sm[max([0,x-1])]
          ylist[i-1] = sm[y]
    xlist[0] = sm[xlist[0]]
    ylist[-1] = sm[ylist[-1]]
    print(sum(xlist)+sum(ylist))
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

def makelist(lst):
	nlst=[]
	if lst[0]=="<":
		for i in range(lst[1]+1):
			nlst.append(i)
	else:
		for i in range(lst[1]+1):
			nlst.append(lst[1]-i)
	return deque(nlst)

def mergelist(a,b):
	if a[-1]>b[0]:
		b.popleft()
	else:
		a.pop()
	return list(a)+list(b)

lst=makelist(splitlist[0])
for i in range(1,n):
	lst=mergelist(lst,makelist(splitlist[i]))
print(sum(lst))

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    flag = True
    l = [""]
    ans = 0
    sm = [i for i in range(0,len(s)+1)]
    for i in range(1,len(sm)):
        sm[i] = sm[i-1]+sm[i]
    for i in range(len(s)):
        if flag:
            l[-1] = l[-1] + s[i]
        else:
            l.append(s[i])
        if i < len(s)-1:
            if s[i] == "<" and s[i+1] == ">":
                flag = False
            else:
                flag = True
    xlist = []
    ylist = []
    for i in l:
        x = 0
        y = 0
        for j in list(i):
            if j == ">":
                x += 1
            else:
                y += 1
        xlist.append(x)
        ylist.append(y)
    for i in range(1,len(l)):
        if ylist[i-1] <= xlist[i]:
            ylist[i-1] = max([0,ylist[i-1]-1])
        else:
          xlist[i] = max([0,xlist[i]-1])
    for i in xlist:
        ans += sm[i]
    for i in ylist:
        ans += sm[i]
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s= str(input())
n = len(s) + 1
a = []
for i in range(n):
    a.append(0)

count = 1
while count>0:
 count = 0
 for i in range(n-1):
    if s[i] == "<" and a[i] >= a[i+1]:
        a[i+1] = a[i] + 1
        count +=1
    elif s[i] == ">" and a[i] <= a[i+1]:
        a[i] = a[i+1] + 1
        count += 1
    else:
        pass
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
S = input()

def count(s):
    count_bigger = s.count('<')
    count_smaller = s.count('>')
    max_count = max(count_bigger, count_smaller)
    return (count_bigger*(count_bigger-1))/2 + (count_smaller*(count_smaller-1))/2 + max_count

ss = ""
answer = 0

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

Submission status: Time Limit Exceeded

Solution code:
s= str(input())
n = len(s) + 1
a = []
for i in range(n):
    a.append(0)

count = 1
while count>0:
 count = 0
 for i in range(n-1):
    if s[i] == "<" and a[i] >= a[i+1]:
        a[i+1] += 1
        count +=1
    elif s[i] == ">" and a[i] <= a[i+1]:
        a[i] += 1
        count += 1
    else:
        pass
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
S = input()
a = [0]

for s in S:
    if s == '>':
        a.append(a[-1] - 1)
    else:
        a.append(a[-1] + 1)
a = [item - min(a) for item in a]

if S[0] == '<':
    a[0] = 0
if S[-1] == '>':
    a[-1] == 0

while True:
    a_prev = a.copy()
    for i in range(1, len(a)-1):
        if a[i-1]<a[i]<a[i+1] or a[i-1]>a[i]>a[i+1]:
            a[i] = min(a[i-1], a[i+1]) + 1
        elif a[i-1]>a[i]<a[i+1]:
            a[i] = 0
        else:
            a[i] = max(a[i-1], a[i+1]) + 1
    if a == a_prev:
        break

if S[0] == '>':
    a[0] = a[1] + 1
if S[-1] == '<':
    a[-1] = a[-2] + 1
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
S = input()

def count(s):
    count_bigger = s.count('<')
    count_smaller = s.count('>')
    max_count = max(count_bigger, count_smaller)
    return (count_bigger*(count_bigger-1))/2 + (count_smaller*(count_smaller-1))/2 + max_count

s_list = []
ss = ""
for i in range(len(S)):
    if i == len(S)-1:
        ss += S[i]
        s_list.append(ss)
    elif S[i] == ">" and S[i+1] == "<":
        ss += S[i]
        s_list.append(ss)
        ss = ""
    else:
        ss += S[i]
answer = 0
for s in s_list:
    answer += count(s)
print(int(answer))

Submission status: Time Limit Exceeded

Solution code:
S=input()
c=0
for i in range(0,len(S)+1):
  c1=0
  c2=0
  for j in range(0,i):
    if S[i-j-1]=='<':
      c1+=1
    else:
      break
  for j in range(i,len(S)):
    if S[j]=='>':
      c2+=1
    else:
      break
  if c1<c2:
    c+=c2
  else:
    c+=c1
print(c)

Submission status: Time Limit Exceeded

Solution code:
S = input()

A = [0]

for i in range(len(S)):
    if S[i] == '<':
        A.append(A[i]+1)
    else:
        A.append(0)
    if A[i+1] < 0:
        A[i+1] += 1
    for j in reversed(range(i+1)):
        if S[j] == '<':
            if A[j] >= A[j+1]:
                A[j]-=1
        elif S[j] == '>':
            if A[j] <= A[j+1]:
                A[j]+=1

print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    S = list(input())
    a = []
    for i in range(0, len(S) + 1):
        a.append(0)
    
    while True:
        change_count = 0
        for i in range(0, len(S)):
            if S[i] == '<' and a[i] >= a[i + 1]:
                a[i + 1] = a[i] + 1
                change_count += 1
            elif S[i] == '>' and a[i] <= a[i + 1]:
                a[i] += 1
                change_count += 1
        if change_count == 0:
            total = 0
            for i in range(0, len(a)):
                total += a[i]
            print(total)
            sys.exit()

main()

Submission status: Accepted

Solution code:
import sys

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

count = 0
for i in a:
    count += i
print(count)

Submission status: Accepted

Solution code:
# coding: utf-8

def main():
    S = list(input())
    N = len(S)
    A = [0] * (N + 1)
    ans = 0

    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] == '>':
            if A[i] <= A[i + 1]:
                A[i] = A[i + 1] + 1

    ans = sum(A)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
S = input()
S = S.replace('><', '>,<').split(',')
ans = 0
for w in S:
    a = w.count('<')
    b = w.count('>')
    mx = max(a, b)
    mn = min(a, b)
    ans += mx * (mx + 1) // 2 + (mn - 1) * mn // 2
print(ans)

Submission status: Accepted

Solution code:

s = str(input())
l = []
t = 0
for i in range(1,len(s)):
    if s[i] != s[i-1]:
        l.append(s[t:i])
        t = i
else:
    l.append(s[t:len(s)])


def calc(n):
    tmp = 0
    for i in range(1,n+1):
        tmp += i
    return tmp

left = 0
right = 0
ans = 0

for i,sg in enumerate(l):
    if sg[0]=='>':
        if left < len(sg):
            ans -= left
            ans += calc(len(sg))
        else:
            ans += calc(len(sg)-1)
    else:
        ans += calc(len(sg))
        left = len(sg)

print(ans)

Submission status: Accepted

Solution code:
S = input()
f = 0
x = 0
y = 0
Y = []
for i in range(len(S)):
  if S[i] == ">":
    if f == 1:
      y += 1
    elif f == 0:
      x = y
      y = 1
      f = 1
  else:
    if f == 0:
      y += 1
    else:
      Y.append([x, y])
      x = 0
      y = 1
      f = 0
if f == 0:
  Y.append([y, 0])
else:
  Y.append([x, y])
      
ans = 0
for y in Y:
  M = max(y)
  m = min(y)
  ans += (M * (M+1) // 2 + m * (m-1) // 2)
print(ans)

Submission status: Accepted

Solution code:
s=input()
l=[]
i=0
while i<len(s):
  k=0
  while s[i]=='<' if i<len(s) else False:
    k+=1
    i+=1
  if k>0:
    l.append(k)
  k=0
  while s[i]=='>' if i<len(s) else False:
    k+=1
    i+=1
  if k>0:
    l.append(k)
sm=0
for i in l:
  sm+=(i*(i+1))//2
for i in range(0 if s[0]=='<' else 1,len(l)-1,2):
  sm-=min(l[i],l[i+1])
 
  
print(sm)

Submission status: Accepted

Solution code:
#!/usr/local/bin/python3
# https://atcoder.jp/contests/agc040/tasks/agc040_a

ans = 0
S = input().replace('><', '>,<').split(',')
for s in S:
    n = s.count('<')
    m = s.count('>')
    ans += (n*(n-1))//2 + (m*(m-1))//2 + max(n, m)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())

n = len(s)

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


R = [0]*(n+1)
cnt = 0
for i in reversed(range(n)):
    if s[i] == '>':
        cnt += 1
    else:
        cnt = 0
    R[i] = cnt

A = [0]*(n+1)
for i in range(n+1):
    A[i] = max(L[i], R[i])
print(sum(A))

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
S = input()
n = len(S)
lis = [0] * (len(S)+1)
for i in range(n):
    if S[i] == '<':
        lis[i+1] = max(lis[i+1],lis[i] + 1)
for i in range(n-1,-1,-1):
    if S[i] == '>':
        lis[i] = max(lis[i], lis[i+1]+1)
print(sum(lis))

Submission status: Accepted

Solution code:
S = list(input().replace("><", ">,<").split(","))
ans = 0
for s in S:
    n = s.count("<")
    m = s.count(">")
    ans += (n * (n - 1)) // 2 + (m * (m - 1)) // 2 + max(n, m)
print(ans)

Submission status: Accepted

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

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

def input_int_map():
    return(map(int,input().split()))

def run():
    S = list(input())

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

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

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

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

    ans = [0] * (len(S) + 1)
    for i in range(len(S) + 1):
        ans[i] = max(left[i], right[i])
    print(sum(ans))

run()

Submission status: Accepted

Solution code:
S = input().replace("><", ">,<").split(",")
ans = 0
for s in S:
    n = s.count("<")
    m = s.count(">")
    ans += (n * (n - 1)) // 2 + (m * (m - 1)) // 2 + max(n, m)
print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
S = S.replace("><", ">,<").split(",")
for s in S:
  a = s.count(">")
  b = s.count("<")
  ans += a * (a - 1) // 2 + b * (b - 1) // 2 + max(a, b)
print(ans)

Submission status: Accepted

Solution code:
S = input().strip()
N = len(S)+1
A = [0 for _ in range(N)]
flag = -1
B = []
for i in range(N-1):
    if flag==-1 and S[i]=="<":
        B.append(i)
        flag = 1
    elif flag==1 and S[i]==">":
        flag = -1
if flag==-1:
    B.append(N-1)
for b in B:
    for i in range(b,N-1):
        if S[i]=="<":
            A[i+1] = max(A[i+1],A[i]+1)
        else:break
    for i in range(b-1,-1,-1):
        if S[i]==">":
            A[i] = max(A[i],A[i+1]+1)
        else:break
print(sum(A))

Submission status: Accepted

Solution code:
s = input()
N = len(s)+1
res = []
ans = 0
i = 0
while i < N-1:
    seq = 1
    while i < N - 2 and s[i] == s[i + 1]:
        i += 1
        seq += 1
    res.append(seq)
    i += 1

if s[0] == '>':
    ans += res[0] * (res[0] + 1) // 2
    res = res[1:]
if s[-1] == '<':
    ans += res[-1] * (res[-1]+1)//2
    res = res[:-1]

for i in range(len(res) // 2):
    tmp = max(res[2 * i], res[2 * i + 1])
    tmp2 = min(res[2 * i], res[2 * i + 1])
    ans += tmp * (tmp + 1) // 2
    ans += tmp2 * (tmp2-1) //2
print(ans)

Submission status: Accepted

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

for i in range(len(s)):
    if s[i] == '<':
        al[i+1] = max(al[i]+1, al[i+1])

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

print(sum(al))

Submission status: Accepted

Solution code:
S = input().replace("><", "> <").split()
ans = 0
for s in S:
    up = s.count("<")
    down = len(s) - up
    if up < down: 
        up -= 1
        ans += up * (up+1) // 2 + down * (down+1) // 2
    else:
        down -= 1
        ans += up * (up+1) // 2 + down * (down+1) // 2
print(ans)

Submission status: Accepted

Solution code:
s = input()

def addAll(end):
  return (end * (end + 1)) // 2

total = 0
index = 0

while len(s) > index:
  leftCount = 0
  rightCount = 0
  while len(s) > index and s[index] == "<":
    leftCount += 1
    index += 1
  while len(s) > index and s[index] == ">":
    rightCount += 1
    index += 1
  maxCount = max(leftCount, rightCount)
  minCount = min(leftCount, rightCount)
  total += addAll(maxCount) + addAll(max(minCount - 1, 0))

print(total)

Submission status: Accepted

Solution code:
s = input()

l = [0]
for c in s:
    if c == "<":
        l.append(l[-1]+1)
    else:
        l.append(0)

r = [0]
for c in s[::-1]:
    if c == ">":
        r.append(r[-1]+1)
    else:
        r.append(0)

ans = 0
for a, b in zip(l, r[::-1]):
    ans += max(a, b)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def renketu(base,a,b):
    if base == 1:
        b.reverse()
    max_ = max(a[-1],b[0])
    a.pop(-1)
    b[0] = max_
    a.extend(b)
    return a,b
    
s = [*input()]
if len(s) == 1:
    print(1)
    exit()
hugo = ["<", ">"]
a = [0]
b = []
base = -1
for i in range(len(s) - 1):
    if base == -1: #一番最初
        base = hugo.index(s[i])
        b = [0,1]
    elif base != hugo.index(s[i]): #符号が切り替わった時
        #前グループの処理
        a,b = renketu(base,a,b)
        #新しい処理
        b = [0,1]
        base = hugo.index(s[i])
    else: #同じ符号が続いてる時
        b.append(b[-1] + 1) 
if hugo.index(s[-1]) == base: #一番ラストの符号
    b.append(b[-1] + 1)
    a,b = renketu(base,a,b)
else:
    #前グループの処理
    a,b = renketu(base,a,b)
    #今回の処理
    if hugo.index(s[-1]) == 1:
        b = [1,0]
    else:
        b = [0,1]
    max_ = max(a[-1],b[0])
    b[0] = max_
    a.pop(-1)
    a.extend(b)
    
print(sum(a))

Submission status: Accepted

Solution code:
s = [*input()]
if len(s) == 1:
    print(1)
    exit()
hugo = ["<", ">"]
a = [0]
b = []
base = -1
for i in range(len(s) - 1):
    if base == -1: #一番最初
        base = hugo.index(s[i])
        b = [0,1]
    elif base != hugo.index(s[i]): #符号が切り替わった時
        #前グループの処理
        if base == 1:
            b.reverse()
        max_ = max(a[-1],b[0])
        a.pop(-1)
        b[0] = max_
        a.extend(b)
        #新しい処理
        b = [0,1]
        base = hugo.index(s[i])
    else: #同じ符号が続いてる時
        b.append(b[-1] + 1) 
if hugo.index(s[-1]) == base: #一番ラストの符号
    b.append(b[-1] + 1)
    if base == 1:
        b.reverse()
    max_ = max(a[-1],b[0])
    b[0] = max_
    a.pop(-1)
    a.extend(b)    
else:
    #前グループの処理
    if base == 1:
        b.reverse()
    max_ = max(a[-1],b[0])
    b[0] = max_
    a.pop(-1)
    a.extend(b)
    
    #今回の処理
    if hugo.index(s[-1]) == 1:
        b = [1,0]
    else:
        b = [0,1]
    max_ = max(a[-1],b[0])
    b[0] = max_
    a.pop(-1)
    a.extend(b)
    
print(sum(a))

Submission status: Accepted

Solution code:
S = list(input())
before = 0
last_upper = -1
count = 0
answer = 0
for i, s in enumerate(S):
  # print(answer, i, before, last_upper)
  if s == '<':
    if before < 0 and last_upper < i-1:
      answer += abs(before)*(i-last_upper)
      before = 0
    elif before > 0 and last_upper < i-1:
      answer -= before*(i-last_upper-1)
      before = 0
    before += 1
    answer += before
    last_upper = i
  else:
    before -= 1
    answer += before
# print(answer, before, last_upper)
if before < 0:
  answer += abs(before)*(len(S)-last_upper)
elif before > 0:
  answer -= before*(len(S)-last_upper-1)
print(answer)

Submission status: Accepted

Solution code:
s = input()
n = len(s) #length s
aa = ['.'] * (n + 1)

if s[0] == '<':
  aa[0] = 0
if s[-1] == '>':
  aa[-1] = 0

for i in range(n-1):
  if s[i] ==  '>' and s[i+1] == '<':
    aa[i+1] = 0 
  elif s[i] == '<' and s[i+1] == '>':
    aa[i+1] = n
    
z = [i for i,x in enumerate(aa) if x == 0]
m = [i for i, x in enumerate(aa) if x == n]


for i in range(len(z)-1):
  aa[m[i]] = max(m[i]-z[i], z[i+1]-m[i])
  aa[m[i]+1] = z[i+1]-m[i]-1
  for j in range(z[i]+1, m[i]):
    aa[j] = aa[j-1] +1
  for k in range(m[i]+2,z[i+1]):
    
    aa[k] = aa[k-1]-1
for i in range(z[-1], n+1):
  if aa[i] == '.':
    aa[i] = aa[i-1]+1
for i in range(z[0]):
  if aa[i] == '.':
    aa[i] = z[0] - i
    

print(sum(aa))

Submission status: Accepted

Solution code:
s = input()
n = len(s) #length s
aa = ['.'] * (n + 1)

if s[0] == '<':
  aa[0] = 0
if s[-1] == '>':
  aa[-1] = 0

for i in range(n-1):
  if s[i] ==  '>' and s[i+1] == '<':
    aa[i+1] = 0 
  elif s[i] == '<' and s[i+1] == '>':
    aa[i+1] = n
    
z = [i for i,x in enumerate(aa) if x == 0]
m = [i for i, x in enumerate(aa) if x == n]


for i in range(len(z)-1):
  aa[m[i]] = max(m[i]-z[i], z[i+1]-m[i])
  aa[m[i]+1] = z[i+1]-m[i]-1
  for j in range(z[i]+1, m[i]):
    aa[j] = aa[j-1] +1
  for k in range(m[i]+2,z[i+1]):
    
    aa[k] = aa[k-1]-1
for i in range(z[-1], n+1):
  if aa[i] == '.':
    aa[i] = aa[i-1]+1
for i in range(z[0]):
  if aa[i] == '.':
    aa[i] = z[0] - i
    

print(sum(aa))

Submission status: Accepted

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

s = input().strip()
n = len(s) + 1

ans = [[0, 0] for _ in range(n)]
# 左に連続する<
for i in range(1, n):
    if s[i-1] == '<':
        ans[i][0] = ans[i-1][0] + 1
# 右に連続する>
for i in range(0, n-1):
    if s[n-2-i] == '>':
        ans[n-2-i][1] = ans[n-1-i][1] + 1
print(sum(max(i) for i in ans))

Submission status: Accepted

Solution code:
S = input()

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

for i in range(len(S)):
    if S[i] == "<":
        ans[i+1] = max(ans[i+1], ans[i]+1)
    
for i in range(len(S)):
    i = len(S)-1 - i
    if S[i] == ">":
        ans[i] = max(ans[i],ans[i+1]+1)

print(sum(ans))

Submission status: Accepted

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

s = list(map(lambda x : 1 if x == '<' else -1, input()))
l = [s[0]]
for c in s[1:]:
    if c * l[-1] > 0:
        l[-1] += c
    else:
        l.append(c)
ans = 0
now = 0
for c in l:
    if c < 0:
        ans -= min(now, abs(c))
    ans += sigma(abs(c))
    now = abs(c)
print(ans)

Submission status: Accepted

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

print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(sum(a))

Submission status: Accepted

Solution code:
s=input()+"<"; n=len(s)
# print(s,n)
bef=-1 ;ans=0 ;i=0
while i<n:
    
    if s[i]=="<":
        ans+=bef+1
        bef+=1
        i+=1
    else:
        cnt=0
        for j in range(i,n):
            if s[j]==">":
                ans+=cnt
                cnt+=1
            else:
                ans+=cnt
                break
        ans+= max(0, bef+1-cnt)
        bef=0
        i+= cnt +1
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

S=tuple(input().strip())
N=len(S)+1
sets = []
count = 0

for c in S:
    d = 1 if c == '<' else -1
    if count * d < 0:
        sets.append(count)
        count = d
    else:
        count += d
sets.append(count)

sum = 0
for i in range(len(sets)):
    k=sets[i]
    if k > 0:
        sum += (k*(k+1))//2
    else:
        sum += (k*(k-1))//2
        if i > 0:
            sum -= min(sets[i-1], -k)

print(sum)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
L=[0]
R=[0]
cnt = 0

for i in range(n):
    if s[i] == '<':
        cnt += 1
    else:
        cnt = 0
    L.append(cnt)
cnt = 0
s = s[::-1]
for i in range(n):
    if s[i]  == '>':
        cnt += 1
    else:
        cnt = 0
    R.append(cnt)

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

print(ans)

Submission status: Accepted

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

l=[0 for i in range(sl+1)]
for i in range(sl):
    if s[i]=='<':
        l[i+1]=max(l[i]+1, l[i+1])

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

print(sum(l))

Submission status: Accepted

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

l=[0 for i in range(sl+1)]
for i in range(sl):
    if s[i]=='<':
        l[i+1]=max(l[i]+1, l[i+1])

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

print(sum(l))

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    s = S()
    
    llst = [0 for _ in range(len(s)+2)]
    rlst = [0 for _ in range(len(s)+2)]

    for i in range(1, len(s)+1):
        if s[i-1] == "<":
            llst[i] = llst[i-1] + 1
    
    for i in range(len(s)-1, -1, -1):
        if s[i] == ">":
            rlst[i] = rlst[i+1] + 1
    
    ans = 0

    for i in range(len(s)+1):
        ans += max(llst[i], rlst[i])

    print(ans)

main()

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    s = S()
    s = s.split("><")
    ans_lst = []

    for part in s:
        lnum = part.count("<")
        rnum = part.count(">")      
        ans_lst.append(lnum*(lnum+1)//2 + rnum*(rnum+1)//2 + max(lnum,rnum)+1)


    if len(s) == 1:
        lnum = s[0].count("<") -1
        rnum = s[0].count(">") -1
        ans_lst[0] = lnum*(lnum+1)//2 + rnum*(rnum+1)//2 + max(lnum,rnum)+1
    else:
        lnum = s[0].count("<") -1
        rnum = s[0].count(">")
        ans_lst[0] = lnum*(lnum+1)//2 + rnum*(rnum+1)//2 + max(lnum,rnum)+1

        lnum = s[-1].count("<")
        rnum = s[-1].count(">") -1
        ans_lst[-1] = lnum*(lnum+1)//2 + rnum*(rnum+1)//2 + max(lnum,rnum)+1

    ans = sum(ans_lst)
    print(ans)

main()

Submission status: Accepted

Solution code:
import sys
import copy
import math
import itertools
import numpy as np
S=input()
N = len(S)+1
a = [0]*N
b = [0]*N
for i in range(N-1):
    if S[i]=="<":
        a[i+1]=a[i]+1

for i in reversed(range(N-1)):
    if S[i]==">":
        b[i]=b[i+1]+1

for i in range(N):
    if a[i] < b[i]:
        a[i]=b[i]

print(sum(a))

Submission status: Accepted

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