#pragma GCC optimize("O3")
#define TASK ""
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#define __USE_MINGW_ANSI_STDIO 0
#include<bits/stdc++.h>
using namespace std;
#define PI acos(-1)
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(c) (c).begin(), (c).end()
#define TIMESTAMP fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock()/CLOCKS_PER_SEC)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair <int, int> pii;
typedef vector <vi> vvi;
typedef vector <pii> vpii;
typedef vector<string> vs;
const int MAXN = 1e5 + 9;
const int MOD = (int)(1e9 + 7);
const int INF = 10000000;
struct level {
ll a, b, p;
};
int n;
level aa[MAXN];
ll prsum[MAXN];
ll sfsum[MAXN];
bool cmp(level l1, level l2) {
if((l1.a + l2.b) * l1.p + (l2.a + l1.a) * l2.p < (l2.a + l1.b) * l2.p + (l2.a + l1.a) * l1.p) return 1;
if((l1.a + l2.b) * l1.p + (l2.a + l1.a) * l2.p > (l2.a + l1.b) * l2.p + (l2.a + l1.a) * l1.p) return 0;
return (l1.a - l1.b < l2.a - l2.b);
}
void input() {
cin >> n;
for(int i = 0; i < n; i++) {
cin >> aa[i].a >> aa[i].b >> aa[i].p;
}
}
void solve() {
sort(aa, aa + n, cmp);
prsum[0] = aa[0].a;
for(int i = 1; i < n; i++) prsum[i] = prsum[i - 1] + aa[i].a;
sfsum[n] = 0;
sfsum[n - 1] = aa[n - 1].b;
for(int i = n - 2; i >= 0; i--) sfsum[i] = sfsum[i + 1] + aa[i].b;
ld ans = 0;
for(int i = 0; i < n; i++) {
ans += (ld(prsum[i]) + ld(sfsum[i + 1])) * (ld(aa[i].p)) / (ld(1e7));
}
cout << fixed << setprecision(10) << ans << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef LOCAL
freopen("xxx.in", "r", stdin);
freopen("xxx.out", "w", stdout);
#else
//fre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