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: Wrong Answer

Solution code:
S = list(input())
zeroone = []
for i in range(len(S)):
    if S[i] == "<":
        zeroone.append(1)
    else:
        zeroone.append(-1)

cnt = [0]
for i in range(len(zeroone)-1):
    if zeroone[i+1] != zeroone[i]:
        cnt.append(i+1)
cnt.append(len(zeroone))

ans = [0] * (len(zeroone)+1)
for i in range(len(zeroone)-1):
    if zeroone[i+1] - zeroone[i] > 0:
        for j in range(i+1, cnt[cnt.index(i+1) + 1]):
            ans[j+1] = ans[j] + 1

        for k in range(cnt[cnt.index(i+1) - 1], i+1)[::-1]:
            ans[k] = max(ans[k+1] + 1, ans[k])

print(sum(ans))

Submission status: Wrong Answer

Solution code:
# A - ><
S = str(input())

ans = 0
tmp = 0
# if S[0] == "<":
#     tmp = 0
# else:
#     tmp = 1


for i in range(len(S)+1):
    if i == 0 and S[0] == "<":
        tmp = 0
    elif i == len(S) and S[i-1] == ">":
        tmp = 0
    elif i == len(S) and S[i-1] == "<":
        tmp += 1
#    elif i == len(S) and S[i] == ">":

    elif S[i-1] == ">" and S[i] == "<":
        tmp = 0
    else:
        tmp += 1
    ans += tmp

print(ans)

Submission status: Wrong Answer

Solution code:
li = list(input())

i = 0
j = 0
j1 = 0
k=1

for l in li:
    if l == '<':
        j += 1
        i += j
        k = 0
        j1 = 1
    elif l == '>':
        if j == 1:
            j = 0
            k += 1
            j1 = 0
        else:
            j = 0
            if j1 == 0:
                i += k
        j1 = 0
        k +=  1
    else:
        break

print(i)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# AGC A

"""
si = "<" : ai < ai + 1
si = ">" : ai > ai + 1
"""
s = input()
res = []
n = 0
i = 0
while i < len(s):
    if s[i] == "<":
        res.append(n)
        n += 1
        i += 1
    else:
        count = 0
        while i < len(s) and s[i] == ">":
            count += 1
            i += 1
        if n < count:
            n += count - n
        else:
            n -= 1
        for _ in range(count):
            res.append(n)
            n -= 1
            
print(sum(res))        
#print(res)

Submission status: Wrong Answer

Solution code:
s = input()

# <>  >< の部分を探す？

# <>の部分が最小になるようにする
# →この部分が一番大きい

# 切り替わる部分を探す

sa = []
now = s[0]
cnt = 0

for i in range(len(s)):
  if s[i] != now:
    sa.append(cnt)
    cnt=1
  else:
    cnt += 1

  now = s[i]

else:
  sa.append(cnt)


ans = 0
# print(sa)

if s[0] == '<':
  for i,n in enumerate(sa):
    if i % 2 == 0:
      ans += (n+1)*n //2
    else:
      ans += (n-1)*n // 2
else:
  for i,n in enumerate(sa):
    if i % 2 == 1:
      ans += (n+1)*n //2
    else:
      ans += (n-1)*n // 2

print(ans)

Submission status: Wrong Answer

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

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


print(sum(a))

Submission status: Wrong Answer

Solution code:
s=input()
l=[]
if s[0]=='<':
  l.append(1)
else:
  l.append(-1)
for i in range(len(s)-1):
  if s[i]=='<' and s[i+1]=='>':
    l.append(-1)
  elif s[i]=='<' and s[i+1]=='<':
    l[-1]+=1
  elif s[i]=='>' and s[i+1]=='>':
    l[-1]-=1
  elif s[i]=='>' and s[i+1]=='<':
    l.append(1)

count=0    

