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:
def calcsum(n):
    return n * (n + 1) // 2

s = str(input())
n = len(s) + 1
arrk = []
arrg = []
tmp = s[0]
cnt = 1
for i in range(1, n-1):
    if s[i] == tmp:
        cnt += 1
    elif s[i] != tmp:
        if tmp == '<':
            arrk.append(cnt)
        else:
            arrg.append(cnt)
        cnt = 1
        tmp = s[i]
if tmp == '<':
    arrk.append(cnt)
else:
    arrg.append(cnt)
#print(arrk, arrg)
ans = 0
for i in range(len(arrk)):
    #print(calcsum(arrk[i]-1))
    ans += calcsum(arrk[i]-1)
for i in range(len(arrg)):
    #print(calcsum(arrg[i]-1))
    ans += calcsum(arrg[i]-1)
#print('ans',ans)
l = min(len(arrg), len(arrk))
#print(l, len(arrg), len(arrk))
if s[0] == '<':
    for i in range(l):
        ans += max(arrg[i], arrk[i])
    if l < len(arrk):
        ans += arrk[len(arrk) - 1]
'''
elif s[0] == '>':
    ans += arrg[0]
    for i in range(l-1):
        ans += max(arrg[i+1], arrk[i])
    if l < len(arrg):
        ans += arrg[len(arrg) - 1]
'''
print(ans)

Submission status: Wrong Answer

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

s = str(input())
n = len(s) + 1
arrk = []
arrg = []
tmp = s[0]
cnt = 1
for i in range(1, n-1):
    if s[i] == tmp:
        cnt += 1
    elif s[i] != tmp:
        if tmp == '<':
            arrk.append(cnt)
        else:
            arrg.append(cnt)
        cnt = 1
        tmp = s[i]
if tmp == '<':
    arrk.append(cnt)
else:
    arrg.append(cnt)
#print(arrk, arrg)
ans = 0
for i in range(len(arrk)):
    #print(calcsum(arrk[i]-1))
    ans += calcsum(arrk[i]-1)
for i in range(len(arrg)):
    #print(calcsum(arrg[i]-1))
    ans += calcsum(arrg[i]-1)
#print('ans',ans)
l = min(len(arrg), len(arrk))
#print(l, len(arrg), len(arrk))
if s[0] == '<':
    for i in range(l):
        ans += max(arrg[i], arrk[i])
    if l < len(arrk):
        ans += arrk[len(arrk) - 1]
elif s[0] == '>':
    ans += arrg[0]
    for i in range(l-1):
        ans += max(arrg[i+1], arrk[i])
    if l < len(arrg):
        ans += arrg[len(arrg) - 1]
print(ans)

Submission status: Wrong Answer

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

s = str(input())
n = len(s) + 1
arrk = []
arrg = []
tmp = s[0]
cnt = 1
for i in range(1, n-1):
    if s[i] == tmp:
        cnt += 1
    elif s[i] != tmp:
        if tmp == '<':
            arrk.append(cnt)
        else:
            arrg.append(cnt)
        cnt = 1
        tmp = s[i]
if tmp == '<':
    arrk.append(cnt)
else:
    arrg.append(cnt)
#print(arrk, arrg)
ans = 0
for i in range(len(arrk)):
    #print(calcsum(arrk[i]-1))
    ans += calcsum(arrk[i]-1)
for i in range(len(arrg)):
    #print(calcsum(arrg[i]-1))
    ans += calcsum(arrg[i]-1)
#print('ans',ans)
if s[0] == '<':
    for i in range(len(arrg)):
        #print('a', max(arrg[i], arrk[i]))
        ans += max(arrg[i], arrk[i])
    if len(arrg) > len(arrk):
        ans += arrg[len(arrg)-1]
    elif len(arrk) > len(arrg):
        ans += arrk[len(arrk)-1]
elif s[0] == '>':
    ans += arrg[0]
    for i in range(len(arrk)-1):
        #print('a', max(arrg[i+1], arrk[i]))
        ans += max(arrg[i+1], arrk[i])
    if len(arrg) > len(arrk):
        ans += arrg[len(arrg)-1]
    elif len(arrk) > len(arrg):
        ans += arrk[len(arrk)-1]
    else:
        if s[n-2] == '<':
            ans += arrk[len(arrk)-1]
