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:
##https://atcoder.jp/contests/agc040/tasks/agc040_a


def find_next_lt_pos(start, s, n):
    for i in range(start, n):
        if s[i] == '<':
            return i
    return -1


def find_next_gt_pos(start, s, n):
    for i in range(start, n):
        if s[i] == '>':
            return i
    return -1


def sum_to_n(n):
    return n*(n + 1) // 2


def same_symbol_len(symb, st_pos, s):
    sp = st_pos
    while s[sp] == symb:
        sp += 1
    return sp


def find_sum(s):
    n = len(s)
    a = [0]*(n + 1)

    cur_pos = 0
    change_pos = find_next_lt_pos(0, s, n)
    if change_pos == -1:
        for i in range(n+1):
            a[i] = n-i
    else:
        for i in range(cur_pos, change_pos+1):
            a[i] = change_pos - i
        cur_pos = change_pos+1

        while cur_pos <= n:
            change_pos = find_next_gt_pos(cur_pos, s, n)
            if change_pos == -1:
                for i in range(cur_pos, n+1):
                    a[i] = i - cur_pos + 1
                cur_pos = n+1
            else:
                change_pos_2 = find_next_lt_pos(change_pos, s, n)
                if change_pos_2 == -1:
                    change_pos_2 = n
                for i in range(cur_pos, change_pos+1):
                    a[i] = 1 + i - cur_pos

                cur_pos = change_pos
                for i in range(cur_pos, change_pos_2 + 1):
                    if change_pos_2 - i > a[i]:
                        a[i] = change_pos_2 - i
                cur_pos = change_pos_2 + 1


        return sum(a)


def solve():
    print(find_sum(input()))


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

a = [0] * (len(s) + 1)
samecount = 0
before = ''
beforebefore = ''
z = 0

for i in s:

    if before == '' and i == '<':
        a[z] = 0
        z += 1
        samecount = 0
    elif before == '' and i == '>':
        samecount = 1
    elif before == '<' and i == '<':
        samecount += 1
        a[z] = samecount
        z += 1
    elif before == '<' and i == '>':
        if beforebefore == '<':
            samecount += 1
            a[z] = samecount
            z += 1
            samecount = 0
        else:
            samecount = 1
    elif before == '>' and i == '>':
        samecount += 1
    elif before == '>' and i == '<':
        if beforebefore == '<':
            a[z] = samecount
            z += 1
        else:
            for j in reversed(range(0, samecount + 1)):
                a[z] = j
                z += 1
        samecount = 0

    beforebefore = before
    before = i

if before == '<':
    samecount += 1
    a[z] = samecount
elif before == '>':
    for j in reversed(range(0, samecount + 1)):
        a[z] = j
        z += 1
    samecount = 0
print(sum(a))

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 = []
LS = []
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)
        LS.append(t_str)
        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] and LS[i]=='>':
            ans -= L[i]
