#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define lcm(a,b) ll lcm_function(ll a , ll b) return (a*b)/__gcd(a,b);
void solve ()
{
int n;cin >> n;
map<int,multiset<int>> mp;
// maximum possible jobs that can be done------
int max_val = INT_MIN;
for(int i = 0 ;i<n;i++)
{
int a,b,c;
cin >> a >> b >> c; //ignore 'a' its just job id, I don't care about it------
mp[b].insert(c); // storing jobs deadline as key in map and storing profit for a particular dealine in sorted order---
max_val = max(max_val,b); //calculating maximum possibel jobs-----
}
multiset<int> final_jobs; // multiset for maximum possible job's profit for every deadline---
for(auto &x:mp)
{
auto it = x.second.end(); // traversing profit in decreasing order for a particular deadline----
it--;
for(int i=0;i<min(x.first,(int)x.second.size());i++) {final_jobs.insert(*it);it--;}
// for a particular deadline, traversing it for min(maximum possilbe jobs for that deadline,given jobs of that deadline)---
}
auto it = final_jobs.end();
it--;
int terms=0,total=0;
for(int i=0;i<min(max_val,(int)final_jobs.size());i++) {terms++;total+=(*it);it--;}
// traversing maximum jobs possible for min(maximum deadline among all, size of final jobs)--
cout<<terms<<" "<<total<<"\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
}
ICAgIAojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcgCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgbGNtKGEsYikgbGwgbGNtX2Z1bmN0aW9uKGxsIGEgLCBsbCBiKSByZXR1cm4gKGEqYikvX19nY2QoYSxiKTsKCnZvaWQgc29sdmUgKCkKewogIGludCBuO2NpbiA+PiBuOwogIG1hcDxpbnQsbXVsdGlzZXQ8aW50Pj4gbXA7CgogIC8vIG1heGltdW0gcG9zc2libGUgam9icyB0aGF0IGNhbiBiZSBkb25lLS0tLS0tCiBpbnQgbWF4X3ZhbCA9IElOVF9NSU47CgogIGZvcihpbnQg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