#P11941. Unique Decipherability of Substitution Rules
Unique Decipherability of Substitution Rules
Unique Decipherability of Substitution Rules
Given 26 strings sa, sb, ..., sz each consisting only of lowercase English letters. For any string t (also containing only lowercase letters), we define its substitution t' by replacing every letter x in t with the corresponding string sx.
For example, if sa = \(\mathtt{ana}\) and sb = \(\mathtt{ban}\), then for t = \(\mathtt{baba}\) we have:
[ \mathtt{baba} \implies \mathtt{ban},\mathtt{ana},\mathtt{ban},\mathtt{ana} ]
The substitution rule is said to be bad (i.e. not uniquely decodable) if there exist two distinct strings \(p\) and \(q\) such that \(p \neq q\) but \(p' = q'\). Otherwise, the rule is called good.
Your task is to determine whether the given substitution rule is good or bad.
Note: All formulas are in \( \LaTeX \) format.
inputFormat
The input consists of 26 lines. The i-th line contains a non-empty string \(s\) (only lowercase letters), corresponding to the mapping for the letter \(\mathtt{chr}(i+96)\).
outputFormat
Output a single line containing either good
if the substitution rule is uniquely decodable, or bad
otherwise.
sample
ana
ban
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
good