def replace(self, seq):
<EOL>seq = list(seq)<EOL>chart = [ [None for _i in range(len(seq)) ] for _i in range(len(seq)) ]<EOL>chart[<NUM_LIT:0>] = [(<NUM_LIT:0>, char) for char in seq]<EOL>for (begin, length, value) in self.find_all(seq):<EOL><INDENT>chart[length-<NUM_LIT:1>][begin] = (length, value)<EOL><DEDENT>for row in range(<NUM_LIT:1>, len(chart)):<EOL><INDENT>for col in range(len(seq) - row):<EOL><INDENT>if chart[row][col] is not None:<EOL><INDENT>continue<EOL><DEDENT>best_score = -<NUM_LIT:1><EOL>best_value = None<EOL>for partition_point in range(row):<EOL><INDENT>x1 = partition_point<EOL>y1 = col<EOL>x2 = row - partition_point - <NUM_LIT:1><EOL>y2 = col + partition_point + <NUM_LIT:1><EOL>s1, v1 = chart[x1][y1]<EOL>s2, v2 = chart[x2][y2]<EOL>score = s1 + s2<EOL>if best_score < score:<EOL><INDENT>best_score = score<EOL>best_value = v1 + v2<EOL>chart[row][col] = (best_score, best_value)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return chart[len(seq)-<NUM_LIT:1>][<NUM_LIT:0>][<NUM_LIT:1>]<EOL>
Performs search and replace on the given input string `seq` using
the values stored in this trie.  This method uses a O(n**2)
chart-parsing algorithm to find the optimal way of replacing
matches in the input.

Arguments:
- `seq`: