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 numpy as np
s = list(input())

judge = 0
judge_min = 0
base = np.zeros(len(s))
for i in range(len(s)):
  if s[-(i+1)] == ">":
    judge += 1
    base[-(i+1)] = judge
  elif s[-(i+1)] == "<":
    judge = 0

ans = 0
if base[0] > 0:
  ans = base[0]
  temp = base[0]
elif base[0] == 0:
  ans = 0
  temp = 0
  
for i in range(1,len(s)):
  if (s[i-1] == ">") and (s[i] == ">"):
    temp = base[i]
  elif (s[i-1] == "<") and (s[i] == "<"):
    temp += 1
  elif (s[i-1] == ">") and (s[i] == "<"):
    temp = 0
  elif (s[i-1] == "<") and (s[i] == ">"):
    temp += 1
    if temp < base[i]:
      temp = base[i]
      
  ans += temp
  
  if (temp > base[i]) and (s[i] == ">"):
    temp -= 1
  
if s[-1] == "<":
  ans += temp+1

print(int(ans))

Submission status: Accepted

Solution code:
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)


def solve(s):
    start_up = s[0] == "<"
    curr_up = start_up
    counts = [1]
    for c in s[1:]:
        if curr_up == (c == "<"):
            counts[-1] += 1
        else:
            curr_up = not curr_up
            counts.append(1)

    curr_up = start_up
    result = counts[0]*(counts[0]-1)//2
    if not curr_up:
        result += counts[0]
    for i in range(1, len(counts)):
        if curr_up:
            result += max(counts[i-1], counts[i])
        result += counts[i]*(counts[i]-1)//2
        curr_up = not curr_up
    if curr_up:
        result += counts[-1]

    return result


if __name__ == "__main__":
    s = str_in()
    out(solve(s))

Submission status: Accepted

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

ans = 0

cnt0 = 0
if S[0] == ">":
    cnt0 += 1
    j = 1
    while j <= len(S)-1 and S[j] == ">":
        cnt0 += 1
        j += 1
ans += cnt0*(cnt0+1)//2


for i in range(1, N-1):
    if S[i-1] == "<" and S[i] == ">":
        j = i-1
        k = i+1
        cnt1 = 0
        cnt2 = 0
        if S[i-1] == "<" and i >= 0:
            while j >= 0 and S[j] == S[i-1] :
                cnt1 += 1 
                j -= 1
        if S[i] == ">":
            while k <= N-1 and S[i] == S[k-1]:
                cnt2 += 1
                k += 1 
        ans += max(cnt1, cnt2)*(max(cnt1, cnt2)+1)//2
        ans += (min(cnt1, cnt2)-1)*(min(cnt1, cnt2))//2


cntn = 0
if S[-1] == "<":
    cntn += 1
    j = -2
    while j >= -len(S) and S[j] == "<":
        cntn += 1
        j -= 1
ans += cntn*(cntn+1)//2


print(ans)

Submission status: Accepted

Solution code:
def cum(n):
  cum = 0
  for i in range(n+1):
    cum += i
  return cum


s = input()

tmp = s[0]
count = 0
l = []

for each in s:
  if each == tmp:
    count += 1
  else:
    l.append(count)
    count = 1
    tmp = each

l.append(count)

ans = 0
if s[0] == "<":
  for i in range(0,len(l),2):
    tmp = l[i:i+2]
    if len(tmp) == 1:
      ans += cum(tmp[0])
    else:
      ans += cum(max(tmp)) + cum(min(tmp)-1)
else:
  ans += cum(l[0])
  for i in range(1, len(l),2):
    tmp = l[i:i+2]
    if len(tmp) == 1:
      ans += cum(tmp[0])
    else:
      ans += cum(max(tmp)) + cum(min(tmp)-1)

print(ans)

Submission status: Accepted

Solution code:
s = str(input()) + '0'
ans = [0] * (len(s))

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

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

print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

N1 = [0]*(len(S)+1)
N2 = [0]*(len(S)+1)

count1 = 0
count2 = 0

for i in range(len(S)):
  if S[i] == "<":
    count1 += 1
    N1[i+1] = count1
  else:
    count1 = 0
    
for i in range(len(S)):
  if S[-(i+1)] == ">":
    count2 += 1
    N2[-(i+2)] = count2
  else:
    count2 = 0
ans = 0
for i in range(len(N1)):
  ans += max(N1[i],N2[i])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(sum(A))

Submission status: Accepted

