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:
def s_in():
    return input()

S = s_in()

if len(S) == 1:
    print(1)
    exit()


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


res = 0
idx = 0


if lis[0][0] == ">":
    res += sum(range(lis[0][1]+1))
    idx += 1

while idx < len(lis):
    if idx+1 == len(lis):
        res += sum(range(lis[idx][1]+1))
        break

    x = lis[idx][1]
    y = lis[idx+1][1]

    res += sum(range(max(x,y)+1)) + sum(range(min(x,y)))

    idx += 2


print(res)

Submission status: Accepted

Solution code:
s=input()

a=[1]
if s[0]!="<":a=[0,1]
for i in range(len(s)-1):
  if s[i]!=s[i+1]:a.append(1)
  else:a[-1]+=1
if s[-1]!=">":a.append(0)

b=0
for i in range(len(a)//2):
  ma,mi=max(a[i*2],a[i*2+1]),min(a[i*2],a[i*2+1])
  b+=ma*(ma+1)//2
  b+=mi*(mi-1)//2
print(b)

Submission status: Accepted

Solution code:
s = input()
index = 0
total = 0
count_less = 0
count_more = 0
while index < len(s):
    count = 0
    while index < len(s) and s[index] == '<':
        count += 1
        index += 1
    count_more = count
    count = 0
    while  index < len(s) and s[index] == '>':
        count += 1
        index += 1
    count_less = count
    if count_more == count_less:
        total += count_less * (count_less + 1) - count_less
    elif count_less > count_more:
        total += count_less * (count_less + 1) // 2
        total += count_more * (count_more - 1) // 2
    else:
        total += count_more * (count_more + 1) // 2
        total += count_less * (count_less - 1) // 2
print(total)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
a = []
 
p = 1
for i in range(n-1):
    if s[i] != s[i+1]:
        a.append(p)
        p = 1
    else:
        p += 1
a.append(p)

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

for i in range(len(a)//2):
    p, q = a[2*i], a[2*i+1]
    x, y = max(p,q), min(p,q) - 1
    ans += x*(x+1)//2 + y*(y+1)//2

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

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

less = np.zeros(n)
more = np.zeros(n)

for i, (ch, ct) in enumerate(zip(s, s[::-1])):
    if ch == '<':
        more[i+1] = more[i] + 1
    if ct == '>':
        less[n-i-2] = less[n-i-1] + 1

rst = [max(m, l) for m, l in zip(more, less)]
print(int(sum(rst)))

Submission status: Accepted

Solution code:
S = input()

gLen = 0
lLen = 0
greater = True
ans = 0
for c in S:
    if greater:
        if c == '>':
            gLen += 1
        else:
            if gLen > lLen:
                ans += lLen * (lLen-1) // 2
                ans += gLen * (gLen+1) // 2
            else:
                ans += lLen * (lLen+1) // 2
                ans += gLen * (gLen-1) // 2
            lLen = 1
            gLen = 0
            greater = False
    else:
        if c == '<':
            lLen += 1
        else:
            greater = True
            gLen = 1
if gLen > lLen:
    ans += lLen * (lLen-1) // 2
    ans += gLen * (gLen+1) // 2
else:
    ans += lLen * (lLen+1) // 2
    ans += gLen * (gLen-1) // 2
print(ans)

Submission status: Accepted

Solution code:
input = raw_input
S = input()
n = len(S) # N-1
s = S


up_count = 0
down_count = 0

start_i = None
for i, c in enumerate(S):
    if c == "<":
        start_i = i
        break
    down_count += 1

if start_i is None:
    start_i = n

nums = []
for num in reversed(range(down_count+1)):
    nums.append(num)

up = True
for c in S[start_i:]: 
    if c == "<":
        if not up: # down->up
            if up_count >= down_count:
                for num in range(1, up_count+1):
                    nums.append(num)
                for num in reversed(range(0, down_count)):
                    nums.append(num)
            else:
                for num in range(0, up_count):
                    nums.append(num)
                for num in reversed(range(1, down_count+1)):
                    nums.append(num)
                 
            down_count = 0
            up_count = 1
            up = True
        else:
            up_count += 1
    else:
        if up:
            up = False
            down_count = 1
        else:
            down_count += 1
        

if up:
    for num in range(up_count+1):
        nums.append(num)
else:
    if up_count >= down_count:
        for num in range(1, up_count+1):
            nums.append(num)
        for num in reversed(range(0, down_count)):
            nums.append(num)
    else:
        for num in range(0, up_count):
            nums.append(num)
        for num in reversed(range(1, down_count+1)):
            nums.append(num)

out = sum(nums)
print(out)

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)+1
f=1
s.append('!')
y=[]
for i in range(n-1):
    if s[i]==s[i+1]:
        f+=1
    else:
        y.append(f)
        f=1
if len(y)==1:
    print(y[0]*(y[0]+1)//2)
    exit()
if s[0]=='<':
    ans=0
    for i in range(len(y)-1):
        ans+=y[i]*(y[i]-1)//2
        if i%2==0:
            ans+=max(y[i],y[i+1])
    if len(y)%2==0:
        ans+=y[-1]*(y[-1]-1)//2
    else:
        ans+=y[-1]*(y[-1]+1)//2
    print(ans)
else:
    ans=0
    for i in range(len(y)-1):
        if i==0:
            ans+=y[i]*(y[i]+1)//2
            continue
        ans+=y[i]*(y[i]-1)//2
        if i%2==1:
            ans+=max(y[i],y[i+1])
    if len(y)%2==0:
        ans+=y[-1]*(y[-1]+1)//2
    else:
        ans+=y[-1]*(y[-1]-1)//2
    print(ans)

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def sigma(b):
    return (b+1)*b//2


S = input()[:-1]
N = len(S)
L = []
if S[0] == ">":
    L.append(("U", 0))
else:
    L.append(("D", 0))
for i, a, b in zip(range(1, N), S, S[1:]):
    if a == b:
        continue
    else:
        if a == "<" and b == ">":
            L.append(["U", i])
        else:
            L.append(["D", i])
if S[-1] == ">":
    L.append(["D", N])
else:
    L.append(["U", N])

ans = 0
if L[0][0] == "U":
    ans += sigma(L[1][1]-L[0][1])
if L[-1][0] == "U":
    ans += sigma(L[-1][1]-L[-2][1])
for i in range(1, len(L)-1):
    if L[i][0] == "U":
        dist_long = max(L[i][1]-L[i-1][1], L[i+1][1]-L[i][1])
        dist_small = min(L[i][1]-L[i-1][1], L[i+1][1]-L[i][1])
        ans += sigma(dist_long) + sigma(dist_small-1)
print(ans)

Submission status: Accepted

Solution code:
S = list(input())
N = len(S) + 1#Nは文字列lの長さ
INF = 10 ** 8

l = [INF] * N

if S[0] == "<":
    l[0] = 0

for i in range(1,N-1):
    if S[i-1] == "<" and S[i] == "<":
        l[i] = l[i-1] + 1
    elif S[i-1] == ">" and S[i] == "<":
        l[i] = 0
    #print(l)

if S[N-2] == "<":
    l[N-1] = l[N-2] + 1
else:
    l[N-1] = 0

for i in range(1,N-1):
    if S[-i] == ">" and S[-i-1] == ">":
        l[-i-1] = l[-i] + 1
    elif S[-i] == ">" and S[-i-1] == "<":
        l[-i-1] = 1 + max(l[-i],l[-i-2])
    #print(l)

if S[0] == ">":
    l[0] = l[1] + 1

print(sum(l))

Submission status: Accepted

Solution code:
def calc(l):
    if l == "":
        return 0

    left = l.count("<")
    right = l.count(">")

    if left == 0:
        return right * (right + 1) // 2

    if right == 0:
        return left * (left + 1) // 2

    return left * (left - 1) // 2 + right * (right - 1) // 2 + max(right, left)

def f():
    S = input()
    res = 0
    l = ""
    for s in S:
        if l == "":
            l += s
            continue

        if l[-1] == ">" and s == "<":
            res += calc(l)
            l = "<"
        else:
            l += s
    res += calc(l)
    print(res)


if __name__ == '__main__':
    f()

Submission status: Accepted

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

lst_0 = []
a = [-1 for i in range(n)]
if s[0] == '<':
    a[0] = 0
    lst_0.append(0)
if s[-1] == '>':
    a[-1] = 0
    lst_0.append(n-1)

mae = s[0]
for i in range(1, n-1):
    now = s[i]
    if mae == '>' and now == '<':
        a[i] = 0
        lst_0.append(i)
    mae = now

for i in lst_0:
    now = i - 1
    kazu = 1
    while now >= 0 and s[now] == '>':
        a[now] = max(a[now], kazu)
        now -= 1
        kazu += 1
    now = i + 1
    kazu = 1
    while now <= n-1 and s[now-1] == '<':
        a[now] = max(a[now], kazu)
        now += 1
        kazu += 1

print(sum(a))

Submission status: Accepted

Solution code:
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline-------------------------------------------
    S = input()
    N = len(S)+1
    ll = []
    j = 0
    ans = 0
    for i in range(N-1):
        if S[i:i+2] == "><":
            ll.append(S[j:i+1])
            j = i+1
    ll.append(S[j:i+1])
    for i in ll:
        p = i.count("<")
        q = i.count(">")
        if p > q:
            ans += (p*(p+1)//2+q*(q-1)//2)
        else:
            ans += (p*(p-1)//2+q*(q+1)//2)
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Accepted

Solution code:
s = str(input())
ans = 0
cnt = 1
lastright = 0
lis = []
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        cnt += 1
    else:
        lis.append(cnt)
        cnt = 1
lis.append(cnt)
if s[0] == "<":
    lis.insert(0,0)
if s[-1] == ">":
    lis.append(0)
for i in range(len(lis)//2-1):
    if lis[2 * i + 1] <= lis[2 * (i + 1)]:
        lis[2 * i + 1] -= 1
    else:
        lis[2 * (i + 1)] -= 1
for num in lis:
    ans += (num * (num + 1))//2
print(ans)

Submission status: Accepted

Solution code:
s=input()+" "
count=[]
left,right=0,0
for i in range(len(s)):
    if s[i]==">" and s[i+1]=="<":
        count.append(s[left:i+1])
        left=i+1
count.append(s[left:])

ans=0
for i in range(len(count)):
    left,right=0,0
    for j in count[i]:
        if j==">":right +=1
        elif j=="<":left +=1
    big_one=max(left,right)
    small_one=min(left,right)
    for k in range(big_one+1):
        ans +=k
    for l in range(small_one):
        ans +=l

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
ass = []
tmp = ''
cnt = 0
for i in range(n):
    if i == 0:
        tmp = s[i]
        cnt = 1
        continue
    if tmp == s[i]:
        cnt += 1
    else:
        tmp = s[i]
        ass.append(cnt)
        cnt = 1
ass.append(cnt)
l = len(ass)
res = 0
if s[0] == '<':
    for i in range(l)[::2]:
        if i == l-1:
            res += (ass[i]+1)*ass[i]//2
            continue
        mm = max(ass[i],ass[i+1])
        nn = min(ass[i],ass[i+1])
        # print(mm,nn)
        res += (mm+1)*mm//2 + (nn-1)*nn//2
else:
    res += (ass[0]+1)*ass[0]//2
    for i in range(1,l)[::2]:
        if i == l-1:
            res += (ass[i]+1)*ass[i]//2
            continue
        mm = max(ass[i],ass[i+1])
        nn = min(ass[i],ass[i+1])
        res += (mm+1)*mm//2 + (nn-1)*nn//2
print(res)

Submission status: Accepted

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

Submission status: Accepted

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


def runLength(s):
    a = []
    for i, c in enumerate(s):
        if len(a) == 0 or a[-1][0] != c:
            a.append([c, 1, i])  # 文字種, 長さ, 開始位置
        else:
            a[-1][1] += 1
    return a


def main():
    s = input().strip()
    ans = [-1]*(len(s)+1)
    a = runLength(s)
    a.sort(key=lambda x: x[1], reverse=True)
    for c, n, i in a:
        if c == "<":
            x = (ans[i] if ans[i] != -1 else 0)
            for j in range(i, i+n+1):
                if ans[j] == -1:
                    ans[j] = x
                x += 1
        else:
            x = (ans[i+n] if ans[i+n] != -1 else 0)
            for j in range(i+n, i-1, -1):
                if ans[j] == -1:
                    ans[j] = x
                x += 1
    print(sum(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    before = " "
    RLE = []
    string = []
    for s in S:
        if s==before:
            RLE[-1] += 1
        else:
            RLE.append(1)
            string.append(s)
        before = s
    # print(RLE)
    # print(string)

    A = [-1]*(len(S)+1) ##最後に0で初期化
    if string[0]=="<":
        A[0]=0
    now = 0
    for i,x in enumerate(RLE):
        s = string[i]
        now += x
        if s=="<":
            pass
        else: #>
            A[now] = 0
    i=0
    while i<(len(S)+1):
        if A[i]==0:
            j=i-1
            while j>=0:
                if S[j]==">":
                    A[j]=max(A[j],A[j+1]+1)
                    j-=1
                else:
                    break

            j=i
            while j<len(S):
                if S[j]=="<":
                    A[j+1]=max(A[j+1],A[j]+1)
                    j+=1
                else:
                    break
        i+=1


    # print(A)
    print(sum(A))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
N = len(S)+1
a = [-1]*N
l = []
for i in range(1,N-1):
    if S[i-1] == '>' and S[i] == '<':
        a[i] = 0
        l.append(i)

if S[0] == '<':
    a[0] = 0
    l.append(0)
if S[-1] == '>':
    a[N-1] = 0
    l.append(N-1)

for i in l:
    j = i-1
    while 0<=j<=N-2 and S[j]=='>' and S[j-1]=='>':
        a[j] = a[j+1]+1
        j -= 1
    j = i+1
    while 0<=j<=N-3 and S[j]=='<' and S[j+1]=='<':
        a[j] = a[j-1]+1
        j += 1

for i in range(1,N-1):
    if a[i] == -1:
        a[i] = max(a[i-1],a[i+1])+1


if S[0] == '>':
    a[0] = a[1]+1

if S[-1] == '<':
    a[N-1] = a[N-2]+1

print(sum(a))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#AGC40 A

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
n = len(s)
f = [i for i in range(n+1)]
f = list(accumulate(f))
lst = []
lst2 = []
i = 0
flg = False
while i < n:
    cnt = 0
    tmp = s[i]
    while i < n:
        if tmp == s[i]:
            i += 1
            cnt += 1
        else:
            break
    if s[i-1] == '<':
        t = cnt
        flg = True
    elif flg:
        lst2.append(min(t,cnt))
        flg = False
    lst.append(f[cnt])
cnt = 0
print(sum(lst) - sum(lst2))

Submission status: Accepted

Solution code:
s=input()
ans=0
l=[]
c=1
now=s[0]
for i in s[1:]:
    if i==now:
        c+=1
    else:
        l.append(c)
        ans+=c*(c+1)//2
        now=i
        c=1
l.append(c)
ans+=c*(c+1)//2
if s[0]=="<":
    for i in range(len(l)//2):
       ans-=min(l[2*i],l[2*i+1])
else:
    for i in range((len(l)-1)//2):
       ans-=min(l[2*i+1],l[2*i+2])
print(ans)

Submission status: Accepted

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

# int(input())
# map(int, input().split())

def solve(s):
    n = len(s)
    t = [-1] * n

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

    for ind, (prev, after) in enumerate(zip(s, s[1:])):
        if prev + after == '><':
            t[ind + 1] = 0
    ku = 0
    hu = 0
    ans = 0
    for ind, c in enumerate(s):
        if t[ind] == 0:
            max_ = max(ku, hu)
            min_ = min(ku, hu)
            ans += (max_ + 1) * max_ // 2
            ans += (min_ - 1) * min_ // 2
            ku = 0
            hu = 0
        if c == '<':
            ku += 1
        else:
            hu += 1
    max_ = max(ku, hu)
    min_ = min(ku, hu)
    ans += (max_ + 1) * max_ // 2
    ans += (min_ - 1) * min_ // 2
    return ans


if __name__ == '__main__':
    s = input()
    print(solve(s))

Submission status: Accepted

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

for i in range(-1, N-1):
    if (i == -1 and S[i+1] == '<') or (i == N - 2 and S[i] == '>') or (S[i] == '>' and S[i+1] == '<'):
        j = 0
        while i - j >= 0 and S[i-j] == '>' and a[i-j] < j + 1:
            a[i-j] = j + 1
            j += 1
        j = 0
        while i + 2 + j < N and S[i+1+j] == '<' and a[i+2+j] < j + 1:
            a[i+2+j] = j + 1
            j += 1
print(sum(a))

Submission status: Accepted

Solution code:
def get_sequence(arr):
    if len(arr) == 0:
        return [], []
    elements = []
    nums = []
    n = 1
    prev = arr[0]
    for c in arr[1:]:
        if c == prev:
            n += 1
        else:
            elements.append(prev)
            nums.append(n)
            prev = c
            n = 1
    elements.append(prev)
    nums.append(n)
    return elements, nums

S = input()
ele, num = get_sequence(S)
ans = 0
s = (ele[0]=='>')

prev = 0
for n in num:
    if s:
        ans += max(n, prev)
    ans += n*(n-1)//2
    prev = n
    s = not s
if s:
    ans += n
print(ans)

Submission status: Accepted

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


def main():
    s = input()

    li = []
    prev = 0
    top = 0
    for i in range(len(s) - 1):
        cs = s[i:i+2]
        if cs == "<>":
            top = i + 1
        elif cs == "><":
            li.append((prev, top, i+1))
            prev = i + 1

    li.append((prev, top, len(s)))

    ans = 0
    for l, t, r in li:
        if l < t < r:
            ld = t - l
            rd = r - t
            mx = max(ld, rd)
            mn = min(ld, rd)
            sm = f(mx) + f(mn - 1)
            ans += sm

        else:
            sm = f(r - l)
            ans += sm

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
N = len(s)
array = [0] * (N+1)
flg = False
for i in range(N):
    if s[i] == '<' and flg:
        array[i+1] = array[i] + 1
        continue
    if s[i] == '<':
        array[i+1] += 1
        flg = True
    else:
        flg = False
flg = False
for i in range(N):
    if array[N-(i+1)] > array[N-i]:
        continue
    if s[N-1-i] == '>' and flg:
        array[N-(i+1)] = array[N-i] + 1
        continue
    if s[N-1-i] == '>':
        array[N-(i+1)] += 1
        flg = True
    else:
        flg = False

# print(array)
print(sum(array))

Submission status: Accepted

Solution code:

S = list(input())
ans = 0
N = len(S)

L = [-1] *( len(S) + 1)

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

i=0
tmp = 0
while (i<N):
    while (i<N and L[i] != 0): i+=1
    tmp = 0
    while (i<N and S[i] == '<'):
        tmp += 1
        L[i+1] = tmp
        i += 1
        

i=N
tmp = 0
while (i>0):
    while (i>0 and L[i] != 0): i-=1
    tmp = 0
    while (i>0 and S[i-1] == '>'):
        tmp += 1
        L[i-1] = max(L[i-1],tmp)
        i -= 1
    
print(sum(L))

Submission status: Accepted

Solution code:
S = input()

N = len(S) + 1
t = [0] * N
p = ''
for i in range(N - 2, -2, -1):
  if p == '>':
    t[i + 1] = t[i + 2] + 1
  p = S[i]
for i in range(N - 1):
  if S[i] == '<':
    t[i + 1] = max(t[i + 1], t[i] + 1)
print(sum(t))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):

    C = None
    n = 0
    l = []
    for c in S:
        if c != C:
            l.append((C, n))
            C = c
            n = 1
        else:
            n += 1
    l.append((C, n))
    l.pop(0)

    if l[0][0] == '>':
        l.insert(0, ('<', 0))
    if l[-1][0] == '<':
        l.append(('>', 0))

    ans = 0
    for i in range(0, len(l), 2):
        _, n1 = l[i]
        _, n2 = l[i+1]
        
        gn = max(n1, n2)
        ln = min(n1, n2) - 1
        ans += (gn**2 + gn)//2
        if ln > 0:
            ans += (ln**2 + ln)//2
    return ans

# ><>>><<><<<<<>>><
def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
# input = sys.stdin.readline

s = input().rstrip()
s = ">" + s + "<"
n = len(s)

lvs = []

ans = [-1] * n
lv = 0
for i, (ch1, ch2) in enumerate(zip(s, s[1:])):
    if ch1 == ">" and ch2 == "<":
        lv = 0
        ans[i+1] = lv
    if ch1 == "<":
        lv += 1
        ans[i+1] = lv

prev = s[-1]
lv = 0
for i in range(n-2, -1, -1):
    if s[i] == ">":
        lv += 1
        ans[i] = max(ans[i], lv)
    elif s[i] == "<":
        lv = 0
    prev = s[i]

print(sum(ans[1:]))

Submission status: Accepted

Solution code:
s=input()

temp=0
ans=0
check=0
for i in range(len(s)):
    if s[i]=='<':
        if temp>0 and s[i-1]=='>':
            ans=ans-(temp*check)
            temp=0
        
        check=0
        temp+=1
        ans+=temp
        i+=1
    else:
        check+=1
        temp-=1
        if temp<0:
            temp=0
            ans+=check
        else:
            ans+=temp
print(ans)

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

S = str(input())
N = len(S)+1
a = [0]*N
ans = int(0)

SUMI = [0]*N
for i in range(N-1):
    SUMI[i+1] = SUMI[i] + (i+1)
#print(SUMI)

k = 1
if S[0]==">":
    k*=(-1)
cur1 = int(0)
cur2 = int(0)
for i in S:
    if k==1:
        if i=="<":
            cur1 +=1
        else:
            k*=(-1)
            cur2 +=1
    else:
        if i==">":
            cur2 +=1
        else:
            k *=(-1)
            ans +=(SUMI[max(cur1,cur2)]+SUMI[max(min(cur1,cur2)-1,0)])
            cur1=1
            cur2=0
#            print(ans)

ans += (SUMI[max(cur1,cur2)]+SUMI[max(min(cur1,cur2)-1,0)])

print(ans)

Submission status: Accepted

Solution code:
s = input()
ans = 0
prev = None
l = 0
r = 0
for x in s:
  if x == '<':
    if prev == '>':
      mx = max(r, l)
      mn = min(r, l)
      ans += mx * (mx + 1) // 2 + mn * (mn - 1) // 2
      l = 0
      r = 0
    l += 1
  else:
    r += 1
  prev = x
else:
  mx = max(r, l)
  mn = min(r, l)
  ans += mx * (mx + 1) // 2 + mn * (mn - 1) // 2
print(ans)

Submission status: Accepted

Solution code:
S = str(input())
N = len(S) + 1
a = [-1] * N


def chmax(a, b):
    if a < b:
        a = b
    return a


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

for i in range(N - 1):
    if a[i] != -1 and S[i] == "<":
        a[i + 1] = a[i] + 1

for i in reversed(range(1, N)):
    if a[i] != -1 and S[i - 1] == ">":
        a[i - 1] = chmax(a[i - 1], a[i] + 1)

print(sum(a))

Submission status: Accepted

Solution code:
a=input()
ans=0
k=0
t=1
n=0
for i in range(len(a)):
  if t:
    if a[i]=="<":
      ans+=k
      k+=1
    else:
      n+=1
      t=0
  else:
    if a[i]==">":
      n+=1
    else:
      ans+=n*(n-1)//2
      ans+=max(k,n)
      n=0
      k=1
      t=1
if a[-1]=="<":
  ans+=k
else:
  ans+=n*(n-1)//2
  ans+=max(k,n)
print(ans)

Submission status: Accepted

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

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

#n = int(input())
#n,m = [int(i) for i in readline().split()]
s = input()
l = len(s)

def calc(a,b):
    c = max(a,b)
    d = min(a,b)
    return c*(c+1)//2 + (d-1)*d//2

#0: < 1: >
now = ">"
ans = 0

cnt0 = 0 #<
cnt1 = 0 #>
for i in s:
    if now != i:
        now = i
        if i == "<":
            ans += calc(cnt0,cnt1)
            cnt0 = 1
            cnt1 = 0
        else: cnt1 += 1
    else:
        if i == ">": cnt1 += 1
        else: cnt0 += 1


if s[-1] == "<":
    ans += cnt0*(cnt0+1)//2
else:
    ans += calc(cnt0,cnt1)

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- Coding: utf-8 -*-

import sys


def main():
    S = input()

    ary = [0]
    now = "<"

    for s in S:
        if s == now:
            ary[-1] += 1
        else:
            ary.append(1)
            now = s

    ans = 0
    for i in range(1, len(ary), 2):
        mi, ma = sorted([ary[i], ary[i-1]])
        ans += ma*(ma+1)//2
        ans += (mi-1)*mi//2
    if len(ary) % 2 == 1:
        ans += ary[-1]*(ary[-1]+1)//2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S=input()
S+="1"
A=[]
count1=0
count2=0
total=0
for i in range(600000):
    total+=i
    A.append(total)

total=0
for i in range(len(S)):
    if S[i]=="<":
        count1+=1
    if S[i]==">":
        count2+=1
    if S[i]==">" and S[i+1]=="<":
        total+=A[max(count1,count2)]
        if min(count1, count2) != 0:
            total+=A[min(count1,count2)-1]
        #print(count1, count2,total)
        count1=0
        count2=0

total+=A[max(count1,count2)]
if min(count1,count2)!=0:
    total+=A[min(count1,count2)-1]
#print(A)
#print(count1,count2)


print(total)

Submission status: Accepted

Solution code:
S = input()
n = len(S)+1
A = [-1] * n
if (S[0] == '<'): A[0] = 0
if (S[-1] == '>'): A[-1] = 0
for i in range(n-2):
    if S[i] + S[i+1] == '><':
        A[i+1] = 0
for i in range(n-1):
    if (A[i] == -1): continue
    if S[i] == '<':
        A[i+1] = A[i] +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(input())
n=len(s)
l=[-1 for i in range(n+1)]
ct=0
ans=0
if s[0]=='<':l[0]=0
if s[n-1]=='>':l[n]=0
for i in range(n-1):
  if s[i]=='>' and s[i+1]=='<':
    l[i+1]=0
for i in range(n):
  if s[i]=='<':
    l[i+1]=l[i]+1
for i in range(n-1,-1,-1):
  if s[i]=='>':
    l[i]=l[i+1]+1

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

Submission status: Accepted

Solution code:
S = input()
N = len(S) + 1
ans = [0] * N
lc, rc = 0, 0
for i in range(N - 1):
    if S[i] == '<':
        ans[i + 1] = ans[i] + 1

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

print(sum(ans))