Problem:


Score : 300 points

Problem Statement

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

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

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

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

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

Constraints

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

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

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

<>>

Sample Output 1

3

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

Sample Input 2

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

Sample Output 2

28



Sample input:
<>>


Sample output:
3

Submission status: Accepted

Solution code:
S = input()
slst = [[] for _ in range(len(S) + 1)]
tmp = S[0]
cnt = 0
index = 0
for i in range(len(S)):
    if tmp == S[i]:
        cnt += 1
    else:
        slst[index].append(tmp)
        slst[index].append(cnt)
        index += 1
        tmp = S[i]
        cnt = 1

slst[index].append(tmp)
slst[index].append(cnt)

dp = [0] * (len(S) + 1)
if slst[0][0] == '<':
    dp[0] = 0
else:
    dp[0] = slst[0][1]

index = 1
for i in range(len(S)):
    if slst[i] == []:
        break

    if slst[i][0] == '>':
        dp[index] = dp[index - 1] + ((slst[i][1]) * ((slst[i][1] - 1))) // 2
        index += 1
    else:
        if slst[i + 1] == []:
            dp[index] = dp[index - 1] + ((slst[i][1] + 1) * ((slst[i][1]))) // 2
            index += 1
        else:
            if slst[i][1] < slst[i + 1][1]:
                tdp = slst[i + 1][1]
                for k in range(1, slst[i][1]):
                    tdp += k
                dp[index] = dp[index - 1] + tdp
                index += 1

            else:
                dp[index] = dp[index - 1] + ((slst[i][1] + 1) * ((slst[i][1]))) // 2
                index += 1


print(dp[index - 1])

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

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


def solve():
    s = list(input())
    res = find_sum(s)
    print(res)


def find_sum(S):
    prev = S[0]
    series = 1
    l = []
    for i in range(1, len(S)):
        if prev == S[i]:
            series += 1
        else:
            l.append((prev, series))
            prev = S[i]
            series = 1
    l.append((prev, series))
    prev_max = l[0][1]
    prev = calc(prev_max)
    res = prev
    for s, n in l[1::]:
        if s == '<':
            prev = calc(n)
            prev_max = n
            res += prev
        else:
            if n >= prev_max:
                res -= prev_max
                prev = calc(n)
                res += prev
            else:
                prev = calc(n - 1)
                res += prev

    return res


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
S = input()
def rle_encode(data):
    encoding = []
    prev_char = ''
    count = 1

    if not data: return ''

    for char in data:
        # If the prev and current characters
        # don't match...
        if char != prev_char:
            # ...then add the count and character
            # to our encoding
            if prev_char:
                encoding.append([int(count), prev_char])
            count = 1
            prev_char = char
        else:
            # Or increment our counter
            # if the characters do match
            count += 1
    else:
        # Finish off the encoding
        encoding.append([int(count), prev_char])
        return encoding

S_rle = list(rle_encode(S))
if len(S_rle) == 1:
  print(sum(range(S_rle[0][0]+1)))
  exit()
total = 0
if S_rle[0][1] == '>':
  head = S_rle[0]
  S_rle.pop(0)
  total += sum(range(head[0]+1))
else:
  head = []
if S_rle[-1][1] == '<':
  tail = S_rle[-1]
  S_rle.pop(-1)
  total += sum(range(tail[0]+1))
else:
  tail = []
body = S_rle[:]
for i in range(len(body)//2):
  num1, num2 = body[2*i][0], body[2*i+1][0]
  total += sum(range(max(num1, num2)+1)) + sum(range(min(num1, num2)))
print(total)

Submission status: Accepted

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

a = [0]*N
#foward
for i, s in enumerate(S):
  if s=="<":
    a[i+1]=a[i]+1
#back
S_ = list(reversed(S))
j=0
for s in S_:
  if s==">":
    if a[N-1-(j+1)]<=a[N-1-j]:
      a[N-1-(j+1)]=a[N-1-j]+1
  j+=1
print(sum(a))

Submission status: Accepted

Solution code:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

s = input()
n = len(s)

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

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

print(sum(l))

Submission status: Accepted

Solution code:
S=input()

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

Submission status: Accepted

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

ans = [0] * N
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))