Solution code:
S = list(map(str, input().rstrip()))

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

for i, s in enumerate(S):
    if s=="<":
        ans[i+1] = max(ans[i+1], ans[i]+1)

ans = ans[::-1]
S = S[::-1]

for i, s in enumerate(S):
    if s==">":
        ans[i+1] = max(ans[i+1], ans[i]+1)

print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=list(str(input()))
a=[]
b=[]

count = 1
direction=S[0]
for i in range(1,len(S)):
  if S[i]== direction:
    count += 1
  else:
    a.append(S[i-1])
    b.append(count)
    direction=S[i]
    count=1
a.append(S[-1])
b.append(count)
m=max(b)+1
dp=[0]*m
for i in range(1,m):
  dp[i] += dp[i-1]+i
ans=0
for i in range(1,len(a)):
  if a[i-1]=='<' and a[i]=='>':
    ans+=dp[max(b[i-1],b[i])] + dp[min(b[i-1],b[i])-1]
  
if a[0]=='>':
  ans+=dp[b[0]]
if a[-1]=='<':
  ans+=dp[b[-1]]
print(ans)

Submission status: Accepted

Solution code:
# AGC040
# A
# ><
import itertools

s_list = input()

n = len(s_list) + 1
a_list = [0]*n
tmp_list = [0]*n

gr = itertools.groupby(s_list)

idx = 0
_tmp = 0
for key, group in gr:
    _num = sum(1 for _ in group)
    if key == "<":
        a_list[idx:idx+_num+1] = list(range(_num+1))
    else:
        a_list[idx] = max(_tmp,_num)
        a_list[idx+1:idx+_num] = list(range(_num-1,0,-1))
        tmp_list[idx] = _num
    idx += _num
    _tmp = _num

# print(a_list)
# print(tmp_list)
print(sum(a_list))

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    S = input()

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def sigma(x):
    a = 0
    for i in range(x):
        a += i + 1
    return a

s = input()
ans = 0
prev = ''
cnt = 0
p_cnt = 0
for i in s:
    if i == prev:
        cnt += 1
    else:
        if i =='<':
            ans += sigma(cnt - 1) + max(cnt, p_cnt)
        else:
            ans += sigma(cnt - 1)
        prev = i
        p_cnt = cnt
        cnt = 1
else:
    if prev == '<':
        ans += sigma(cnt)
    else:
        ans += sigma(cnt - 1) + max(cnt, p_cnt)
print(ans)

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():  
    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))    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

if s[0] == ">":
	gcnt, lcnt = 0, 1
else:
	gcnt, lcnt = 1, 0
ans = 0

for i in range(lens-1):
	if s[i] == ">":
		if s[i+1] == "<":
			ans += (gcnt*(gcnt-1))//2
			ans += (lcnt*(lcnt-1))//2
			ans += max(gcnt, lcnt)
			gcnt = 1
			lcnt = 0
		else:
			lcnt += 1
	else:
		if s[i+1] == "<":
			gcnt += 1
		else:
			lcnt += 1

ans += (gcnt*(gcnt-1))//2
ans += (lcnt*(lcnt-1))//2
ans += max(gcnt, lcnt)
print(ans)

Submission status: Accepted

Solution code:
def main():
    A = list(input())
    cnt = 0
    nums_right = []
    nums_left = []
    current_right = 0
    current_left = 0
    for a in A:
        nums_right.append(current_right)
        if a == "<":
            current_right += 1
        else:
            current_right = 0
    else:
        nums_right.append(current_right)

    for a_ in A[::-1]:
        nums_left.append(current_left)
        if a_ == ">":
            current_left += 1
        else:
            current_left = 0
    else:
        nums_left.append(current_left)

    nums_left = nums_left[::-1]

    for nr, nl in zip(nums_right, nums_left):
        cnt += max(nr, nl)
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()

x = 0
l = [0] * len(s)
for i in range(len(s)):
    if s[i] == "<":
        x += 1
        l[i] = x
    else:
        x = 0

x = 0
r = [0] * len(s)
for i in range(len(s))[::-1]:
    if s[i] == ">":
        x += 1
        r[i] = x
    else:
        x = 0

ans = l[-1] + r[0]
for i in range(len(s)-1):
    ans += max(l[i], r[i+1])
    
print(ans)

Submission status: Accepted

Solution code:
S = list(map(str, input()))
N = len(S)+1
List = [0]*N
rightcount = 0
leftcount = 0

if S[0] == "<":
    leftcount+=1