print(ans)

Submission status: Wrong Answer

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

s = str(input())
n = len(s) + 1
arrk = []
arrg = []
tmp = s[0]
cnt = 1
for i in range(1, n-1):
    if s[i] == tmp:
        cnt += 1
    elif s[i] != tmp:
        if tmp == '<':
            arrk.append(cnt)
        else:
            arrg.append(cnt)
        cnt = 1
        tmp = s[i]
if tmp == '<':
    arrk.append(cnt)
else:
    arrg.append(cnt)
#print(arrk, arrg)
ans = 0
for i in range(len(arrk)):
    #print(calcsum(arrk[i]-1))
    ans += calcsum(arrk[i]-1)
for i in range(len(arrg)):
    #print(calcsum(arrg[i]-1))
    ans += calcsum(arrg[i]-1)
#print('ans',ans)
if s[0] == '<':
    for i in range(len(arrg)):
        #print('a', max(arrg[i], arrk[i]))
        ans += max(arrg[i], arrk[i])
elif s[0] == '>':
    ans += arrg[0]
    for i in range(len(arrk)-1):
        #print('a', max(arrg[i+1], arrk[i]))
        ans += max(arrg[i+1], arrk[i])
    if s[n-2] == '<':
        ans += arrk[len(arrk)-1]
if len(arrg) > len(arrk):
    ans += arrg[len(arrg)-1]
if len(arrk) > len(arrg):
    ans += arrk[len(arrk)-1]
print(ans)

Submission status: Wrong Answer

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

s = str(input())
n = len(s) + 1
arrk = []
arrg = []
tmp = s[0]
cnt = 1
for i in range(1, n-1):
    if s[i] == tmp:
        cnt += 1
    elif s[i] != tmp:
        if tmp == '<':
            arrk.append(cnt)
        else:
            arrg.append(cnt)
        cnt = 1
        tmp = s[i]
if tmp == '<':
    arrk.append(cnt)
else:
    arrg.append(cnt)
#print(arrk, arrg)
ans = 0
for i in range(len(arrk)):
    #print(calcsum(arrk[i]-1))
    ans += calcsum(arrk[i]-1)
for i in range(len(arrg)):
    #print(calcsum(arrg[i]-1))
    ans += calcsum(arrg[i]-1)
#print('ans',ans)
if s[0] == '<':
    for i in range(len(arrg)):
        #print('a', max(arrg[i], arrk[i]))
        ans += max(arrg[i], arrk[i])
    if len(arrg) > len(arrk):
        ans += arrg[len(arrg)-1]
    if len(arrk) > len(arrg):
        ans += arrk[len(arrk)-1]
elif s[0] == '>':
    ans += arrg[0]
    for i in range(len(arrk)-1):
        #print('a', max(arrg[i+1], arrk[i]))
        ans += max(arrg[i+1], arrk[i])
    if s[n-2] == '<':
        ans += arrk[len(arrk)-1]
print(ans)

Submission status: Wrong Answer

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

s = str(input())
n = len(s) + 1
arrk = []
arrg = []
tmp = s[0]
cnt = 1
for i in range(1, n-1):
    if s[i] == tmp:
        cnt += 1
    elif s[i] != tmp:
        if tmp == '<':
            arrk.append(cnt)
        else:
            arrg.append(cnt)
        cnt = 1
        tmp = s[i]
if tmp == '<':
    arrk.append(cnt)
else:
    arrg.append(cnt)
#print(arrk, arrg)
ans = 0
for i in range(len(arrk)):
    #print(calcsum(arrk[i]-1))
    ans += calcsum(arrk[i]-1)
for i in range(len(arrg)):
    #print(calcsum(arrg[i]-1))
    ans += calcsum(arrg[i]-1)
#print('ans',ans)
if s[0] == '<':
    for i in range(len(arrg)):
        #print('a', max(arrg[i], arrk[i]))
        ans += max(arrg[i], arrk[i])
elif s[0] == '>':
    ans += arrg[0]
    for i in range(len(arrk)-1):
        #print('a', max(arrg[i+1], arrk[i]))
        ans += max(arrg[i+1], arrk[i])