Submission status: Accepted

Solution code:
import re
S = input()

po=[]
ne=[]
li = [m.span()[0] for m in re.finditer('><', S)]
result = []
n = 0
for i in S:
    if i == "<":
        n += 1
    else:
        break
po.append(n)
for i in li:
    s = "<"
    n = 0
    while s == S[i+1]:
        n += 1
        i += 1
        if i+1 >= len(S):
            break
    po.append(n)
for i in li:
    s = ">"
    n = 0
    while s == S[i]:
        n += 1
        i -= 1
        if i < 0:
            break
    ne.append(n)
n = 0
for i in S[::-1]:
    if i == ">":
        n += 1
    else:
        break
ne.append(n)
for i,l in enumerate(po):
    if l < ne[i]:
        if l > 0:
            result.append((1/2)*(l-1)*l)
        if ne[i] > 0:
            result.append((1/2)*ne[i]*(ne[i]+1))
    else:
        if l > 0:
            result.append((1/2)*l*(l+1))
        if ne[i] > 0:
            result.append((1/2)*ne[i]*(ne[i]-1))
print(int(sum(result)))

Submission status: Accepted

Solution code:
s=input()
tmp=[0]
cnt=0
for i in range(len(s)):
    if s[i]=='<':
        tmp.append(tmp[i]+1)
    else :
        tmp.append(0)

for i in reversed(range(len(s))):
    if s[i]=='>':
        tmp[i]=max(tmp[i],tmp[i+1]+1)
print(sum(tmp))

Submission status: Accepted

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    S = args[0]
    A = [0 for _ in range(len(S)+1)]

    m = 0
    for n in range(1, len(S)+1):
        if 0 < m:
            A[n] = m
            m -= 1
        elif S[n-1] == '<':
            A[n] = A[n-1]+1
        else:
            m = 0
            while n+m < len(S) and S[n+m] == '>':
                m += 1

            A[n-1] = max(m+1, A[n-1])
            A[n] = m
            m -= 1

    # for n in range(0, len(S)):
    #     print('{}{}'.format(A[n], S[n]), end='')
    # print(A[-1])

    return str(sum(A))


if __name__ == "__main__":
    print(solve(*[input() for _ in range(1)]))

Submission status: Accepted

Solution code:
S = input()
N = len(S)+1
k = 0
score= 0
countup = 0
countdown = 0
final = None
for i in range(N-1):
  if S[i] == "<":
    if final == ">":
      score += int(countdown*(countdown-1)/2)
      if countup <= countdown:
        score += countdown - countup
      countup = 0
    countdown = 0
    final = "<"
    countup += 1
    score += countup
  elif S[i] == ">":
    final = ">"
    countdown += 1
if final == ">":
  score += int(countdown*(countdown-1)/2)
  if countup <= countdown:
    score += countdown - countup
print(score)

Submission status: Accepted

Solution code:
S = input()
dp = []
cnt = 1
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 1
    else:
        dp.append(cnt)
        cnt = 1
dp.append(cnt)
ans = 0
if S[0] == '<':
    for i in range(0, len(dp)-1, 2):
        N = max(dp[i], dp[i+1])
        n = min(dp[i], dp[i+1])
        ans += sum(range(N+1)) + sum(range(n))
    if len(dp)%2 == 1:
        ans += sum(range(dp[-1]+1))
else:
    ans += sum(range(dp[0]+1))
    for i in range(1, len(dp)-1, 2):
        N = max(dp[i], dp[i+1])
        n = min(dp[i], dp[i+1])
        ans += sum(range(N+1)) + sum(range(n))
    if len(dp)%2 == 0:
        ans += sum(range(dp[-1]+1))
print(ans)

Submission status: Accepted

Solution code:
s=input()+"1"
a=0
b=[]
i=0
l=len(s)
e=0
while True:
    if s[i]==s[i+1]:
        a+=1
    else:
        b.append(a+1)
        a=0
    i+=1
    if i+1>=l:
        break
if s[-2]=='<':
    b.append(0)