else:
    rightcount+=1

for i in range(1, N-1):
    if S[i] == "<":
        leftcount+=1
        if S[i-1] == "<":
            List[i] = List[i-1]+1
        elif S[i-1] == ">":
            for j in range(rightcount):
                List[i-j] = j
            if List[i-rightcount]<=List[i-rightcount+1]:
                List[i-rightcount] = List[i-rightcount+1] + 1
            rightcount = 0


    if S[i] == ">":
        rightcount+=1
        if S[i-1] =="<":
            for j in range(leftcount+1):
                List[i-j] = leftcount - j
            leftcount = 0

if S[N-2] == "<":
    List[N-1] = List[N-2] + 1
else:
    for j in range(rightcount):
        List[N-1-j] = j
    if List[N-1-rightcount]<=List[N-1-rightcount+1]:
        List[N-1-rightcount] = List[N-1-rightcount+1] + 1

print(sum(List))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
n=len(s)
l=[[0,0] for i in range(n+1)]
ri,le=0,0
for i in range(n):
    l[i][0]=le
    l[-1-i][1]=ri
    if "<"==s[i]:le+=1
    else:le=0
    if ">"==s[-1-i]:
        ri+=1
    else:ri=0

l[n][0]=le
l[0][1]=ri
print(sum(max(a,s) for a,s in l))

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

S = input()

S = S.replace("><", ">,<").split(",")

ans = 0
for t in S:
    a = t.count(">")
    b = t.count("<")
    tmp = max(a, b) + sum(range(a)) + sum(range(b))
    ans += tmp
print(ans)

Submission status: Accepted

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

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

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

print(sum(res))

Submission status: Accepted

Solution code:
s = input()

a = [0] * (len(s)+1)

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

for j in range(larger_count+1):
    a[len(a)-j-1] = max(a[len(a)-j-1], j)

print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import itertools
S = input()
RevS = reversed(S)
L = [0]#左の<
R = [0]#右の>
cur = 0
for s in S:
    if s == "<":
        cur += 1
    else:
        cur = 0
    L.append(cur)
cur = 0
for r in RevS:
    if r == ">":
        cur += 1
    else:
        cur = 0
    R.append(cur)
R.reverse()
ans = 0
for n in range(len(S)+1):
    ans += max(L[n],R[n])
print(ans)

Submission status: Accepted

Solution code:
S = input()
S = S.replace('><','>,<').split(',')

ans = 0

for s in S:
    small = s.count('<')
    big = s.count('>')
    tmp = max(small,big)\
        + (max(small,big)-1)*max(small,big)//2\
        + (min(small,big)-1)*min(small,big)//2
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
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)
    else:
        a[i] = max(a[i],a[i+1]+1)

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


print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
num = []
pre = S[0]
cnt = 0
for s in S:
    if s == pre:
        cnt += 1
    else:
        num.append(cnt)
        pre = s
        cnt = 1
num.append(cnt)

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

ans = 0
for i in range(0, len(num), 2):
    b = max(num[i], num[i+1])
    c = min(num[i], num[i+1])
    ans += (b*(b+1))//2 + ((c-1)*c)//2
print(ans)

Submission status: Accepted

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

lr = []
num = []
a = S[0]
cnt = 0
for s in S:
    if s == a:
        cnt += 1
    else:
        num.append(cnt)
        if a == '<':
            lr.append(1)
        else:
            lr.append(0)
        a = s
        cnt = 1
num.append(cnt)
if a == '<':
    lr.append(1)
else:
    lr.append(0)

ans = 0
if (len(lr) == 1 and lr[0] == 0) or (len(lr) > 1 and lr[0] == 0):
    ans += (num[0]*(num[0]+1))//2
    lr, num = lr[1:], num[1:]
if (len(lr) == 1 and lr[0] == 1) or (len(lr) > 1 and lr[-1] == 1):
    ans += (num[-1]*(num[-1]+1))//2
    lr.pop()
    num.pop()

if not lr:
    print(ans)
    exit()

for i in range(0, len(lr), 2):
    if num[i] == num[i+1]:
        b = num[i]
        c = num[i]
    elif num[i] < num[i+1]:
        b = num[i+1]
        c = num[i]
    else:
        b = num[i]
        c = num[i+1]
    ans += (b*(b+1))//2 + ((c-1)*c)//2
print(ans)

Submission status: Accepted

Solution code:
s=input()
s+='?'
x=[]
ch=1
if s[0]=='>':
    x.append(0)
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        ch+=1
    else:
        x.append(ch)
        ch=1
