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:
#C
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 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=list(input())

right = [0]

left = [0]

count = 0
for i in range(len(s)):
    if s[i] == '<':
        count += 1
    else:
        count = 0
    right.append(count)
count = 0
for i in range(len(s)-1,-1,-1):
    if s[i] == '>':
        count += 1
    else:
        count = 0
    left.append(count)
left.reverse()

ans = 0

for i in range(len(s)+1):
    ans += max(right[i],left[i])
print(ans)

Submission status: Accepted

Solution code:
S = input()

tmp1 = [0 for _ in range(len(S)+1)]
tmp2 = [0 for _ in range(len(S)+1)]

for i in range(len(S)):
  if S[i] == '>':
    tmp1[i] = 1
  else:
    tmp2[i+1] = 1

for i in range(1, len(S)+1):
  if tmp1[-i-1] != 0:
    tmp1[-i-1] = tmp1[-i] + tmp1[-i-1]

for i in range(2, len(S)+1):
  if tmp2[i] != 0:
    tmp2[i] = tmp2[i] + tmp2[i-1]

ans = 0
for i in range(len(S)+1):
  ans += max(tmp1[i], tmp2[i])

print(ans)

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    s = IS()
    n = len(s)
    a = [0]
    now = 0
    for si in s:
        if si == '<':
            now += 1
        else:
            now = 0
        a.append(now)
    b = [0]
    now = 0
    for si in s[::-1]:
        if si == '>':
            now += 1
        else:
            now = 0
        b.append(now)
    b = b[::-1]
    ans = sum([max(a[i], b[i]) for i in range(n+1)])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
ans = 0
cnt = 0
tmp = 0
pre = '>'
last = '>' if s[-1]=='<' else '<'
for now in s+last:
    if pre==now:
        cnt += 1
    else:
        if now=='<':
            ans += max(cnt, tmp)
            tmp = 0
        else:
            tmp = cnt
        ans += cnt*(cnt-1)//2
        cnt = 1
    pre = now
ans += tmp
print(ans)

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] = 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 = list(input())
ans = []
N = len(S) + 1

lr = [[] for _ in range(N)]

# 左から見る
temp = 0
for i in range(N):
    if i == 0:
        lr[i].append(0)
    else:
        if S[i-1] == "<":
            temp += 1
            lr[i].append(temp)
        else:
            temp = 0
            lr[i].append(temp)

# 右から見る
temp = 0
for i in reversed(range(N)):
    if i == N - 1:
        lr[i].append(0)
    else:
        if S[i] == ">":
            temp += 1
            lr[i].append(temp)
        else:
            temp = 0
            lr[i].append(temp)

ans = []
for i in range(N):
    ans.append(max(lr[i]))
print(sum(ans))

Submission status: Accepted

Solution code:
def main():
    S = input()
    N = len(S)+1
    now = 0
    A = [0]
    for s in S:
        if s == "<":
            now += 1
        else:
            now = 0
        A.append(now)
    B = [0]
    now = 0
    for s in S[::-1]:
        if s == ">":
            now += 1
        else:
            now = 0
        B.append(now)
    B = B[::-1]
    ans = sum( [ max(A[i], B[i]) for i in range(N)])
    
    print(ans)
        
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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


def read():
    S = input().strip()
    return S,

def cumsum(a):
    for i in range(1, len(a)):
        a[i] += a[i-1]
    return a

def solve(S):
    S = S + '.'
    N = len(S)
    pairs = []
    i = 0
    while S[i] != '.':
        n_close = 0
        n_open = 0
        while S[i] == '>':
            i += 1
            n_close += 1
        while S[i] == '<':
            i += 1
            n_open += 1
        pairs.append((n_close, n_open))
    
    T = cumsum([i for i in range(N)])
    
    ans = 0
    for n_close, n_open in pairs:
        ans += T[n_close] + T[n_open]
    for i in range(1, len(pairs)):
        ans -= min(pairs[i-1][1], pairs[i][0])
    return ans

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Accepted

Solution code:
S=input()
chk = S[0]
cnt =1
cnt_list=[]
ans = 0
for i in S[1:]:
    if chk==i:
        cnt += 1
    else:
        ans += cnt*(cnt-1)//2
        cnt_list.append(cnt)
        cnt = 1
        chk = i
