def context(words, i, j, width=5):
    """
    words: list(str)
    i, j, width: int, all in terms of words not chars
    indexes i..j in l are the string, add context of with <width> words both sides
    returns the context string plus the index of the first letter of l[i]
    [ 0 - - - - - - i - - j - - - - - - ], width=3
              - - - i - - j - - -
    context is surrounded by dots when l has more
    """
    if j < i:
        i, j = j, i
    if i < 0:
        i = 0
    i0 = max(i-width, 0)
    j0 = min(j + width + 1, len(words))
    with_context = " ".join(words[i0:j0])
    offset = len(" ".join(words[i0:i]))
    if i > 0 and offset > 0:
        offset += 1
    if i0 > 0:
        with_context = "... " + with_context
        offset += 4
    if j0 < len(words):
        with_context = with_context + " ..."
    assert with_context[offset] == words[i][0]
    return with_context, offset