    if (magnitude >= pool.cumulative * 4) revert NotValid();
(604800 * 604800 + x * x)**0.5 - x < 4 * x
def computeMagnitude(_duration, cumulative):
    return int((_duration**2 + cumulative**2)**0.5) - cumulative

def assetValid4(_magnitude, _cumulative, tag):
    # print(_magnitude, _cumulative * 4)
    assert _magnitude < _cumulative * 4, f"Not Valid here #{tag}"

def update(_duration, _averageMagnitude, _cumulative, _NO):
    print(f"======{_NO}======")
    magnitude0 = computeMagnitude(_duration, _cumulative)
    print("duration, cumulative_before", _duration, _cumulative)
    assetValid4(magnitude0, _cumulative, _NO)
    _averageMagnitude = int((_averageMagnitude + magnitude0) / _NO)
    if _duration >= _cumulative:
        print("cumulative_delta", _averageMagnitude)
        _cumulative += _averageMagnitude
    else:
        print("cumulative_delta", -_averageMagnitude)
        _cumulative -= _averageMagnitude
    print("averageMagnitude,cumulative_after", _averageMagnitude, _cumulative)
    return _averageMagnitude, _cumulative

def main():
    averageMagnitude = 0
    cumulative = 7 * 24 * 3600
    # 1
    NO = 1
    duration0 = 1004800
    averageMagnitude, cumulative = update(duration0, averageMagnitude, cumulative, NO)
    cache_c_delta0 = averageMagnitude
    
    # 2 
    NO += 1
    duration1 = 1172776
    averageMagnitude, cumulative = update(duration1, averageMagnitude, cumulative, NO)

    # after #1 unlock
    # pool.cumulative -= #1.averageMagnitude
    print("=================")
    cumulative_after_unlock = cumulative - cache_c_delta0
    print(cumulative_after_unlock, cumulative_after_unlock <= 123454)
    
main()
 python3 cumulative.py
======1======
duration, cumulative_before 1004800 604800
cumulative_delta 567977
averageMagnitude,cumulative_after 567977 1172777
======2======
duration, cumulative_before 1172776 1172777
cumulative_delta -526878
averageMagnitude,cumulative_after 526878 645899
=================
77922 True
