#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, d, cnt = 0;
int s[300] = { 0 };
int a[300] = { 0 };
cin >> n >> d;
for (int i = 0; i < n * 3; i++)
{
cin >> a[i];
}
for (int i = 0; i < n; i++)
{
sort(a + i * 3, a + i * 3 + 3);
}
for (int i = 0; i < n; i++)
{
if (d <= a[i * 3 + 2] - a[i * 3])
{
cnt++;
s[i] = (a[i * 3 + 2] + a[i * 3 + 1] + a[i * 3]) / 3;
}
}
int sum = 0;
for (int i = 0; i < n; i++)
{
sum += s[i];
}
cout << cnt << ' ' << sum;
return 0;
}