#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n, d, a, b, c, cnt=0, sum=0;
cin >> n >> d;
for(int i=1; i<=n; i++)
{
cin >> a >> b >> c;
int maxv=max(max(a,b), c);
int minv=min(min(a,b), c);
if(maxv-minv >= d) {cnt++; sum+=(a+b+c)/3;}
}
cout << cnt << " " << sum << "\n";
}