trik
Professor Djuric enjoys performing card tricks. His favorite trick goes like this: the professor puts N cards on the table so that they are arranged facedown in an array (so no one can see which card is it). After that, he asks someone from the audience to point to one of the cards. To the amazement of the audience, the professor guesses which card it is and proves it by flipping the card.
Just a few people know that the professor performs this trick by using a miniature supercomputer located in his golden tooth. Before the start of the performance, he loads data about the deck of cards into the computer (the deck may contain every card an arbitrary number of times). After that, he arranges the cards on the table in the following way. First, he puts down all of the hearts, then spades, then diamonds, and finally clubs. Cards from each suit are solved from the smallest to largest (2 3 4 5 6 7 8 9 10 J K Q A). When an observer points to the card, the professor quickly counts which card from the left is it, and then clenches his jaw a certain number of times to relay this information to the computer. He then quickly receives the information telling him which card has been chosen.
Professor Djuric amused his friends many times with this trick. But, alas! Just before the world tour, the computer software broke down. Your task is to write a new program that will help the professor perform his favorite trick.
8 5
L6 K10 SQ KA D6 S2 SQ KK Output:
K10Explanation: Professor Djuric sorted the cards this way: S2 SQ SQ L6 K10 KK KA D6. In this arrangement, the fifth card from the left is K10.
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.