if l[0]>0:
  if len(l)%2==0:
    for i in range(len(l)//2):
      M=max(abs(l[i*2]),abs(l[i*2+1]))
      m=min(abs(l[i*2]),abs(l[i*2+1]))
      count+=(M*(M+1)/2+m*(m-1)/2)
    print(int(count))
  elif len(l)%2==1:
    count+=abs(l[0])*(abs(l[0]-1))/2
    for i in range(len(l)//2):
      M=max(abs(l[i*2]),abs(l[i*2+1]))
      m=min(abs(l[i*2]),abs(l[i*2+1]))
      count+=(M*(M+1)/2+m*(m-1)/2)
    count+=abs(l[-1])*(abs(l[-1])+1)/2
    print(int(count))
else:
  if len(l)%2==0:
    count+=abs(l[0])*(abs(l[0])+1)/2
    for i in range((len(l)-1)//2):
      M=max(abs(l[i*2+1]),abs(l[i*2+2]))
      m=min(abs(l[i*2+1]),abs(l[i*2+2]))
      count+=(M*(M+1)/2+m*(m-1)/2)
    count+=abs(l[-1])*(abs(l[-1])+1)/2
    print(int(count))
  else:
    count+=abs(l[0])*(abs(l[0])+1)/2
    for i in range((len(l)-1)//2):
      M=max(abs(l[i*2+1]),abs(l[i*2+2]))
      m=min(abs(l[i*2+1]),abs(l[i*2+2]))
      count+=(M*(M+1)/2+m*(m-1)/2)
    print(int(count))

Submission status: Wrong Answer

Solution code:
S=input()

ans=0
flag=False
if S[0]=='<':
  cnt1,cnt2=1,0
else:
  cnt1,cnt2=0,1  
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)

Submission status: Wrong Answer

Solution code:
# A - ><
S = str(input())

ans = 0
tmp = 0
# if S[0] == "<":
#     tmp = 0
# else:
#     tmp = 1


for i in range(len(S)+1):

    if i == len(S) and S[i-1] == ">":
        tmp = 0
    elif i == len(S) and S[i-1] == "<":
        tmp += 1
#    elif i == len(S) and S[i] == ">":

    elif S[i-1] == ">" and S[i] == "<":
        tmp = 0
    else:
        tmp += 1
    ans += tmp

print(ans)

Submission status: Wrong Answer

Solution code:
S=input()

Submission status: Wrong Answer

Solution code:
import math

S = list(input())
ans = 0
lrlist = []
left = 0
right = 0
if S[0] == '<':
  flag = 0
else:
  flag = 1
anslist = []

for i in range(len(S)):
  if S[i-1] != S[i]:
    lrlist.append(max(left, right))
    right = 0
    left = 0
  if S[i] == '>':
    left += 1
  else:
    right += 1
  if i == len(S)-1:
    lrlist.append(max(left, right))

for i in range(len(lrlist)):
  if flag % 2 == 0:
    if lrlist[i] != 1:
      ans += (1/2)*(lrlist[i])*(lrlist[i]+1)
      anslist.append((1/2)*(lrlist[i])*(lrlist[i]+1))
    else:
      if i == 0:
        ans += 1
        anslist.append(1)
    flag += 1
  else: #flag % 2 == 1
    if lrlist[i] != 1:
      if lrlist[i-1] > lrlist[i]:
        ans += (1/2)*(lrlist[i]-1)*(lrlist[i])
        anslist.append((1/2)*(lrlist[i]-1)*(lrlist[i]))
      else:
        ans += (1/2)*(lrlist[i])*(lrlist[i]+1)
        anslist.append((1/2)*(lrlist[i])*(lrlist[i]+1))
    flag += 1
print(int(ans))

Submission status: Wrong Answer

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)):
    print(result)
    print(conseq[i], tmp_s)
    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)
        #result += conseq[i+1]-conseq[i]
        tmp_s = '<'
print(result)

Submission status: Wrong Answer

Solution code:
s=input()
l=[]
if s[0]=='<':
  l.append(1)
else:
  l.append(-1)
for i in range(len(s)-1):
  if s[i]=='<' and s[i+1]=='>':
    l.append(-1)
  elif s[i]=='<' and s[i+1]=='<':
    l[-1]+=1
  elif s[i]=='>' and s[i+1]=='>':
    l[-1]-=1
  elif s[i]=='>' and s[i+1]=='<':
    l.append(1)

count=0    

