프로그램 명: hidden-code
제한시간: 1 초

It’s time to put your hacking skills to the test! You’ve been called upon to help crack enemy codes in the current war on... something or another. Anyway, the point is that you have discovered the encryption technique used by the enemy; it is quite simple, and proceeds as follows. Note that all strings contain only uppercase letters of the alphabet.

1. We are given a key K and a plaintext P which is encrypted character-by-character to produce a ciphertext C of the same length.

2. If |K| is the length of the key K, then the first |K| characters of C are obtained by adding the first |K| characters of P to the characters of K, where adding two letters means interpreting them as numbers (A = 0, B = 1, and so on) and taking the sum modulo 26. That is, Ci = (Pi +Ki) mod 26 for i = 1, . . . ,|K|. If |K| > |P|, then the extra characters in K are ignored.

3. The remaining characters of P, i.e. Pi for i > |K|, are encrypted using the previous ciphertext characters by Ci = (Pi + Ci-|K|) mod 26 for i = |K| + 1, . . . ,|P|.

As an example, consider the encryption of the string “STANFORD” using the key “ACM”:

  STA NFORD
+ ACM SVMFA
----------
  SVM FAAWD

Knowing this, you are well on your way to being able to read the enemy’s communications. Luckily, you also have several pairs of plaintexts and ciphertexts which your team recovered, all of which are known to be encrypted with the same key. Help ?nd the key that the enemy is using.

입력

출력

Print a single line that contains the shortest possible key or “Impossible” (quotes added for clarity) if no possible key could have produced all of the encryptions.

입출력 예

입력

1
A B

출력

B

입력

3
STANFORD SVMFAAWD
AVOWIENR AXAWFEJW
VAMRI VCYMK

출력

ACM

입력

3
ABCDEFGHIJKLMNOPQRSTUVWXYZ AAAAAAAAAAAAAAAAAAAAAAAAAA
Y Y
Z Z

출력

AZYXWVUTSRQPONMLKJIHGFEDCB

입력

2
A B
B A

출력

Impossible
출처:standford/2011/

[질/답] [제출 현황] [푼 후(0)]
[ 채 점 ] [홈으로]  [뒤 로]