#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
long double getWinProbability(long double ra, long double rb) {
return 1.0 / (1.0 + pow((long double) 10.0, (rb - ra) / 400.0));
}
long double aggregateRatings(vector<long double> teamRatings)
{
long double left = 1;
long double right = 1E4;
for (int tt = 0; tt < 100; tt++) {
long double r = (left + right) / 2.0;
long double rWinsProbability = 1.0;
forn(i, teamRatings.size())
rWinsProbability *= getWinProbability(r, teamRatings[i]);
long double rating = log10(1 / (rWinsProbability) - 1) * 400 + r;
if (rating > r)
left = r;
else
right = r;
}
return (left + right) / 2.0;
}
int main() {
vector<long double> teamRating = {2589, 2115, 2411, 2336, 2142, 1939, 2691,
2411, 1794, 2123, 2226, 2185, 2106, 2297, 1862, 2164, 2190, 1961,
2753, 2730, 2599, 2516, 3129};
cout << aggregateRatings(teamRating);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgoKI2RlZmluZSBmb3JuKGksIG4pIGZvciAoaW50IGkgPSAwOyBpIDwgaW50KG4pOyBpKyspCiAKIApsb25nIGRvdWJsZSBnZXRXaW5Qcm9iYWJpbGl0eShsb25nIGRvdWJsZSByYSwgbG9uZyBkb3VibGUgcmIpIHsKICAgIHJldHVybiAxLjAgLyAoMS4wICsgcG93KChsb25nIGRvdWJsZSkgMTAuMCwgKHJiIC0gcmEpIC8gNDAwLjApKTsKfQpsb25nIGRvdWJsZSBhZ2dyZWdhdGVSYXRpbmdzKHZlY3Rvcjxsb25nIGRvdWJsZT4gdGVhbVJhdGluZ3MpCnsKICAgIGxvbmcgZG91YmxlIGxlZnQgPSAxOwogICAgbG9uZyBkb3VibGUgcmlnaHQgPSAxRTQ7CgogICAgZm9yIChpbnQgdHQgPSAwOyB0dCA8IDEwMDsgdHQrKykgewogICAgICAgIGxvbmcgZG91YmxlIHIgPSAobGVmdCArIHJpZ2h0KSAvIDIuMDsKCiAgICAgICAgbG9uZyBkb3V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