from typing import List
import math


def calc_new_ahc_rating(past_perfs: List[float], perf: float) -> float:
    """
    AHCに沿ってレーティングを求める (https://www.dropbox.com/s/ne358pdixfafppm/AHC_rating.pdf?dl=0)
    past_perfs: 過去のパフォーマンス
    perf: 今回のパフォーマンス
    returns: new rating
    """
    R = 0.8271973364
    S = 724.4744301
    Q = sorted([p - S*math.log(j) for p in past_perfs + [perf] for j in range(1, 101)], reverse=True)
    numerator = sum([Q[i-1]*R**i for i in range(1, 101)])
    denominator = sum([R**i for i in range(1, 101)])
    r = numerator / denominator

    if r >= 400:
        return r
    else:
        return 400 / math.exp((400 - r) / 400.0)