from sys import argv, exit class DefaultDict(dict): def __init__(self,default): super(DefaultDict, self).__init__() self.default = default def __getitem__(self, key): return self.get(key, self.default) if len(argv) <= 2: print("%s " % argv[0]) exit(1) format_left = argv[1] format_right = argv[2] cache = DefaultDict("") _format = lambda: '%{l}' + (format_left % cache) + '%{r}' + (format_right % cache) while True: print(_format()) tag,content = input().rstrip('\n').split(' ',1) cache[tag] = content