x.append(0)
a=0
for i in range(len(x)-1):
    if i%2==0 and x[i]<=x[i+1]:
        a+=x[i+1]
        for j in range(x[i]):
            a+=j
        for j in range(x[i+1]):
            a+=j
    elif i%2==0 and x[i]>x[i+1]:
        a+=x[i]
        for j in range(x[i]):
            a+=j
        for j in range(x[i+1]):
            a+=j
if (len(x)-1)%2==1:
    for j in range(x[len(x)-1]):
        a+=j
print(a)

Submission status: Accepted

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

i = 0
left = 0
right = 0
ans = 0
tmp = 0

while i < n-1:
	if s[i] == '<':
		break
	i += 1
	tmp += 1
ans += tmp * (tmp + 1) // 2
while i < n-1:
	if i == n-2:
		if s[i] == '>':
			right += 1
			break
		else:
			left += 1
			break
	if s[i] == '<' and s[i+1] == '>':
		left += 1
		while True:
			if s[i+1+right] == '>':
				right += 1
				if i+1+right == n-1:
					break
			else:
				break
		if left >= right:
			ans += left * (left + 1) // 2 + (right - 1) * right // 2
		else:
			ans += right * (right + 1) // 2 + (left - 1) * left // 2
		i += right + 1
		left = 0
		right = 0
	elif s[i] == '<':
		left += 1
		i += 1

