X=lambda x:x=="X" A=lambda x:"XO"[X(x)] Y=lambda y:(A(y[0])+y+A(y[-1]),"".join(A(c)for c in y)) y=raw_input() l=len(y) y,_=Y(y) _,x=Y(y) z=0 while 1: s=t="" for i in range(1,l+2):a=x[i-1];b=x[i];c=y[i-1];d=y[i];s+=" ++-+|++++|+-++ "[X(a)*8+X(b)*4+X(c)*2+X(d)]+" -"[b!=d];t+=" |"[c!=d]+y[i] print s[:-1] if z<l:print t[:-1] x=y;z+=1 if z==l:_,y=Y(y) else:y=raw_input();y,_=Y(y)
Note that non-ascii characters in the above source code will be escaped (such as \x9f).