Problem:


Score : 300 points

Problem Statement

Given is a string S of length N-1.
Each character in S is < or >.

A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be good when the following condition is satisfied for all i (1 \leq i \leq N-1):

If S_i= <: a_i<a_{i+1}

If S_i= >: a_i>a_{i+1}

Find the minimum possible sum of the elements of a good sequence of N non-negative integers.

Constraints

2 \leq N \leq 5 \times 10^5

S is a string of length N-1 consisting of < and >.

Input

Input is given from Standard Input in the following format:

S

Output

Find the minimum possible sum of the elements of a good sequence of N non-negative integers.

Sample Input 1

<>>

Sample Output 1

3

a=(0,2,1,0) is a good sequence whose sum is 3.
There is no good sequence whose sum is less than 3.

Sample Input 2

<>>><<><<<<<>>><

Sample Output 2

28



Sample input:
<>>


Sample output:
3

Submission status: Accepted

Solution code:
s = input()
n = len(s)
box = []

l = 1
for i in range(n-1):
    if s[i+1] == s[i]:
        l += 1
    else:
        box.append(l)
        l = 1
box.append(l)

def sum_(a):
    return (a+1) * a // 2

ans = 0
if s[0] == '>':
    ans += sum_(box[0])
    if (len(box)-1) % 2 == 1:
        ans += sum_(box[-1])
        for i in range(1, len(box)-1, 2):
            if box[i+1] >= box[i]:
                ans += sum_(box[i+1]) + sum_(box[i]-1)
            else:
                ans += sum_(box[i]) + sum_(box[i+1]-1)
    else:
        for i in range(1, len(box)-1, 2):
            if box[i+1] >= box[i]:
                ans += sum_(box[i+1]) + sum_(box[i]-1)
            else:
                ans += sum_(box[i]) + sum_(box[i+1]-1)
else:
    if len(box) % 2 == 1:
        ans += sum_(box[-1])
        for i in range(0, len(box) - 1, 2):
            if box[i + 1] >= box[i]:
                ans += sum_(box[i + 1]) + sum_(box[i] - 1)
            else:
                ans += sum_(box[i]) + sum_(box[i + 1] - 1)
    else:
        for i in range(0, len(box) - 1, 2):
            if box[i + 1] >= box[i]:
                ans += sum_(box[i + 1]) + sum_(box[i] - 1)
            else:
                ans += sum_(box[i]) + sum_(box[i + 1] - 1)

print(ans)

Submission status: Accepted

Solution code:
S = input()
n = len(S) + 1
S_ = ">" + S + "<"
A = [0 for _ in range(n)]
B = [0 for _ in range(n)]
for i in range(1, n):
    if S_[i] == "<":
        A[i] = A[i-1] + 1
for i in range(2, n+1):
    if S_[-i] == ">":
        B[-i] = B[-i+1] + 1
ans = 0
for i in range(n):
    ans += max(A[i], B[i])
print(ans)

Submission status: Accepted

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

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

ae = [0] * n
for j in range(n - 2, -1, -1):
    if s[j] == '>':
        ae[j] = ae[j + 1] + 1
    else:
        ae[j] = 0

print(sum([max(aw[i], ae[i]) for i in range(n)]))

Submission status: Accepted

Solution code:
S = input()

prev = S[0]
start = 0
ans = [0]
for i in range(len(S)):
    if S[i]==prev:
        if S[i]=="<":
            ans.append(ans[-1]+1)
        else:
            ans.append(ans[-1]-1)
    else:
        #print(ans)
        if prev==">":
            for j in range(start,i+1):
                if j==start:
                    ans[start] = max(ans[start],ans[start]-ans[-1])
                else:
                    ans[j]-=ans[-1]
        start = i
        prev = S[i]
        if S[i]=="<":
            ans.append(ans[-1]+1)
        else:
            ans.append(ans[-1]-1)

if prev==">":
    for j in range(start,len(S)+1):
        if j==start:
            ans[start] = max(ans[start],ans[start]-ans[-1])
        else:
            ans[j]-=ans[-1]


print(sum(ans))

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
 
