import random as U
E= enumerate
def T( b, x, y) :
D= { }
for i in b:D[ i[ x] ] = D.get ( i[ x] , [ ] ) +[ i[ y] ]
return D
def B( b) :
P= [ ( x, y) for x, r in E( b) for y, k in E( r) if ' ' != k] ; p= [ *P]
while p:
q= [ ( r:= p.pop ( 0 ) , [ r] ) ]
while q:
( x, y) , r= q.pop ( 0 )
for j, k in ( x+1 , y) , ( x-1 , y) , ( x, y-1 ) , ( x, y+1 ) :
V= ( j, k)
if ( len ( b) > j> -1 < k< len ( b[ 0 ] ) ) *( len ( r) < 2or V!= r[ -2 ] ) :
if j== x and '-' == b[ j] [ k] or k== y and '|' == b[ j] [ k] or b[ x] [ y] != b[ j] [ k] :
if V in r:yield r; p= [ *( { *p} -{ *r} ) ] ; q= [ ]
elif V in P:q+= ( V, [ *r, V] ) ,
def f( b) :
K= [ ]
for i in B( b) :Q, W= T( i, 0 , 1 ) , T( i, 1 , 0 ) ; K+= [ ( x, y) for x, r in E( b) for y, k in E( r) if ' ' == k and x in Q and min ( Q[ x] ) <= y<= max ( Q[ x] ) and y in W and min ( W[ y] ) <= x<= max ( W[ y] ) ]
x, y= U.choice ( K) ; b[ x] [ y] = '*'
return b
s= """
---
| |
---
"""
s1= """
----
| |- ---
| | | |
----- ---
"""
s2= """
---
| |
-- --
| |
-----
"""
s3= """
-------
| --- |
| | | |
| --- |
-------
"""
def to_art( t) :
return [ [ *i] for i in filter ( None , t.split ( '\n ' ) ) ]
for i in f( to_art( s) ) :
print ( '' .join ( i) )
for i in f( to_art( s1) ) :
print ( '' .join ( i) )
for i in f( to_art( s2) ) :
print ( '' .join ( i) )
for i in f( to_art( s3) ) :
print ( '' .join ( i) )
aW1wb3J0IHJhbmRvbSBhcyBVCkU9ZW51bWVyYXRlCmRlZiBUKGIseCx5KToKIEQ9e30KIGZvciBpIGluIGI6RFtpW3hdXT1ELmdldChpW3hdLFtdKStbaVt5XV0KIHJldHVybiBECmRlZiBCKGIpOgogUD1bKHgseSlmb3IgeCxyIGluI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