print(int(ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    s = lines[0]

    return (s, )

def solve(s):
 

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

    b = a.copy()    
    b[-1] = 0
    for i in range(len(s) - 1, -1, -1):
        if s[i] == '>':
            b[i-1] = b[i] + 1
        else:
            b.append(0)
    c = [] 
    for i in range(len(a)):

        if a[i] > b[i]:
            c.append(a[i])
        else:
            c.append(b[i])
             
    return sum(c)  

def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Submission status: Wrong Answer

Solution code:
s = input()

n = len(s) + 1
ans = 0
# for i in range(n - 1):
i = 0
while i < n - 1:
    uCount = 0 # '<'
    dCount = 0 # '>'
    while s[i] == '<' and i < n - 2:
        uCount += 1
        i += 1
    while s[i] == '>' and i < n - 2:
        dCount += 1
        i += 1
    if uCount > dCount:
        ans += sum(range(0, uCount + 1))
        ans += sum(range(0, dCount))
    elif uCount <= dCount:
        ans += sum(range(0, dCount + 1))
        ans += sum(range(0, uCount))
    if i == n - 2 and s[i] == '<':
        ans += 1
        i += 1
    elif i == n - 2 and s[i] == '>':
        i += 1
print(ans)

Submission status: Wrong Answer

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-1
        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: 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
    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:
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 and j1 == 1:
            k = 1
        else:
            i += k
        j  = 0
        j1 = 0
        k += 1
        
    else:
        break
 
print(i)

Submission status: Wrong Answer

Solution code:
A=list(input())
A.insert(0, '>')
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 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:
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:
import re
def sum_z_to_k(k):
    ##print("k",k)
    return (k+1)*k/2

def set_min_lr(map_lr, i):
    if map_lr[i] == 0:
        l,r = 0,0
    elif map_lr[i] == 1:
        l,r = 0,1
    elif map_lr[i] == 2:
        l,r = 1,0
    elif map_lr[i] == 3:
        l,r = 1,1
    return l,r

S = str(input())
N = len(S) + 1
score = 0

S_split_tani = re.split("(><)", S)
#print(S_split_tani)

map_lr = [0]*len(S_split_tani)
for i,s in enumerate(S_split_tani[:-1]):
    if s =="><":
        map_lr[i]=-1
        if map_lr[i-1]==1 or map_lr[i-1]==2:
            map_lr[i-1]=3
        else:
	        map_lr[i-1]=1

        if map_lr[i+1]==2 or map_lr[i+1]==1:
            map_lr[i+1]=3
        else:
    	    map_lr[i+1]=2
#print(map_lr)
for i,s in enumerate(S_split_tani):
    #print(score)
    if s =="><":
        continue
    else:
        min_l, min_r = set_min_lr(map_lr, i)
        rl = re.split("(<>)", s)
        #print("rl,min",rl,min_r,min_l)
        if len(rl) == 1:# none <>
            if len(rl[0]) == 0:# null
                score += 1
            else:
                score += sum_z_to_k(len(rl[0]) + 1)
        elif len(rl) == 3:
            r = rl[2]
            l = rl[0]
            #print("len rl",len(r),len(l))
            if len(r) == 0 and len(l) == 0:
                score+=1
            else:
                tmp_max = max(len(r) + min_r, len(l) + min_l)
                tmp_min = min(len(r) + min_r, len(l) + min_l)
                #print("tmp",tmp_min,tmp_max)
                score += sum_z_to_k(tmp_max+1)
                if tmp_min != 0:
                    score += sum_z_to_k(tmp_min)

print(score)

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])

if sum(ans) == 0:
    for j in range(0, cnt[1]):
        ans[j+1] = ans[j] + 1
    for k in range(cnt[-2], cnt[-1])[::-1]:
        ans[k] = max(ans[k+1] + 1, ans[k])

print(sum(ans))

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
ans = 0
cnt = 0
tmp = 0
i = 0
if S[i] == "<":
  while S[i] == "<":
    if i == N - 1:
      ans += 1
      break
    cnt += 1
    if S[i+1] == ">":
      ans += cnt * (cnt + 1) // 2
      tmp = cnt
      cnt = 0
      i += 1
      while S[i] == ">":
        cnt += 1
        i += 1
        if i == N:
          i -= 1
          break
      ans += (cnt - 1) * (cnt) // 2
      if tmp >= cnt:
        pass
      else:
        ans += cnt - tmp
      cnt = 0
    else:
      i += 1
else:
  while S[i] == ">":
    cnt += 1
    i += 1
    if i == N:
      i -= 1
      break
  ans += cnt * (cnt + 1) // 2
  if S[i] == "<":
    while S[i] == "<":
      if i == N - 1:
        ans += 1
        break
      cnt += 1
      if S[i+1] == ">":
        ans += cnt * (cnt + 1) // 2
        tmp = cnt
        cnt = 0
        i += 1
        while S[i] == ">":
          cnt += 1
          i += 1
          if i == N:
            i -= 1
            break
        ans += (cnt - 1) * (cnt) // 2
        if tmp >= cnt:
          pass
        else:
          ans += cnt - tmp
        cnt = 0
      else:
        i += 1
print(ans)

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 = []
LS = []
t = 1
t_str = ''

s0 = S[0:1]
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)
        LS.append(t_str)
        t = 1
        t_str = S[i+1]
    
    if i == len(S)-2:
        L.append(t)