print(ans + left * (left + 1) // 2 + right * (right + 1) // 2 )

Submission status: Accepted

Solution code:
def compute_score(sub):
    max_i = max(sub)
    min_i = min(sub)
    score = max_i * (max_i + 1) * (1 /2) + min_i * (min_i - 1) * (1/2)
    return score

S = input()
sub = [0, 0]
ans = 0
flag = False
for s in S:
    if s == '<' and flag:
        ans += compute_score(sub)
        sub = [0, 0]
        flag = False
    if s == '>':
        flag = True
    if s == '<':
        sub[0] += 1
    else:
        sub[1] += 1
ans += compute_score(sub)
print(int(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 list(range(len(S)))[::-1]:
    if S[i] == ">" and a[i + 1] >= a[i]:
        a[i] = a[i + 1] + 1

print(sum(a))

Submission status: Accepted

Solution code:
def main():
	S = input()
	h = [0] * (len(S) + 1)

	#  <  となっている場合だけを考える
	# a[i] < a[i+1] でない場合、a[i] に +1 したものを a[i+1] にする
	for i in range(len(S)):
		if(S[i] == "<"):
			h[i+1] = max(h[i+1], h[i] + 1)

	# > となっている場合だけを考える
	# a[i-1] > a[i] でない場合、a[i] に +1 したものを a[i-1] にする
	# この時この操作は逆順から行う
	for i in range(len(S), 0, -1):
		if(S[i-1] == ">"):
			h[i-1] = max(h[i-1], h[i] + 1)

	print(sum(h))

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
s = input()
n=len(s)
R=[0]*(n+1)
L=[0]*(n+1)
for i in range(n):
    if s[i]=='<':
        R[i+1]=R[i]+1
for i in range(n-1,-1,-1):
    if s[i]=='>':
        L[i]=L[i+1]+1
res = [x if x>y else y for x,y in zip(R,L)]
print(sum(res))

Submission status: Accepted

Solution code:
s = input()
cnt = 0
n = len(s)
al = [0]*(n+1)
ag = [0]*(n+1)
for i in range(n):
    if s[i] == '<':
        al[i+1] = al[i] + 1
for i in range(n-1, -1, -1):
    if s[i] == '>':
        ag[i] = ag[i+1] + 1
a = [x if x > y else y for x, y in zip(al, ag)]
print(sum(a))

Submission status: Accepted

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

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

for i in range(n)[::-1]:
    if s[i] == '>':
        a_greater[i] = a_greater[i+1] + 1

a = [x if x > y else y for x, y in zip(a_less, a_greater)]

print(sum(a))

Submission status: Accepted

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

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

for i in range(n - 1):
    j = n - i - 2
    prev = A[j + 1]
    if S[j] == ">":
        A[j] = max(A[j], prev + 1)

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from sys import stdin

s = stdin.readline().rstrip()
n = len(s)
s = '|' + s + '|'
r = [0] * (n + 1)
l = [0] * (n + 1)

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

ans = 0
for i in range(n + 1):
    ans += max(r[i], l[i])
# print(r, l)
print(ans)

Submission status: Accepted

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

sstreak = 0
bstreak = 0
for i in range(len(S)):
  if S[i] == "<":
    if 0 < bstreak:
      A[i-bstreak] = max(bstreak, sstreak)
      bstreak -= 1
      while 0 < bstreak:
        A[i-bstreak] = bstreak
        bstreak -= 1
      sstreak = 0
    A[i] = sstreak
    sstreak += 1
  else:
    bstreak += 1
i+=1
if S[-1] == "<":
  A[i] = sstreak

if 0 < bstreak:
  A[i-bstreak] = max(bstreak, sstreak)
  bstreak -= 1
  while 0 < bstreak:
    A[i-bstreak] = bstreak
    bstreak -= 1

print(sum(A))

Submission status: Accepted

Solution code:

def main():
    S = list(input())
    lenS = len(S)
    bfr = -1
    cnt = 0
    ans = []
    dwn = 0
    S.append('<')
    while cnt <= lenS:
        nxt = S[cnt]
        if nxt == '<' and dwn == 0:
            ans.append(max(0,bfr+1))
            bfr = max(0, bfr+1)
            cnt += 1
        elif nxt == '<' and dwn > 0:
            ans.append(max(bfr+1, dwn))
            ans += range(dwn-1, -1, -1)
            bfr = 0
            cnt += 1
            dwn = 0
        else:
            dwn += 1
            cnt += 1
    #print(ans)
    print(sum(ans))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(sys.stdin.readline())
    del s[len(s)-1]
    l = len(s) + 1
    ans = [0] * l

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

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

    print(sum(ans))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
SUM=0
p=0;q=0
b=0

j=0
while s[j]==">":
    j+=1
    if j==len(s):
        break
SUM+=(1+j)*j//2
if j!=len(s):
    h=s[j]
    for i in range(j,len(s)):
        if s[i]==h and b==0:
            p+=1
        if s[i]!=h:
            q+=1
            b=1
        if (s[i]==h and b==1) or (i==len(s)-1):
            w1=max(p,q)
            w2=min(p,q)
            SUM+=(1+w1)*w1//2+w2*(w2-1)//2
            if (s[i]==h and b==1) and (i==len(s)-1):
                SUM+=1
            b=0
            p=1;q=0
        
print(SUM)

Submission status: Accepted

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

s='|'+s+'|'

dp=[0]*(n+1)

#数列aの各項a_iについて、左右に連続する'<<<','>>>'の数をそれぞれカウント、
#その最大がa_iの最小値となる
R = [0]*(n+1)
L = [0]*(n+1)

#left count <<<
for i in range(1,n+1):
    if s[i]=='<':
        L[i] = L[i-1]+1
    else:
        L[i]=0
#right count >>>
for i in range(n-1,-1,-1):
    if s[i+1]=='>':
        R[i] = R[i+1]+1
    else:
        R[i]=0
ans=0
for i in range(n+1):
    ans+=max(R[i],L[i])
#print(L,R,s)
print(ans)

Submission status: Accepted

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


def left(T, S, a, i):
    # ...>>><
    j = 1
    l = i
    while 0 <= l:
        if S[l] == ">" and a[l] < j:
            a[l] = j
            l -= 1
            j += 1
        else:
            break


def right(T, S, a, i):
    # ><<<...
    j = 1
    r = i
    while r <= T - 1:
        if S[r] == "<" and a[r + 1] < j:
            a[r + 1] = j
            r += 1
            j += 1
        else:
            break


def main():
    S = input().rstrip()

    T = len(S)
    N = T + 1
    a = [-1] * N

    if S[0] == "<":
        a[0] = 0
        right(T, S, a, 0)
    for i in range(T - 1):
        if S[i] == ">" and S[i + 1] == "<":
            a[i + 1] = 0
            left(T, S, a, i)
            right(T, S, a, i + 1)
    if S[T - 1] == ">":
        a[N - 1] = 0
        left(T, S, a, T - 1)

    ans = sum(a)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)
res = [0] * (n + 1)
t = 0
for i in range(n):
	if s[i] == '<':
		t += 1
	else:
		t = 0
	res[i + 1] = t

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

print(sum(res))

Submission status: Accepted

Solution code:
s=input()
n=len(s)
# 左から < かどうかを見る
cnt=0
r=[0]*(n+1)
tmp=s[0]
for i in range(n):
    if s[i]=='<':
        cnt+=1
    else:
        tmp=s[i]
        cnt=0
    r[i+1]=cnt

# 右から > かどうかを見る
cnt=0
tmp=s[n-1]
l=[0]*(n+1)
for i in range(n-1,-1,-1):
    if s[i]=='>':
        cnt+=1
    else:
        tmp=s[i]
        cnt=0
    l[i]=cnt

ans=0
for i in range(n+1):
    ans+=max(r[i],l[i])
print(ans)

Submission status: Accepted

Solution code:




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


lst = [0] * N

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

for i in range(N-2,-1,-1):
    if S[i] == ">":
        lst[i] = max(lst[i], lst[i+1] + 1)


print(sum(lst))

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(N-2, -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)

L=[0]*(N+1)
R=[0]*(N+1)
for i in range(1,N+1):
    if S[i-1]=="<":
        L[i]=L[i-1]+1
    if S[-(i)]==">":
        R[-(i+1)]=R[-i]+1
ans=[0]*(N+1)
for i in range(N+1):
    ans[i]=max(L[i],R[i])
print(sum(ans))

Submission status: Accepted

Solution code:
from sys import stdin
S = str(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに

n = len(S)+1
sho = [0]*n
dai = [0]*n

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

for i,s in enumerate(S[::-1]):
    i = n-i-2
    if s == "<":
        dai[i]=0
    else:
        dai[i] = dai[i+1] +1

seq = [max(x,y) for x,y in zip(sho,dai)]

print(sum(seq))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    inp = input()

    nle = 0
    ngt = 0
    ans = 0
    for i in range(len(inp)):
        if inp[i] == '>':
            nle += 1
        else:
            ngt += 1

        if (i + 1 < len(inp) and inp[i] == '>' and inp[i + 1] == '<') or (i == len(inp) - 1):
            ans += (max(nle, ngt) * (max(nle, ngt) + 1)) / 2
            ans += (min(nle, ngt) * (min(nle, ngt) - 1)) / 2
            nle = 0
            ngt = 0

    print(int(ans))

Submission status: Accepted

Solution code:
s = input() #sys.stdin.readlineは最後が改行
n = len(s)

INF = float('inf')

a = [-INF]*(n+1)

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

    if s[i] =='>' and s[i+1]=='<':
        a[i+1]=0


def left(i):
    while True:
        if i ==0:
            break
        if s[i-1] == '>' and a[i-1] <=a[i]:
            a[i-1]=a[i]+1
        else:
            break
        i-=1

def right(i):
    while True:
        if i==n:
            break
        if s[i] == '<' and a[i]>=a[i+1]:
            a[i+1]=a[i]+1
        else:
            break
        i+=1

for i in range(n+1):
    if a[i] == 0:
        left(i)
        right(i)

print(sum(a))

Submission status: Accepted

Solution code:
s=input()
n=len(s)+1
cnt = 1
pool = -1
ans = 0
for i in range(1,n-1):
    if s[i-1]== s[i] == '<':
        cnt += 1
    elif s[i-1] == '<' and s[i] == '>':
        ans += cnt*(cnt-1)//2
        pool = cnt
        cnt = 1
    elif s[i-1] == s[i] == '>':
        cnt += 1
    else:
        ans += cnt*(cnt-1)//2
        ans += max(cnt,pool)
        cnt = 1
ans += cnt*(cnt+1)//2
print(ans)

Submission status: Accepted

Solution code:
from itertools import groupby

r = p = 0
for k, g in groupby(input()):
    i = 0
    for _ in g:
        i += 1
        r += i
    if k == '>':
        r -= min(i, p)
    p = i
print(r)

Submission status: Accepted

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

l = [0 for _ in range(n+1)]
r = [0 for _ in range(n+1)]

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

t = 0
for i in range(n+1):
    t += max(l[i],r[i])
print(t)

Submission status: Accepted

Solution code:
s = input()

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

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

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


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

print(sum(a))

Submission status: Accepted

Solution code:
def main():
    S = input()
    N = len(S) + 1
    cc_s = [0] * N
    cc_d = [0] * N
    for i in range(N-1):
        if S[i] == '<':
            cc_s[i+1] = cc_s[i] + 1
    iS = S[::-1]
    for i in range(N-1):
        if iS[i] == '>':
            cc_d[i+1] = cc_d[i] + 1
    cc_d = cc_d[::-1]
    output = 0
    for a, b in zip(cc_s, cc_d):
        output += max(a, b)
    print(output)
    return

if __name__ == '__main__':
    main()