Necklace
A jeweler has been tasked with creating an exclusive necklace for the Queen. The necklace must be composed of silver, gold, and bronze beads, arranged in a specific sequence. Each type of bead—gold, silver, and bronze—is identical and can be used interchangeably within its type. The jeweler has already prepared the beads and strung them on a long rod. He is now ready to assemble the necklace by removing beads one at a time from either end of the rod and threading them onto a string, eventually connecting the two ends of the string seamlessly. This connection can occur between any two beads.
However, the beads on the rod may not be in the order required for the necklace. As a result, during the assembly process, the jeweler may need to set some beads aside temporarily. The goal is to minimize the maximum number of beads set aside at any point during the assembly.
Input
The first line of input contains a single integer L (1 ≤ L ≤ 1000)—the total number of beads in the necklace. The second line contains a string of L characters (each either G, S, or B, representing gold, silver, or bronze beads) that describes the desired final arrangement of the necklace (as if it were cut at any point and laid out straight). The third line contains a string of L characters that represent the current order of beads on the rod. The jeweler can only remove beads from the left end of the rod. It is guaranteed that the necklace can be assembled from the given bead arrangement.
Output
The output should be a single line indicating the minimum possible maximum number of beads the jeweler will need to set aside during the assembly of the necklace.