HJS
InterviewTime limit1sMemory limit1024 MB
Given three H/J/S patterns of equal length, check whether distinct digits 1 to 9 can be assigned to H, J, and S so that the numbers satisfy p < q < r.
- Level
Medium4 of 10
- Topics
- Brute force, Implementation, String
- Solved
- No attempts yet
Problem
In 2123, a different way to express numbers exists, called the Hongjin number.
A Hongjin number is a string made of three characters, H, J, and S. Assign the digits 1 through 9 to H, J, and S, each to a different digit, and the string represents a number. For example, the Hongjin number HJSHJH can represent 358353 and 914919, but it cannot represent 131131 or 555555.
Given three Hongjin numbers P, Q, and R of the same length, check whether there exist assignments of H, J, and S such that the numbers p, q, and r represented by P, Q, and R satisfy . The digits assigned to H, J, and S are shared by P, Q, and R.
Input
The first line contains N, the length of P, Q, and R. The next three lines contain the strings P, Q, and R in that order.
Output
If there exist assignments of H, J, and S that satisfy the condition, print HJS! HJS! HJS! on the first line. Otherwise, print Hmm... on the first line.