if s[n-2] == '<':
    ans += arrk[len(arrk)-1]
print(ans)

Submission status: Wrong Answer

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

s = str(input())
n = len(s) + 1
arrk = []
arrg = []
tmp = s[0]
cnt = 1
for i in range(1, n-1):
    if s[i] == tmp:
        cnt += 1
    elif s[i] != tmp:
        if tmp == '<':
            arrk.append(cnt)
        else:
            arrg.append(cnt)
        cnt = 1
        tmp = s[i]
if tmp == '<':
    arrk.append(cnt)
else:
    arrg.append(cnt)
#print(arrk, arrg)
ans = 0
for i in range(len(arrk)):
    #print(calcsum(arrk[i]-1))
    ans += calcsum(arrk[i]-1)
for i in range(len(arrg)):
    #print(calcsum(arrg[i]-1))
    ans += calcsum(arrg[i]-1)
#print('ans',ans)
if s[0] == '<':
    for i in range(len(arrg)):
        #print('a', max(arrg[i], arrk[i]))
        ans += max(arrg[i], arrk[i])
elif s[0] == '>':
    ans += arrg[0]
    for i in range(len(arrk)-1):
        #print('a', max(arrg[i+1], arrk[i]))
        ans += max(arrg[i], arrk[i])
if s[n-2] == '<':
    ans += arrk[len(arrk)-1]
print(ans)

Submission status: Wrong Answer

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

s = str(input())
n = len(s) + 1
arrk = []
arrg = []
tmp = s[0]
cnt = 1
for i in range(1, n-1):
    if s[i] == tmp:
        cnt += 1
    elif s[i] != tmp:
        if tmp == '<':
            arrk.append(cnt)
        else:
            arrg.append(cnt)
        cnt = 1
        tmp = s[i]
if tmp == '<':
    arrk.append(cnt)
else:
    arrg.append(cnt)
#print(arrk, arrg)
ans = 0
for i in range(len(arrk)):
    #print(calcsum(arrk[i]-1))
    ans += calcsum(arrk[i]-1)
for i in range(len(arrg)):
    #print(calcsum(arrg[i]-1))
    ans += calcsum(arrg[i]-1)
#print('ans',ans)
if s[0] == '<':
    for i in range(len(arrg)):
        #print('a', max(arrg[i], arrk[i]))
        ans += max(arrg[i], arrk[i])
elif s[0] == '>':
    for i in range(len(arrk)):
        #print('a', max(arrg[i], arrk[i]))
        ans += max(arrg[i], arrk[i])
if len(arrg) > len(arrk):
    ans += arrg[len(arrg) - 1]
if len(arrk) > len(arrg):
    ans += arrk[len(arrk) - 1]
print(ans)

Submission status: Wrong Answer

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

s = str(input())
n = len(s) + 1
arrk = []
arrg = []
tmp = s[0]
cnt = 1
for i in range(1, n-1):
    if s[i] == tmp:
        cnt += 1
    elif s[i] != tmp:
        if tmp == '<':
            arrk.append(cnt)
        else:
            arrg.append(cnt)
        cnt = 1
        tmp = s[i]
if tmp == '<':
    arrk.append(cnt)
else:
    arrg.append(cnt)
print(arrk, arrg)
ans = 0
for i in range(len(arrk)):
    #print(calcsum(arrk[i]-1))
    ans += calcsum(arrk[i]-1)
for i in range(len(arrg)):
    #print(calcsum(arrg[i]-1))
    ans += calcsum(arrg[i]-1)
#print('ans',ans)
if s[0] == '<':
    for i in range(len(arrg)):
        #print('a', max(arrg[i], arrk[i]))
        ans += max(arrg[i], arrk[i])
elif s[0] == '>':
    for i in range(len(arrk)):
        #print('a', max(arrg[i], arrk[i]))
        ans += max(arrg[i], arrk[i])
if len(arrg) > len(arrk):
    ans += arrg[len(arrg) - 1]
if len(arrk) > len(arrg):
    ans += arrk[len(arrk) - 1]
print(ans)

