{"problem":{"name":"038. Unshuffle the Cards","description":{"content":"You are given a shuffled deck of cards, and your task is to return them to sorted order. Sorted order involves the cards being sorted first by their numbers, and if their numbers are equal, being sort","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10269038"},"statements":[{"statement_type":"Markdown","content":"You are given a shuffled deck of cards, and your task is to return them to sorted order. Sorted order involves the cards being sorted first by their numbers, and if their numbers are equal, being sorted by their suit. In the sorting, clubs comes before diamonds, which comes before hearts, which comes before spades. The deck may not be complete, i.e. some cards may be missing. Assume that aces are always the highest possible card for this problem.\n\nThe first line of input contains a single integer $n$ (1 < $n$ <= 52): the number of cards in the deck. The next line contains $n$ space-separated blocks, each representing a card. Each block will contain one character representing the value of the card, and a second character representing the suit of the card. *No \"10\" cards will be given in the input.*\n\nOutput $n$ space-separated blocks: the deck, after sorting is complete.\n\n## Input\n\nThe first line of input contains a single integer $n$ (1 < $n$ <= 52): the number of cards in the deck. The next line contains $n$ space-separated blocks, each representing a card. Each block will contain one character representing the value of the card, and a second character representing the suit of the card. *No \"10\" cards will be given in the input.*\n\n## Output\n\nOutput $n$ space-separated blocks: the deck, after sorting is complete.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ n \\in \\mathbb{Z} $, $ 1 < n \\leq 52 $, be the number of cards.  \nLet $ C = \\{c_1, c_2, \\dots, c_n\\} $ be the set of cards, where each card $ c_i = (v_i, s_i) $:  \n- $ v_i \\in \\{2,3,4,5,6,7,8,9,J,Q,K,A\\} $ is the value (as a character),  \n- $ s_i \\in \\{\\text{C}, \\text{D}, \\text{H}, \\text{S}\\} $ is the suit (Club, Diamond, Heart, Spade).  \n\nDefine a total order $ \\prec $ on cards:  \n- First, order by value: $ v \\prec v' $ iff $ \\text{rank}(v) < \\text{rank}(v') $, where:  \n  $$\n  \\text{rank}(v) = \n  \\begin{cases}\n  2 & \\text{if } v = '2' \\\\\n  3 & \\text{if } v = '3' \\\\\n  \\vdots & \\\\\n  9 & \\text{if } v = '9' \\\\\n  10 & \\text{if } v = 'J' \\\\\n  11 & \\text{if } v = 'Q' \\\\\n  12 & \\text{if } v = 'K' \\\\\n  13 & \\text{if } v = 'A' \\\\\n  \\end{cases}\n  $$\n- If values are equal, order by suit: $ \\text{C} \\prec \\text{D} \\prec \\text{H} \\prec \\text{S} $, with ranks $ 0,1,2,3 $ respectively.\n\n**Objective**  \nOutput the sequence $ C' = (c'_1, c'_2, \\dots, c'_n) $, a permutation of $ C $, such that:  \n$$\nc'_1 \\prec c'_2 \\prec \\cdots \\prec c'_n\n$$","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10269038","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}