def main():
    s = input().strip()
    # tmp = 0
    # mx = 0
    # for ch in s:
    #     if ch == ">"
    #         tmp -= 1
    #     else:
    #         tmp += 1
    #
    #     if abs(tmp) > mx:
    #         mx = abs(tmp)
    #
    fwd = [0]
    rev = [0]
    tmp = 0
    mn = 0
    for ch in s:
        # print(ch)
        if ch == "<":
            tmp += 1
        else:
            tmp = 0
        fwd.append(tmp)
 
    for ch in s[::-1]:
        # print(ch)
        if ch == ">":
            tmp += 1
        else:
            tmp = 0
        rev.append(tmp)
    rev.reverse()
    # print(fwd, rev)
    print(sum([max(i, j) for i, j in zip(fwd, rev)]))
 
    #     if mn > tmp:
    #         mn = tmp
    #     print(tmp)
    #
    # ans = 0
    # print(mn)
    # ttmp = max(0, -mn)
    # for ch in s:
    #     ans += ttmp
    #     if ch == ">":
    #         ttmp -= 1
    #     else:
    #         ttmp += 1
    #
    # print(ans)
    return
 
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
ans = 0
now = s[0]
MAX = 1
n = 1
for i in s[1:]:
  if now != i:
    if i == ">":
      ans += n*(n-1)//2
      MAX = n
    else:
      ans += n*(n-1)//2 + max(MAX,n)
      MAX = 1
    n = 1
    now = i
  else:
    n += 1

MAX = max(MAX,n)
ans += n*(n-1)//2 + max(MAX,n)
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)+1
A = [None]*n
flag = False
for i in range(n-1):
    if i==0 and s[i]=='<':
        A[0]=0
    elif 1<=i<=n-2 and s[i-1]=='>' and s[i]=='<':
        A[i]=0
    elif i==n-2 and s[i]=='>':
        A[n-1]=0
for i in range(n-1):
    if A[i]==0:
        flag = True
    if flag and s[i]=='<':
        A[i+1] = A[i]+1
    if flag and s[i]=='>':
        flag = False
for i in range(n-1):
    if A[-1-i]==0:
        flag = True
    if flag and s[-1-i]=='>':
        if A[-2-i] == None:
            A[-2-i] = A[-1-i]+1
        else:
            A[-2-i] = max(A[-2-i],A[-1-i]+1)
    if flag and s[-1-i]=='<':
        flag = False
print(sum(A))

Submission status: Accepted

Solution code:
import itertools
import re
s = input()
pattern = "<+|>+"
result = re.finditer(pattern, s)

lis_list = []
for res in result:
  tmp = res.group()
  #print(tmp)
  if tmp[0]=="<":
    lis = list(range(len(res.group())+1))
  else:
    lis = list(reversed(list(range(len(res.group())+1))))

  lis_list.append(lis)

#print(lis_list)

for i in range(len(lis_list)-1):
  if lis_list[i][-1]<lis_list[i+1][0]:
    lis_list[i] = lis_list[i][:-1]
  else:
    lis_list[i+1] = lis_list[i+1][1:]
#print(lis_list)
all = list(itertools.chain.from_iterable(lis_list))
print(sum(all))

Submission status: Accepted

Solution code:
s=input()
s=s+"X"
lists=[]
counter=1
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        counter+=1
    else:
        lists.append(counter)
        counter=1
n=len(lists)
if s[0]=="<" and s[-2]=="<":
    lists.append(1)
    
elif s[0]=="<" and s[-2]==">":
    pass
    
elif s[0]==">" and s[-2]=="<":
    lists.insert(0,1)
    lists.append(1)
    
elif s[0]==">" and s[-2]==">":
    lists.insert(0,1)
    
k=len(lists)//2
ans=0
for i in range(k):
    a=lists[i*2]
    b=lists[i*2+1]
    maxi=max(a,b)
    mini=min(a,b)
    ans+=maxi*(maxi+1)//2+mini*(mini-1)//2
print(ans)

Submission status: Accepted

Solution code:
from itertools import groupby
s=input()
if s[0]=='>':
  s='<'+s
g=groupby(s)
a=[]
for i,j in g:
  a.append(len(list(j)))
def sum(n):
  return n*(n+1)//2
x=0
if len(a)%2==1:
  a+=[1]
for i in range(0,len(a),2):
  x+=sum(min(a[i],a[i+1])-1)
  x+=sum(max(a[i],a[i+1]))
print(x)

Submission status: Accepted

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

now=0
chi=0
swit=0
kao=[]
if s[0]=='<':
    kao.append(0)