Submission status: Wrong Answer

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

s = str(input())
n = len(s) + 1
arrk = []
arrg = []
tmp = s[0]
cnt = 1
for i in range(1, n-1):
    if s[i] == tmp:
        cnt += 1
    elif s[i] != tmp:
        if tmp == '<':
            arrk.append(cnt)
        else:
            arrg.append(cnt)
        cnt = 1
        tmp = s[i]
if tmp == '<':
    arrk.append(cnt)
else:
    arrg.append(cnt)
#print(arrk, arrg)
ans = 0
for i in range(len(arrk)):
    #print(calcsum(arrk[i]-1))
    ans += calcsum(arrk[i]-1)
for i in range(len(arrg)):
    #print(calcsum(arrg[i]-1))
    ans += calcsum(arrg[i]-1)
#print(ans)
if s[0] == '<':
    for i in range(len(arrg)):
        #print(max(i, arrg[i], arrk[i]))
        ans += max(arrg[i], arrk[i])
    if s[len(s) - 1] == '<':
        ans += arrk[len(arrk)-1]
else:
    for i in range(len(arrk)):
        #print(max(i, arrg[i], arrk[i]))
        ans += max(arrg[i], arrk[i])
    if s[len(s) - 1] == '>':
        ans += arrg[len(arrg)-1]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    S = input()
    N = len(S)
    A = [0] * (N + 1)
    init = []
    for i in range(N - 1):
        if  S[i] == ">" and S[i + 1] == "<": init.append(i + 1)
    #right

    if A[0] == "<":
        d = 2
        A[d] = A[d - 1] + 1
        while d <= N - 1:
            if S[d] == ">": break
            d += 1
            A[d] = A[d-1] + 1

    for s in init:
        d = s + 1
        A[d] = A[d - 1] + 1
        while d <= N - 1:
            if S[d] == ">": break
            d += 1
            A[d] = A[d-1] + 1

    #left
    if S[N - 1] == ">":
        d = N - 1
        while d >= 0:
            if S[d] == "<": break
            A[d] = max(A[d], A[d+1] + 1)
            d -= 1
            
    for s in init:
        d = s - 1
        while d >= 0:
            if S[d] == "<": break
            A[d] = max(A[d], A[d+1] + 1)
            d -= 1

    print(sum(A))
    #print(A)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    S = input()
    N = len(S)
    A = [0] * (N + 1)
    init = []
    for i in range(N - 1):
        if  S[i] == ">" and S[i + 1] == "<": init.append(i + 1)
    #right
    if S[0] == "<":
        for i in range(N):
            if S[i] == ">": break
            A[i+1] = A[i] + 1

    for s in init:
        d = s + 1
        A[d] = A[d - 1] + 1
        while d <= N - 1:
            if S[d] == ">": break
            d += 1
            A[d] = A[d-1] + 1
    print(A)
    #left
    if S[N - 1] == ">":
        for i in reversed(range(N)):
            if S[i] == "<": break
            A[i] = A[i + 1] + 1
            
    for s in init:
        d = s - 1
        while d >= 0:
            if S[d] == "<": break
            A[d] = max(A[d], A[d+1] + 1)
            d -= 1

    print(sum(A))
    #print(A)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    S = input()
    N = len(S)
    A = [0] * (N + 1)
    init = []
    for i in range(N - 1):
        if  S[i] == ">" and S[i + 1] == "<": init.append(i + 1)
    #right
    if S[0] == "<":
        A[1] = A[0] + 1
        for i in range(1, N):
            A[i + 1] = A[i] + 1
            if S[i] == ">": break

    for s in init:
        d = s + 1
        A[d] = A[d - 1] + 1
        while d <= N - 1:
            if S[d] == ">": break
            d += 1
            A[d] = A[d-1] + 1
    #print(A)
    #left
    if S[N - 1] == ">":
        for i in reversed(range(N)):
            if S[i] == "<": break
            A[i] = A[i + 1] + 1
            
    for s in init:
        d = s - 1
        while d >= 0:
            if S[d] == "<": break
            A[d] = max(A[d], A[d+1] + 1)
            d -= 1

    print(sum(A))
    #print(A)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    S = input()
    N = len(S)
    A = [0] * (N + 1)
    init = []
    for i in range(N - 1):
        if  S[i] == ">" and S[i + 1] == "<": init.append(i + 1)
    #right
    if S[0] == "<":
        for i in range(1, N):
            A[i] = A[i-1] + 1
            if S[i] == ">": break

    for s in init:
        d = s + 1
        A[d] = A[d - 1] + 1
        while d <= N - 1:
            if S[d] == ">": break
            d += 1
            A[d] = A[d-1] + 1
    #print(A)
    #left
    if S[N - 1] == ">":
        for i in reversed(range(N)):
            if S[i] == "<": break
            A[i] = A[i + 1] + 1
            
    for s in init:
        d = s - 1
        while d >= 0:
            if S[d] == "<": break
            A[d] = max(A[d], A[d+1] + 1)
            d -= 1

    print(sum(A))
    #print(A)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
