def from_pos(lengths, pos):
    """Transform position to row+col."""
    orig_pos = pos
    for row, length in enumerate(lengths):
        if pos > length:
            pos -= length
        else:
            return row, pos
    raise ValueError('Bad pos: {0}!'.format(orig_pos))
