main=interact$ \c->unlines$w$g`map`lines c g x='|':h x++"|" h(a:b:c)=a:(if a==b then ' ' else '|'):h(b:c) h x=x v(a:b:c)=a:k(zipWith f a b):v(b:c) where f a b|or[a=='|',b=='|']='|' f a b|a/=b='-' f a b=' ' k('-':'|':s)="-+"++k s k('|':'-':s)='+':k('-':s) k('-':' ':s)="--"++k s k(' ':'-':s)='-':k('-':s) k(x:s)=x:k s k x=x v x=x w x=[map t(head x)]++v x++[map t(last x)] t '|'='+' t x='-'