s = input()
if s[0] == ">":
    s="<"+s
if s[-1] == ">":
    s=s+"<"
if s[-1] == "<":
    s=s+"><"

cc = 0
r = []
for b, c in zip(s, s[1:]):
    cc += 1
#    print(b, c)
    if b == "<" and c == ">":
        d = cc
        cc = 0
    if b == ">" and c == "<":
        r.append((d, cc))
        cc = 0
R = 0
for x, y in r:
#    print(x,y)
    R += (x-1)*x//2+(y-1)*y//2+max(x,y)
#    print((x-1)*x//2+(y-1)*y//2+max(x,y))
print(R)

Submission status: Wrong Answer

Solution code:
S = [False if s == "<" else True for s in input()]

N = len(S) + 1

a = [0] * N

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

for i in range(N-2, 0, -1):
    if S[i]:
        a[i] = max(a[i], a[i+1] + 1)

print(sum(a))

Submission status: Wrong Answer

Solution code:
s = input()

flag = 0
ans = 0
cnt_a = 0
cnt_b = 0

for i in range(len(s)):
    if s[i] == '>' and flag == 0:
        cnt_a += 1
    if s[i] == '>' and flag == 1:
        ans += cnt_a * (cnt_a+1) // 2
        cnt_a = 0
        flag = 1
    if s[i] == '<' and flag == 0:
        ans += cnt_b * (cnt_b + 1) // 2
        cnt_b = 0
        flag = 0
    if s[i] == '<' and flag == 1:
        cnt_b += 1

ans += cnt_a * (cnt_a+1) // 2
ans += cnt_b * (cnt_b+1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
a = 0
for i in range(len(s) - 1):
    if s[i] == "<" and s[i+1] == ">":
        c_d = c_s = 0
        for j in reversed(range(i+1)):
            if s[j] == "<": c_d += 1
            else: break
        for j in range(i+1,len(s)):
            if s[j] == ">": c_s += 1
            else: break
        ma, mi = max(c_d, c_s), min(c_d, c_s) - 1
        a += int(ma*(ma+1)/2 + mi*(mi+1)/2)
    else: continue
c = 0
for i in reversed(range(len(s))):
    if s[i] == "<": c += 1
    else:
        a += int(c*(c+1)/2)
        break
print(a)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s) + 1 # 箱の数

dat = [0] * n
num, last = n, 0
# 0文字目からなめる
cnt = 0
for i in range(n):
    # 文字列が最後までくる、あるいは、単調増加にできないなら、
    # (つまり、この区間は"<" = 単調増加をイメージしている)
    if i == n - 1 or s[i] == ">":
        # その区間をなるべく大きな数になるように埋める
        num = cnt
        for j in range(i, last - 1, -1):
            dat[j] = str(num)
            num -= 1
        last = i + 1
        cnt = 0
    else:
        cnt += 1
#print("")
#print(" ".join(dat))

dat2 = ["0"] * n
last = n-1
# 0文字目からなめる
cnt = 0
for i in range(n - 1, -1, -1):
    # 文字列が最後までくる、あるいは、単調増加にできないなら、
    # (つまり、この区間は"<" = 単調増加をイメージしている)
    if i == 0 or s[i - 1] == "<":
        # その区間をなるべく大きな数になるように埋める
        for j in range(last, i-1, -1):
            dat2[j] = str(cnt)
            cnt += 1
        last = i -1
        cnt = 0