for i in range(ng):
    if s[i]=='>':
        swit=1
    else:
        if swit==1:
            kao.append(i)
        swit=0

if s[-1]=='>':
    kao.append(ng)


kaz=[-1]*(ng+1)
for k in kao:
    kaz[k]=0

for i in range(len(kao)):
    swit=0
    ima=kao[i]
    while swit==0:
        if ima+1<len(kaz):
            if s[ima]=='<':
                kaz[ima+1]=kaz[ima]+1
                ima+=1
            else:
                swit=1
        else:
            swit=1

for i in range(len(kao)):
    swit=0
    ima=kao[i]-1
    loop=0
    while swit==0:
        loop+=1
        if ima>=0:
            if s[ima]=='>':
                if kaz[ima]<kaz[ima+1]+1:
                    kaz[ima]=kaz[ima+1]+1
                ima-=1
            else:
                swit=1
        else:
            swit=1

print(sum(kaz))

Submission status: Accepted

Solution code:
s = list(input())
l_ans = [0 for _ in range(len(s)+1)]
r_ans = [0 for _ in range(len(s)+1)]
ans = [0 for _ in range(len(s)+1)]
l_level = 0
r_level = 0
for i in range(len(s)):
    if s[i] == '<':
        l_level += 1
    else:
        l_level = 0
    l_ans[i+1] = l_level

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

for i in range(len(ans)):
    ans[i] = max(l_ans[i], r_ans[i])
# print(ans,sum(ans))
# print(l_ans,r_ans)
print(sum(ans))

Submission status: Accepted

Solution code:
#!/usr/bin/python3

import array
import math
import os
import sys


def main():
    S = inp()
    print(solve(S))


def solve(S):
    N = len(S) + 1
    A = [-1] * N

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

    for i in range(N):
        if A[i] != 0:
            continue

        j = i - 1
        while j >= 0 and S[j] == '>':
            A[j] = max(A[j], A[j + 1] + 1)
            j -= 1

        j = i + 1
        while j < N and S[j - 1] == '<':
            A[j] = max(A[j], A[j - 1] + 1)
            j += 1

    dprint(A)
    return sum(A)


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


def rle(s):
    import itertools
    return list(map(lambda x: (x[0], len(list(x[1]))), itertools.groupby(s)))


s = rs()
ss = rle(s)
res = 0
index = 0
if ss[0][0] == '>':
    x = ss[0][1]
    res += x * (x + 1) // 2
    index = 1
for xx, yy in zip(ss[index::2], ss[index + 1::2]):
    x = xx[1]
    y = yy[1]
    z = max(x, y)
    w = min(x, y) - 1
    res += z * (z + 1) // 2 + w * (w + 1) // 2
if ss[-1][0] == '<':
    x = ss[-1][1]
    res += x * (x + 1) // 2
print(res)

Submission status: Accepted

Solution code:
S = input()

nums = []

cnt = 1
pre = S[0]

for i in range(1, len(S)):
    if pre != S[i]:
        nums.append(cnt)
        pre = S[i]
        cnt = 1
    else:
        cnt += 1

nums.append(cnt)

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


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