cnt_list.append(cnt)
ans += cnt*(cnt-1)//2
if S[0]=="<":
    for i,j in zip(cnt_list[::2],cnt_list[1::2]):
        ans += max(i,j)
    if len(cnt_list)%2!=0:
        ans += cnt_list[-1]
else:
    ans += cnt_list[0]
    for i,j in zip(cnt_list[1::2],cnt_list[2::2]):
        ans += max(i,j)
    if len(cnt_list)%2==0:
        ans += cnt_list[-1]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = list(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)
    # print(a)

for i in reversed(range(N)):
    if S[i] == '>':
        a[i] = max(a[i], a[i + 1] + 1)
    # print(a)

print(sum(a))
# print(a)

Submission status: Accepted

Solution code:
def myAnswer(S:list) -> int:
   N = len(S)+1
   ans = [0]*N
   for i in range(len(S)-1,-1,-1):
      if(S[i] == ">"):
         ans[i] = ans[i+1]+1
   # print(ans)
   for i in range(len(S)):
      if(S[i]== "<"):
         if(ans[i] >= ans[i + 1]):
            ans[i + 1] = ans[i]+1
   # print(ans)
   return sum(ans)
def modelAnswer(S:list) -> int:
   l = [0 for i in range(len(S)+1)]
   for n,s in enumerate(S):
      if(s == "<"):
         l[n+1] = l[n] + 1
   for n,s in enumerate(S[::-1]):
      if(s == ">"):
         tmp = l[len(S) - n] + 1
         if (tmp > l[len(S) - n - 1]):
            l[len(S) -n - 1] = tmp
   return sum(l)
def main():
   S = list(input())
   print(myAnswer(S[:]))
if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
from copy import copy, deepcopy
from collections import Counter
from math import sqrt

MOD = 10**9 + 7

S = list(input())
if S[0] == '>':
    S.insert(0, '<')
if S[-1] == '<':
    S.insert(len(S), '>')

low = [i for i, v in enumerate(S) if i > 0 and S[i-1] == '>' and S[i] == '<']
high = [i for i, v in enumerate(S) if i > 0 and S[i-1] == '<' and S[i] == '>']

if S[0] == '<':
    low.insert(0, 0)
elif S[0] == '>':
    high.insert(0, 0)

if S[-1] == '<':
    high.append(len(S))
elif S[-1] == '>':
    low.append(len(S))

ans = 0


def s(i):
    return i * (i+1) // 2


for i in range(len(high)):
    lh = abs(high[i] - low[i])
    hl = abs(low[i+1] - high[i])
    ans += s(max(lh, hl)) + s(min(lh, hl)-1)

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:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    S = input()
    L = len(S)
    A = [0] * (L+1)
    for i in range(L):
        if S[i]=='<':
            A[i+1] = max(A[i] + 1, A[i+1])
    for i in range(L)[::-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 f(n):
    return (n - 1) * n // 2


S = input()
arr = []
i = 0
while len(S) > i:
    s = i
    while i + 1 < len(S) and S[i] == S[i + 1]:
        i += 1
    arr.append(i - s + 1)
    i += 1

ans = 0
if S[0] == '>':
    ans += f(arr[0] + 1)
    arr = arr[1:]

if S[-1] == '<':
    ans += f(arr[-1] + 1)
    arr = arr[:-1]

for i in range(0, len(arr), 2):
    ans += max(arr[i], arr[i + 1]) + f(arr[i]) + f(arr[i + 1])

print(ans)

Submission status: Accepted

Solution code:
S = input()

d = [0] * (len(S) + 1)
for i in range(len(S)):
    if (S[i] == '<'):
        d[i + 1] = max(d[i + 1], d[i] + 1)
for i in range(len(S))[::-1]:
    if (S[i] == '>'):
        d[i] = max(d[i], d[i + 1] + 1)

print(sum(d))

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)
for i in range(n)[::-1]:
    if S[i] == '>':
        a[i] = max(a[i], a[i+1] + 1)
