From 2011 facebook is organizing a Facebook hacker cup every year around feb, visit Facebook hacker cup homepage for more details
This question is the second question(Carried 35 marks out of 100) for the Round 1 of 2013 hacker cup. only top 500 contestants will be moved to Round 2.
Problem Statement
You are designing a new encryption system that works in the following way:
For server-client communication you need a key k, composed of m sections, each of length l, and the key consists only of lowercase characters in the set {a, b, c, d, e, f}. The server has a key k1 and the client has a key k2 where:
- k1 = f(k). f is a function that receives a key and replace some random letters by ? indicating that those characters can be any lowercase letter of the set described before.
- k2 = f(g(k)). g is a function that takes a key and produces a random permutation of its m sections. And f is the function defined above.
For example: let m = 3, l = 2
- f(‘abacbc’) = ‘?ba??c’
- g(‘abacbc’) = ‘acbcab’ (each section was moved one place to the left).
Your task is given k1 and k2, find key k. If there are several solutions, print the lexicographically smallest key. And if there is no solution at all, print “IMPOSSIBLE” (without the quotes).