# print(L)
# print(LS)
odd = 0
even = 0
mozi = ''
for i in range(len(L)):
    if i%2 == 0:
        odd = 0
        even = 0
        if i <len(L)-1:
            mozi = LS[i]

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

# print(L)
# print(LS)
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 and LS[i]=='<':
        if i%2==0 and L[i]==L[i+1]:
            ans -= L[i]
print(int(ans))

Submission status: Wrong Answer

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

Solution code:
# import numpy as np
# import time

def main():
    s = input()
    # 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[0] == '>':
        n_list[0] = n_list[1]+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
        
            
        # 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: 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 = []
LS = []
t = 1
t_str = ''

s0 = S[0:1]
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)
        LS.append(t_str)
        t = 1
        t_str = S[i+1]
    
    if i == len(S)-2:
        L.append(t)

# print(L)
# print(LS)
odd = 0
even = 0
mozi = ''
for i in range(len(L)):
    if i%2 == 0:
        odd = 0
        even = 0
        if i <len(L)-1:
            mozi = LS[i]

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

# print(L)
# print(LS)
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:
# import numpy as np
# import time

def main():
    s = input()
    # 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[0] == '>':
        n_list[0] = n_list[1]+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, -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
        
            
        # 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: 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 and  j1 == 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:
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)-1) :
        if ss[i]==-1:
            ss[i]=max(kind[j],kind[j+1])
            j+=2
else:
    j=0
    for i in range(0,len(s)-1) :
        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(kind)
# print(ss)
print(ans)

Submission status: Wrong Answer

Solution code:
S = list ( input("") )
sum_list = [-100 for _ in range( len(S) + 1 )]
if S[0] == "<":
    sum_list[0] = 0
if S[len(S) - 1] == ">":
    sum_list[len(S)] = 0
for i in range( 1, len(S) ):
    before_check = i - 1
    after_check = i
    if S[before_check] == ">" and S[after_check] == "<":
        sum_list[i] = 0

a = list(sum_list)      
for i in range( 1, len(S) + 1 ):
    before_check = i - 1
    if a[i] == -100:
        if S[before_check] == "<":
            a[i] = a[i-1] + 1
        if S[before_check] == ">":
            a[i] = a[i-1] - 1 
            
b = list(sum_list)
for j in range( len(S)-1,0,-1  ):
    after_check = j
    if b[j] == -100:
        if S[after_check] == "<":
            b[j] = b[j+1] - 1
        if S[after_check] == ">":
            b[j] = b[j+1] + 1 

answer = list()
for i in range(len(a)):
    if a[i] >= b[i]:
        answer.append(a[i])
    else:
        answer.append(b[i])
        
print(sum(answer))

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
ans = 0
cnt = 0
tmp = 0
i = 0
while i < N - 1:
  cnt = 0
  tmp = 0
  if S[i] == "<":
    while S[i] == "<":
      if i == N - 1:
        ans += 1
        break
      cnt += 1
      if S[i+1] == ">":
        ans += cnt * (cnt + 1) // 2
        tmp = cnt
        cnt = 0
        i += 1
        while S[i] == ">":
          cnt += 1
          i += 1
          if i == N:
            i -= 1
            break
        ans += (cnt - 1) * (cnt) // 2
        if tmp >= cnt:
          pass
        else:
          ans += cnt - tmp
        cnt = 0
      else:
        i += 1
  else:
    while S[i] == ">":
      cnt += 1
      i += 1
      if i == N:
        i -= 1
        break
    ans += cnt * (cnt + 1) // 2
    if S[i] == "<":
      while S[i] == "<":
        if i == N - 1:
          ans += 1
          break
        cnt += 1
        if S[i+1] == ">":
          ans += cnt * (cnt + 1) // 2
          tmp = cnt
          cnt = 0
          i += 1
          while S[i] == ">":
            cnt += 1
            i += 1
            if i == N:
              i -= 1
              break
          ans += (cnt - 1) * (cnt) // 2
          if tmp >= cnt:
            pass
          else:
            ans += cnt - tmp
          cnt = 0
        else:
          i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# Grand Contest 040 - Q1

