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

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

ans=0

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

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

print(ans)

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

S = list(input())

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

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

l.append((prev, series))

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

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

print(int(res))

Solution (Python):

S = str(input())

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

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


for t in tani:
    

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

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



print(sum(ans))

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

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

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

Solution (Python):



def main():
    s = input()
    
    
    n_list = [0] * (len(s)+1)
    

    for i in range(1, len(s)):
        if s[i-1] == '<':
            n_list[i] = n_list[i-1]+1
        else: 
            if s[i] == '>':
                continue
            
            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] == '>':
        
        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(int(sum(n_list)))


if __name__ == "__main__":
    
    main()

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

Solution (Python):
S=input()

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

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

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

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

ans.append(count)

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

print(int(ans_sum))

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

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

Solution (Python):



def main():
    s = input()
    
    
    n_list = [0] * (len(s)+1)
    

    for i in range(1, len(s)):
        if s[i-1] == '<':
            n_list[i] = n_list[i-1]+1
        else: 
            if s[i] == '>':
                continue
            
            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] == '>':
        
        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(int(sum(n_list)))


if __name__ == "__main__":
    
    main()

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

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

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

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

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

Solution (Python):
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)
        
        
        
        cnt=1
    if s[i]=='<':
        ss[i]=j
        j+=1
    else:
        j=0
kind.append(cnt)
j=0
for i in range(-1,-len(s)-1,-1):
    if s[i]=='>':
        ss[i]=j
        j+=1
    else:
        j=0
if ss[0]==-1:
    ss[0]=ss[1]+1


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

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

print(ans)

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

Solution (Python):


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

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

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

for i, char in enumerate(s_list):
    
    is_ou = False
    is_totsu = False
    if i == s_l - 1:
        if char == ">":
            is_ou = True
    else:
        if s_list[i] == "<" and s_list[i + 1] == ">":
            is_totsu = True
        elif s_list[i] == ">" and s_list[i + 1] == "<":
            is_ou = True

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

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

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

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

total = 0

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

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


ans = total
print(ans)

Solution (Python):
import sys
import math

input = sys.stdin.readline

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

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

ans = 0

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

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





print(sum(sl))

Solution (Python):
str_S = input()

int_a = [0]
cnt = 0

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

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



ans = 0

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

print(ans)

Solution (Python):
s = list(input())

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

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

nums.append(count)

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

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

print(score)

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

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

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

rec(0)

print(sum(tmp))

Solution (Python):
import sys
from operator import itemgetter
input = sys.stdin.readline

_s = input()


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

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

    print(int(minisum))


chker(_s)

Solution (Python):
import re

S = raw_input()

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

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

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

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

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

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

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

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

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

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

Solution (Python):
from itertools import groupby

S = input()

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

INF = float("inf")

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

print(ans)

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

s_kigo_map = [] 
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:
    sum_num += (0 +s_kigo_map[i][1] )*(s_kigo_map[i][1]+1)//2
    print(sum_num)
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
            
        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])
            
    else:  
        sum_num += (0 +s_kigo_map[i][1] )*(s_kigo_map[i][1]+1)//2
        

    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
                
            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])
                
        else:  
            sum_num += (s_kigo_map[i][1] - 1 )*(s_kigo_map[i][1])//2
            
    print(sum_num)

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

def solve(i, d):
	ans = 0
	if i >= d : 
		i += 1
	elif i < d:
		d += 1
	for c in range(i):
		ans += c
	for c in range(d):
		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

sum += solve(inc, dec)

print(sum)

Solution (Python):
s = input()

def pa(ai, an, n):
    
    s = (ai+an)*n//2
    
    return s


c = []
ant = s[0]
cont = 1
for i in s[1:]:
    if i != ant:    
        c.append((cont, ant))
        ant = i
        cont = 1
    else:   
        cont += 1
        
c.append((cont, ant))

soma = 0

for x in range(len(c)):
    i = c[x]
    if i[1] == '<':
        soma += pa(0, i[0]-1, i[0])
    else:
        soma += pa(i[0], 1, i[0])
        if x>0:
            off = max(0, c[x-1][0] - i[0])
            
            soma += off

if c[-1][1] == '<':
    soma += c[-1][0]
    
print(soma)

Solution (Python):

s = input()

small_mode = s[0] == '<'
initial_small_mode = small_mode
idx = 0
nums = []
while idx < len(s):
    if small_mode:
        num = 0
        while idx < len(s) and s[idx] == '<':
            num += 1
            idx += 1
        nums.append(num)
        if idx >= len(s):
            break
        else:
            small_mode = not small_mode
    elif not small_mode:
        num = 0
        while idx < len(s) and s[idx] == '>':
            num += 1
            idx += 1
        nums.append(num)
        if idx >= len(s):
            break
        else:
            small_mode = not small_mode

seq = []


if initial_small_mode:
    seq.append(0)
else:
    seq.append(nums[0])

for idx, run in enumerate(nums):
    if initial_small_mode:
        for i in range(1, run + 1):

            if i == run and idx < len(nums) -1 and nums[idx + 1] > run:
                seq.append(nums[idx + 1])
            else:
                seq.append(i)
    else:
        for i in range(run - 1, -1, -1):
            seq.append(i)
    initial_small_mode = not initial_small_mode





print(sum(seq))

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