#print("")
#print(" ".join(dat2))


res = []
for i in range(len(dat)):
    res.append(int(max(dat[i], dat2[i])))
#print(" ".join(list(map(str, res))))

print(sum(res))

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s) + 1

dat = [0] * n
num, last = n, 0
# 0文字目からなめる
cnt = 0
for i in range(n):
    # 文字列が最後までくる、あるいは、単調増加にできないなら、
    # (つまり、この区間は"<" = 単調増加をイメージしている)
    if i == n - 1 or s[i] == ">":
        # その区間をなるべく大きな数になるように埋める
        num = cnt
        for j in range(i, last - 1, -1):
            dat[j] = str(num)
            num -= 1
        last = i + 1
        cnt = 0
    else:
        cnt += 1
#print("")
#print(" ".join(dat))

dat2 = ["0"] * n
last = n-1 - 1
# 0文字目からなめる
cnt = 0
for i in range(n - 2, -1, -1):
    # 文字列が最後までくる、あるいは、単調増加にできないなら、
    # (つまり、この区間は"<" = 単調増加をイメージしている)
    if i == 0 or s[i] == "<":
        # その区間をなるべく大きな数になるように埋める
        for j in range(last+1, i, -1):
            dat2[j] = str(cnt)
            cnt += 1
        last = i - 1
        cnt = 0
#print("")
#print(" ".join(dat2))

#print(len(s))

res = []
for i in range(len(dat)):
    res.append(int(max(dat[i], dat2[i])))
#print(" ".join(list(map(str, res))))

print(sum(res))

Submission status: Wrong Answer

Solution code:
s = input()
import itertools
def countstrs(s):
    return [(k, len(list(g))) for k, g in itertools.groupby(s)]
c = countstrs(s)
ma , mi  = 0, 0
c = 0
r = []
for i in range(len(s)):
    r.append(c)
    if s[i] == "<":
        c += 1
    else:
        c -= 1
r = max(r) - min(r) + 1
res = 0
for i in range(r+1):
    res += i
print(res)

Submission status: Wrong Answer

Solution code:
S = input()
A = []
A.append(0)

for i in range(len(S)):
    if S[i] == "<":
        A.append(A[i] + 1)
    else:
        A.append(0)

for i in range(len(S)):
    if S[len(S) - i - 1] == ">":
        A[len(S) - i - 1] = max(A[len(S) - i - 1], A[len(S) - i] + 1)
    else:
        continue

print(A)
print(sum(A))

Submission status: Wrong Answer