ans = 0
for i in range(len(nums) // 2):
    max_ = max(nums[2 * i], nums[2 * i+1])
    min_ = min(nums[2 * i], nums[2 * i+1])
    ans += cal_sum(max_)
    ans += cal_sum(min_ - 1)

print(ans)

Submission status: Accepted

Solution code:
s=input()
c,d,e,f=0,0,0,0
for i in s:
    if i=="<":
        if e==0:
            c+=1
        else:
            e=0
            c,d=max(c,d),min(c,d)
            f+=(c*(c+1))//2+(d*(d-1))//2
            c,d=1,0
    else:
        e=1
        d+=1
c,d=max(c,d),min(c,d)
print(f+(c*(c+1))//2+(d*(d-1))//2)

Submission status: Accepted

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

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

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

s = 0
for n in ns:
    s += n

print(s)

Submission status: Accepted

Solution code:
def main():
    s=list(input())
    key=0
    key2=0
    cnt1=0
    cnt2=0
    ans=0
    for i in range(len(s)):
        if key==0 and s[i]=="<":
            cnt1+=1
            key2=1
        elif key==0 and s[i]==">":
            key=1
            cnt2+=1
            key2=0
        elif key==1 and s[i]==">":
            cnt2+=1
            key2=0
        elif key==1 and s[i]=="<":
            M=max(cnt1,cnt2)
            m=min(cnt1,cnt2)
            ans+= (( M * (M+1) )//2 ) + (( m * (m-1) ) //2 )
            key=0
            key2=1
            cnt1=1
            cnt2=0
    if key==1:
        M=max(cnt1,cnt2)
        m=min(cnt1,cnt2)
        ans+= (( M * (M+1) )//2 ) + (( m * (m-1) ) //2 )
    if key2==1:
        ans+=(cnt1*(cnt1+1))//2
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from itertools import groupby
    s=input()
    if(s[0]==">"):
        s="<"+s
    if(s[-1]=="<"):
        s=s+">"
    G=groupby(s)
    ans=0
    for i,g in enumerate(G):
        if(i%2==0):
            a=len(list(g[1]))
        else:
            b=len(list(g[1]))
            c=max(a,b)
            ans+=a*(a-1)//2+b*(b-1)//2+c
    print(ans)
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

S = input()
now = 0
ans = 0
las = ""
lasstr = 0

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

for i in range(len(S)):

    if S[i] == "<":
        lis[i+1] = max(lis[i+1],lis[i]+1)

#print (lis)

for i in range(len(S)):

    i = len(S)-1 - i

    if S[i] == ">":
        lis[i] = max(lis[i],lis[i+1]+1)

#print (lis)
print (sum(lis))

Submission status: Accepted

Solution code:
s=input()
n=len(s)-1
cut =[-1]+ [i for i in range(len(s)-1) if s[i:i+2]=="><" ] + [n]
div = [s[cut[i]+1:cut[i+1]+1] for i in range(len(cut)-1)]
ans=0
for d in div:
    sr = d.count("<")
    sl = d.count(">")
    smax=max(sr,sl)
    smin=min(sr,sl)
    ans+=smax*(smax+1)//2 + smin*(smin-1)//2
print(ans)

Submission status: Accepted

Solution code:
s = input()
if s[0] == '>':
  s = '<' + s
if s[-1] == '<':
  s = s + '>'
feat = []
combo = 1
n = len(s)
for i in range(1,n):
  if s[i-1] == s[i]:
    combo += 1
  else:
    feat.append(combo)
    combo = 1
feat.append(combo)
#print(feat)
m = len(feat)
ans = 0
for i in range(m):
  ans += feat[i] * (feat[i]-1) // 2
for j in range(m//2):
  ans += max( feat[2*j] , feat[2*j+1] )
print(ans)

Submission status: Accepted

Solution code:
# import sys
# input = sys.stdin.readline
s = input()
n = len(s)
ans = 0
t = 0
d = 0
m=0
for i in range(n):
    if s[i] == "<":
        d = 0
        t += 1
        ans += t
    else:
        if d==0:
            m = t
        t = 0
        d += 1
        ans += d-1
        if d-1 >= m:
            ans +=1
    # print(t,d,m,ans)
            
print(ans)

Submission status: Accepted

Solution code:
S = list(input())

a = "<"
b = ">"

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

L = len(S)
t = 0

bc = 0
if S[0] == b:
  bc = 0
  for i in range(L):
    if S[i] == b:
      bc += 1
    else:
      t = i
      break
  else:
    print(nasu(bc))
    exit()
      
ans = nasu(bc)
bc = 0
ac = 0
f = True

while t < L:
  if f:
    if S[t] == a:
      ac += 1
    else:
      bc += 1
      f = False
  else:
    if S[t] == b:
      bc += 1
    else:
      if ac > bc:
        ac, bc = bc, ac
      ans += nasu(ac - 1) + nasu(bc)
      ac = 1
      bc = 0
      f = True
  t += 1

if bc != 0:
  if ac > bc:
    ac, bc = bc, ac
  ans += nasu(ac - 1) + nasu(bc)
else:
  ans += nasu(ac)

print(ans)

Submission status: Accepted

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

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

ans_r = [-1] * N
ans_r[-1] = 0
combo = 0
for j in range(N - 1):
    i = N - 2 - j
    if S[i] == '>':
        combo += 1
    else:
        combo = 0
    ans_r[i] = combo

# print("#", ans_l)
# print("#", ans_r)
ans = [max(tmp_l, tmp_r) for tmp_l, tmp_r in zip(ans_l, ans_r)]

print(sum(ans))

Submission status: Accepted

Solution code:
def main():
    s = input()
    max_ = 0
    min_ = 0
    cnt = 0
    l=[0]
    for i in range(len(s)):
        if s[i] == "<":
            cnt += 1
        else:
            cnt = 0
        l.append(cnt)
    cnt = 0
    for i in range(len(s),0,-1):
        if s[i-1] == ">":
            cnt += 1
        else:
            cnt = 0
        l[i-1]=max(l[i-1],cnt)
    print(sum(l))
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
a = 0
hoge = -1
v = 0
ans = 0
for i in S:
    if i == "<":
        a += 1
        ans += a
        v = a
        hoge = -1
    else:
        hoge += 1
        a = 0
        if hoge < v:
            ans += hoge
        else:
            ans += hoge+1
print(ans)

Submission status: Accepted

Solution code:
s = ">" + input() + "<"
n = len(s)-1
a = [10**10 for _ in range(n)]

for i in range(n):
	if s[i] == ">" and s[i+1] == "<":
		a[i] = 0

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

#print(a)

for i in range(n-1, 0, -1):
	if s[i] == ">":
		if a[i-1] == 10**10:
			a[i-1] = a[i]+1
		else:
			a[i-1] = max(a[i-1], a[i]+1)

#print(a)

print(sum(a))

Submission status: Accepted

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

S=input().strip()

from collections import deque
Q=deque(S)

ANS=0

count=0
while len(Q)>0 and Q[0]==">":
    count+=1
    Q.popleft()

ANS+=count*(count+1)//2
count=0

while len(Q)>0 and Q[-1]=="<":
    count+=1
    Q.pop()

ANS+=count*(count+1)//2

if Q==deque():
    print(ANS)
    sys.exit()

Q=list(Q)

count=1
LIST=[]

for i in range(1,len(Q)):
    if Q[i]==Q[i-1]:
        count+=1
    else:
        LIST.append(count)
        count=1

LIST.append(count)

for i in range(0,len(LIST),2):
    s,t=sorted((LIST[i],LIST[i+1]))

    ANS+=t*(t+1)//2+s*(s-1)//2

print(ANS)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
INF = 10**9
ans = [INF] * (n+1)


memo = {}
if s[0] == "<":
    ans[0] = 0
    memo[0] = 1 
if s[n-1] == ">":
    ans[n] = 0
    memo[n] = 1
for i in range(n-1):
    if s[i] == ">" and s[i+1] == "<":
        ans[i+1] = 0
        memo[i+1] = 1
        

for i in memo:
    cnt = 1
    tmp = i - 1
    while True:
        if tmp >= 0 and s[tmp] == ">":
            ans[tmp] = cnt
            cnt += 1
            tmp -= 1
        else:
            break
    cnt = 1
    tmp = i
    while True:
        if tmp < n and s[tmp] == "<":
            ans[tmp+1] = cnt
            cnt += 1
            tmp += 1
        else:
            break

for i in range(n-1):
    if s[i] == "<" and s[i+1] == ">":
        ans[i+1] = max(ans[i], ans[i+2]) + 1
print(sum(ans))

Submission status: Accepted

Solution code:
import itertools
s = input()

ans = [0]
si = itertools.groupby(s)
for key, value in si:
    l = len(list(value))

    if key == "<":
        for i in range(1, l+1):
            ans.append(i)
    else:
        if ans[-1] < l:
            ans.pop()
            for i in range(1, l+1):
                ans.append(i)
        else:
            for i in range(1, l):
                ans.append(i)

print(sum(ans))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = S()
    s.insert(0,">")
    n = len(s)
    s.append("<")
    f = [0]*n
    l = []
    for i in range(n):
        if s[i] == ">" and s[i+1] == "<":
            f[i] = 1
            l.append(i)
    ans = [0]*n
    for i in l:
        j = i
        while j < n-1 and not f[j+1] and s[j+1] == "<":
            ans[j+1] = max(ans[j+1],ans[j]+1)
            j += 1
    for i in l:
        j = i
        while j > 0 and not f[j-1] and s[j] == ">":
            ans[j-1] = max(ans[j-1],ans[j]+1)
            j -= 1
    print(sum(ans))
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:

import math
def solve():
  s = input()
  n = len(s) + 1
  que = [0]*n
  que2 = [0]*n
  now = 0
  for i in range(n-1):
    if s[i] == "<":
      que[i+1] = now + 1
      now += 1
    else:
      now = 0
      que[i+1] = now

  s2 = s[::-1]
  now = 0
  for i in range(n-1):
    if s2[i] == ">":
      que2[i+1] = now+1
      now += 1
    else:
      now = 0
      que2[i+1] = now
  que2 = que2[::-1]
  ans = 0
  for i in range(n):
    ans += max(que[i],que2[i])
  print(ans)

solve()

Submission status: Accepted

Solution code:
S=input()
l=len(S)
L1=[0]*(l+1)
L2=[0]*(l+1)
for i in range(l):
    if S[i]=='<':
        L1[i+1]=L1[i]+1
    else:
        L1[i+1]=0
for i in reversed(range(l)):
    if S[i]=='>':
        L2[i]=L2[i+1]+1
    else:
        L2[i]=0
Ans=[0]*(l+1)
for i in range(l+1):
    Ans[i]=max(L1[i],L2[i])
print(sum(Ans))

Submission status: Accepted

Solution code:
S = input()

i = 0
ans = 0
l = r = 0
while i < len(S) and S[i] == '>':
    l += 1
    i += 1
ans += l*(l+1)//2

while i < len(S):
    l = r = 0
    while i < len(S) and S[i] == '<':
        l += 1
        i += 1
    while i < len(S) and S[i] == '>':
        r += 1
        i += 1
    mx,mn = max(l,r),min(l,r)
    ans += mx*(mx+1)//2
    ans += mn*(mn-1)//2
print(ans)

Submission status: Accepted

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

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

for i in range(len(S)):
    
    if S[-i-1] == '>':
        a2[i+1] = a2[i] + 1
    else:
        a2[i+1] = 0

ans = 0
for i in range(len(S) + 1):
    ans += max(a1[i], a2[-i-1])
print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S) + 1
Ans = [0]
a = 0
for c in S:
    if c=="<":
        a += 1
        Ans.append(a)
    else:
        a = 0
        Ans.append(a)

a = 0
for c, i in zip(S[::-1], range(N-2, -1, -1)):
    if c==">":
        a += 1
    else:
        a = 0
    Ans[i] = max(Ans[i], a)

#print(Ans)
print(sum(Ans))

Submission status: Accepted

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

tmp = 1
ens = list(enumerate(s))
for i, c in ens:
    if c == '<':
        ans[i + 1] = tmp
        tmp += 1
    else:
        tmp = 1

tmp = 1
for i, c in reversed(ens):
    if c == '>':
        ans[i] = max(ans[i], tmp)
        tmp += 1
    else:
        tmp = 1
print(sum(ans))

Submission status: Accepted

Solution code:
from itertools import groupby
x = input()
if x[0] == ">":
	x = "<" + x
if x[-1] == "<":
	x += ">"
l = [len(list(g)) for k, g in groupby(x)]
ans = 0
for i, j in zip(*[iter(l)] * 2):
	M = max(i, j)
	m = min(i, j)
	ans += M * (M + 1) // 2 + m * (m - 1) // 2
print(ans)

Submission status: Accepted

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

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

N = len(S)+1

from_left = [0]*N
from_right = [0]*N

for i,s in enumerate(S,1):
    if s == '>':
        from_left[i] = 0
    else:
        from_left[i] = from_left[i-1]+1

for i,s in enumerate(S[::-1]):
    i = N-2-i
    if s == '<':
        from_right[i] = 0
    else:
        from_right[i] = from_right[i+1]+1

seq = [x if x>y else y for x,y in zip(from_left,from_right)]

answer = sum(seq)
print(answer)

Submission status: Accepted

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

A = [0] * N
B = [0] * N

for i in range(1, N):
    if s[i-1] == "<":
        A[i] = A[i-1] + 1
for i in range(N-1)[::-1]:
    if s[i] == ">":
        B[i] = B[i+1] + 1

C = [max(A[i], B[i]) for i in range(N)]
print(sum(C))

Submission status: Accepted

Solution code:
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

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

S = sys.stdin.readline().rstrip()
N = len(S) + 1

ans = np.zeros(N,dtype=int)
cnt = 0
for i, c in enumerate(S, start=1):
    if c == '<':
        cnt += 1
    else:
        cnt = 0
    ans[i] = cnt
for i, c in enumerate(S[::-1], start=1):
    if c == '>':
        cnt += 1
    else:
        cnt = 0
    ans[~i] = max(cnt, ans[~i])
print(ans.sum())

Submission status: Accepted

Solution code:
import os
import sys
from collections import defaultdict as ddic, Counter, deque
from itertools import combinations, permutations, product
import bisect, heapq

FAST_INPUT = 0
if FAST_INPUT:
    from atexit import register
    from io import BytesIO
 
    sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
    sys.stdout = BytesIO()
    register(lambda: os.write(1, sys.stdout.getvalue()))
 
rr = lambda: sys.stdin.readline().rstrip('\r\n')
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
MOD = 10**9 + 7

DEBUG = 0
if DEBUG:
    import random
    random.seed(0)
    ri = random.randint

#####

def solve(N, A):
    ans = [1] * N
    for i in range(N - 1):
        if S[i] == '<':
            ans[i+1] = ans[i] + 1
    
    for i in range(N - 2, -1, -1):
        if S[i] == '>':
            ans[i] = max(ans[i], ans[i+1] + 1)
    #print ans
    return sum(ans) - N
    
#####
S = rr()
N = len(S)
print solve(N+1, S)

Submission status: Runtime Error

Solution code:
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
sm=0
for i in l:
  sm+=(i*(i+1))//2
  
print(sm)

Submission status: Runtime Error

Solution code:
s = [*input()]
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: Runtime Error

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

if s[0] == '<':
  aa[0] = 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
    
id0 = [i for i,x in enumerate(aa) if x == 0]
idm = [i for i, x in enumerate(aa) if x == n]


for i in range(len(id0)-1):
  aa[idm[i]] = max(idm[i]-id0[i], id0[i+1]-idm[i])

for i in range(n):
  if s[i] == '<' and aa[i+1] == '.':
    aa[i+1] = aa[i] + 1
for i in range(n-1, 0,-1):
  if aa[i] == '.' and s[i] == '>':
    aa[i] = aa[i+1] +1

print(sum(aa))

Submission status: Runtime Error

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)):
    if S[-(i+1)] == ">":
        ans[-(i+2)] = max(ans[(i+2)], ans[-(i+1)]+1)
        
print(sum(ans))

Submission status: Runtime Error

Solution code:
s = input()
l = [s[0]]
for c in s[1:]:
    if c in l[-1]:
        l[-1] += c
    else:
        l.append(c)
a = []
now = 0
for c in l:
    if '<' in c:
        if now == 0:

            for i in range(len(c) + 1):
                a.append(i)
        else:
            for i in range(1, len(c) + 1):
                a.append(i)
        now = len(c)
    if '>' in c:
        if now <= len(c):
            a.pop()
            for i in reversed(range(len(c) + 1)):
                a.append(i)
        else:
            for i in reversed(range(len(c))):
                a.append(i)
        now = len(c) + 1
print(sum(a))

Submission status: Runtime Error

Solution code:
s=input()
a=[0]*len(s)
for i in range(len(s)+1):
    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: Runtime Error

Solution code:
s=input()
print(s.count("<"))
print(s.count(">"))
print(len(s))
a=[0]*len(s)
for i in range(len(s)+1):
    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: Runtime Error

Solution code:
s = list(input())
L = 0
R = 0
tmp = []
for i in range(len(s)):
    if s[i] == "<":
        L += 1
    if s[i] == ">":
        R += 1
    if i == len(s)-1:
        if L == 0 or R == 0:
            tmp.append(L)
            tmp.append(R)
            L = 0
            R = 0
            break
        elif L > R:
            tmp.append(L)
            tmp.append(R-1)
            L = 0
            R = 0
            break
        elif L < R:
            tmp.append(L-1)
            tmp.append(R)
            L = 0
            R = 0
            break
    if s[i] == ">" and s[i+1] == "<":
        if L == 0 or R == 0:
            tmp.append(L)
            tmp.append(R)
            L = 0
            R = 0
        elif L > R:
            tmp.append(L)
            tmp.append(R-1)
            L = 0
            R = 0
        elif L < R:
            tmp.append(L-1)
            tmp.append(R)
            L = 0
            R = 0
ans = 0
for i in range(len(tmp)):
    if tmp[i] % 2 == 0:
        ans += (tmp[i] * (tmp[i] + 1) // 2)
    else:
        ans += ((tmp[i] - 1) * ((tmp[i] - 1) + 1) // 2 + tmp[i])
print(ans)