if l[0]>0:
  if len(l)%2==0:
    for i in range(len(l)//2):
      M=max(abs(l[i*2]),abs(l[i*2+1]))
      m=min(abs(l[i*2]),abs(l[i*2+1]))
      count+=(M*(M+1)/2+m*(m-1)/2)
    print(int(count))
  elif len(l)%2==1:
    count+=abs(l[0])*(abs(l[0]-1))/2
    for i in range(len(l)//2):
      M=max(abs(l[i*2]),abs(l[i*2+1]))
      m=min(abs(l[i*2]),abs(l[i*2+1]))
      count+=(M*(M+1)/2+m*(m-1)/2)
    count+=abs(l[-1])*(abs(l[-1])+1)/2
    print(int(count))
else:
  if len(l)%2==0:
    count+=abs(l[0])*(abs(l[0])+1)/2
    for i in range((len(l)-1)//2):
      M=max(abs(l[i*2+1]),abs(l[i*2+2]))
      m=min(abs(l[i*2+1]),abs(l[i*2+2]))
      count+=(M*(M+1)/2+m*(m-1)/2)
    count+=abs(l[-1])*(abs(l[-1])-1)/2
    print(int(count))
  else:
    count+=abs(l[0])*(abs(l[0])+1)/2
    for i in range((len(l)-1)//2):
      M=max(abs(l[i*2+1]),abs(l[i*2+2]))
      m=min(abs(l[i*2+1]),abs(l[i*2+2]))
      count+=(M*(M+1)/2+m*(m-1)/2)
    print(int(count))

Submission status: Wrong Answer

Solution code:
S = input()
s_len = len(S)

s_kigo_map = [] # [[0,1],[1,2]] 0 = < , 1 = >
init_s = S[0]
right_count = 0
left_count = 0
max_len = 0
if S[0] == '<':
    s_num = 0
else:
    s_num = 1
s_count = 1
for i in range(1,s_len):
    if S[0] == '<':
        right_count += 1
    else:
        left_count += 1
    if init_s == S[i]:
        s_count += 1
    else:
        if max_len < s_count:
            max_len = s_count
        s_kigo_map.append([s_num,s_count])
        if S[i] == '<':
            s_num = 0
        else:
            s_num = 1
        init_s = S[i]
        s_count = 1
s_kigo_map.append([s_num,s_count])

next_num = 0
sum_num = 0

i = 0
if len(s_kigo_map) == 1:
    print(1)
else:
    if s_kigo_map[i][0] == 0: # <の時
        if s_kigo_map[i][1] >= s_kigo_map[i+1][1]:
            sum_num += (0 +s_kigo_map[i][1] )*(s_kigo_map[i][1]+1)//2
            #next_num = next_num + s_kigo_map[i][0]
        else: # `差分を増やす必要がある`
            sum_num += ( (0 +s_kigo_map[i][1] )*(s_kigo_map[i][1]+1)//2 )+ ( s_kigo_map[i+1][1] - s_kigo_map[i][1])
            #next_num = next_num + s_kigo_map[i+1][0] 
    else:  # >の時
        sum_num += (0 +s_kigo_map[i][1] )*(s_kigo_map[i][1]+1)//2
        #next_num = 0

    for i in range(1,len(s_kigo_map)):
        if s_kigo_map[i][0] == 0: # <の時
            if i == len(s_kigo_map) -1:
                sum_num += (1 +s_kigo_map[i][1] )*s_kigo_map[i][1]//2
                break
            if s_kigo_map[i][1] >= s_kigo_map[i+1][1]:
                sum_num += (1 +s_kigo_map[i][1] )*s_kigo_map[i][1]//2
                #next_num = next_num + s_kigo_map[i][0]
            else: # `差分を増やす必要がある`
                sum_num += ( (1 +s_kigo_map[i][1])*s_kigo_map[i][1]//2 ) + ( s_kigo_map[i+1][1] - s_kigo_map[i][1])
                #next_num = next_num + s_kigo_map[i+1][0] 
        else:  # >の時
            sum_num += (s_kigo_map[i][1] - 1 )*(s_kigo_map[i][1])//2
            #next_num = 0
    print(sum_num)

Submission status: Wrong Answer

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

s = list(input().rstrip('\n'))
gr = itertools.groupby(s)
ans = 0
keys = []
ls = []

for key, group in gr:
    l = len(list(group))
    keys.append(key)
    ls.append(l)
    for i in range(1, l+1):
        ans += i

for i in range(len(ls)-1):
    if s[0] == '<' and i % 2 == 0 and ls[i] > ls[i+1] and i+1 != len(ls)-1:
        ans -= ls[i+1]
    elif s[0] == '>' and i % 2 == 1 and ls[i] > ls[i+1] and i+1 != len(ls)-1:
        ans -= ls[i+1]

if keys[0] == '<' and ls[0] == 1:
    ans -= 1
if keys[-1] == '>' and ls[-1] == 1:
    ans -= 1

print(ans)

Submission status: Wrong Answer

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))
stock = [0, 0]
index = 0
for i, (num, sign) in enumerate(S_rle):
  if sign == '>':
    stock[0] -= num
  elif sign == '<':
    stock[0] += num
  if stock[0] <= stock[1]:
    stock[1] = stock[0]
    index = i

total = 0
stock = [0, 0]
former = S_rle[:index+1]
latter = S_rle[index+1:]
for i in range(len(former)):
  num, sign = former[-(i+1)]
  if sign == '>':
    total += stock[0]*num + sum(range(num+1))
    stock[0] += num
  elif sign == '<':
    if i == len(former) - 1:
      total += sum(range(num))
    else:
      total += stock[0]*num - sum(range(num+1))
    stock[0] = min(stock[0]-num, num-1)
stock = [0, 0]
for i in range(len(latter)):
  num, sign = latter[i]
  if sign == '<':
    total += stock[0]*num + sum(range(num+1))
    stock[0] += num
  elif sign == '>':
    stock[0] = min(stock[0]-num, num-1)
    if i == len(latter)-1:
      total += sum(range(num))
    else:
      total += sum(range(num))
    stock[0] = 0
  
print(total)

Submission status: Wrong Answer

Solution code:
S=input()

ans=0
flag=False
if S[0]=='<':
  cnt1,cnt2=1,0
else:
  cnt1,cnt2=0,1  
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>1 or cnt2>1:
  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)+1)
  else:
    print(int(ans))

Submission status: Wrong Answer

Solution code:
S=input()

ans=0
flag=False
if S[0]=='<':
  cnt1,cnt2=1,0
else:
  cnt1,cnt2=0,1  
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>1 or cnt2>1:
  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)+1)
  else:
    print(ans)

