def weighted_similarity(average_similarities):
    """
    Calculates weighted similarities based on the formula
    from the article. The longest n-gram has the biggest
    weight.

    :param average_similarities: average similarities between the most similar n-grams
    :return: weighted similarity of different lengths of n-grams
    """
    g = len(average_similarities)
    denominator = g * (g + 1) / 2
    return sum((i_ + 1) * avg_similarity / denominator for i_, avg_similarity in enumerate(average_similarities))