Problem:

  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Line Gimmick

You are in front of a linear gimmick of a game. It consists of $N$ panels in a row, and each of them displays a right or a left arrow.

You can step in this gimmick from any panel. Once you get on a panel, you are forced to move following the direction of the arrow shown on the panel and the panel will be removed immediately. You keep moving in the same direction until you get on another panel, and if you reach a panel, you turn in (or keep) the direction of the arrow on the panel. The panels you passed are also removed. You repeat this procedure, and when there is no panel in your current direction, you get out of the gimmick.

For example, when the gimmick is the following image and you first get on the 2nd panel from the left, your moves are as follows.

 Move right and remove the 2nd panel.

 Move left and remove the 3rd panel.

 Move right and remove the 1st panel.

 Move right and remove the 4th panel.

 Move left and remove the 5th panel.

 Get out of the gimmick.

You are given a gimmick with $N$ panels. Compute the maximum number of removed panels after you get out of the gimmick.

Input

The input consists of two lines. The first line contains an integer $N$ ($1 \leq N \leq 100,000$) which represents the number of the panels in the gimmick. The second line contains a character string $S$ of length $N$, which consists of '>' or '<'. The $i$-th character of $S$ corresponds to the direction of the arrow on the $i$-th panel from the left. '<' and '>' denote left and right directions respectively.

Output

Output the maximum number of removed panels after you get out of the gimmick.

Sample Input 1

7
>><>>>

Output for the Sample Input 4

5



Sample input:
7
>>


Sample output:
7

Submission status: Wrong Answer

Solution code:
input()
s=input()
print(len(s)-min(s.find('>'),s.rfind('<')-1))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
print(n-min(s.find('>'),n-s.rfind('<')-1))

Submission status: Accepted

Solution code:
#!/usr/bin/python

import re

def main():
    n = int(raw_input())
    s = raw_input()

    print n-min(map(lambda x: x.end()-x.start(), [re.search(r'^<*', s), re.search(r'>*$', s)]))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    n = I()
    s = S()
    a = [2] + [None if s[i] == '>' else 1 for i in range(n)] + [2]

    def f(i):
        if i < 0 or i > n+1:
            return (0, None)
        c = 0
        nl = i-1
        nr = i+1
        ni = i
        while a[ni] != 2:
            if a[ni] is None:
                ni = nr
                nr += 1
            else:
                ni = nl
                nl -= 1
            c += 1
        return (c, ni == 0)

    ma = n+1
    mi = 0
    mm = (ma+mi) // 2
    r = 0
    while ma > mi:
        mm = (ma+mi) // 2
        c,ff = f(mm)
        if r < c:
            r = c
        if ff:
            mi = mm + 1
        else:
            ma = mm
    for i in range(mm-1,mm+2):
        c,ff = f(i)
        if r < c:
            c = r

    return r



print(main())

Submission status: Accepted

Solution code:
import re
n = int(input())
s = input()
res = 10**10
res = min(res, len(re.search(r'^<*', s).group()))
res = min(res, len(re.search(r'>*$', s).group()))
print(n-res)