Solution code:
s = input()
ans = cnt = 0
s_ = s[0]
for s_i in s:
    if s_i == s_:
        cnt += 1
        ans += cnt
    else:
        s_ = s_i
        ans += cnt
        cnt = 0
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  import sys
  input = sys.stdin.readline

  f = "" # 前回のステップの文字 "<" or ">" 
  ans = 0 # Answer
  count = 0 # Ai
  continuous = 0 # ">" が何回連続するか
  
  for m in input():
    if m=="<":
      if f==">" and count>0:
        # 清算
        ans-=count*continuous
        count=0
      count+=1
        
    else:
      if f=="<":
        # セット
        continuous=0
      count-=1
      continuous+=1
      if count==-1:
        ans+=continuous
        count=0
        continue

    ans+=count
    f=m

  print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
  import sys
  input = sys.stdin.readline

  f = "" # 前回のステップの文字 "<" or ">" 
  ans = 0 # Answer
  count = 0 # Ai
  continuous = 0 # ">" が何回連続するか
  
  for m in str(input()):
    if m=="<":
      if f==">" and count>0:
        # 清算
        ans-=count*continuous
        count=0
      count+=1
        
    else:
      if f=="<":
        # セット
        continuous=0
      count-=1
      continuous+=1
      if count==-1:
        ans+=continuous
        count=0
        continue

    ans+=count
    f=m

  print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
  from itertools import groupby

  s = list(input())
  f = 0
  ans = 0

  for k,v in groupby(s):
    d = len(tuple(v))
    left = d if k==">" else 0
    right = d if k=="<" else 0
    ans += -1*f*(f<left) + d*(d+1)//2 -left*(f>left)  
    f = right 

  print(ans) 

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import groupby
s=list(input())
f=0
ans=0
for k,v in groupby(s):
  d=len(list(v))
  g=d+1 if k==">" else 0 
  ans+=( max(f,g)-min(f,g)+d*(d+1)//2-g )
  f=d+1 if k=="<" else 0
print(ans)

Submission status: Wrong Answer

Solution code:
s=list(input())
f=s[0]
now=0
suc=0
ans=0
for o in s:
  if f=="<" and o=="<":
    now+=1
    ans+=now
    #print(o,now,ans)
  if f=="<" and o==">":
    suc=1
    now+=1
    ans+=now
    #print(o,now,ans)
  if f==">" and o=="<":
    now-=1
    if now>=0:
      ans-=(suc-1)*now
      now=0
    else:
      ans+=suc
      now=0
    suc=0
    #print(o,now,ans)
  if f==">" and o==">":
    now-=1
    if now==-1:
      ans+=suc
      now=0
    else:
      ans+=now
    suc+=1
  print(o,suc)
  f=o

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

S = input().strip()

N = len(S) + 1

NH = [0 for i in range(N)]


#print(NH)

cnt = 0

for i in range(len(S)):
    if S[i] == ">":
        for j in range(cnt,i+1):
            NH[j] += 1
    else:
        if i < len(S)-1 and S[i+1] == "<":
            NH[i+1] +=1
        cnt = i+1

#print(NH)
t = 0

for i in NH:
    t += i
print(t)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def calc(N):
    return sum(int(x) for x in str(N))


def main():
    # sys.stdin = open("sample.txt")
    S = Scanner.string()
    ans = 0
    i = 0
    A = [0] * (len(S) + 1)
    B = [0] * (len(S) + 1)
    i = len(S) - 1
    while i >= 0:
        if S[i] == ">":
            A[i + 1] = 0
            while i > 0 and S[i] == ">":
                i -= 1
                A[i+1] = A[i+2] + 1
        i -= 1
    i = 0
    while i < len(S):
        if S[i] == "<":
            B[i] = 0
            while i < len(S) and S[i] == "<":
                i += 1
                B[i] = B[i-1] + 1
        i += 1
    ans = 0
    for i in range(len(S) + 1):
        ans += max(A[i], B[i])
    print(ans)

    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
S=list(input())

nums=[1 if S[0]=="<" else -1]
for i in range(len(S)-1):
    if S[i+1]==S[i]:
        if S[i+1]=="<":
            nums[-1]+=1
        else:
            nums[-1]-=1
    else:
        if S[i+1]=="<":
            nums.append(1)
        else:
            nums.append(-1)

ans=0
if nums[0]<0:
    are=-nums.pop(0)
    ans+=are*(are+1)//2
    if nums:
        pass
    else:
        print(ans)
        exit()
if nums[-1]>0:
    are=nums.pop(-1)
    ans+=are*(are+1)//2
    if nums:
        pass
    else:
        print(ans)
        exit()

temp=list(map(lambda x:abs(x)-1,nums))
temp=list(map(lambda x:x*(x+1)//2,temp))

print(temp)
ans+=sum(temp)
#print(ans)
for i in range(len(nums)-1):
    if nums[i]>0:
        ans+=max(nums[i],-nums[i+1])

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
S=list(input())

nums=[1 if S[0]=="<" else -1]
for i in range(len(S)-1):
    if S[i+1]==S[i]:
        if S[i+1]=="<":
            nums[-1]+=1
        else:
            nums[-1]-=1
    else:
        if S[i+1]=="<":
            nums.append(1)
        else:
            nums.append(-1)

ans=0
if nums[0]<0:
    are=nums.pop(0)
    ans+=are*(are+1)//2
    if nums:
        pass
    else:
        print(ans)
        exit()
if nums[-1]>0:
    are=nums.pop(-1)
    ans+=are*(are+1)//2
    if nums:
        pass
    else:
        print(ans)
        exit()

temp=list(map(lambda x:abs(x)-1,nums))
temp=list(map(lambda x:x*(x+1)//2,temp))

ans+=sum(temp)
#print(ans)
for i in range(len(nums)-1):
    if nums[i]>0:
        ans+=max(nums[i],-nums[i+1])

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
S=list(input())

nums=[1 if S[0]=="<" else -1]
for i in range(len(S)-1):
    if S[i+1]==S[i]:
        if S[i+1]=="<":
            nums[-1]+=1
        else:
            nums[-1]-=1
    else:
        if S[i+1]=="<":
            nums.append(1)
        else:
            nums.append(-1)

ans=0
if nums[0]<0:
    are=nums.pop(0)
    ans+=are*(are+1)//2
    if nums:
        pass
    else:
        print(ans)
        exit()
if nums[-1]>0:
    are=nums.pop(-1)
    ans+=are*(are+1)//2
    if nums:
        pass
    else:
        print(ans)
        exit()

temp=list(map(lambda x:abs(x)-1,nums))
temp=list(map(lambda x:x*(x+1)//2,temp))

ans+=sum(temp)
#print(ans)
for i in range(len(nums)-1):
    if nums[i]>0:
        ans+=max(nums[i],-nums[i+1])
print(nums)
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    S = input()
    lenS = len(S)
    sumS = 0
    cumS = [0] * (lenS + 2)
    for i in range(1, lenS + 2): cumS[i] = cumS[i-1] + i
    if S[0] == "<": l, s = 1, 0
    else: l, s = 0, 1
    for i in range(1, lenS):
        if S[i] == ">": s += 1
        else:
            if S[i-1] == "<": l += 1
            else:
                if l >= s: sumS += cumS[l] + cumS[s - 1]
                else: sumS = cumS[l-1] + cumS[s]
                l, s = 1, 0
    if l >= s:
        if s > 0: sumS += cumS[l] + cumS[s-1]
        else: sumS += cumS[l]
    else: sumS += cumS[l - 1] + cumS[s]

    print(sumS)

    return 0

if __name__ == "__main__": solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
l=[]
ans=0
cnt=1
k=0
t=[]
a=0
for i in range(len(s)):
  a+=i
  t.append(a)
for i in range(len(s)-1):
    if s[i]==s[i+1]:
      cnt+=1
    else:
      l.append([s[i],cnt])
      cnt=1
l.append([s[len(s)-1],cnt])
if len(l)==1:
  print(l[0][1])
else:
  while k<len(l)-1:
    if l[k][0]=='<' and l[k+1][0]=='>':
      ans+=t[max(l[k][1],l[k+1][1])]+t[min(l[k][1],l[k+1][1])-1]
      l.remove(l[k])
      l.remove(l[k])
      k=0
    else:
      k+=1
  if len(l)==2:
    if l[0][0]=='<' and l[1][0]=='>':
      ans+=t[max(l[0][1],l[1][1])]+t[min(l[0][1],l[1][1])-1]
    else:
      ans+=t[l[0][1]]+t[l[1][1]]
  elif len(l)==1:
    ans+=t[l[0][1]]
  print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
A = [-1] * (l+1)

inf = float("inf")
tmp = ""
for i in range(l):
	if i == 0:
		if s[i] == ">":
			A[i] = inf
		else:
			A[i] = 0

		tmp = s[i]

	if i == l-1:
		if s[i] == ">":
			A[-1] = 0
		else:
			A[i] = inf

	if s[i] == tmp:
		continue
	elif s[i] == ">" and tmp == "<":
		A[i] = inf
		tmp = ">"
	elif s[i] == "<" and tmp == ">":
		A[i] = 0
		tmp = "<"

ans = 0
flg = 0
cnt = 0
pool = 0
for i in range(l+1):
	if A[i] == inf:
		flg = 1
		pool = cnt
		cnt = 0
		continue
	if A[i] == 0:
		if flg == 1:
			ans += max(pool, cnt) + 1
		flg = 0
		cnt = 0
		pool = 0
		continue
	
	cnt += 1
	ans += cnt

if flg == 1:
	ans += max(pool, cnt) + 1


print(ans)

Submission status: Wrong Answer

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

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