Sour Face
Time limit1sMemory limit1024 MB
Count the coin-flip sequences that trim characters from both ends until the remaining string is k '>' characters followed by k '<' characters, modulo 10^9 + 7.
- Level
Medium5 of 10
- Topics
- String, Combinatorics, Brute force
- Solved
- No attempts yet
Problem
Suminee sees the shape >< as a sour face. Specifically, a string that Suminee feels is a sour face is as follows.
- > appears times and < appears times in a row. Here is a positive integer of at least .
By this definition, >><< and >>><<< are both sour faces. However, ><<< is not, because the counts of > and < differ, and <> is not, because the bracket order is wrong.
Suminee wants to remove every character except those that form a sour face from a given string consisting only of > and <. Removing characters one by one is dull, so Seungjun proposed a game in which Suminee makes a sour face.
- Flip a coin. If it lands heads, remove the first character of the string. If it lands tails, remove the last character.
Suminee may end the coin flipping at any time. If the string is a sour face when Suminee stops, Suminee wins.
Given a string of length consisting only of > and <, find the number of ways Suminee can win the game, modulo .
Input
The first line contains the size of the string ().
The second line contains the string of length consisting only of > and <.
Output
Print the number of coin-flip sequences that win the game, modulo .