if s[0]=='>':
    b.insert(0,0)
for i in range(len(b)//2):
    c,d=max(b[i*2],b[i*2+1]),min(b[i*2],b[i*2+1])
    e+=(c*(c+1)//2)+(d*(d-1)//2)
print(e)

Submission status: Accepted

Solution code:
from itertools import*
s=input()
x=[[k,len(list(v))]for k,v in groupby(s)]

ans=0
#print(x)
for i in range(len(x)):
    try:
        if x[i][0]=="<" and x[i+1][0]==">":
            n=max(x[i][1],x[i+1][1])
            m=min(x[i][1],x[i+1][1])
            ans+=(n+1)*n//2+(m-1)*m//2
    except:
        break

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

print(ans)

Submission status: Accepted

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

S = list(input())

prev = S[0]
series = 1
l = []

for i in range(1, len(S)):
    if prev == S[i]:
        series += 1
    else:
        l.append((prev, series))
        prev = S[i]
        series = 1

l.append((prev, series))

prev_max = l[0][1]
prev = calc(prev_max)
res = prev

for s, n in l[1::]:
    if s == '<':
        prev = calc(n)
        prev_max = n
        res += prev
    else:
        if n >= prev_max:
            res -= prev_max
            prev = calc(n)
            res += prev
        else:
            prev = calc(n-1)
            res += prev

print(int(res))

Submission status: Accepted

Solution code:
# A - ><
S = str(input())
####
ans = [0] * (len(S)+1)
tani = []

for i,s in enumerate(S+'<'):
    if s == '<':
        if i == 0:
            tani.append(i)
        elif S[i-1] == '>':
            tani.append(i)
#print(tani)

for t in tani:
    #print('tani', t)

    i = t
    val = 0
    while True:
        if i >= len(S):
            break
        if S[i] == '>':
            break
        if ans[i+1] < val + 1:
            ans[i+1] = val + 1
        i += 1
        val += 1

    i = t
    val = 0
    while True:
        if i <= 0:
            break
        if S[i-1] == '<':
            break
        if ans[i-1] < val + 1:
            ans[i-1] = val + 1
        i -= 1
        val += 1

#print(ans)

print(sum(ans))

Submission status: Accepted

Solution code:
s = input()
n = len(s) + 1
ans = 0
val = 0
segument = 0
buf = "<"
for char in s:
    if char == ">":
        if buf == "<":
            segument = 0
        val -= 1
        ans += val
        segument += 1
    else:
        if buf == "<":
            val += 1
            ans += val
            segument += 1
        else:
            if val < 0:
                ans -= (segument + 1) * val
            elif val > 0:
                ans -= segument * val
            segument = 0
            val = 1
            ans += val
    buf = char
if buf == ">":
    if val < 0:
        ans -= (segument + 1) * val
    elif val > 0:
        ans -= segument * val
print(ans)

Submission status: Accepted

Solution code:
import copy
S = input()
ans = 0
cnt1 = 1
cnt = []
i = 0
if len(S)==1:
    print(1)
    exit()
before = S[0]
for i in range(1,len(S)):
    if S[i] == before:
        cnt1 += 1
    else:
        cnt.append([cnt1,before])
        before = S[i]
        cnt1 = 1
if cnt1 > 0:
    cnt.append([cnt1,S[i]])
cnt2 = copy.deepcopy(cnt)
for i in range(1,len(cnt)):
    if cnt2[i-1][1] == "<":
        if cnt2[i-1][0] < cnt2[i][0]:
            if cnt[i-1][0] > 0:
                cnt[i-1][0] -= 1
        else:
            if cnt[i][0] > 0:
                cnt[i][0] -= 1

for i in range(len(cnt)):
    ans += cnt[i][0]*(cnt[i][0]+1)//2
print(ans)

Submission status: Accepted

Solution code:
# import numpy as np
# import time

def main():
    s = input()
    # s = '<>>><<><<<<<>>><' # test
    # s = '>>>>>>>'
    n_list = [0] * (len(s)+1)
    # n_list = np.zeros(len(s)+1)

    for i in range(1, len(s)):
        if s[i-1] == '<':
            n_list[i] = n_list[i-1]+1
        else: # i = >
            if s[i] == '>':
                continue
            # j = i # jは左側の                           文字のインデックス
            k = 1                          
            for j in range(i, 1, -1):
                if s[j-1] == '<':
                    n_list[j] = max(n_list[j-1], n_list[j+1])+1
                    break
                n_list[j-1] = k
                k+=1
    
    if s[-1] == '<':
        n_list[-1] = n_list[-2]+1
    elif s[-1] == '>':
        # j = i # jは左側の                           文字のインデックス
        k = 1                     
        for j in range(len(s), 1, -1):
            if s[j-1] == '<':
                n_list[j] = max(n_list[j-1], n_list[j+1])+1
                break
            n_list[j-1] = k
            k+=1
    if s[0] == '>':
        n_list[0] = n_list[1]+1
            
        # print('i={} {}'.format(i, n_list))    
 
    # print(n_list)
    print(int(sum(n_list)))


if __name__ == "__main__":
    # start = time.time()
    main()    
    # elapsed_time = time.time() - start
    # print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")

Submission status: Accepted

Solution code:
S =input()
ZeroAdd =[]
for i in range(len(S)):
    if i == 0 and S[0] == "<":
        ZeroAdd.append(0)
    elif i == len(S)-1 and S[-1] == ">":
        ZeroAdd.append(len(S))
    elif S[i-1]==">" and S[i]=="<":
        ZeroAdd.append(i)
ans = 0
moji ="a"
if ZeroAdd[0] != 0:
    n = ZeroAdd[0]
    ans += n*(n+1)//2
if ZeroAdd[-1] != len(S):
    n = len(S) - ZeroAdd[-1]
    ans += n*(n+1)//2
if len(ZeroAdd)>1:
    for i in range(len(ZeroAdd)-1):
        moji = S[ZeroAdd[i]:ZeroAdd[i+1]]
        Sa = moji.count("<")
        La = moji.count(">")
        if Sa > La:
            n = Sa
            m = La - 1
        else:
            n = La
            m = Sa - 1
        ans += n*(n+1)//2+m*(m+1)//2
print(ans)

Submission status: Accepted

Solution code:
S=input()

ans=0
flag=False
if S[0]=='<':
  cnt1,cnt2=1,0
  for i in range(1,len(S)):
    if S[i-1]!=S[i]:
      if flag==False:
        flag=True
      else:
        flag=False
        if cnt1>cnt2:
          ans+=(cnt1*(cnt1+1)/2) + ((cnt2-1)*cnt2/2)
        else:
          ans+=((cnt1-1)*cnt1/2) + (cnt2*(cnt2+1)/2)
        cnt1,cnt2=0,0

    if S[i]=='<':
      cnt1+=1
    else:
      cnt2+=1
  if cnt1!=0 or cnt2!=0:
    if cnt1>cnt2:
      ans+=(cnt1*(cnt1+1)/2) + ((cnt2-1)*cnt2/2)
    else:
      ans+=((cnt1-1)*cnt1/2) + (cnt2*(cnt2+1)/2)
    print(int(ans))
  else:
    if S[-1]=='>':
      print(int(ans))
    else:
      print(int(ans)+1)
else:
  cnt1,cnt2=0,1
  for i in range(1,len(S)):
    if S[i-1]!=S[i]:
      if flag==True:
        flag=False
      else:
        flag=True
        if cnt1>cnt2:
          ans+=(cnt1*(cnt1+1)/2) + ((cnt2-1)*cnt2/2)
        else:
          ans+=((cnt1-1)*cnt1/2) + (cnt2*(cnt2+1)/2)
        cnt1,cnt2=0,0

    if S[i]=='<':
      cnt1+=1
    else:
      cnt2+=1
  if cnt1!=0 or cnt2!=0:
    if cnt1>cnt2:
      ans+=(cnt1*(cnt1+1)/2) + ((cnt2-1)*cnt2/2)
    else:
      ans+=((cnt1-1)*cnt1/2) + (cnt2*(cnt2+1)/2)
    print(int(ans))
  else:
    if S[-1]=='>':
      print(int(ans))
    else:
      print(int(ans)+1)

Submission status: Accepted

Solution code:
s = input()
ans = []
count = 1
ans_sum = 0
key = s[0]
def goukei(a):
    if a == 0 or a == -1:
        return 0
    if a == 1:
        return 1
    else:
        return (1+a)/2*a
for i in range(1,len(s)):
    if key == s[i]:
        count += 1
    else:
        ans.append(count)
        count = 1
        key = s[i]

ans.append(count)

if s[0] == "<":
    if len(ans)%2==1:
        ans.append(0)
    for a,b in zip(ans[0::2],ans[1::2]):
        #print("{} {}".format(a,b))
        if a < b:
            ans_sum += goukei(a-1)
            if b == 1:
                ans_sum += 0
            else:
                ans_sum += goukei(b)
        elif b < a:
            ans_sum += goukei(a)
            ans_sum += goukei(b-1)
        else:
            ans_sum += goukei(a)
            ans_sum += goukei(b-1)
        #print(ans_sum)
else:
    ans_sum += goukei(ans[0])
    if len(ans[1:])%2 == 1:
        ans.append(0)
    for a,b in zip(ans[1::2],ans[2::2]):
        if a < b:
            ans_sum += goukei(a-1)
            if b == 1:
                ans_sum += 0
            else:
                ans_sum += goukei(b)
        elif b < a:
            ans_sum += goukei(a)
            ans_sum += goukei(b-1)
        else:
            ans_sum += goukei(a)
            ans_sum += goukei(b-1)

print(int(ans_sum))

Submission status: Accepted

Solution code:
s = input()
s += '<' if s[-1] == '>' else '>'
n = len(s)
f = lambda x: x * (x + 1) // 2

ans = 0
a, k = 1, 0
for i in range(n-1):
    if s[i] == s[i+1]:
        a += 1
        ans += a
    else:
        if s[i] == '<':
            k = a
        else:
            ans -= min(a, k)
        a = 1
        ans += a
print(ans)

Submission status: Accepted

Solution code:
# import numpy as np
# import time

def main():
    s = input()
    # s = '<>>><<><<<<<>>><' # test
    # s = '>>>>>>>'
    n_list = [0] * (len(s)+1)
    # n_list = np.zeros(len(s)+1)

    for i in range(1, len(s)):
        if s[i-1] == '<':
            n_list[i] = n_list[i-1]+1
        else: # i = >
            if s[i] == '>':
                continue
            # j = i # jは左側の                           文字のインデックス
            k = 1                          
            for j in range(i, 1, -1):
                if s[j-1] == '<':
                    n_list[j] = max(n_list[j-1], n_list[j+1])+1
                    break
                n_list[j-1] = k
                k+=1
    
    if s[-1] == '<':
        n_list[-1] = n_list[-2]+1
    elif s[-1] == '>':
        # j = i # jは左側の                           文字のインデックス
        k = 1                     
        for j in range(len(s), 1, -1):
            if s[j-1] == '<':
                n_list[j] = max(n_list[j-1], n_list[j+1])+1
                break
            n_list[j-1] = k
            k+=1
    if s[0] == '>':
        n_list[0] = n_list[1]+1
            
        # print('i={} {}'.format(i, n_list))    
 
    # print(n_list)
    print(int(sum(n_list)))


if __name__ == "__main__":
    # start = time.time()
    main()    
    # elapsed_time = time.time() - start
    # print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")

Submission status: Accepted

Solution code:
S = [c for c in input()]
N = len(S)
L = []
R = []
S.append('f')

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

M = len(L)
if L[0] < 0:
  R.append(abs(L[0]))

for j in range(M-1):
  if L[j] > 0:
    R.append(max([abs(L[j]),abs(L[j + 1])]))
    R.append(min([abs(L[j]),abs(L[j + 1])])-1)
if L[-1] > 0:
  R.append(abs(L[-1]))

print(sum([(1+k)*k//2 for k in R]))

Submission status: Accepted

Solution code:
s=list(input())

ss=[-1]*(len(s)+1)
kind=[]
i=0
tmp=s[0]
cnt=0
j=0
for i in range(len(s)):
    if tmp == s[i]:
        cnt+=1
    else:
        tmp=s[i]
        kind.append(cnt)
        # if mx < cnt:
        #     mx=cnt
        #     mxidx=i
        cnt=1
    if s[i]=='<':
        ss[i]=j
        j+=1
    else:
        j=0
kind.append(cnt)
j=0
for i in range(-1,-len(s)-1,-1):
    if s[i]=='>':
        ss[i]=j
        j+=1
    else:
        j=0
if ss[0]==-1:
    ss[0]=ss[1]+1


if ss[-1]==-1:
    ss[-1]=ss[-2]+1
    j=0

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

print(ans)

Submission status: Accepted

Solution code:
import sys
s=input()
def wa(i):
  return (i+1)*i/2
sa=s.split("<")
sb=s.split(">")
ta=[i for i in [len(i) for i in sa] if i!=0]
tb=[i for i in [len(i) for i in sb] if i!=0]
ma=[wa(i) for i in ta]
mb=[wa(i) for i in tb]
goukei=sum(ma)+sum(mb)
n=max(len(ta),len(tb))
so=list(s)
if len(ma)==0 or len(mb)==0:
  print(int(goukei))
  sys.exit()
if so[0]=="<":
  if so[len(s)-1]=="<":
    for i in range(n-1):
      if ma[i]<mb[i]:
        goukei=goukei-ta[i]
      else:
        goukei=goukei-tb[i]
    print(int(goukei))
  else:
    for i in range(n):
      if ma[i]<mb[i]:
        goukei=goukei-ta[i]
      else:
        goukei=goukei-tb[i]
    print(int(goukei))
else:
  if so[len(s)-1]==">":
    for i in range(n-1):
      if ma[i+1]<mb[i]:
        goukei=goukei-ta[i+1]
      else:
        goukei=goukei-tb[i]
    print(int(goukei))
  else:
    if len(ta)==1:
      print(int(goukei))
    else:
      for i in range(n-1):
        if ma[i+1]<mb[i]:
          goukei=goukei-ta[i+1]
        else:
          goukei=goukei-tb[i]
      print(int(goukei))

Submission status: Accepted

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

S = input()
s_list = list(S)
w_list = [0]
min_n = 0
s_l = len(s_list)
totsu_list = [False]

if s_list[0] == "<":
    ou_list = [True]
else:
    ou_list = [False]

t_list = []
if ou_list[0]:
    t_list = ["ou"]
else:
    t_list = ["totsu"]

for i, char in enumerate(s_list):
    # 凹であるかどうか
    is_ou = False
    is_totsu = False
    if i == s_l - 1:
        if char == ">":
            is_ou = True
    else:
        if s_list[i] == "<" and s_list[i + 1] == ">":
            is_totsu = True
        elif s_list[i] == ">" and s_list[i + 1] == "<":
            is_ou = True

    ou_list.append(is_ou)
    totsu_list.append(is_totsu)
    if is_ou:
        t = "ou"
    elif is_totsu:
        t = "totsu"
    elif char == "<":
        t = "up"
    else:
        t = "down"
    t_list.append(t)

    if char == "<":
        w_list.append(w_list[i] + 1)
    else:
        w_list.append(w_list[i] - 1)
        min_n = min(w_list[i] - 1, min_n)

x_list = []
d = abs(min_n)
w_len = len(w_list)
for i, w in enumerate(w_list):
    t = t_list[i]
    if t == "ou":
        x = 0
    elif t == "up" or i == w_len - 1:
        x = x_list[i - 1] + 1
    else:
        x = w_list[i] + d
    x_list.append(x)

x_len = len(x_list)
y_list = x_list[:]

total = 0

for i in range(x_len):
    idx = x_len - (i + 1)
    t = t_list[idx]
    if t == "down":
        y_list[idx] = y_list[idx + 1] + 1
    elif t == "ou" or t == "down":
        pass
    elif t == "totsu":
        if idx == 0 or idx == x_len:
            pass
        else:
            a = y_list[idx - 1]
            b = y_list[idx + 1]
            y_list[idx] = max(a, b) + 1
    total += y_list[idx]

if len(y_list) >= 3:
    if t_list[0] == "totsu":
        total -= y_list[0]
        total += y_list[1] + 1
    if t_list[-1] == "totsu":
        total -= y_list[-1]
        total += y_list[-2] + 1

# ans = sum(z_list)
ans = total
print(ans)

Submission status: Accepted

Solution code:
import sys
import math

input = sys.stdin.readline

S = input()
a = []
b = []

for num,i in enumerate(S):
  if num != 0 and num != len(S)-1:
    if i == "<":
      if S[num-1] == ">":
        b.append("".join(a))
        a = []
  elif S[-1] == "<":
    if S[num-1] == ">":
      b.append("".join(a))
      a = []
      
  a.append(i)
b.append("".join(a))

ans = 0

for j in range(len(b)):
  mx = max(b[j].count("<"),b[j].count(">"))
  mn = min(b[j].count("<"),b[j].count(">"))
  
  ans += mx * (mx + 1) // 2
  if mn >= 2:
    ans += (mn-1) * mn // 2
    
print(ans)

Submission status: Accepted

Solution code:
s = input()
al = len(s) + 1
m = ''
n = 0
su = 0
li = []
sl = []
for c in s:
    if m == '':
        m = c
    if m != c:
        li.append(n)
        m = c
        n = 0
    if c == '>': 
        n += 1
    else:
        n -= 1
li.append(n)
ni = 0
for ll in li:
    if ll < 0:
        ni = abs(ll)
        continue
    else:
        if ni != 0:
            if len(sl) == 0:
                sl.append(0)
            for nii in range(ni):
                sl.append(nii + 1)
            if ni < ll:
                sl.pop(-1)
            else:
                ll -= 1
        for lll in range(ll, -1, -1):
            sl.append(lll)
        ni = 0
if ni != 0:
    for nii in range(ni):
        sl.append(nii + 1)

#print(li)
#print(al)
#print(sl)
#print(len(sl))
print(sum(sl))

Submission status: Accepted

Solution code:
str_S = input()

int_a = [0]
cnt = 0

for i in range(len(str_S)):
	if str_S[i] == "<":
		if cnt != 0:
			int_a[i - cnt] = max(int_a[i - cnt], cnt)
			for j in range(cnt):
				int_a[i - j] = j

		int_a.append(int_a[i] + 1)
		cnt = 0
	
	else:
		if i == len(str_S) -1 :
			if int_a[i] == 0:
				int_a[i - cnt] = max(int_a[i - cnt], cnt+1)
				for j in range(cnt):
					int_a[i - j] = cnt - j
		else:
			int_a.append(0)
			cnt += 1		



ans = 0

for k in range(len(int_a)):
	ans += int_a[k]

print(ans)

Submission status: Accepted

Solution code:
s = list(input())

now = '>'
count = 0
nums = []
score = 0

for i in range(len(s)) :
    if s[i] == now :
        count += 1
    else :
        nums.append(count)
        count = 1
        now = s[i]

nums.append(count)

if s[len(s) - 1] == '>' :
    nums.append(0)

for j in range(len(nums)) :
    score += nums[j] * (nums[j] + 1) //2
    if j > 0 and j % 2 == 0 :
        if nums[j - 1] > nums[j] :
            score -= nums[j]
        else :
            score -= nums[j - 1]

print(score)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)

s = input()
n = len(s) + 1
tmp = [0]*n

def rec(i, prev=None):
    if i == n-1:
        if prev == ">":
            tmp[i] = 0
        else:
            tmp[i] = tmp[i-1]+1
        return tmp[i]
    if prev is None:
        if s[i] == "<":
            tmp[i] = 0
            rec(i+1,prev="<")
        else:
            tmp[i] = rec(i+1,prev=">")+1
    else:
        if s[i] == "<":
            if prev == ">":
                tmp[i] = 0
                rec(i+1,prev="<")
            else:
                tmp[i] = tmp[i-1]+1
                rec(i+1,prev="<")
        else:
            if prev == ">":
                tmp[i] = rec(i+1,prev=s[i])+1
            else:
                tmp[i] = max(tmp[i-1], rec(i+1,s[i]))+1
    return tmp[i]

rec(0)
#print(tmp)
print(sum(tmp))

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
input = sys.stdin.readline

_s = input()


def chker(s):
    l, r, minisum = 0, 0, 0
    if s[0] == '<':
        l += 1
    elif s[0] == '>':
        r += 1
    for i in range(1, len(s)):
        if s[i - 1] == '>' and s[i] == '<':
            l, r = (l, r) if l > r else (r, l)
            minisum += l * (l + 1) / 2 + r * (r - 1) / 2
            l, r = 1, 0
        else:
            if s[i] == '<':
                l += 1
            elif s[i] == '>':
                r += 1

    l, r = (l, r) if l > r else (r, l)
    minisum += l * (l + 1) / 2 + r * (r - 1) / 2

    print(int(minisum))


chker(_s)

Submission status: Accepted

Solution code:
import re

S = raw_input()

array = []
prev = None
for i in S:
    if prev is None:
        prev = i
        duplicate_count = 1
        continue
    if prev == i:
        duplicate_count += 1
    else:
        array.append((prev, duplicate_count))
        duplicate_count = 1
    prev = i
array.append((prev, duplicate_count))

array = [(k, range(v + 1)) for k, v in array]

for i in range(len(array) - 1):
    if array[i][0] == '<' and array[i + 1][0] == '>':
        if array[i][1][-1] < array[i + 1][1][-1]:
            array[i] = array[i][0], array[i][1][:-1]
        else:
            array[i + 1] = array[i + 1][0], array[i + 1][1][:-1]
print sum(sum(v) for k, v in array)

Submission status: Accepted

Solution code:
S = list(input().split('><'))
if len(S) != 1:
    for n in range(len(S)):
        if n == 0:
            S[n] = S[n] + '>'
        elif n == len(S)-1:
            S[n] = '<' + S[n]
        else:
            S[n] = '<' + S[n] + '>'
ans = 0
for n in range(len(S)):
    a = S[n].count('<')
    b = len(S[n])-a
    if a >= b:
        ans += a*(a+1)//2
        ans += b*(b-1)//2
    else:
        ans += b*(b+1)//2
        ans += a*(a-1)//2
print(ans)

Submission status: Accepted

Solution code:
s = str(input())
l = list(s)
a = 1
result = 0
first_s = l[0]
tmp_s = first_s
count = 0
conseq = []
for item in l:
    if item == tmp_s:
        count += 1
    else:
        conseq.append(count)
        count = 1
        tmp_s = item
conseq.append(count)

def my_sum(n, m):
    if n == m:
        return n
    else:
        tmp = 0
        for i in range(n, m+1):
            tmp += i
        return tmp

if first_s == '>':
    result = conseq[0]
tmp_s = first_s
for i in range(len(conseq)):
    if i+1 == len(conseq):
        if tmp_s =='<':
            result += my_sum(0, conseq[i])
        else:
            result += my_sum(0, conseq[i]-1)
        break
    if tmp_s == '<':
        if conseq[i] >= conseq[i+1]:
            result += my_sum(0, conseq[i])
        else:
            result += my_sum(0, conseq[i])
            result += conseq[i+1]-conseq[i]
        tmp_s = '>'
    else:
        result += my_sum(0,conseq[i]-1)
        tmp_s = '<'
print(result)

Submission status: Accepted

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

for i in range(len(s)):
    if s[i]=='<' and arr[i]>=arr[i+1]:
        arr[i+1]=arr[i]+1
print(sum(arr))

Submission status: Accepted

Solution code:
from itertools import groupby

S = input()

G = [(k, len(tuple(v))) for k, v in groupby(S)]

INF = float("inf")

ans = 0
pre_k, pre_v = "", INF
for k, v in G:
    ans += v * (v + 1) // 2
    if pre_k == "<" and k == ">":
        ans -= min(pre_v, v)
    pre_k, pre_v = k, v

print(ans)