def calc_func(n):
    num_list = range(n)
    # print('num_list',num_list)
    ret = 0
    for i in range(len(num_list)):
        ret += num_list[i]
    # print('ret',ret)
    return ret

S = list(input())

char_list = []
number_list = []
counter = 1
for i in range(len(S)):
    # 配列の最後だったら
    if i == len(S)-1:
        number_list.append(counter)
        char_list.append(S[i])
        break
    if S[i] == S[i+1]:
        counter += 1
    elif S[i] != S[i+1]:
        number_list.append(counter)
        char_list.append(S[i])
        counter = 1
# print('文字数え：',number_list)
# print('文字リスト：', char_list)

answer = 0

for i in range(len(number_list)):
    if char_list[i] == '<':
        answer += calc_func(number_list[i])
        # print(calc_func(number_list[i]))
    elif char_list[i] == '>' and number_list[i-1] < number_list[i]:
        answer += number_list[i] + calc_func(number_list[i])
        # print(calc_func(number_list[i]))
    elif char_list[i] == '>' and number_list[i-1] > number_list[i]:
        answer += number_list[i-1] + calc_func(number_list[i])
        # print(number_list[i-1] + calc_func2(number_list[i]))

if char_list[len(number_list)-1] == '<' and number_list[len(number_list)-1] == 1:
    answer += 1


print(answer)

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import time

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

    for i in range(1, len(s)+1):
        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[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: Wrong Answer

Solution code:
S = list(input())

DEBUG = False
val = 0
sum_val = 0

updown = []
SAME_FLAG = False
XXX = False
cnt = 0
for i in range(len(S)):
    cnt += 1
    if S[i] == '<':
        mul = 1
    elif S[i] == '>':
        mul = -1
    
    if i == len(S)-1 or S[i] != S[i+1]:
        updown.append(cnt*mul)
        cnt = 0
if DEBUG:
    print(updown)

for i, ele in enumerate(updown):   
    if i == len(updown)-1:
        if (SAME_FLAG is True or XXX is True):
            sum_ser = sum(list(range(abs(ele))))
        else:
            sum_ser = sum(list(range(abs(ele)+1)))
    else:
        if abs(updown[i]) < abs(updown[i+1]) or SAME_FLAG is True or XXX is True:
            sum_ser = sum(list(range(abs(ele))))
            XXX = False
        elif abs(updown[i]) >= abs(updown[i+1]):
            sum_ser = sum(list(range(abs(ele)+1)))
            if updown[i+1] < 0:
                XXX = True
            if abs(updown[i]) == abs(updown[i+1]):
                SAME_FLAG = True
            else:
                SAME_FLAG = False
    
    if DEBUG:
        print('i=%d : ele = %d : sum_ser = %d'%(i,abs(ele),sum_ser))
    sum_val += sum_ser
print(sum_val)

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)
    count+=abs(l[-1])*(abs(l[-1])-1)/2
    print(int(count))

Submission status: Wrong Answer

Solution code:
S = input()
right = "<"
left = ">"
a = [float(0)] * (len(S) + 1)
for i in range(len(S)):
  #####
  #if i >= 10:
  #  print(i, end="")
  #  print(a)
  #######

  if S[i] == right:
    a[i + 1] = max(a[i] + 1, 1)
    if i == 0:
      a[i] = -float('inf')
  #>
  elif S[i] == left:
    #><の時は最小
    if (i != len(S) - 1 and S[i + 1] == right) or i == len(S) - 1:
      if i != len(S) - 1 and S[i + 1] == right:
        a[i + 1] = -float('inf')
      else:
        a[i + 1] == 0
      #前の>を遡る
      for j in range(0, i)[::-1]:
        #print(i)
        if S[j] == right:
          if S[j + 1] == left and j != i - 1:
            a[j + 1] = max([a[j + 2] + 1, a[j + 1], 1])
          break
        a[j + 1] = max(a[j + 2] + 1, 1)
    else:
      a[i + 1] = a[i] - 1
a = [a for a in a if a != -float('inf')]

print(sum(a))

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 == '<':
    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
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)