import sys n=[x for x in sys.stdin] w=n[0].rstrip() a=" "*len(w) def h(l):return l.replace(w,a).replace(w[::-1],a) for s in zip(*[h("".join(r))for r in zip(*[h(l)for l in n[1:]])]): print"".join(s),
Note that non-ascii characters in the above source code will be escaped (such as \x9f).