https://ihhqbblgaq.blogspot.com/2021/07/how-to-find-average-value-on-interval.html