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 = input()

N = len(S) + 1
L = []
counter = 0

for n in range(N-2):
    counter += 1
    if S[n]!=S[n+1]:
        L.append(counter)
        counter = 0
            
L.append(counter+1)

K = len(L)//2

if S[0]=='<':
    for k in range(K):
        if L[2*k] <= L[2*k+1]:
            L[2*k] -= 1
        else:
            L[2*k+1] -= 1

else:
    for k in range(K-1):
        if L[2*k+1] <= L[2*k+2]:
            L[2*k+1] -= 1
        else:
            L[2*k+2] -= 1
        
print(sum([l*(l+1)//2 for l in L]))

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)
    if l != 1:
        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+1] != 1 and ls[i] > ls[i+1]:
        ans -= ls[i+1]
    elif s[0] == '>' and i % 2 == 1 and ls[i+1] != 1 and ls[i] > ls[i+1]:
        ans -= ls[i+1]

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

print(ans)

Submission status: Wrong Answer

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

ans = 0

con = 0
x = S[0]
i = 0
while x != "<":
  con += 1
  x = S[i]
  if x == ">":
    i += 1
  if i == N-1:
    x = "<"
ans += con * (con - 1) / 2

#print(i , N)
if i == N-1:
  ans += con

#print(i)
mae = 0
con = 1
x = "<"
i += 1
#print(i,N)
while i < N - 1:
  if S[i] == x:
    #print(i)
    con += 1
  else:
    ans += con * (con-1)/2
    if S[i] == ">":
      mae = con
    else:
      ans += max(con, mae)
      mae = 0
    con = 1
    x = S[i]
    #print(ans, i, con, mae)
  i += 1
#print(ans, con)
ans += con * (con-1)/2 
#print(ans)
ans += max(con, mae)

print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

# N,M = list(map(int, input().split()))

S = input()
set_array = []
prev_set_len = 0
total = 0

prev_check_point = 0
mountains = []
valleys = [0]
for i in range(len(S)-1):
    if S[i] == "<" and S[i+1] == ">":
        mountains.append(i+1)
    elif S[i] == ">" and S[i+1] == "<":
        valleys.append(i+1)

valleys.append(len(S))

if len(mountains) == 0 and len(valleys) == 2:
    print((len(S)+1)*(len(S)//2))
    exit()
if len(mountains) == 0 and len(valleys) == 3:
    left = valleys[1]
    right = len(S) - valleys[1]
    total += (left+1)*left//2
    total += (right+1)*right//2
    print(total)
    exit()

for i, mountain in enumerate(mountains):
    left = mountain - valleys[i]
    right = valleys[i+1] - mountain

    if left > right:
        total += (left+1)*left//2
        total += (right-1+1)*(right-1)//2
    else:
        total += (right+1)*right//2
        total += (left-1+1)*(left-1)//2

if valleys[-2] > mountains[-1]:
    right = len(S) - valleys[-2]
    total += (right+1)*right//2
if valleys[1] < mountains[0]:
    left = valleys[1]
    total += (left+1)*left//2

print(total)

Submission status: Wrong Answer

Solution code:
import math
def till_sum(n):
    return((n) * (n - 1) / 2)
s = list(input())
count = 0
ls = []
for i in range(len(s)):
    count += 1
    if len(s) - 1 == i:
        break
    else:
        if s[i] != s[i+1]:
            ls.append(count)
            count = 0
ls.append(count)
print(ls)
result = sum(map(till_sum, ls))
if s[0] == "<":
    for i in range(math.ceil(len(ls)/2)):
        if len(ls) - 1 == 2*i:
            result += ls[2*i]
        else:
            if ls[2*i] < ls[2*i + 1]:
                result += ls[2*i + 1]
            if ls[2*i] >= ls[2*i + 1]:
                result += ls[2*i]
else:
    result += ls[0]
    ls = ls[1:]
    for i in range(math.ceil(len(ls)/2)):
        if len(ls) - 1 == 2*i:
            result += ls[2*i]
        else:
            if ls[2*i] < ls[2*i + 1]:
                result += ls[2*i + 1]
            if ls[2*i] >= ls[2*i + 1]:
                result += ls[2*i]
print(int(result))

Submission status: Wrong Answer

Solution code:
S = input()
#print(len(S))
s_list = []
head_num = 10**6 if S[0] == ">" else 0
s_list.append(head_num)
for i in range(len(S)-1):
    if S[i] == ">" and S[i+1] == "<":
        s_list.append(0)
    elif S[i] == "<":
        s_list.append(s_list[i]+1)
    else:
        s_list.append(s_list[i]-1)
if S[len(S)-1] == "<":
    s_list.append(s_list[len(S)-1] +1)
else:
    s_list.append(s_list[len(S)-1] -1)

#print(s_list)
count = 1
s_list[len(s_list)-1] = 0 if s_list[len(s_list)-1] < 0 else s_list[len(s_list)-1] 
#print(s_list)
for i in range(len(S)-1,0,-1):
    if S[i] == ">" and S[i-1] == ">":
    #if S[i] == ">":
        s_list[i] = count
        count += 1
    elif S[i] == ">" and S[i-1] == "<":
        s_list[i] = max(s_list[i-1], s_list[i+1]) + 1
    else:
        count = 1

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

#print(len(s_list))
#print(s_list)

sum = 0
for i in range(len(s_list)):
    sum += s_list[i]

print(sum)

Submission status: Wrong Answer

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
S = input()
n = len(S)
S = S + " "
ans = 0
l = 0
r = 0
temp = 0
if S[0] == '<':
    temp = -1
else:
    for i in range(n):
        if S[i] == '>' and S[i + 1] == ('<'):
            temp = i
            break
        if i == n - 1:
            print((n + 1) * n // 2)
            exit()

ans += (temp + 1) * (temp + 2) // 2
i = max(temp, 0)

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

l, r = min(l, r), max(l, r)
ans += l * (l - 1) // 2 + r * (r + 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())

idx = [0]
ans = 0
for i in range(len(s) - 1):
    if s[i] == ">" and s[i + 1] == "<":
        idx.append(i)
# print(len(idx))

if len(idx) == 1:
    # ans = s.count("<") + s.count(">")
    a = s.count("<")
    l = s.count(">")
    n = len(s)
    ans += n * (a + l) // 2 - 1
else:
    for j in range(1, len(idx) - 1):
        a = s[idx[j - 1] : idx[j + 1]].count("<")
        l = s[idx[j - 1] : idx[j + 1]].count(">")
        n = idx[j + 1] - idx[j - 1] + 1
        ans += n * (a + l) // 2 - 1

print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
if S[-1] == '<':
  S.append('>')
else:
  S.append('<')
output = 0
count = 0
num_list = []

if S[0] == '>':
  model = 0
else:
  model = 1
s_pre = S[0]
for i in range(len(S)):
  s = S[i]
  if s != s_pre or i == len(S)-1:
    num_list.append(count)
    count = 1
    s_pre = s
  else: 
    count += 1
if model == 0:
  output += num_list[0]*(num_list[0]+1)/2
  num_list = num_list[1:]

for i in range(len(num_list)//2):
  n_max = max(num_list[2*i], num_list[2*i+1]) #同じ場合考える
  n_min = min(num_list[2*i], num_list[2*i+1])
  print(n_max, n_min)
  output += n_max*(n_max+1)/2
  output += (n_min-1)*n_min/2
if len(num_list)%2 == 1:
  output += num_list[-1]*(num_list[-1]+1)/2
print(int(output))

Submission status: Wrong Answer

Solution code:
s = input()
tmp = [0]
tmpsc = 1
tmpsum = 0
for i, a in enumerate(s):
    if a == '<':
        if i == 0:
            tmp.append(tmp[i] + 1)
        else:
            #if tmp[i] >= 0:
            if s[i-1] == '<':
                tmp.append(tmp[i] + 1)
                tmpsc = 1
            else:
                tmp.append(1)
                tmpsum += tmp[i] * tmpsc * -1
                tmpsc = 1

    else:
        tmp.append(tmp[i] - 1)
        tmpsc += 1

# print(tmpsc1,tmpsc2)
if s[-1] == '>':
    #print('a')
    #print(tmp[-1],tmpsc)
    tmpsum += tmp[-1] * tmpsc * -1
print(sum(tmp) + tmpsum)

#print(tmp)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s) +1
li = [-1] * n

if s[0]=="<":
  li[0]=0
else:
  li[0]=n
if s[-1]==">":
  li[-1]=0
else:
  li[-1]=n
for i in range(1,n):
  if s[i-1:i+1]=="><":
    li[i]=0
for i in range(1,n):
  for j in range(1,n-1):
    if (li[j-1]==i-1 and s[j-1]=="<") or (li[j+1]==i-1 and s[j]==">"):
      li[j]=i
if s[0]==">":
  li[0]=li[1]+1
if s[-1]=="<":
  li[-1]=li[-2]+1
print(li)
print(sum(li))

Submission status: Wrong Answer

Solution code:
S = str(input())

tmp_list = [0]
bigger = True
for i in range(len(S)):
    if (bigger and S[i] == '<') or (not bigger and S[i] == '>'):
        tmp_list[-1] += 1
    else:
        tmp_list.append(1)
        bigger = not bigger
print(tmp_list)

if len(tmp_list) % 2 == 1:
    tmp_list.append(0)

def func(x):
    return x * (x + 1) // 2

ans = 0
for i in range(len(tmp_list) // 2):
    a = tmp_list[i * 2]
    b = tmp_list[i * 2 + 1]
    if a > b:
        a, b = b, a
    ans += func(a - 1)
    ans += func(b)

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
t = s.split(">")
t2 = s.split("<")
a = []
b = []
for i in t:
    if i != '':
        a.append(i)

for i in t2:
    if i != '':
        b.append(i)
n = len(a)
n2 = len(b)
if len(b) == 1 and len(a) == 1:
    if s[0] == '>':
        y = len(b[0])
        x = len(a[0])
        sums = 0
        sums += (x * (x + 1)) / 2
        sums += (y * (y + 1)) / 2
        print(int(sums))
        exit()

tmp = min(n, n2)
sums = 0
if n2 > n:
    for i in range(tmp):
        x = len(a[i])
        y = len(b[i+1])
        if x > y:
            sums += (x * (x + 1)) / 2
            sums += (y * (y - 1)) / 2
        else:
            sums += (x * (x - 1)) / 2
            sums += (y * (y + 1)) / 2
elif n > n2:
    for i in range(tmp):
        x = len(a[i])
        y = len(b[i])
        if x > y:
            sums += (x * (x + 1)) / 2
            sums += (y * (y - 1)) / 2
        else:
            sums += (x * (x - 1)) / 2
            sums += (y * (y + 1)) / 2
elif n == n2:
    for i in range(tmp):
        x = len(a[i])
        y = len(b[i])
        if x > y:
            sums += (x * (x + 1)) / 2
            sums += (y * (y - 1)) / 2
        else:
            sums += (x * (x - 1)) / 2
            sums += (y * (y + 1)) / 2
if n > n2:
    x = len(a[n-1])
    sums += (x * (x + 1)) / 2
elif n2 > n:
    x = len(b[0])
    sums += (x * (x + 1)) / 2

print(int(sums))

Submission status: Wrong Answer

Solution code:
import random
i=input()
j=random.randint(1,10)
print(j)

Submission status: Wrong Answer

Solution code:
strings = input()

first = strings[0]

slist=[]
bef = None
for s in strings:
    if bef is None:
        slist += [1]
        bef = s
        continue
    
    if s==bef:
        slist[-1] += 1
        bef=s
    else:
        slist += [1]
        bef=s
ans = 0
if first == '<':
    for i in range(len(slist)//2):
        if slist[i*2] < slist[i*2+1]:
            ans += sum(list(range(slist[i*2+1]-slist[i*2]+1,slist[i*2+1]+1)))+sum(range(slist[i*2+1]))
        else:
            ans += sum(range(1,slist[i*2]+1))+sum(range(slist[i*2+1]))
    if len(slist)%2 == 1:
        ans += sum(range(1,slist[-1]+1))
        
else:
    ans += sum(range(slist[0]))
    for i in range(1,((len(slist)-1)//2)+1):
        if slist[i*2-1] < slist[i*2]:
            ans += sum(list(range(slist[i*2]-slist[i*2-1]+1,slist[i*2]+1)))+sum(range(slist[i*2]))
        else:
            ans += sum(range(1,slist[i*2-1]+1))+sum(range(slist[i*2]))
    if len(slist)%2 == 0:
        ans += sum(range(slist[-1]))
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)+1
lsfg = [0]*n
flag = 0
ans = 0

for i in range(n-2):
    if s[i] != s[i+1]:
        flag += 1
        if s[i] == "<":
            lsfg[i+1] = -2
        else:
            lsfg[i+1] = -1

if flag == 0:
    p = 0
    for i in range(n):
        ans += p
        p += 1
else:
    for i in range(n):
        k = 0
        j = 0
        if lsfg[i] == -1:
            while i-k > 0:
                k += 1
                if lsfg[i-k] != -2:
                    lsfg[i-k] = k
                else:
                    break
            while i+j < n-1:
                j += 1
                if lsfg[i+j] != -2:
                    lsfg[i+j] = j
                else:
                    break

    lsfg = [0] + lsfg + [0]

    for i in range(n):
        if lsfg[i+1] == -2:
            if lsfg[i] > lsfg[i+2]:
                lsfg[i+1] = lsfg[i] +1
            else:
                lsfg[i+1] = lsfg[i+2] +1
        elif lsfg[i+1] == -1:
            lsfg[i+1] = 0

    ans = sum(lsfg)
    
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
ans = 0
now = 0
count = 0
a = 0
for i in S:
  if i == "<":
    if count > 0:
      if count == 1:
        now = 0
        count = 0
      else:
        if count > now:
          ans = ans +  sum(range(1, count+1)) - now
          now = 0
          count = 0
        else:
          ans = ans + sum(range(1, count))
          now = 0
          count = 0
    now += 1
    a = 1
  else:
    if a == 1:
      ans += sum(range(1, now+1))
      a = 0
    count += 1
if a == 1:
  ans += sum(range(1, now+1))
elif count > 0:
  if count == 1:
    now = 0
    count = 0
  else:
    if count > now:
      ans = ans +  sum(range(1, count+1)) - now
      now = 0
      count = 0
    else:
      ans = ans + sum(range(1, count))
      now = 0
      count = 0
  
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
tmp = [0]
tmpsc = 1
tmpsum = 0
for i, a in enumerate(s):
    if a == '<':
        if i == 0:
            tmp.append(tmp[i] + 1)
        else:
            #if tmp[i] >= 0:
            if s[i-1] == '<':
                tmp.append(tmp[i] + 1)
                tmpsc = 1
            else:
                tmp.append(1)
                tmpsum += tmp[i] * tmpsc * -1
                tmpsc = 1

    else:
        tmp.append(tmp[i] - 1)
        tmpsc += 1

# print(tmpsc1,tmpsc2)
if s[-1] < '>':
    #print(tmp[-1],tmpsc)
    tmpsum += tmp[i] * tmpsc * -1
print(sum(tmp)+ tmpsum)

#print(tmp)

Submission status: Wrong Answer

Solution code:
s = input()
b = s[0]
cou = 0
if len(s)==2:
    if s[0]=='>' and s[1] =='<':
        print(2)
        exit()

lis = []
for i in s:
    if b ==i:
        if i=='<':
            cou-=1
        else:
            cou+=1
    else:
        lis.append(cou)
        b = i
        if b=='<':
            cou =-1
        else:
            cou = 1
lis.append(cou)
l = len(lis)
sum = 0

for i in range(0,l,2):
    if i+1 == l and (i+1)%2==1:
        a = abs(lis[i])
        sum += a*(a+1)//2
        break
    a = abs(lis[i])
    b = abs(lis[i+1])

    if a < b:
      sum += b*(b+1)//2
      sum += (a-1)*a//2
    else:
        sum += a*(a+1)//2
        sum += (b-1)*b//2        
print(sum)

Submission status: Wrong Answer

Solution code:
s=input()
a=[]
su=0
k=0
def wa(x):
  j=0
  t=0
  for i in range(x):
    j+=1
    t+=j
  return t
def unkosumaho(x):
  b=0
  c=0
  for i in range(len(x)):
    if x[i]=='<':
      b+=1
    else:
      c+=1
  return wa(max(b,c))+wa(min(b,c)-1)
for i in range(len(s)-1):
  if s[i]=='>':
    if s[i+1]=='<':
      a.append(s[k:i+1])
      k=i+1
  if i==len(s)-2:
      a.append(s[k:])
for i in a:
  su+=unkosumaho(i)
print(su)

Submission status: Wrong Answer

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
S = input()
n = len(S)
S = S + " "
ans = 0
l = 0
r = 0
temp = 0
for i in range(n):
    if S[i] == '>' and S[i + 1] == ('<'):
        temp = i
        break
    if i == n - 1:
        temp = n-1
if S[0] == '<':
    temp = -1
ans += (temp + 1) * (temp + 2) // 2
i = max(temp, 0)
while(i < n):
    while (i < n and S[i] == '<'):
        l += 1
        i += 1
    while (i < n and S[i] == '>'):
        r += 1
        i += 1
    l, r = min(l, r), max(l, r)
    ans += l * (l - 1) // 2 + r * (r + 1) // 2
    l = 0
    r = 0

l, r = min(l, r), max(l, r)
ans += l * (l - 1) // 2 + r * (r + 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
tmp1 = 1
tmp2 = 1
yet = 0
ans = 0
for i in range(len(s)-1):
    if s[i] == '<' and s[i+1] == '<':
        tmp1 += 1
    elif s[i] == '>' and s[i+1] == '>':
        tmp2 += 1
    elif s[i] == '>' and s[i+1] == '<':
        if tmp1 >= tmp2:
            ans += (tmp1*(tmp1+1))//2 + ((tmp2-1)*tmp2)//2
        else:
            ans += (tmp2*(tmp2+1))//2 + ((tmp1-1)*tmp1)//2
        tmp1 = 1
        tmp2 = 1
        yet = i + 1
        if i+1 == len(s)-1:
            ans += 1
if yet != len(s)-1:
    if s[-1] == '>':
        if tmp1 >= tmp2:
            ans += (tmp1*(tmp1+1))//2 + ((tmp2-1)*tmp2)//2
        else:
            ans += (tmp2*(tmp2+1))//2 + ((tmp1-1)*tmp1)//2
    else:
        ans += (tmp1*(tmp1+1))//2
print(ans)

Submission status: Wrong Answer

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
S = input()
n = len(S)
S = S + " "
ans = 0
l = 0
r = 0
temp = 0
for i in range(n):
    if S[i] == '>' and S[i + 1] == ('<'):
        temp = i
        break
if S[0] == '<':
    temp = -1
elif temp == 0:
    temp = n-1
ans += (temp + 1) * (temp + 2) // 2
i = max(temp, 0)
while(i < n):
    while (i < n and S[i] == '<'):
        l += 1
        i += 1
    while (i < n and S[i] == '>'):
        r += 1
        i += 1
    l, r = min(l, r), max(l, r)
    ans += l * (l - 1) // 2 + r * (r + 1) // 2
    l = 0
    r = 0

l, r = min(l, r), max(l, r)
ans += l * (l - 1) // 2 + r * (r + 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
s=list(input())
count=0
count1=0
ans=0
for i in range(len(s)):
    if s[i]=='<' and i==len(s)-1:
        count+=1
        ans+=count*(count+1)//2
        #print(ans)
    elif s[i]=='>' and i==len(s)-1:
        count1+=1
        if count1==1:
            ans+=count1*(count1-1)//2
        else:
            ans+=count1*(count1+1)//2
        #print(ans)
    if count>0 and s[i]=='>':
        if count==1:
            if i==2 or i==len(s)-1:
                ans+=1
                count=0
                count1+=1
                continue
            else:
                count=0
                count1+=1
                continue
        else:
            if i==len(s)-1:
                ans+=(count-1)*count//2
                count=0
                count1+=1
                #print(ans)
                continue
            else:
                ans+=(count+1)*count//2
                count=0
                count1+=1
                #print(ans)
                continue
    elif count1>0 and s[i]=='<':
        if count1==1:
            if i==2 or i==len(s)-1:
                ans+=1
                count1=0
                count+=1
                continue
            else:
                count1=0
                count+=1
                continue
        else:
            if i==len(s)-1:
                ans+=(count1-1)*count1//2
                count1=0
                count+=1
                #print(ans)
                continue
            else:
                ans+=(count1+1)*count1//2
                count1=0
                count+=1
                #print(ans)
                continue
        #------------------------------------------
    if s[i]=='<':
        count+=1
    else:
        count1+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import operator
def compare(a, relate, b):
    ops = {'>': operator.gt,
           '<': operator.lt}
    return ops[relate](a, b)

#def dfs(a, o):
  
  
S = input()
a = []
o = []
for _ in range(len(S) + 1):
  a.append(0)
for s in S:
  o.append(s)
o = o[::-1]
#print(a)
#print(o)
for i, s in enumerate(S):
  if i == len(S):
    break
  if o[i] == "<":
    while (compare(a[i], o[i], a[i + 1]) is False):
      a[i + 1] += 1
  elif o[i] == ">":
    while (compare(a[i], o[i], a[i + 1]) is False):
      a[i] += 1
#print(a)
s = 0
for e in a:
  s += e
print(s)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
#標準入力から文字列Sを取得
S = input()

#文字列Sの長さを取得
N = len(S)

#空のリストを用意
a = [0]

#<と>の順番に応じて初期の山の形を決定
for i in range(N):
    if S[i] == '<':
        a.append(a[i]+1)
    else:
        a.append(a[i]-1)

#aの最小値
min(a)

#山をずらす値
shift_value = 0 - min(a)

#aの全要素にシフト値を加える
newa = [n+shift_value for n in a]

#端の補正
if S[0] == '<':
    newa[0] = 0
if S[N-1] == '>':
    newa[N] = 0
    
#aの全要素の和
sum(newa)

Submission status: Wrong Answer

Solution code:
S = list(input())
if S[-1] == '<':
  S.append('>')
else:
  S.append('<')
output = 0
count = 0
num_list = []

if S[0] == '>':
  model = 0
else:
  model = 1
s_pre = S[0]
for i in range(len(S)):
  s = S[i]
  if s != s_pre or i == len(S)-1:
    num_list.append(count)
    count = 1
    s_pre = s
  else: 
    count += 1
#print(num_list, model)
if model == 0:
  output += num_list[0]
  num_list == num_list[1:]


for i in range(len(num_list)//2):
  n_max = max(num_list[2*i], num_list[2*i+1]) #同じ場合考える
  n_min = min(num_list[2*i], num_list[2*i+1])
  #print(n_max, n_min)
  output += n_max*(n_max+1)/2
  output += (n_min-1)*n_min/2
if len(num_list)%2 == 1:
  output += num_list[-1]*(num_list[-1]+1)/2
print(int(output))

Submission status: Wrong Answer

Solution code:
S = list(input())
A = [0] * (len(S)+1)
imos = [0] * (len(S))
for i in range(len(S)):
    if S[i] == '>':
        imos[i] = 1
    else:
        imos[i] = -10000000
imos += [0]
for i in range(len(S), 0, -1):
    imos[i-1] = max(0, imos[i-1] + imos[i])

for i in range(len(S)):
    if S[i] == '<':
        A[i+1] = max(imos[i+1], A[i]+1)
    else:
        A[i+1] = max(0, min(A[i]-1, imos[i+1]))
print(sum(A))

Submission status: Wrong Answer

Solution code:
S = list(input())
A = [0] * (len(S)+1)
imos = [0] * (len(S))
for i in range(len(S)):
    if S[i] == '>':
        imos[i] = 1
    else:
        imos[i] = -10000000
imos += [0]
for i in range(len(S), 0, -1):
    imos[i-1] = max(0, imos[i-1] + imos[i])

for i in range(len(S)):
    if S[i] == '<':
        A[i+1] = max(imos[i+1], A[i]+1)
    else:
        A[i+1] = max(0, min(A[i]-1, imos[i+1]))
print(sum(A))
print(A)
print(imos)

Submission status: Wrong Answer

Solution code:
s = input()

def calc_sum(n):
    if n <= 0:
        return 0
    return (n+1)*n/2

length = len(s)

num_g = 0
num_l = 0

prev = 1
cur = -1

out = 0

for i in range(length):
    if s[i] == '<':
        cur = 1
    else:
        cur = 0
        
    if prev == 1 and cur == 1:
        num_g += 1
    elif prev == 1 and cur == 0:
        num_l += 1
    elif prev == 0 and cur == 0:
        num_l += 1
    elif prev == 0 and cur == 1:
        out += calc_sum(max(num_g, num_l)) + calc_sum(min(num_g, num_l)-1)
        
        num_g = 1
        num_l = 0
    
    prev = cur
    
if cur == 1:
    out += calc_sum(num_g)
else:
    out += calc_sum(max(num_g, num_l)) + calc_sum(min(num_g, num_l)-1)
    
print(str(out))

Submission status: Wrong Answer

Solution code:
s = input()
t = s.split(">")
t2 = s.split("<")
a = []
b = []
for i in t:
    if i != '':
        a.append(i)

for i in t2:
    if i != '':
        b.append(i)
n = len(a)
n2 = len(b)
if len(b) == 1 and len(a) == 1:
    if s[0] == '>':
        y = len(b[0])
        x = len(a[0])
        sums = 0
        sums += (x * (x + 1)) / 2
        sums += (y * (y + 1)) / 2
        print(int(sums))
        exit()

tmp = min(n, n2)
sums = 0
for i in range(tmp):
    x = len(a[i])
    y = len(b[i])
    if x > y:
        sums += (x * (x + 1)) / 2
        sums += (y * (y - 1)) / 2
    else:
        sums += (x * (x - 1)) / 2
        sums += (y * (y + 1)) / 2
if n > n2:
    x = len(a[n-1])
    sums += (x * (x + 1)) / 2
elif n2 > n:
    x = len(b[0])
    sums += (x * (x + 1)) / 2

print(int(sums))

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)+1
lsfg = [0]*n

for i in range(n-2):
    if s[i] != s[i+1]:
        if s[i] == "<":
            lsfg[i+1] = -2
        else:
            lsfg[i+1] = -1

for i in range(n):
    k = 0
    j = 0
    if lsfg[i] == -1:
        while i-k > 0:
            k += 1
            if lsfg[i-k] != -2:
                lsfg[i-k] = k
            else:
                break
        while i+j < n-1:
            j += 1
            if lsfg[i+j] != -2:
                lsfg[i+j] = j
            else:
                break

lsfg = [0] + lsfg + [0]

for i in range(n):
    if lsfg[i+1] == -2:
        if lsfg[i] > lsfg[i+2]:
            lsfg[i+1] = lsfg[i] +1
        else:
            lsfg[i+1] = lsfg[i+2] +1
    elif lsfg[i+1] == -1:
        lsfg[i+1] = 0

ans = sum(lsfg)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)+1
lsfg = [0]*n

for i in range(n-2):
    if s[i] != s[i+1]:
        if s[i] == "<":
            lsfg[i+1] = -2
        else:
            lsfg[i+1] = -1

for i in range(n):
    k = 0
    j = 0
    if lsfg[i] == -1:
        while i-k > 0:
            k += 1
            if lsfg[i-k] != -2:
                lsfg[i-k] = k
            else:
                break
        while i+j < n-1:
            j += 1
            if lsfg[i+j] != -2:
                lsfg[i+j] = j
            else:
                break

lsfg = [0] + lsfg + [0]

for i in range(n):
    if lsfg[i+1] == -2:
        if lsfg[i] > lsfg[i+2]:
            lsfg[i+1] = lsfg[i] +1
        else:
            lsfg[i+1] = lsfg[i+2] +1
    elif lsfg[i+1] == -1:
        lsfg[i+1] = 0

print(lsfg)
ans = sum(lsfg)
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
S.append(0)
lenS = len(S)
ans = 0
n = 0
while n < lenS-1:
    a = 1
    b = 1
    while S[n] == '<' and S[n+1] == '<':
        n += 1
        a += 1
    n += 1
    while S[n] == '>' and S[n+1] == '>':
        n += 1
        b += 1
    n += 1
    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: Wrong Answer

Solution code:
S = input()
count_1 = 0
count_2 = 0
count_max = 0
count_min = 0
counter = 0
for i in range(len(S)):
    if i != (len(S) - 1):
        if S[i] == "<":
            if count_2 == 0:
                count_1 += 1
                
            else:
                count_max = max(count_1,count_2)
                count_min = min(count_1,count_2)
                counter += ((count_max)*(count_max + 1) + (count_min)*(count_min - 1))/2
                count_1 = 1
                count_2 = 0

        elif S[i] == ">":
            count_2 += 1
            
    else:
        if S[i] == "<":
            if count_2 == 0:
                counter += count_1 + 1
            else:
                count_max = max(count_1,count_2)
                count_min = min(count_1,count_2)
                counter += ((count_max)*(count_max + 1) + (count_min)*(count_min - 1))/2 + 1
        else:
            count_2 += 1
            count_max = max(count_1,count_2)
            count_min = min(count_1,count_2)
            counter += ((count_max)*(count_max + 1) + (count_min)*(count_min - 1))/2
            
print(int(counter))

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
    total+=gr*(1+gr)/2
    total+=(lt-1)*lt/2+1
    gr=0
    lt=0

print(int(total))

Submission status: Wrong Answer

Solution code:
import numpy as np
S = input().strip()
a=-np.ones(len(S)+1)
for i in range(len(S)):
    if i==0:
        if S[0]=='<':
            a[0]=0
    elif i==len(S)-1:
        if S[i]=='>':
            a[i+1]=0
    elif i<len(S)-1:
        if S[i]=='>'and S[i+1]=='<':
            a[i+1]=0
        
for i in range(len(S)):
    if a[i]!=-1:
        if S[i]=='<':
            a[i+1]=a[i]+1
for i in reversed(range(len(S))):
    if a[i+1]!=-1:
        if S[i]=='>':
            if S[i-1]=='<':
                if a[i]<a[i+1]+1:
                    a[i]=a[i+1]+1
            else:
                a[i]=a[i+1]+1
print(int(sum(a)))

Submission status: Wrong Answer

Solution code:
S = input()
#print(len(S))
s_list = []
head_num = 10**6 if S[0] == ">" else 0
s_list.append(head_num)
for i in range(len(S)-1):
    if S[i] == ">" and S[i+1] == "<":
        s_list.append(0)
    elif S[i] == "<":
        s_list.append(s_list[i]+1)
    else:
        s_list.append(s_list[i]-1)
if S[len(S)-1] == "<":
    s_list.append(s_list[len(S)-1] +1)
else:
    s_list.append(s_list[len(S)-1] -1)

#print(s_list)
count = 1
s_list[len(s_list)-1] = 0 if s_list[len(s_list)-1] < 0 else s_list[len(s_list)-1] 

for i in range(len(S)-1,-1,-1):
    if S[i] == ">" and S[i-1] == ">":
    #if S[i] == ">":
        s_list[i] = count
        count += 1
    elif S[i] == ">" and S[i-1] == "<":
        s_list[i] = max(s_list[i-1], s_list[i+1]) + 1
    else:
        count = 1
#print(len(s_list))
#print(s_list)

sum = 0
for i in range(len(s_list)):
    sum += s_list[i]

print(sum)

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
    total+=gr*(1+gr)/2+1
    total+=(lt-1)*lt/2
    gr=0
    lt=0

print(int(total))

Submission status: Wrong Answer

Solution code:
import itertools
s=input()
splitlist=[[k, len(list(g))] for k, g in itertools.groupby(s)]
n=len(splitlist)
#print(splitlist)

def total(lst):
	return lst[1]*(lst[1]+1)//2


ans=0
for i in range(n):
	ans+=total(splitlist[i])
	if splitlist[i][0]==">":
		ans-=min(splitlist[i-1][1],splitlist[i][1])
print(ans)