def text_justification(words, max_width):
ret = []  <EOL>row_len = <NUM_LIT:0>  <EOL>row_words = []  <EOL>index = <NUM_LIT:0>  <EOL>is_first_word = True  <EOL>while index < len(words):<EOL><INDENT>while row_len <= max_width and index < len(words):<EOL><INDENT>if len(words[index]) > max_width:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>tmp = row_len<EOL>row_words.append(words[index])<EOL>tmp += len(words[index])<EOL>if not is_first_word:<EOL><INDENT>tmp += <NUM_LIT:1>  <EOL><DEDENT>if tmp > max_width:<EOL><INDENT>row_words.pop()<EOL>break<EOL><DEDENT>row_len = tmp<EOL>index += <NUM_LIT:1><EOL>is_first_word = False<EOL><DEDENT>row = "<STR_LIT>"<EOL>if index == len(words):<EOL><INDENT>for word in row_words:<EOL><INDENT>row += (word + '<STR_LIT:U+0020>')<EOL><DEDENT>row = row[:-<NUM_LIT:1>]<EOL>row += '<STR_LIT:U+0020>' * (max_width - len(row))<EOL><DEDENT>elif len(row_words) != <NUM_LIT:1>:<EOL><INDENT>space_num = max_width - row_len<EOL>space_num_of_each_interval = space_num // (len(row_words) - <NUM_LIT:1>)<EOL>space_num_rest = space_num - space_num_of_each_interval * (len(row_words) - <NUM_LIT:1>)<EOL>for j in range(len(row_words)):<EOL><INDENT>row += row_words[j]<EOL>if j != len(row_words) - <NUM_LIT:1>:<EOL><INDENT>row += '<STR_LIT:U+0020>' * (<NUM_LIT:1> + space_num_of_each_interval)<EOL><DEDENT>if space_num_rest > <NUM_LIT:0>:<EOL><INDENT>row += '<STR_LIT:U+0020>'<EOL>space_num_rest -= <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>row += row_words[<NUM_LIT:0>]<EOL>row += '<STR_LIT:U+0020>' * (max_width - len(row))<EOL><DEDENT>ret.append(row)<EOL>row_len = <NUM_LIT:0><EOL>row_words = []<EOL>is_first_word = True<EOL><DEDENT>return ret<EOL>
:type words: list
:type max_width: int
:rtype: list