<s> import sys , re , os <EOL> from collections import defaultdict <EOL> def field_controle ( input ) : <EOL> bOUT = open ( input ) <EOL> sampleline = bOUT . readline ( ) <EOL> bOUT . close ( ) <EOL> samplefields = sampleline . split ( ) <EOL> if ( samplefields [ <NUM_LIT:1> ] != "<STR_LIT:->" and samplefields [ <NUM_LIT:1> ] != "<STR_LIT:+>" ) : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> def histogrammer ( input , output , Nfactor , minrange , maxrange ) : <EOL> IN = open ( input ) <EOL> OUT = open ( output , "<STR_LIT:w>" ) <EOL> Nfactor = float ( Nfactor ) <EOL> print >> OUT , field_controle ( input ) <EOL> hist_dict = defaultdict ( lambda : defaultdict ( lambda : defaultdict ( int ) ) ) <EOL> for line in IN : <EOL> fields = line . split ( ) <EOL> if fields [ <NUM_LIT:1> ] == "<STR_LIT:+>" : <EOL> polarity = "<STR_LIT>" <EOL> else : <EOL> polarity = "<STR_LIT>" <EOL> item = fields [ <NUM_LIT:2> ] <EOL> size = len ( fields [ <NUM_LIT:4> ] ) <EOL> if polarity == "<STR_LIT>" : <EOL> hist_dict [ item ] [ polarity ] [ size ] += <NUM_LIT:1> <EOL> else : <EOL> hist_dict [ item ] [ polarity ] [ size ] -= <NUM_LIT:1> <EOL> IN . close ( ) <EOL> for item in sorted ( hist_dict ) : <EOL> for polarity in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> for size in range ( minrange , maxrange + <NUM_LIT:1> ) : <EOL> print >> OUT , "<STR_LIT>" % ( polarity , size , hist_dict [ item ] [ polarity ] [ size ] * Nfactor , item ) <EOL> OUT . close ( ) <EOL> histogrammer ( sys . argv [ <NUM_LIT:1> ] , sys . argv [ <NUM_LIT:2> ] , sys . argv [ <NUM_LIT:3> ] , int ( sys . argv [ <NUM_LIT:4> ] ) , int ( sys . argv [ <NUM_LIT:5> ] ) ) </s>
