<s> from __future__ import print_function , unicode_literals <EOL> import sys <EOL> import functools <EOL> def debug ( fn ) : <EOL> def wrapper ( * args , ** kwargs ) : <EOL> print ( fn . __name__ , '<STR_LIT>' ) <EOL> print ( sorted ( args ) , tuple ( sorted ( kwargs . items ( ) ) ) ) <EOL> res = fn ( * args , ** kwargs ) <EOL> print ( res ) <EOL> return res <EOL> return wrapper <EOL> class cache ( object ) : <EOL> def __init__ ( self , fn ) : <EOL> self . fn = fn <EOL> self . _cache = { } <EOL> functools . update_wrapper ( self , fn ) <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> key = str ( args ) + str ( kwargs ) <EOL> if key in self . _cache : <EOL> ret = self . _cache [ key ] <EOL> else : <EOL> ret = self . _cache [ key ] = self . fn ( * args , ** kwargs ) <EOL> return ret <EOL> def clear_cache ( self ) : <EOL> self . _cache = { } <EOL> def stdout_encode ( u , default = '<STR_LIT>' ) : <EOL> encoding = sys . stdout . encoding or default <EOL> if sys . version_info > ( <NUM_LIT:3> , <NUM_LIT:0> ) : <EOL> return u . encode ( encoding ) . decode ( encoding ) <EOL> return u . encode ( encoding ) </s>
