def encode_captions(captions):
    """
    Convert all captions' words into indices.
    
    Input:
    - captions: dictionary containing image names and list of corresponding captions
    
    Returns:
    - word_to_idx: dictionary of indices for all words
    - idx_to_word: list containing all words
    - vocab_size: number of words
    """
    word_counts = {}
    for name, caption_list in captions.items():
        for caption in caption_list:
            for word in caption.split():
                if word not in word_counts:
                    word_counts[word] = 1
                else:
                    word_counts[word] += 1
    idx_to_word = ['<START>', '<END>', '<PAD>'] + [w for w in word_counts if w not in ['<START>', '<END>', '<PAD>']]
    word_to_idx = {}
    for i in range(len(idx_to_word)):
        word_to_idx[idx_to_word[i]] = i
    vocab_size = len(idx_to_word)
    return word_to_idx, idx_to_word, vocab_size