Submission status: Wrong Answer

Solution code:
# import numpy as np

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

    for i in range(0, len(s)):
        if s[i] == '<':
            n_list[i+1] = n_list[i]+1
        else: # i = >
            j = i # jは左側の                           文字のインデックス
            k = 1                          
            for j in range(i, 0, -1):
                if s[j] == '<':
                    n_list[j+1] = max(n_list[j], n_list[j+2])+1
                    break
                n_list[j] = k                
                j-=1
                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__":
    main()

Submission status: Wrong Answer

Solution code:
# ><
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

S = si()
L = []
t = 1
t_str = ''
for i in range(len(S)-1):
    if i == 0:
        t = 1
        t_str = S[i]

    if t_str == S[i] and S[i]==S[i+1]:
        t += 1
    else:
        L.append(t)
        t = 1
        t_str = S[i+1]
    
    if i == len(S)-2:
        L.append(t)

# print(L)
odd = 0
even = 0
for i in range(len(L)):
    if i%2 == 0:
        odd = 0
        even = 0

        odd = L[i]
    
    if i%2 == 1:
        even = L[i]
        if odd < even:
            L[i-1] -= 1
        elif odd > even:
            L[i] -= 1

# print(L)
ans = 0
for i in range(len(L)):
    l = L[i]
    ans += (l*(l+1))/2
    if len(L)>1 and i !=len(L)-1:
        if i%2==0 and L[i]==L[i+1]:
            ans -= L[i]
print(int(ans))

Submission status: Wrong Answer

Solution code:
S=list(input())
ans=[0]*(len(S)+1)
j=1
k=1

