{"trustable":false,"sections":[{"title":"","value":{"format":"PLAIN","content":"Card Hand Sorting\nWhen dealt cards in the card game Plump it is a good\nidea to start by sorting the cards in hand by suit and\nrank. The different suits should be grouped and the\nranks should be sorted within each suit. But the order\nof the suits does not matter and within each suit, the\ncards may be sorted in either ascending or descending\norder on rank. It is allowed for some suits to be sorted\nin ascending order and others in descending order.\nSorting is done by moving one card at a time from\nits current position to a new position in the hand, at\nthe start, end, or in between two adjacent cards. What\nis the smallest number of moves required to sort a\ngiven hand of cards?\n"}},{"title":"Input","value":{"format":"PLAIN","content":"The first line of input contains an integer n (1 ≤ n ≤ 52), the number of cards in the hand.\nThe second line contains n pairwise distinct space-separated cards, each represented by two\ncharacters. The first character of a card represents the rank and is either a digit from 2 to 9 or\none of the letters T, J, Q, K, and A representing Ten, Jack, Queen, King and Ace, respectively,\ngiven here in increasing order. The second character of a card is from the set {s, h, d, c}\nrepresenting the suits spades ♠, hearts ♥, diamonds ♦, and clubs ♣."}},{"title":"Output","value":{"format":"PLAIN","content":"Output the minimum number of card moves required to sort the hand as described above"}},{"title":"Sample Input 1","value":{"format":"PLAIN","content":"4\n2h Th 8c Qh"}},{"title":"Sample Output 1","value":{"format":"PLAIN","content":"1\n"}},{"title":"Sample Input 2","value":{"format":"PLAIN","content":"7\n9d As 2s Qd 2c Jd 8h"}},{"title":"Sample Output 2","value":{"format":"PLAIN","content":"2"}},{"title":"Sample Input 2","value":{"format":"PLAIN","content":"4\n2h 3h 9c 8c"}},{"title":"Sample Output 3","value":{"format":"PLAIN","content":"0"}}]}