# print(a)
print(sum(a))

Submission status: Accepted

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

for i in range(N - 1, 0, -1):
    if S[i - 1] == ">":
        if ans[i - 1] > ans[i]:
            continue
        else:
            ans[i - 1] = ans[i] + 1

print(sum(ans))

Submission status: Accepted

Solution code:
s=input()
ans=0
seq_up=0
seq_down=0
d='>'
u='<'
if s[0]==u:
  seq_up+=1
else:
  seq_down+=1
for i in range(1,len(s)):
  if s[i]==u:
    if s[i]!=s[i-1]:
      ans+=max(seq_up*(seq_up-1)//2,0)
      #print(ans)
      ans+=max(seq_down*(seq_down-1)//2,0)
      #print(ans)
      ans+=max(seq_up,seq_down)
      #print(ans)
      seq_up=1
      seq_down=0
      #print('+',seq_up)
    else:
      seq_up+=1
      #print('+',seq_up)
  else:
    seq_down+=1
    #print('-',seq_down)
m=max(seq_up,seq_down)+1
ans+=m*(m-1)//2
print(ans)

Submission status: Accepted

Solution code:
s = list(input())
if s[0] == ">":
    s.insert(0, "<")
if s[len(s) - 1] == "<":
    s.append(">")
t = "<"
a, b = 0, 0
ans = 0
for i in s:
    if i == "<":
        if not b == 0:
            x = max(a, b)
            y = min(a, b) - 1
            ans += (x * (x + 1)) // 2 + (y * (y + 1)) // 2
            a, b = 0, 0
        a += 1
    else:
        b += 1
x = max(a, b)
y = min(a, b) - 1
ans += (x * (x + 1)) // 2 + (y * (y + 1)) // 2
print(ans)

Submission status: Accepted

Solution code:
s = input().replace('><','> <').split()
ans = 0
#print(list(s))
for st in s:
    lt = st.count('<')
    gt = len(st) - lt
    if lt > gt:
        gt -= 1
    else:
        lt -= 1
    ans += (lt*lt+lt)//2 + (gt*gt+gt)//2
print(ans)

Submission status: Accepted

Solution code:
import sys

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


def resolve():
    s = input()
    n = len(s)

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

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

    res = 0
    for i in range(n + 1):
        res += max(A[i], B[i])

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
s=input()
rl=[]
ll=[]
c=0
for i in range(len(s)-1):
  c+=1
  if s[i]!=s[i+1]:
    if s[i]=='<':
      rl.append(c)
    else:
      ll.append(c)
    c=0
if s[len(s)-1]=='<':
  rl.append(c+1)
else:
  ll.append(c+1)

rn=len(rl)
ln=len(ll)
ans=0
if s[0]=='<':
  for i in range(ln):
    M=max(rl[i], ll[i])
    m=min(rl[i], ll[i])
    ans+=M*(M+1)//2+m*(m-1)//2
  if rn>ln:
    ans+=rl[-1]*(rl[-1]+1)//2
else:
  rl=[0]+rl
  ans+=ll[0]*(ll[0]+1)//2
  for i in range(1, ln):
    M=max(rl[i], ll[i])
    m=min(rl[i], ll[i])
    ans+=M*(M+1)//2+m*(m-1)//2
  if rn==ln:
    ans+=rl[-1]*(rl[-1]+1)//2
print(ans)

Submission status: Accepted

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

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

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

print(sum(a))

Submission status: Accepted

Solution code:
S = input()
ans = [0 for _ in range(len(S) + 1)]
t = 0
for i in range(len(S)):
    if S[i] == "<":
        t += 1
    else:
        t = 0
    ans[i + 1] = t
# print(ans)

t = 0
for i in reversed(range(1, len(S) + 1)):
    if S[i - 1] == ">":
        t += 1
    else:
        t = 0
    ans[i - 1] = max(ans[i - 1], t)
print(sum(ans))

Submission status: Accepted

Solution code:
S = input()
zero = []
turn = []

def sum_n(n):
    return (n ** 2 + n) // 2

for i, s in enumerate(S):
    if i == 0:
        if s == '<':
            zero.append(i)
        else:
            turn.append(i)
            zero.append(-1)
    else:
        if s_ == '>' and s == '<':
            zero.append(i)
        elif s_ == '<' and s == '>':
            turn.append(i)
    if i == len(S) - 1:
        if s == '>':
            zero.append(i + 1)
        else:
            turn.append(i + 1)
            zero.append(i + 2)
    s_ = s

#print(len(zero), zero)
#print(len(turn), turn)

ans = 0

for i in range(len(turn)):
    ans += sum_n(zero[i+1] - turn[i] - 1)
    ans += sum_n(turn[i] - zero[i] - 1)
    ans += max(zero[i+1] - turn[i], turn[i] - zero[i])
print(ans)

Submission status: Accepted

Solution code:
s=input()
ans1=[]
ans1.append(0)
now=0
for i in s:
    if i == "<":
        now+=1
    else:
        now=0
    ans1.append(now)
ans2=[]
ans2.append(0)
now=0
for i in reversed(s):
    if i == ">":
        now+=1
    else:
        now=0
    ans2.append(now)

ans=[]
for i in range(len(ans1)):
    ans.append(max(ans1[i],ans2[len(ans1)-i-1]))
print(sum(ans))

Submission status: Accepted

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

count=1
a=[]
for i in range(1,n):
  if s[i]==s[i-1]:
    count += 1
  else:
    a.append(count)
    count=1
if count!=0:
  a.append(count)

size=len(a)
a.append(0)

total = 0

if s[0] == "<":
  for i in range((size+1)//2):
    large=max(a[2*i],a[2*i+1])
    small=min(a[2*i],a[2*i+1])
    total += (large+1)*large//2 + small*(small-1)//2
  print(total)
  
if s[0] == ">":
  total += a[0]*(a[0]+1)//2
  for i in range(size//2):
    large=max(a[2*i+1],a[2*i+2])
    small=min(a[2*i+1],a[2*i+2])
    total += (large+1)*large//2 + small*(small-1)//2
  print(total)

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
s = input()
n = len(s)
x = []
up = True
cnt = 0
for i in range(n):
    if s[i] == "<":
        if up:
            cnt += 1
        else:
            x.append(-cnt)
            up = True
            cnt = 1
    else:
        if up:
            x.append(cnt)
            up = False
            cnt = 1
        else:
            cnt += 1
if up:
    x.append(cnt)
else:
    x.append(-cnt)
# print(x)
m = len(x)
ans = 0
for i in range(0, m, 2):
    if i == m - 1:
        ans += x[i] * (x[i] + 1) // 2
        break
    a, b = max(x[i], abs(x[i + 1])), min(x[i], abs(x[i + 1]))
    # print((a * (a + 1) + (b - 1) * b) // 2)
    ans += (a * (a + 1) + (b - 1) * b) // 2
print(ans)

Submission status: Accepted

Solution code:
s=input()
# ai=max(左にある<の連続数,右にある>の連続数)
n=len(s)+1
dr,dl=[0]*n,[0]*n
# dl[i]:区切りiの左にある<の連続数。dl[0]=0
# dr[i]:区切りiの右にある>の連続数。dl[-1]=0
# ともにlen=n
p=''
cl,cr=0,0
for i in range(n-1):
      if s[i]=='<':
            cl+=1
      else:
            cl=0
      dl[i+1]=cl
      if s[-(i+1)]=='>':
            cr+=1
      else:
            cr=0
      dr[-(i+2)]=cr
ans=0
for i in range(n):
      ans+=max(dl[i],dr[i])
print(ans)

Submission status: Accepted

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

a=[0]*(N+1)
for i in range(N):
    if (s[i]=='<'):
        a[i+1]=a[i]+1

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

Submission status: Accepted

Solution code:
s = input()

c = 0
dp = [0] * (len(s) + 1)
for i in range(len(s)):
    if s[i] == '<':
        c += 1
        dp[i + 1] = c
    else:
        c = 0
c = 0
for i in range(len(s))[::-1]:
    if s[i] == '>':
        c += 1
        dp[i] = max(dp[i], c)
    else:
        c = 0
ans = sum(dp)
print(ans)

Submission status: Accepted

Solution code:
s=input()+' '
p=0
l=list()
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        p+=1
    else:
        if s[i]=='<':
            l.append([0,'<',p+1])
        else:
            l.append([p+1,'>',0])
        p=0
a=sum([sum(range(i[2]+1)) if i[1]=='<' else sum(range(i[0]+1)) for i in l])
b=sum([min(l[i][2],l[i+1][0]) for i in range(len(l)-1)])
print(a-b)

Submission status: Accepted

Solution code:
s=input()
n=len(s)+1
lst=[]
now='<'
cnt=0
for i in range(n-1):
    if s[i]!=now:
        lst.append(cnt)
        cnt=1
        now=s[i]
    else:
        cnt+=1
lst.append(cnt)
if len(lst)%2==1:
    lst.append(0)
ans=0
for i in range(0,len(lst),2):
    x=lst[i]
    y=lst[i+1]
    if x>=y:
        ans+=0.5*x*(1+x)+0.5*y*(y-1)
    else:
        ans+=0.5*y*(1+y)+0.5*x*(x-1)
print(int(ans))

Submission status: Accepted

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

def main():
    S = input() + "🐦"
    l = 0
    r = 0
    for i in range(len(S)):
        if S[i:i+2] == "><" or S[i:i+2] == ">🐦":
            r += 1
            yield r
            yield -min(l, r)
            l = 0
            r = 0
        else:
            if S[i] == "<":
                l += 1
                yield l
            elif S[i] == ">":
                r += 1
                yield r
    

    # 0<1<2<(3|7)>6>5>4>3>2>1>0
    # 0<1<2<3<4<5<(6|4)>3>2>1>0
    # >>0<<<<
    # >>>>0<<


print(sum(main()))

Submission status: Accepted

Solution code:
s = input()
ans = 0
t = [0 for i in range(len(s) + 1)]
tmp = 0
for i in range(1, len(s) + 1):
    if s[i - 1] == '<':
        tmp += 1
    else:
        tmp = 0
    t[i] = tmp

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

Submission status: Accepted

Solution code:
s = list(input().rstrip())
n=len(s)+1
from_left = [0]*n
from_right = [0]*n
ans=0
i=0
for i,ss in enumerate(s,1):
    if ss == '>':
        from_left[i] = 0
    else:
        from_left[i] = from_left[i-1]+1
for i,ss in enumerate(s[::-1]):
    i = n-2-i
    if ss == '<':
        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()

a = []
b = [0]
tmp = S[0]

for i in range(len(S)):
    if tmp == S[i] == "<":
        b.append(b[-1]+1)
    elif tmp == S[i] == ">":
        b.append(b[-1]-1)
    else:
        min_b = min(b[0], b[-1])
        if min_b < 0:
            b = list(map(lambda x: x-min_b, b))
        a.append(b)
        if S[i] == "<":
            b = [0,1]
        else:
            b = [0,-1]
    tmp = S[i]
min_b = min(b[0], b[-1])
if min_b < 0:
    b = list(map(lambda x: x-min_b, b))
a.append(b)

ans = 0
tmp = -1
for x in a:
    ans += max(tmp, x[0])
    ans += sum(x) - x[0] - x[-1]
    tmp = x[-1]
ans += x[-1]

print(ans)

Submission status: Accepted

Solution code:
S = input()

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

for i in range(len(S)-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()
n = len(s)
ans = 0
c = [0]*(n+1)
for i in range(n):
    if s[i]=='<':
        c[i+1] = c[i]+1
for i in range(n-1,-1,-1):
    if s[i]=='>':
        c[i] = max(c[i],c[i+1]+1)
print(sum(c))

Submission status: Accepted

Solution code:
s=str(input())
n=len(s)
a=[0]
count=0
for i in range(n):
    if s[i:i+1]=='<':
        count+=1
        a.append(count)
    else:
        count=0
        a.append(0)
#print(a)
count=0
for i in range(n-1,-1,-1):
    if s[i:i+1]=='>':
        count+=1
        a[i]=max(a[i],count)
    else:
        count=0

print(sum(a))

Submission status: Accepted

Solution code:
def main():
    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)
    
    #print(ans)
            
    for i in reversed(range(len(s))):
        if s[i] == '>':
            ans[i] = max(ans[i], ans[i + 1] + 1)
    
    #print(ans)
    print(sum(ans))



if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

for i in range(N-1):
  s = S[i]
  if s == '<':
    from_left[i+1] = from_left[i] + 1

for i in range(N-2,-1,-1):
  s = S[i]
  if s == '>':
    from_right[i] = from_right[i+1] + 1
    
ans = 0
for i in range(N):
  ans += max(from_left[i],from_right[i])
  
print(ans)

Submission status: Accepted

Solution code:
s=input()
a=[0]*(len(s)+1)
b=[0]*(len(s)+1)
flag=0
for i in range(len(s)):
    if s[i]=="<" and flag==0:
        flag=1
        a[i+1]=1
    elif s[i]=="<" and flag==1:
        a[i+1]=a[i]+1
    else:
        flag=0
flag=0
for i in range(len(s)-1,-1,-1):
    if s[i]==">" and flag==0:
        flag=1
        b[i]=1
    elif s[i]==">" and flag==1:
        b[i]=b[i+1]+1
    else:
        flag=0
c=[]
for i in range(len(s)+1):
    c.append(max(a[i],b[i]))
print(sum(c))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
a = [0] * (N+1)
index = 0
while index < N:
  tmp = S[index]
  count = 1
  if index < N-1:
    while S[index+count] == tmp:
      count += 1
      if index+count == N:
        break
  if tmp == '<':
    for j in range(count+1):
      a[index+j] = max(a[index+j],j)
  else:
    for j in range(count+1):
      a[index+count-j] = max(a[index+count-j],j)
  index += count
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def modelAnswer(S:list) -> int:
   l = [0 for i in range(len(S)+1)]
   for n,s in enumerate(S):
      if(s == "<"):
         l[n+1] = l[n] + 1
   for n,s in enumerate(S[::-1]):
      if(s == ">"):
         tmp = l[len(S) - n] + 1
         if (tmp > l[len(S) - n - 1]):
            l[len(S) -n - 1] = tmp
   return sum(l)
def main():
   S = list(input())
   print(modelAnswer(S[:]))
if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
from itertools import*
a = b = 0
for k, n in groupby(input()):
  n = len(list(n))
  a -= n*~n//2 + min(n, b)*(k==">")
  b = n
print(a)

Submission status: Accepted

Solution code:
#AGC040-A
s = list(input())
 
ans = [0 for _ in range(len(s)+1)]
 
for i in range(len(s)):
    if s[i] == '<':
        ans[i+1] = ans[i]+1

for j in range(len(s)-1,-1,-1):
    if s[j] == '>':
        tmp = ans[j+1] + 1
        if tmp > ans[j]:
            ans[j] = tmp
                
print(sum(ans))

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()
Slist = S.replace("><",">,<").split(",")
ans = 0
for s in Slist:
    cnt = Counter(s)
    num = max(cnt["<"],cnt[">"])
    ans += (num+1)*num//2
    num = min(cnt["<"],cnt[">"]) - 1
    ans += (num+1)*num//2

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

Solution code:
#AGC040-A
s = list(input())

ans = [0 for _ in range(len(s)+1)]

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

for j in range(len(s)-1,-1,-1):
    if s[j] == '>':
        tmp = ans[j+1] + 1
        if tmp > ans[j]:
            ans[j] = tmp
                
print(sum(ans))

Submission status: Accepted

Solution code:
def GetPoint(U,D):
    N = 0
    if U >= D:
        N += D*(D-1)/2 + U*(U+1)/2
    else:
        N += D*(D+1)/2 + U*(U-1)/2
    return N
S = input()
N = 0
U = 0
D = 0
for i in range(len(S)):
    if S[i] == "<":
        U += 1
    elif S[i] == ">":
        D += 1
    if i<len(S)-1:
        if (S[i]==">" and S[i+1]=="<"):
            N += GetPoint(U,D)
            U=0
            D = 0
N += GetPoint(U, D)
    # elif S[i] == "<" and S[i+1] == ">":

print(int(N))