tmp = S[0]
cnt = 0
cnt2 = 0
l = []
for i in range(N-1):
    if S[i] == tmp:
        cnt += 1
    else:
        tmp = S[i]
        l.append(cnt)
        cnt = 1

else:
    l.append(cnt)


if S[0] == '>':
    l = [1] + l    
if len(l) % 2 == 1:
    l.append(1)

ans = 0    
for i in range(0, len(l), 2):
    a, b = max(l[i], l[i+1]), min(l[i], l[i+1])
    ans += ((a * (a+1)) //2) + ((b * (b-1)) //2)

print(ans)

Solution (Python):
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+min(a[i],a[i+1])
    else:
        if i%2==1:
            sa=sa+min(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))

Solution (Python):
from itertools import groupby
s=[[k, len(list(g))] for k, g in groupby(list(input()))]
a=[0]
for i in s:
    if i[0]=="<":
        n=0
        if a[-1] == 0:
            a.pop(-1)
        for j in range(i[1]+1):
            a.append(n)
            n+=1
    else:
        n=i[1]
        if a[-1] <= n:
            a.pop(-1)
        else:
            n-=1
        for j in range(i[1]+1):
            a.append(n)
            if n == 0:
                break
            n-=1
print(sum(a))

Solution (Python):
S = input()
n = len(S)
ans = 0
p = 0
q = 0
m = 1
s = ['>']
for i in range(n):
    s.append(S[i])
s.append('<')
for i in range(1,n+2):
    if s[i] == '<':
        if s[i-1] == '>':
            if p > 0:
                ans += (1-m)*(q-1)
            else:
                ans += (1-m)*q
            p = 0
            q = 0
            m = 1
        else:
            p += 1
            ans += p
    else:
        if s[i-1] == '<':
            p += 1
            q += 1
        else:
            p += -1
            q += 1
        m = p
        ans += p
    
print(ans)

Solution (Python):
s = input()
n = len(s)+1
ans = 0
ls = [0]*n

tmp = 0

for i in range(n-1):
    if s[i] == "<":
        if i < n-2:
            if s[i+1] == "<":
                    tmp += 1
                    ans += tmp
            else:
                tmp += 1
                ans += tmp
                ls[i+1] = tmp
                tmp = 0
        else:
            tmp += 1
            ans += tmp
    else:
        tmp = 0
tmp = 0

for i in range(n-1):
    if s[n-i-2] == ">":
        if n-i-2 > 0:
            if s[n-i-3] == ">":
                tmp += 1
                ans += tmp
            else:
                tmp += 1
                if ls[n-i-2] < tmp:
                    ans += tmp - ls[n-i-2]
                tmp = 0
        else:
            tmp += 1
            ans += tmp

print(ans)

Solution (Python):
S = input()
from itertools import groupby
S_length = len(S)
k = 1
s_l=[k*len(list(g)) for k, g in groupby(S)]
  
        
        
def n_sum(n):
  return n*(n+1)//2
        

s_l_length = len(s_l)
answer=0
if s_l[0][0]=='<':
  if s_l_length%2==0:
    for i in range(0,s_l_length,2):
      s_1=s_l[i]
      s_2=s_l[i+1]
      s_1_l=len(s_1)
      s_2_l=len(s_2)
      if s_1_l<=s_2_l:
        answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
      else:
        answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
  else:
    for i in range(0,s_l_length,2):
      if i==s_l_length-1:
        answer+=n_sum(len(s_l[i]))
      else:
        s_1=s_l[i]
        s_2=s_l[i+1]
        s_1_l=len(s_1)
        s_2_l=len(s_2)
        if s_1_l<=s_2_l:
          answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
        else:
          answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
          
else:
  answer+=n_sum(len(s_l.pop(0)))
  s_l_length-=1
  if s_l_length%2==0:
    for i in range(0,s_l_length,2):
      s_1=s_l[i]
      s_2=s_l[i+1]
      s_1_l=len(s_1)
      s_2_l=len(s_2)
      if s_1_l<=s_2_l:
        answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
      else:
        answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
  else:
    for i in range(0,s_l_length,2):
      if i==s_l_length-1:
        answer+=n_sum(len(s_l[i]))
      else:
        s_1=s_l[i]
        s_2=s_l[i+1]
        s_1_l=len(s_1)
        s_2_l=len(s_2)
        if s_1_l<=s_2_l:
          answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
        else:
          answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
  
      
print(answer)

Solution (Python):
s = list(input())
sc = [0]*(len(s)+1)
key = 0
pre = ''
n = len(s)
        
if s[0] == '<':
    sc[0] = 0
    sc[1] = 1
    pre = 'l'
else:
    key += 1
    pre = 'r'
    
for i in range(1,n):
    if pre == 'l':
        if s[i] == '<':
            sc[i] = sc[i-1] + 1
            pre = 'l'
        else:
            sc[i] = sc[i-1] + 1
            key += 1
            pre = 'r'
    else:
        if s[i] == '<':
            while key > 0:
                sc[i-key] = max(key,sc[i-key])
                key = key -1
            sc[i] = 0
            sc[i+1] = 1
            pre = 'l'
        else:
            key += 1
            pre = 'r' 
    
if pre == 'l':
    sc[n] = sc[n-1] + 1
else:
    while key > 0:
        sc[n-key] = max(key,sc[n-key])
        sc[n] = 0
        key = key -1
        
print(sum(sc))

Solution (Python):
moji = list(input())
listlist=[]
inlist=[]
result=0
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)