def METHOD_NAME(text, changes):
  characters = list(text)
  additions = []
  for cmd, start_pos, count, text in changes:
    if cmd == 'delete':
      for i in range(count):
        print(cmd, start_pos + i, count, characters[start_pos + i])
        characters[start_pos + i] = ''
    elif cmd == 'insert-after':
      additions.append((start_pos, text))
    elif cmd == 'delete-ws':
      for i in reversed(range(start_pos, start_pos + count)):
        if not characters[i].isspace():
          break
        characters[i] = ''
    else:
      raise Exception('unknown command: {0}'.format(cmd))
  # Process additions in reverse to make this algorithm easier.
  additions = sorted(additions, key=lambda entry: entry[0])
  while additions:
    pos, c = additions.pop()
    characters.insert(pos + 1, c)
  return ''.join(characters)