You are a guitar player, and you have a lot of sheet music that you want to play. Unfortunately, you are not a very good singer, so you can only sing music that is played in a certain key. Therefore, you want to transpose your sheet music, so you can play it in a key that you can sing in.
In this problem, we will consider 24 different chords. The following 12 are the base ones:
The other 12 chords are the same ones, but then with an 'm' concatenated to the end. They are called minor. So Am, A#m, Bm, etc.
As you can see, certain chords have a '#', called "sharp". Every "sharp"-chord, can be replaced by its corresponding "flat"-chord (written by adding a 'b' to the end of the next higher chord). So for example C# and Db are the same chords. Let's write the chords again, this time using the "flat"-notation:
As you can see the chords wrap around, so after Ab comes A, Bb, etc. The minor chords in "flat"-notation are Am, Bbm, Bm, etc.
Sheet music consists of a row of chords optionally separated by vertical bars. A certain piece of sheet music may look like this:
Here you see 4 groups of 3 chords, separated by vertical bars. The key of a song is always the first chord (so "G" in this case). The key of the song determines if we use the "sharp"-notation, or the "flat"-notation. Keys where you use the "flat"-notation are:
With all other keys, you should use the "sharp"-notation.
The difference between 2 chords is defined as the number of positions between the first and the second one. For example, the difference between B and E is 5, while the difference between Db and A# is -3 (or 9, because the chords wrap around).
You will be given a String sheetMusic. Concatenate all elements of sheetMusic to get the whole music piece. You will also be given a String newKey, the key to which you have to transpose the sheet music. To transpose the music, first take the difference between the key of the original song and newKey. Let's call this value diff. Then, replace each chord in the original sheet music with the chord diff positions after it. If newKey is one of the chords that use "flat"-notation, then all tranposed chords should use the "flat"-notation. Otherwise, all chords in the output should use the "sharp"-notation. All minor chords must remain minor and non-minor chords must remain non-minor. The first chord of the original song and newKey will either both be minor or both be non-minor. The first chord of the original song and newKey will be either both in minor or both not in minor.
Return a String containing the sheetMusic transposed to newKey. The output should use the exact same notation as the input (same number of bars between chords and 1 space between 2 adjacent chords or bars). Please note that sheetMusic may not necessarily obey the rules for "flat" and "sharp" notations, but your return value must use the proper notation. See examples for clarification.
|-||sheetMusic will contain between 1 and 50 elements, inclusive.|
|-||Each element of sheetMusic will contain between 1 and 50 characters, inclusive.|
|-||The valid chords are the chords described in the statement, and each of those in minor (so Am, A#m, Bbm, Bm, etc.).|
|-||newKey will be a valid chord.|
|-||The concatenation of sheetMusic will be a space-separated list of valid chords and vertical bars ('|') , and there will be exactly one space (' ') between 2 elements (quotes for clarity only).|
|-||The concatenation of sheetMusic will not contain leading or trailing spaces or vertical bars.|
|-||sheetMusic will contain at least 1 chord.|
|-||The first chord of the original song and newKey will either both be minor or both be non-minor.|