for i in range(len(S)):
  if S[i] == "<":
    if S[i-1] == ">" and ans[j-1] != 0:
      ans[j]=0
    else:
      ans[j]=ans[j-1]+1
    k=j
  else:
    if S[i-1] == "<":
      ans[j]=0
    else:
      ans[j]=ans[j-1]-1
    if ans[j] < 0:
      for l in range(k, j+1):
        if l==k and ans[k]-(j-k) > ans[j]:
          continue
        ans[l]+=1
  j+=1
print(sum(ans))

Submission status: Wrong Answer

Solution code:
S=input()

ans=0
flag=False
if S[0]=='<':
  cnt1,cnt2=1,0
else:
  cnt1,cnt2=0,1  
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>1 or cnt2>1:
  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:
  print(int(ans)+1)

Submission status: Wrong Answer

Solution code:
S = list(input())

now = 0
bunki = 0
renzoku = 0
res = 0

for i in range(1, len(S)):
    if S[i] == '<':
        renzoku = 0
        if S[i-1] == '>':
            now = 1
        else:
            now += 1
    else:
        renzoku += 1
        if S[i-1] == '<':
            bunki = now
        if i + 1 < len(S) and S[i+1] == '<' and now > 0:
            res -= (now - 1) * (renzoku - 1)
            now = 0
        else:
            now -= 1

    if now < 0:
        res += ((now * (-1)) + bunki)
    else:
        res += now

print(res)

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    s = input()
    # s = '<><><><><><><><><>'
    n_list = np.zeros(len(s)+1)

    for i in range(0, len(s)):
        if s[i] == '<':
            n_list[i+1] = n_list[i]+1
        else: # i = >
            j = i # jは左側の                           文字のインデックス
            k = 1                          
            for j in range(i, 0, -1):
                if s[j] == '<':
                    n_list[j+1] = max(n_list[j], n_list[j+2])+1
                    break
                n_list[j] = k                
                j-=1
                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__":
    main()

Submission status: Wrong Answer

Solution code:
A=list(input())
N=len(A)
B=[0]*N
for i in range(N):
    if A[i]=='<':
        B[i]=-1
    if A[i]=='>':
        B[i]=1
point=[0]*1

for i in range(N-1):
    if B[i]==1 and B[i+1]==-1:
        point.append(i)
point.append(N)

gr=0
lt=0
total=0
for i in range(len(point)-1):
    for j in range(point[i],point[i+1]):
       
        if A[j]=='>':
            gr+=1
        if A[j]=='<':
            lt+=1
    if i==0:
        gr+=1
        
    if gr<lt:
        tmp=lt
        lt=gr
        gr=tmp
            
    total+=gr*(1+gr)/2
    total+=(lt-1)*lt/2
    gr=0
    lt=0

print(int(total))

Submission status: Wrong Answer

Solution code:
import math

S = list(input())
ans = 0
lrlist = []
left = 0
right = 0
if S[0] == '<':
  flag = 0
else:
  flag = 1
anslist = []

for i in range(len(S)):
  if S[i-1] != S[i]:
    lrlist.append(max(left, right))
    right = 0
    left = 0
  if S[i] == '>':
    left += 1
  else:
    right += 1
  if i == len(S)-1:
    lrlist.append(max(left, right))

for i in range(len(lrlist)):
  if flag % 2 == 0:
    if lrlist[i] != 1:
      ans += (1/2)*(lrlist[i])*(lrlist[i]+1)
      anslist.append((1/2)*(lrlist[i])*(lrlist[i]+1))
    else:
      if lrlist[i-1] > lrlist[i]:
        ans += 1
        anslist.append(1)
    flag += 1
  else: #flag % 2 == 1
    if lrlist[i] != 1:
      if lrlist[i-1] > lrlist[i]:
        ans += (1/2)*(lrlist[i]-1)*(lrlist[i])
        anslist.append((1/2)*(lrlist[i]-1)*(lrlist[i]))
      else:
        ans += (1/2)*(lrlist[i])*(lrlist[i]+1)
        anslist.append((1/2)*(lrlist[i])*(lrlist[i]+1))
    flag += 1
