def sortsummary(beam, beta=0):
    """
    Sort the generated summaries by beam search, with length penalty considered.
    
    Input:
        - beam (beam_search.Beam): 'Beam' object finished with beam search.
        - beta (float): length penalty when sorting. Default: 0 (no length penalty).

    Output:
        - ssa (list[tuple]): 'List[Tuple]' of (score_avg, sentence, alignment, sim_score, lm_score).
    """
    sents = []
    aligns = []
    score_avgs = []
    sim_scores = []
    lm_scores = []

    for ks in beam.endbus:
        sent, rebeam = beam.retrieve(ks[0] + 1, ks[1])
        score_avg = ks[2] / (ks[1] ** beta)

        sents.append(sent)
        aligns.append(beam.retrieve_align(rebeam))
        score_avgs.append(score_avg)
        sim_scores.append(ks[3])
        lm_scores.append(ks[4])

    ssa = sorted([(score_avgs[i], sents[i], aligns[i], sim_scores[i], lm_scores[i]) for i in range(len(sents))],
                 reverse=True)

    return ssa