AYJCC24 P5 - Strangely Sentient Arrows


Submit solution


Points: 10 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
Assembly, Awk, Brain****, C, C++, Java, Lua, Pascal, Perl, PyPy 2, PyPy 3, Python, Sed

Franklin has stumbled across \(N\) arrows in a line, which we will denote \(A\). Each arrow is either pointed left or right.

The arrows then decide to start reordering themselves. Each minute, if two arrows are pointing directly at each other and are adjacent, they will swap positions. Otherwise, they will not move.

Formally, each minute, if there exists an index \(i\) such that \(A_i\) is > and \(A_{i+1}\) is <, \(A_i\) will become < and \(A_{i+1}\) will become >.

Help Franklin determine how long it will take for the arrows to sort themselves (every left pointing arrow is to the left of every right pointing arrow).

Constraints

Each element in \(A\) will be < or >.

Subtask 1 [30%]

\(1 \le N \le 10^2\)

Subtask 2 [70%]

\(1 \le N \le 10^6\)

Input Specification

The first line contains \(N\).

The second line contains \(N\) characters, all either < or >.

Output Specification

Output one integer, the time in minutes it will take for the arrows to sort themselves.

Sample Input 1

2
<>

Sample Output 1

0

Sample Input 2

5
>><><

Sample Output 2

3

Sample Input 3

6
>>><<<

Sample Output 3

5

Comments

There are no comments at the moment.