<s> """<STR_LIT>""" <EOL> from collections import deque <EOL> __author__ = '<STR_LIT>' <EOL> class Solution ( object ) : <EOL> def __init__ ( self ) : <EOL> self . lst = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . middle = [ "<STR_LIT:0>" , "<STR_LIT:1>" , "<STR_LIT>" ] <EOL> def findStrobogrammatic ( self , n ) : <EOL> ret = [ ] <EOL> self . build ( n , deque ( ) , ret ) <EOL> return ret <EOL> def build ( self , n , cur , ret ) : <EOL> """<STR_LIT>""" <EOL> if n % <NUM_LIT:2> == <NUM_LIT:1> and len ( cur ) == <NUM_LIT:0> : <EOL> for elt in self . middle : <EOL> cur . append ( elt ) <EOL> self . build ( n , cur , ret ) <EOL> cur . pop ( ) <EOL> else : <EOL> if len ( cur ) == n : <EOL> ret . append ( "<STR_LIT>" . join ( cur ) ) <EOL> return <EOL> for elt in self . lst : <EOL> if not ( elt == "<STR_LIT>" and len ( cur ) == n - <NUM_LIT:2> ) : <EOL> cur . appendleft ( elt [ <NUM_LIT:0> ] ) <EOL> cur . append ( elt [ <NUM_LIT:1> ] ) <EOL> self . build ( n , cur , ret ) <EOL> cur . pop ( ) <EOL> cur . popleft ( ) <EOL> class SolutionArray ( object ) : <EOL> def __init__ ( self ) : <EOL> self . map1 = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> def findStrobogrammatic ( self , n ) : <EOL> """<STR_LIT>""" <EOL> ret = [ ] <EOL> self . build ( n , [ ] , ret ) <EOL> return ret <EOL> def build ( self , n , cur , ret ) : <EOL> """<STR_LIT>""" <EOL> if n % <NUM_LIT:2> == <NUM_LIT:1> and len ( cur ) == <NUM_LIT:0> : <EOL> for i in [ "<STR_LIT:0>" , "<STR_LIT:1>" , "<STR_LIT>" ] : <EOL> cur . append ( i ) <EOL> self . build ( n , cur , ret ) <EOL> cur . pop ( ) <EOL> return <EOL> if len ( cur ) / <NUM_LIT:2> == n / <NUM_LIT:2> : <EOL> ret . append ( "<STR_LIT>" . join ( cur ) ) <EOL> return <EOL> for elt in self . map1 : <EOL> if elt != "<STR_LIT>" or len ( cur ) != n - <NUM_LIT:2> : <EOL> cur . insert ( <NUM_LIT:0> , elt [ <NUM_LIT:0> ] ) <EOL> cur . append ( elt [ <NUM_LIT:1> ] ) <EOL> self . build ( n , cur , ret ) <EOL> cur . pop ( ) <EOL> cur . pop ( <NUM_LIT:0> ) <EOL> class SolutionOutputLimitExceeded ( object ) : <EOL> def __init__ ( self ) : <EOL> self . map = { <EOL> "<STR_LIT:1>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:0>" : "<STR_LIT:0>" <EOL> } <EOL> self . middle = [ "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT:0>" ] <EOL> def findStrobogrammatic ( self , n ) : <EOL> """<STR_LIT>""" <EOL> ret = [ ] <EOL> self . build ( <NUM_LIT:0> , n , [ ] , ret ) <EOL> return ret <EOL> def build ( self , idx , n , cur , ret ) : <EOL> if idx == n / <NUM_LIT:2> : <EOL> if n % <NUM_LIT:2> != <NUM_LIT:0> : <EOL> for m in self . middle : <EOL> if m != "<STR_LIT:0>" or idx != <NUM_LIT:0> : <EOL> temp = list ( cur ) <EOL> temp . append ( m ) <EOL> for i in xrange ( idx - <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> temp . append ( self . map [ temp [ i ] ] ) <EOL> ret . append ( "<STR_LIT>" . join ( temp ) ) <EOL> else : <EOL> temp = list ( cur ) <EOL> for i in xrange ( idx - <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> temp . append ( self . map [ temp [ i ] ] ) <EOL> ret . append ( "<STR_LIT>" . join ( temp ) ) <EOL> return <EOL> for k in self . map . keys ( ) : <EOL> if k != "<STR_LIT:0>" or idx != <NUM_LIT:0> : <EOL> cur . append ( k ) <EOL> self . build ( idx + <NUM_LIT:1> , n , cur , ret ) <EOL> cur . pop ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> assert Solution ( ) . findStrobogrammatic ( <NUM_LIT:3> ) == [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] </s>