print(int(ans))

Submission status: Wrong Answer

Solution code:
S = input().strip()
count=1
a=[]
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        count=count+1
    else:
        a.append(count)
        count=1
    
if S[len(S)-1]!=S[len(S)-2]:
    a.append(1)
else:
    a.append(count)
sa=0
for i in range(len(a)-1):
    if S[0]=='<':
        if i%2==0:
            sa=sa+abs(a[i]-a[i+1])
    else:
        if i%2==1:
            sa=sa+abs(a[i]-a[i+1])
wa=0
for i in range(len(a)):
    wa=wa+((a[i]+1)*a[i]/2)
print(int(wa-sa))

Submission status: Wrong Answer

Solution code:
s=input()
l=[]
if s[0]=='<':
  l.append(1)
else:
  l.append(-1)
for i in range(len(s)-1):
  if s[i]=='<' and s[i+1]=='>':
    l.append(-1)
  elif s[i]=='<' and s[i+1]=='<':
    l[-1]+=1
  elif s[i]=='>' and s[i+1]=='>':
    l[-1]-=1
  elif s[i]=='>' and s[i+1]=='<':
    l.append(1)

count=0    

if l[0]>0:
  if len(l)%2==0:
    for i in range(len(l)//2):
      M=max(abs(l[i*2]),abs(l[i*2+1]))
      m=min(abs(l[i*2]),abs(l[i*2+1]))
      count+=(M*(M+1)/2+m*(m-1)/2)
    print(int(count))
  elif len(l)%2==1:
    count+=abs(l[0])*(abs(l[0]-1))/2
    for i in range(len(l)//2):
      M=max(abs(l[i*2]),abs(l[i*2+1]))
      m=min(abs(l[i*2]),abs(l[i*2+1]))
      count+=(M*(M+1)/2+m*(m-1)/2)
    count+=abs(l[-1])*(abs(l[-1])+1)/2
    print(int(count))
else:
  if len(l)%2==0:
    for i in range(len(l)//2):
      M=max(abs(l[i*2]),abs(l[i*2+1]))
      m=min(abs(l[i*2]),abs(l[i*2+1]))
      count+=(M*(M+1)/2+m*(m-1)/2)
    count+=abs(l[-1])*(abs(l[-1])+1)/2
    print(int(count))
  else:
    for i in range((len(l)-1)//2):
      M=max(abs(l[i*2]),abs(l[i*2+1]))
      m=min(abs(l[i*2]),abs(l[i*2+1]))
      count+=(M*(M+1)/2+m*(m-1)/2)
    count+=abs(l[-1])*(abs(l[-1])+1)/2
    print(int(count))

Submission status: Wrong Answer

Solution code:
S = input()
kei = 0
k = []
l = []
if S[0] == '<':
  k.append(0)
for i in range(len(S)-1):
  if S[i] == '>' and S[i+1] == '<':
    k.append(i+1)
  elif S[i] == '<' and S[i+1] == '>':
    l.append(i+1)
if S[-1] == '>':
  k.append(len(S)+1)
for p in range(len(k)-1):
  a = k[p+1]-l[p] 
  b = l[p] - k[p]
  if a > b :
    kei += a*(a+1)/2 + b*(b-1)/2
  else:
    kei += a*(a-1)/2 + b*(b+1)/2
print(kei)

Submission status: Wrong Answer

Solution code:
moji = list(input())
listlist=[]
inlist=[]
result=0
if moji[0]=='>':
    inlist.append(2)
else:
    pass
for i in range(len(moji)-1):
    if moji[i] == '>' and moji[i+1]=='<':
        listlist.append(inlist)
        result += 1 + max([inlist.count(1),inlist.count(2)])
        for m in range(inlist.count(1)+1):
            result += m
        for n in range(inlist.count(2)+1):
            result += n
        inlist=[]
    elif moji[i] == '>' and moji[i+1]=='>':
            inlist.append(1)
    elif moji[i] == '<' and moji[i+1]=='<':
            inlist.append(2)
    elif moji[i] == '<' and moji[i+1]=='>':
            inlist.append(3)
if moji[len(moji)-2] == '>' and moji[len(moji)-1]=='<':
    result +=1
elif moji[len(moji)-2] == '>' and moji[len(moji)-1]=='>':
    result += 1 + max([inlist.count(1),inlist.count(2)])
    for m in range(inlist.count(1)+1):
        result += m
    for n in range(inlist.count(2)+1):
        result += n
elif moji[len(moji)-2] == '<' and moji[len(moji)-1]=='<':
        result += 1 + max([inlist.count(1),inlist.count(2)])
        for m in range(inlist.count(1)+1):
            result += m
        for n in range(inlist.count(2)+1):
            result += n
elif moji[len(moji)-2] == '<' and moji[len(moji)-1]=='>':
        result += 1 + max([inlist.count(1),inlist.count(2)])
        for m in range(inlist.count(1)+1):
            result += m
        for n in range(inlist.count(2)+1):
            result += n
print(result)

Submission status: Wrong Answer

Solution code:

S = input()
N = len(S) + 1
result = [ -1 for i in range(N) ]

def countContinueChar(index):
    startChar = S[index]
    count = 0
    for i in range(index, N-1):
        if S[i] != startChar:
            break
        count += 1
    return count

def getValueOfIndex(index, current, prev = '', preprev = ''):
    if S[index] == '<':
        if prev == '>':
            return 0
        else:
            return current + 1
    else:
        if prev == '<':
            v = countContinueChar(index)
            if v < current + 1:
                return current + 1
            else:
                return v
        else:
            if preprev == '<':
                return countContinueChar(index)
            else:
                return current - 1

current = -1
prev = ''
preprev = ''
sum = 0
for i in range(N):
    if i == N-1:
        if S[-1] == '<':
            result[i] = current + 1
            sum += current + 1
        #else:
            #result[i] = 0
        break
    if i > 0:
        prev = S[i - 1]
    if i > 1:
        preprev = S[i - 2]
    current = getValueOfIndex(i, current, prev, preprev)
    #result[i] = current
    sum += current

#print(result)
print(sum)

Submission status: Wrong Answer

Solution code:
S = input()

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


prev = ""
for i in range(len(S)):
    # print(S[i])
    if S[i] == "<":
        ans[i + 1] = ans[i] + 1
        prev = "<"

    # print(ans)
ans.reverse()
print()
for i in range(len(S)):
    # if S[len(S) - 1 - i] == ">":
    #     print("<")
    # else:
    #     print(">")
    # print(S[len(S)-1-i])
    if S[len(S)-1-i] == ">" and (ans[i+1] == 0 or ans[i+1] == 1):
        ans[i + 1] = ans[i] + 1
        prev = ">"
    # print(ans)
# print()
print(sum(ans))

Submission status: Wrong Answer

Solution code:
str_S = input()

int_a = [0]
cnt = 0

for i in range(len(str_S)):
	if str_S[i] == "<":
		int_a.append(int_a[i] + 1)
		cnt = 0
	else:
		if cnt == 0:
			int_a.append(0)
		else:
			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] += 1

			int_a.append(int_a[i] - 1)

		cnt += 1		

ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
inc = 0
dec = 0
sum = 0

def solve(i, d):
	ans = 0
	if i > d and d > 0: 
		d -= 1
	elif i < d and i > 0:
		i -= 1
	for c in range(i+1):
		ans += c
	for c in range(d+1):
		ans += c
	return ans

for i in range(len(S)):
	if S[i] == '<':
		if dec > 0:
			sum += solve(inc, dec)
			inc = 0
			dec = 0
		inc += 1
	if S[i] == '>':
		dec += 1
	#print(i, inc, dec, sum)
sum += solve(inc, dec)

print(sum)

Submission status: Wrong Answer

Solution code:
S = input().strip()
V = []
for i in range(len(S)-1):
    if S[i]==">" and S[i+1]=="<":
        V.append(i+1)
if S[-1]==">":
    V.append(len(S))
B = [0 for _ in range(len(S)+1)]
for i in range(len(S)):
    if S[i]==">":
        B[i+1] = B[i]-1
    else:
        B[i+1] = B[i]+1
for j in V:
    if B[j]<0:
        B[j] = 0
        cur = j-1
        while cur>=0 and S[cur]==">":
            B[cur] = max(B[cur],B[cur+1]+1)
            cur -= 1
        cur = j
        while cur<len(S) and S[cur]=="<":
            B[cur+1]=B[cur]+1
            cur += 1
    elif B[j]>0:
        B[j] = 0
        cur = j-1
        while cur>=0 and S[cur]==">":
            if cur-1>=0 and S[cur-1]==">":
                B[cur] = B[cur+1]+1
            elif cur-1>=0 and S[cur-1]=="<":
                B[cur] = max(B[cur],B[cur+1]+1)
            cur -= 1
        cur = j
        while cur<len(S) and S[cur]=="<":
            B[cur+1] = B[cur]+1
            cur += 1
print(sum(B))

Submission status: Wrong Answer

Solution code:
s = list(input())

lens = len(s)
if lens == 1:
  print(1)
  exit()
  
li = [0] * (len(s) + 1)
for itr, val in enumerate(s):
  if itr == 0:
    if val == "<":
      li[0] = 0
  else:
    if (s[itr - 1] == "<" and s[itr] == "<"):
      li[itr] = li[itr - 1] + 1
#    elif s[itr - 1] == ">" and s[itr] == "<":
#      li[itr] = 0
    if s[itr] == "<" and itr == lens - 1:
      li[itr + 1] = li[itr] + 1

for itr, val in enumerate(reversed(s)):
  if itr == 0:
    if val == ">":
      li[lens] = 0
  else:
    if s[lens - itr - 1] == ">" and s[lens - itr] == ">":
      li[lens - itr] = li[lens - itr + 1] + 1
    if s[0] == ">":
      li[0] = li[1] + 1
      
for itr, val in enumerate(s):
  if itr > 0:
    if s[itr - 1] == "<" and s[itr] == ">":
      li[itr] = max(li[itr - 1],li[itr + 1]) + 1 

print(li)
print(sum(li))

Submission status: Wrong Answer

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

s = list(input().rstrip('\n'))
gr = itertools.groupby(s)
ans = 0
keys = []
ls = []

for key, group in gr:
    l = len(list(group))
    keys.append(key)
    ls.append(l)
    for i in range(1, l+1):
        ans += i

for i in range(len(ls)-1):
    if s[0] == '<' and i % 2 == 0 and ls[i] > ls[i+1]:
        ans -= ls[i+1]
    elif s[0] == '>' and i % 2 == 1 and ls[i] > ls[i+1]:
        ans -= ls[i+1]

if keys[0] == '<' and ls[0] == 1:
    ans -= 1
if keys[-1] == '>' and ls[-1] == 1:
    ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

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


prev = ""
for i in range(len(S)):
    print(S[i])
    if S[i] == "<":
        ans[i + 1] = ans[i] + 1
        prev = "<"

    print(ans)
ans.reverse()
print()
for i in range(len(S)):
    print(S[len(S)-1-i])
    if S[len(S)-1-i] == ">" and (ans[i+1] == 0 or ans[i+1] == 1):
        ans[i + 1] = ans[i] + 1
        prev = ">"
    print(ans)
print()
print(sum(ans))

Submission status: Wrong Answer

Solution code:
s = input()
lr = []
if s[len(s)-1] == '>':
    s_add = s + '<'
else:
    s_add = s + '>'
cnt = 1
for i in range(1,len(s_add)):
    if s_add[i] == s_add[i-1]:
        cnt += 1
    else:
        lr.append(cnt)
        cnt = 1
# print(lr)
if s[0] == '<':
    num = 0
    for i,val in enumerate(lr):
        if val != 1:
            for j in range(1,val):
                num += j
        if i%2 == 0:
            if i+1 > len(lr)-1:
                num += lr[i]
            else:
                num += max(lr[i],lr[i+1])
else:
    num = 0
    for i,val in enumerate(lr):
        if val != 1:
            for j in range(1,val):
                num += j
        if i%2 == 1:
            if i+1 > len(lr)-1:
                num += lr[i]
            elif i == 0:
                num += lr[i]
            else:
                num += max(lr[i],lr[i+1])
    

print(num)