SP16778 CSHOWB - Sir and the Guitar
Description
After teaching guitar to Jimmy Page (Led Zeppelin Band Guitarist), Sir Jadeja has decided to do something new. Sir Jadeja took out his guitar and started playing a melody he composed when he was 2 months old.
The guitar as usual has 6 strings denoted by numbers through 1 to 6. Each string is divided into P frets denoted by numbers 1 to P. A melody is a sequence of tones, where each tone is produced by picking a string pressed on a specific fret (for example: 4th string pressed on 8th fret). If a string is pressed on several frets, the produced tone will be the one corresponding to the highest of those frets. For instance, if the 3rd string is already pressed on the 5th fret, and the tone which corresponds to the 7th fret is to be produced, the string can be pressed on the 7th fret and picked without releasing the 5th fret. If a tone that corresponds to the 2nd fret on the same string is to be produced next, it is necessary to release both 5th and 7th frets and only then press 2nd.
Sir Jadeja feeling tired wants to play the melody with minimum number of finger movements. Note that press or release a single fret counts as one finger move. String picking is not a finger move, but rather a guitar pick move and should not be counted. Remember that picking a string with not affect frets being pressed on other string. You can assume that Sir Jadeja has enough fingers to press all the frets on all string at the same time (yes, that many).
Input Format
N/A
Output Format
N/A