<>=~$"; @s=<>; for(1..$'){ $a=7; /./,$a&=$&=~y/GCP/356/rfor@s; $a=~y/1-7/GPPCGC/||last; $z.=$a; @s=grep{s/.//;$&eq$a}@s; } print@s?-1:$z;