Line Gimmick
Time limit5sMemory limit512 MB
Given a row of panels with arrows, pick a starting panel and count how many panels can disappear if the walk is chosen to maximize that count.
- Level
Medium6 of 10
- Topics
- Greedy, Implementation, Simulation, Math
- Solved
- No attempts yet
Problem
You are standing in front of the line gimmick of a game. The gimmick is a row of panels, and each panel displays either a right arrow or a left arrow.
You can step onto the gimmick from any panel. Once you step onto a panel, you are forced to move in the direction of the arrow on that panel, and the panel disappears at once. You keep moving in the same direction until you reach another panel. When you reach a panel, you turn to the direction of its arrow, and you keep going straight if that arrow points the way you are already moving. Every panel you pass disappears as well. You repeat this, and when no panel is left in the direction you are moving, you leave the gimmick.
For example, take a gimmick whose arrows read >, >, <, >, < from the left. If you first step onto the 2nd panel from the left, you move like this.
- Move right, and the 2nd panel disappears.
- Move left, and the 3rd panel disappears.
- Move right, and the 1st panel disappears.
- Move right, and the 4th panel disappears.
- Move left, and the 5th panel disappears.
- Leave the gimmick.

You are given a gimmick with panels. Compute the largest number of panels that can disappear before you leave the gimmick.
Input
The first line contains the number of panels ().
The second line contains a string of length made up of the characters > and < only. The -th character of is the arrow direction of the -th panel from the left, where < means left and > means right.
Output
Print the largest number of panels that can disappear before you leave the gimmick.