Card Draw
InterviewTime limit1sMemory limit1024 MB
For each day's four cards, check whether they form a consecutive triple, a triple of identical cards, or two identical pairs.
- Level
Easy3 of 10
- Topics
- Implementation, Brute force
- Solved
- No attempts yet
Problem
Sangpil studies algorithms every day by solving problems steadily. After solving problems for a long time, he felt tired and needed a day off. So he decided to pick his rest days by drawing cards.
The deck has 27 cards. Each card shows one nonzero digit and one lowercase letter, m, p, or s (1m, 2m, , 9m, 1p, 2p, , 9p, 1s, 2s, , 9s). He draws one card, memorizes it, and returns it to the deck. He repeats this 4 times. If the 4 drawn cards satisfy at least one of the rules below, he rests that day.
- Three cards have the same letter, and their digits are consecutive. The three consecutive digits must be different from each other.
- Three cards have the same letter and the same digit.
- When the cards are split into two pairs, the cards in each pair have the same digit and letter.
Sangpil drew the cards for days 1 to T in advance, but he could not easily tell which days were rest days. He thought he could solve it with the algorithms he had studied so far. Today he decided to rest, so he asked you to figure it out.
Input
The first line contains an integer T ().
From line 2 to line , line contains the 4 cards drawn for day , separated by spaces ().
Output
Print T lines. On line , print :) if day is a rest day, and :( otherwise.