#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <fstream>

typedef long long ll;

using namespace std;

int com(const void * x, const void * y){
	return (*(ll*)x - *(ll*)y);
}

int main(){
	//ifstream fin("input.txt");
	ll n, d;
	cin >> n >> d;
	vector<ll> m(n), s1(n);
	for (ll i = 0; i < n; i++){
		cin >> m[i] >> s1[i];
	}
	ll max = 0;
	for (ll i = 0; i < n; i++){
		if (max < m[i])
			max = m[i];
	}
	vector<ll> s(max+1);
	for (ll i = 0; i < n; i++){
		if (s[m[i]] < s1[i]){
			s[m[i]] = s1[i];
		}
	}
	qsort(&m[0], n, sizeof(ll), com);
	//for (ll i = 0; i < n; i++) cout << m[i] << " ";
	//vector<ll> sum(n);
	int ans = 0;//the max sum of S[i]
	int j = 0; //second pointer
	int sum = 0;
	for (int i = 0; i < n; i++){
		while (j < n && abs(m[i] - m[j]) < d){
			sum = sum + s[m[j]];
			j++;
		}
		ans < sum ? ans = sum : ans = ans;
		if (j>=n){
			break;
		}
		sum = sum - s[m[i]];
	}
	cout << ans << endl;
	//system("pause");
	return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>
#include <fstream>

#define F first
#define S second

typedef long long ll;

using namespace std;

int main(){
	//ifstream fin("input.txt");
	const int N = 100001;
	pair<int, int> a[N];
	ll n, d;
	cin >> n >> d;
	for (int i = 0; i < n; i++){
		cin >> a[i].F >> a[i].S;
	}
	sort(a, a + n);
	ll sum = 0;// the sum of elements from i to j;
	int j = 0;//the second pointer;
	ll ans = 0;
	for (int i = 0; i < n; i++){
		while (j < n && abs(a[i].F - a[j].F) < d){
			sum = sum + a[j].second;
			j++;
		}
		ans > sum ? ans = ans : ans = sum;
		if (j >= n) break;
		sum = sum - a[i].S;
	}
	cout << ans << endl;
	//system("pause");
	return 0;
}


#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <fstream>

typedef long long ll;

using namespace std;

int com(const void * x, const void * y){
	return (*(ll*)x - *(ll*)y);
}

int main(){
	//ifstream fin("input.txt");
	ll n, d;
	cin >> n >> d;
	vector<ll> m(n), s1(n);
	for (ll i = 0; i < n; i++){
		cin >> m[i] >> s1[i];
	}
	ll max = 0;
	for (ll i = 0; i < n; i++){
		if (max < m[i])
			max = m[i];
	}
	vector<ll> s(max+1);
	for (ll i = 0; i < n; i++){
		if (s[m[i]] < s1[i]){
			s[m[i]] = s1[i];
		}
	}
	qsort(&m[0], n, sizeof(ll), com);
	//for (ll i = 0; i < n; i++) cout << m[i] << " ";
	//vector<ll> sum(n);
	ll ans = 0;//the max sum of S[i]
	int j = 0; //second pointer
	ll sum = 0;
	for (int i = 0; i < n; i++){
		while (j < n && abs(m[i] - m[j]) < d){
			sum = sum + s[m[j]];
			j++;
		}
		ans < sum ? ans = sum : ans = ans;
		if (j>=n){
			break;
		}
		sum = sum - s[m[i]];
	}
	cout << ans << endl;
	//system("pause");
	return 0;
}


#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <fstream>

typedef long long ll;

using namespace std;

int com(const void * x, const void * y){
	return (*(ll*)x - *(ll*)y);
}

int main(){
	//ifstream fin("input.txt");
	ll n, d;
	cin >> n >> d;
	vector<ll> m(n), s1(n);
	for (ll i = 0; i < n; i++){
		cin >> m[i] >> s1[i];
	}
	ll max = 0;
	for (ll i = 0; i < n; i++){
		if (max < m[i])
			max = m[i];
	}
	vector<ll> s(max+1);
	for (ll i = 0; i < n; i++){
		if (s[m[i]] < s1[i]){
			s[m[i]] = s1[i];
		}
	}
	qsort(&m[0], n, sizeof(ll), com);
	//for (ll i = 0; i < n; i++) cout << m[i] << " ";
	vector<ll> sum(n);
	ll count = 0; //the length of sum at the moment
	sum[0] = s[m[0]];
	for (ll i = 0; i < n - 1; i++){
		if ((m[i + 1] - m[i] < d) && -((m[i + 1] - m[i]) < d)){
			sum[count] += s[m[i+1]];
		}
		else{
			count++;
			sum[count] = s[m[i + 1]];
		}
	}
	max = 0;
	for (ll i = 0; i < n; i++){
		if (max < sum[i]){
			max = sum[i];
		}
	}
	cout << max << endl;
	//system("pause");
	return 0;
}


#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>

#define F first
#define S second
typedef long long ll;

using namespace std;

int main(){
	int n;
	ll d;
	cin >> n >> d;
	const int N = 100001;
	pair<int, int> a[N];
	for (int i = 0; i < n; i++){
		cin >> a[i].first >> a[i].second;
	}
	sort(a, a + n);
	ll sum = 0;
	ll ans = 0;
	int j = 0; //second pointer;
	for (int i = 0; i < n; i++){
		while (j < n && abs(a[i].first - a[j].first) < d){
			sum += a[j].second;
			j++;
		}
		ans < sum ? ans = sum : ans = ans;
		if (j == n){
			break;
		}
		sum = sum - a[i].S;
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <fstream>

using namespace std;

int com(const void * x, const void * y){

	return (*(int*)x - *(int*)y);
}

int main(){
	//ifstream fin("input.txt");
	int n, d;
	cin >> n >> d;
	vector<int> m(n), s1(n);
	for (int i = 0; i < n; i++){
		cin >> m[i] >> s1[i];
	}
	int max = 0;
	for (int i = 0; i < n; i++){
		if (max < m[i])
			max = m[i];
	}
	vector<int> s(max+1);
	for (int i = 0; i < n; i++){
		if (s[m[i]] < s1[i]){
			s[m[i]] = s1[i];
		}
	}
	qsort(&m[0], n, sizeof(int), com);
	vector<int> sum(n);
	int count = 0; //the length of sum at the moment
	sum[0] = s[m[0]];
	for (int i = 0; i < n - 1; i++){
		if ((m[i + 1] - m[i] < d) && -((m[i + 1] - m[i]) < d)){
			sum[count] += s[m[i+1]];
		}
		else{
			count++;
			sum[count] = s[m[i + 1]];
		}
	}
	max = 0;
	for (int i = 0; i < n; i++){
		if (max < sum[i]){
			max = sum[i];
		}
	}
	cout << max << endl;
	//system("pause");
	return 0;
}


#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <fstream>

using namespace std;

int com(const void * x, const void * y){

	return (*(int*)x - *(int*)y);
}

int main(){
	ifstream fin("input.txt");
	int n, d;
	fin >> n >> d;
	vector<int> m(n), s1(n);
	for (int i = 0; i < n; i++){
		fin >> m[i] >> s1[i];
	}
	int max = 0;
	for (int i = 0; i < n; i++){
		if (max < m[i])
			max = m[i];
	}
	vector<int> s(max+1);
	for (int i = 0; i < n; i++){
		if (s[m[i]] < s1[i]){
			s[m[i]] = s1[i];
		}
	}
	qsort(&m[0], n, sizeof(int), com);
	vector<int> sum(n);
	int count = 0; //the length of sum at the moment
	sum[0] = s[m[0]];
	for (int i = 0; i < n - 1; i++){
		if ((m[i + 1] - m[i] < d) && -((m[i + 1] - m[i]) < d)){
			sum[count] += s[m[i+1]];
		}
		else{
			count++;
			sum[count] = s[m[i + 1]];
		}
	}
	max = 0;
	for (int i = 0; i < n; i++){
		if (max < sum[i]){
			max = sum[i];
		}
	}
	cout << max << endl;
	//system("pause");
	return 0;
}


#include "iostream"
#include "algorithm"
typedef long long ll;
const int M=1e5+5;

using namespace std;

struct Friend
{
	ll my;
	ll fs;
}f[M];

bool compare(Friend a,Friend b)
{
	return a.my<b.my;
}

int main()
{
	int n=0,d=0;
	while(cin>>n>>d)
	{
		for(int i=0;i<n;i++)
		cin>>f[i].my>>f[i].fs;

		sort(f,f+n,compare);

		ll sum=0;

		for(int i=0;i<n;i++)
		{
			ll beginMoney=f[i].my,add=0;
			for(int j=i;j<n;j++)
			{
				if(f[j].my-f[i].my<d)
					add+=f[j].fs;
				else
					break;
			}
			sum=max(sum,add);
		}
		cout<<sum<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
const int MX = 1e5 + 5;
struct Node
{
    ll money, Friend;
    bool operator< (const Node node)const{
        if(money != node.money)
            return money < node.money;
        return Friend < node.Friend;
    }
}e[MX];
ll n;
ll d;
int main()
{
    while(scanf("%I64d%I64d", &n, &d) != EOF)
    {
        for(int i = 1; i <= n; i++)
        {
            scanf("%I64d%I64d", &e[i].money, &e[i].Friend);
        }
        sort(e + 1, e + 1 + n);
        ll l = 1, r = 1;
        ll sum = 0, max_ = 0;
        while(r <= n)
        {
            if(abs(e[r].money - e[l].money) < d)
            {
                sum += e[r].Friend;
                r++;
            }
            else
            {
                sum -= e[l].Friend;
                l++;
            }
            max_ = max(max_, sum);
        }
        printf("%I64d\n", max_);
    }
    return 0;
}


#include "iostream"
#include "algorithm"
typedef long long ll;
const int M=1e5+5;

using namespace std;

struct Friend
{
	ll my;
	ll fs;
}f[M];

bool compare(Friend a,Friend b)
{
	return a.my>b.my;
}

int main()
{
	int n=0,d=0;
	while(cin>>n>>d)
	{
		for(int i=0;i<n;i++)
		cin>>f[i].my>>f[i].fs;

		sort(f,f+n,compare);

		ll sum=0;

		for(int i=0;i<n;i++)
		{
			ll beginMoney=f[i].my,add=0;
			for(int j=i;j<n;j++)
			{
				if(f[j].my-f[i].my<d)
					add+=f[j].fs;
				else
					break;
			}
			sum=max(sum,add);
		}
		cout<<sum<<endl;
	}
	return 0;
}


#include "iostream"
#include "algorithm"
typedef long long ll;
const int M=1e5+5;

using namespace std;

struct Friend
{
	ll my;
	ll fs;
}f[M];

//bool compare(Friend a,Friend b)
//{
//	return a.my<b.my;
//}

int main()
{
	int n=0,d=0;
	while(cin>>n>>d)
	{
		for(int i=0;i<n;i++)
		cin>>f[i].my>>f[i].fs;

		sort(f,f+n);

		ll sum=0;

		for(int i=0;i<n;i++)
		{
			ll beginMoney=f[i].my,add=0;
			for(int j=i;j<n;j++)
			{
				if(f[j].my-f[i].my<d)
					add+=f[j].fs;
				else
					break;
			}
			sum=max(sum,add);
		}
		cout<<sum<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
const int MX = 1e5 + 5;
struct Node
{
    int money, Friend;
    bool operator< (const Node node)const{
        if(money != node.money)
            return money < node.money;
        return Friend < node.Friend;
    }
}e[MX];
int n;
ll d;
int main()
{
    while(scanf("%d%I64d", &n, &d) != EOF)
    {
        for(int i = 1; i <= n; i++)
        {
            scanf("%d%d", &e[i].money, &e[i].Friend);
        }
        sort(e + 1, e + 1 + n);
        int l = 1, r = 1, sum = 0, max_ = 0;
        while(r <= n)
        {
            if(abs(e[r].money - e[l].money) < d)
            {
                sum += e[r].Friend;
                r++;
            }
            else
            {
                sum -= e[l].Friend;
                l++;
            }
            max_ = max(max_, sum);
        }
        printf("%d\n", max_);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
const int MX = 1e5 + 5;
struct Node
{
    int money, Friend;
    bool operator< (const Node node)const{
        if(money != node.money)
            return money < node.money;
        return Friend > node.Friend;
    }
}e[MX];
int n;
ll d;
int main()
{
    while(scanf("%d%I64d", &n, &d) != EOF)
    {
        for(int i = 1; i <= n; i++)
        {
            scanf("%d%d", &e[i].money, &e[i].Friend);
        }
        sort(e + 1, e + 1 + n);
        int l = 1, r = 1, sum = 0, max_ = 0;
        while(r <= n)
        {
            if(abs(e[r].money - e[l].money) < d)
            {
                sum += e[r].Friend;
                r++;
            }
            else
            {
                sum -= e[l].Friend;
                l++;
            }
            max_ = max(max_, sum);
        }
        printf("%d\n", max_);
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <stdio.h>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <iomanip>
#include <cmath>

using namespace std;

#define FOR(i,n) for (long long i = 0; i < n; ++i)

typedef pair <int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;

const int MAXN = (int)1e5 + 5;

int n, d;
int t;
VI a;
VI dr;

void quickSort(int left, int right) {
    int i = left, j = right;
    int tmp;
    int pivot = a[(left + right) / 2];

    while (i <= j) {
        while (a[i] < pivot)
            ++i;
        while (a[j] > pivot)
            --j;
        if (i <= j) {
            tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
            tmp = dr[i];
            dr[i] = dr[j];
            dr[j] = tmp;
            ++i;
            --j;
        }
    };

    if (left < j)
        quickSort(left, j);
    if (i < right)
        quickSort(i, right);

}
int main()
{
    cin >> n >> d;
    FOR(i, n)
    {
        scanf("%d", &t);
        a.push_back(t);
        scanf("%d", &t);
        dr.push_back(t);
    }
    quickSort(0, n-1);

    int max = 0;
    int l = 0, r = 0;
    int res = 0;
    while (r < n)
    {
        while (a[r] - a[l] < d)
        {
            res += dr[r];
            ++r;
            if (r == n)
                break;
        }
        if (res > max)
            max = res;
        res -= dr[l];
        ++l;
    }

    cout << max;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <stdio.h>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <iomanip>
#include <cmath>

using namespace std;

#define FOR(i,n) for (long long i = 0; i < n; ++i)

typedef pair <int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;

const int MAXN = (int)1e5 + 5;

int n, d;
int t;
VI a;
VI dr;

void quickSort(int left, int right) {
    int i = left, j = right;
    int tmp;
    int pivot = a[(left + right) / 2];

    while (i <= j) {
        while (a[i] < pivot)
            ++i;
        while (a[j] > pivot)
            --j;
        if (i <= j) {
            tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
            tmp = dr[i];
            dr[i] = dr[j];
            dr[j] = tmp;
            ++i;
            --j;
        }
    };

    if (left < j)
        quickSort(left, j);
    if (i < right)
        quickSort(i, right);

}
int main()
{
    cin >> n >> d;
    FOR(i, n)
    {
        scanf("%d", &t);
        a.push_back(t);
        scanf("%d", &t);
        dr.push_back(t);
    }
    quickSort(0, n-1);

    int max = 0;
    int l = 0, r = 0;
    while (r < n)
    {
        int res = 0;
        while (a[r] - a[l] < d)
        {
            res += dr[r];
            ++r;
            if (r == n)
                break;
        }
        if (res > max)
            max = res;
        res -= dr[l];
        ++l;
    }

    cout << max;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <stdio.h>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <iomanip>
#include <cmath>

using namespace std;

#define FOR(i,n) for (long long i = 0; i < n; ++i)

typedef pair <int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;

const int MAXN = (int)1e5 + 5;

int n, d;
int t;
VI a;
VI dr;

void quickSort(int left, int right) {
    int i = left, j = right;
    int tmp;
    int pivot = a[(left + right) / 2];

    while (i <= j) {
        while (a[i] < pivot)
            ++i;
        while (a[j] > pivot)
            --j;
        if (i <= j) {
            tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
            tmp = dr[i];
            dr[i] = dr[j];
            dr[j] = tmp;
            ++i;
            --j;
        }
    };

    if (left < j)
        quickSort(left, j);
    if (i < right)
        quickSort(i, right);

}
int main()
{
    cin >> n >> d;
    FOR(i, n)
    {
        scanf("%d", &t);
        a.push_back(t);
        scanf("%d", &t);
        dr.push_back(t);
    }
    quickSort(0, n-1);

    int max = 0;
    int l = 0, r = 0;
    int res = 0;
    while (r < n)
    {
        while (a[r] - a[l] < d)
        {
            res += dr[r];
            ++r;
            if (r == n)
                break;
        }
        if (res > max)
            max = res;
        res -= dr[l];
        ++l;
        --r;
    }

    cout << max;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <stdio.h>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <iomanip>
#include <cmath>

using namespace std;

#define FOR(i,n) for (long long i = 0; i < n; ++i)

typedef pair <int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;

const int MAXN = (int)1e5 + 5;

int n, d;
int t;
VI a;
VI dr;

void quickSort(int left, int right) {
    int i = left, j = right;
    int tmp;
    int pivot = a[(left + right) / 2];

    while (i <= j) {
        while (a[i] < pivot)
            ++i;
        while (a[j] > pivot)
            --j;
        if (i <= j) {
            tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
            tmp = dr[i];
            dr[i] = dr[j];
            dr[j] = tmp;
            ++i;
            --j;
        }
    };

    if (left < j)
        quickSort(left, j);
    if (i < right)
        quickSort(i, right);

}
int main()
{
    cin >> n >> d;
    FOR(i, n)
    {
        scanf("%d", &t);
        a.push_back(t);
        scanf("%d", &t);
        dr.push_back(t);
    }
    quickSort(0, n-1);

    LL max = 0;
    int l = 0, r = 0;
    LL res = 0;
    while (r < n)
    {
        while (a[r] - a[l] < d)
        {
            res += dr[r];
            ++r;
            if (r == n)
                break;
        }
        if (res > max)
            max = res;
        res -= dr[l];
        ++l;
    }

    cout << max;
    return 0;
}


#include <iostream>
#include <map>

using namespace std;

int main() {
	long n, d;
	cin >> n >> d;
	map<long, long> sumD;
	for (long i = 0; i < n; i++) {
		long m, s;
		cin >> m >> s;
		sumD[m] += s;
	}

	long long s = 0;
	map<long, long>::iterator i1 = sumD.begin(), i2 = sumD.begin();
	while (i2 != sumD.end() && (*i2).first - (*i1).first < d) {
		s += (*i2).second;
		++i2;
	}

	long long s1 = s;
	while (i2 != sumD.end()) {
		s1 += (*i2).second;
		while ((*i2).first - (*i1).first >= d) {
			s1 -= (*i1).second;
			++i1;
		}
		if (s1 > s)
			s = s1;
		++i2;
	}
	cout << s;
	//system("pause");
	return 0;
}


#include <iostream>
#include <map>

using namespace std;

int main() {
	long n, d;
	cin >> n >> d;
	map<long long, long long> sumD;
	for (long i = 0; i < n; i++) {
		long m, s;
		cin >> m >> s;
		sumD[m] += s;
	}

	unsigned long long s = 0;
	map<long long, long long>::iterator i1 = sumD.begin(), i2 = sumD.begin();
	while (i2 != sumD.end() && (*i2).first - (*i1).first < d) {
		s += (*i2).second;
		++i2;
	}

	unsigned long long s1 = s;
	while (i2 != sumD.end()) {
		s1 += (*i2).second;
		while ((*i2).first - (*i1).first >= d) {
			s1 -= (*i1).second;
			++i1;
		}
		if (s1 > s)
			s = s1;
		++i2;
	}
	cout << s;
	//system("pause");
	return 0;
}


#include <iostream>
#include <map>

using namespace std;

int main() {
	long n, d;
	cin >> n >> d;
	map<long, long> sumD;
	for (long i = 0; i < n; i++) {
		long m, s;
		cin >> m >> s;
		sumD[m] += s;
	}

	long s = 0;
	map<long, long>::iterator i1 = sumD.begin(), i2 = sumD.begin();
	while (i2 != sumD.end() && (*i2).first - (*i1).first < d) {
		s += (*i2).second;
		++i2;
	}

	long s1 = s;
	while (i2 != sumD.end()) {
		s1 += (*i2).second;
		while ((*i2).first - (*i1).first >= d) {
			s1 -= (*i1).second;
			++i1;
		}
		if (s1 > s)
			s = s1;
		++i2;
	}
	cout << s;
	//system("pause");
	return 0;
}


#include <iostream>
#include <map>

using namespace std;

int main() {
	long n, d;
	cin >> n >> d;
	map<long, long> sumD;
	for (long i = 0; i < n; i++) {
		long m, s;
		cin >> m >> s;
		sumD[m] += s;
	}

	long s = 0;
	map<long, long>::iterator i1 = sumD.begin(), i2 = sumD.begin();
	while (i2 != sumD.end() && (*i2).first - (*i1).first < d) {
		s += (*i2).second;
		++i2;
	}

	int s1 = s;
	while (i2 != sumD.end()) {
		s1 += (*i2).second;
		while ((*i2).first - (*i1).first >= d) {
			s1 -= (*i1).second;
			++i1;
		}
		if (s1 > s)
			s = s1;
		++i2;
	}
	cout << s;
	//system("pause");
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

bool func(pair<int, long long> a, pair<int, long long> b)
{
	return a.first < b.first;
}

int main()
{
	int n, d;
	map<int, long long> a;
	pair<int, long long> tmp;
	map<int, long long>::iterator it;

	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> tmp.first >> tmp.second;
		it = a.find(tmp.first);
		if (it != a.end())
			it->second += tmp.second;
		else
			a.insert(tmp);
	}

	long long sum, result = 0;
	for (map<int, long long>::iterator i = a.begin(); i != a.end(); i++)
	{
		sum = i->second;
		map<int, long long>::iterator j = i;
		j++;
		map<int, long long>::iterator k = a.lower_bound(i->first + d);
		while (j != k)
		{
			sum += j->second;
			j++;
		}
		//for (; j != a.end(); j++)
		//{
		//	if (j->first - i->first < d)
		//		sum += j->second;
		//	else
		//		break;
		//}
		if (sum > result)
			result = sum;
	}

	cout << result;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

bool func(pair<int, long long> a, pair<int, long long> b)
{
	return a.first < b.first;
}

int main()
{
	int n, d;
	map<int, long long> a, b;
	pair<int, long long> tmp;
	map<int, long long>::iterator it;
	long long sum, result;

	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> tmp.first >> tmp.second;
		it = a.find(tmp.first);
		if (it != a.end())
		{
			it->second += tmp.second;	// cho a
			it = b.find(tmp.first);
			it->second += tmp.second;	// cho b
		}
		else
		{
			a.insert(tmp);
			b.insert(tmp);
		}
	}

	if (n == 1)
	{
		cout << a.begin()->second;
		return 0;
	}

	map<int, long long>::iterator j = a.end(), i = j;
	j--; j--; i--;
	while (j != a.begin())
	{
		j->second += i->second;
		i--;
		j--;
	}
	j->second += i->second;

	i = a.begin();
	j = b.begin();
	for (; i != a.end(); i++)
	{
		it = a.lower_bound(i->first + (d - 1));
		if (it == a.end())
		{
			i->second = j->second;
		}
		else
		{
			if (it->first - i->first >= d)
			{
				it--;	// find element smaller
				if (it == i)
				{
					i->second = j->second;
				}
				else if (it->first - i->first < d)
				{
					it++;
					i->second -= it->second;
				}
			}
			else
			{
				it++;	// find element bigger d
				if (it != a.end())
				{
					i->second -= it->second;
				}
			}
		}
		j++;
	}

	it = a.begin();
	result = 0;
	for (; it != a.end(); it++)
		if (it->second > result)
			result = it->second;

	cout << result;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

bool func(pair<int, int> a, pair<int, int> b)
{
	return a.first < b.first;
}

int main()
{
	int n, d;
	pair<int, int> *a;

	cin >> n >> d;
	a = new pair<int, int>[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].first >> a[i].second;
	}

	sort(a, a + n, func);
	long long sum, result = 0;
	for (int i = 0; i < n; i++)
	{
		sum = a[i].second;
		for (int j = i + 1; j < n; j++)
		{
			if (a[j].first - a[i].first < d)
				sum += a[j].second;
			else
				break;
		}
		if (sum > result)
			result = sum;
	}

	cout << result;

	delete[]a;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

bool func(pair<int, long long> a, pair<int, long long> b)
{
	return a.first < b.first;
}

int main()
{
	int n, d;
	map<int, long long> a;
	pair<int, long long> tmp;
	map<int, long long>::iterator it;

	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> tmp.first >> tmp.second;
		it = a.find(tmp.first);
		if (it != a.end())
			it->second += tmp.second;
		else
			a.insert(tmp);
	}

	long long sum, result = 0;
	for (map<int, long long>::iterator i = a.begin(); i != a.end(); i++)
	{
		sum = i->second;
		map<int, long long>::iterator j = i;
		j++;
		for (; j != a.end(); j++)
		{
			if (j->first - i->first < d)
				sum += j->second;
			else
				break;
		}
		if (sum > result)
			result = sum;
	}

	cout << result;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

bool func(pair<int, long long> a, pair<int, long long> b)
{
	return a.first < b.first;
}

int main()
{
	int n, d;
	map<int, long long> a, b;
	pair<int, long long> tmp;
	map<int, long long>::iterator it;
	long long sum, result;

	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> tmp.first >> tmp.second;
		it = a.find(tmp.first);
		if (it != a.end())
		{
			it->second += tmp.second;	// cho a
			it = b.find(tmp.first);
			it->second += tmp.second;	// cho b
		}
		else
		{
			a.insert(tmp);
			b.insert(tmp);
		}
	}

	if (n == 1)
	{
		cout << a.begin()->second;
		return 0;
	}

	map<int, long long>::iterator j = a.end(), i = j;
	j--; j--; i--;
	while (j != a.begin())
	{
		j->second += i->second;
		i--;
		j--;
	}
	j->second += i->second;

	i = a.begin();
	j = b.begin();
	for (; i != a.end(); i++)
	{
		it = a.lower_bound(i->first + (d - 1));
		if (it == a.end())
		{
			//i->second = j->second;
		}
		else
		{
			if (it->first - i->first >= d)
			{
				it--;	// find element smaller
				if (it == i)
				{
					i->second = j->second;
				}
				else if (it->first - i->first < d)
				{
					it++;
					i->second -= it->second;
				}
			}
			else
			{
				it++;	// find element bigger d
				if (it != a.end())
				{
					i->second -= it->second;
				}
			}
		}
		j++;
	}

	it = a.begin();
	result = 0;
	for (; it != a.end(); it++)
		if (it->second > result)
			result = it->second;

	cout << result;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

bool func(pair<int, long long> a, pair<int, long long> b)
{
	return a.first < b.first;
}

int main()
{
	int n, d;
	map<int, long long> a, b;
	pair<int, long long> tmp;
	map<int, long long>::iterator it;
	long long sum, result;

	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> tmp.first >> tmp.second;
		it = a.find(tmp.first);
		if (it != a.end())
		{
			it->second += tmp.second;	// cho a
			it = b.find(tmp.first);
			it->second += tmp.second;	// cho b
		}
		else
		{
			a.insert(tmp);
			b.insert(tmp);
		}
	}

	if (a.size() == 1)
	{
		cout << a.begin()->second;
		return 0;
	}
	if (d == 1)
	{
		it = a.begin();
		result = 0;
		for (; it != a.end(); it++)
			if (it->second > result)
				result = it->second;

		cout << result;
		return 0;
	}

	map<int, long long>::iterator j = a.end(), i = j;
	j--; j--; i--;
	while (j != a.begin())
	{
		j->second += i->second;
		i--;
		j--;
	}
	j->second += i->second;

	i = a.begin();
	j = b.begin();
	for (; i != a.end(); i++)
	{
		it = a.lower_bound(i->first + (d - 1));
		if (it == a.end())
		{
			//i->second = j->second;
		}
		else
		{
			if (it->first - i->first >= d)
			{
				it--;	// find element smaller
				if (it == i)
				{
					i->second = j->second;
				}
				else if (it->first - i->first < d)
				{
					it++;
					i->second -= it->second;
				}
			}
			else
			{
				it++;	// find element bigger d
				if (it != a.end())
				{
					i->second -= it->second;
				}
			}
		}
		j++;
	}

	it = a.begin();
	result = 0;
	for (; it != a.end(); it++)
		if (it->second > result)
			result = it->second;

	cout << result;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

bool func(pair<int, int> a, pair<int, int> b)
{
	return a.first < b.first;
}

int main()
{
	int n, d;
	map<int, long> a;
	pair<int, long> tmp;
	map<int, long>::iterator it;

	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> tmp.first >> tmp.second;
		it = a.find(tmp.first);
		if (it != a.end())
			it->second += tmp.second;
		else
			a.insert(tmp);
	}

	long long sum, result = 0;
	for (map<int, long>::iterator i = a.begin(); i != a.end(); i++)
	{
		sum = i->second;
		map<int, long>::iterator j = i;
		j++;
		for (; j != a.end(); j++)
		{
			if (j->first - i->first < d)
				sum += j->second;
			else
				break;
		}
		if (sum > result)
			result = sum;
	}

	cout << result;

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>

//#pragma comment(linker, "/STACK:10000000")

using namespace std;

//const int N = 1e5+10;
const int N = 100010;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen ("input.txt","r",stdin);
        //freopen ("output.txt","w",stdout);
    #endif

    int n,d;
    cin >> n >> d;
    pair<int,int> mas[N];

    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        mas[i].first=x;mas[i].second=y;
    }

    std::sort(mas,mas+n);
    long long sum=mas[0].second;
    long long mm=0;
    for(int i=1;i<n;i++){
        if((mas[i].first-mas[i-1].first) <= d){
            sum+=mas[i].second;
        }else{
            mm=max(mm,sum);
            sum=0;
            sum+=mas[i].second;
        }
    }
    mm=max(mm,sum);
    for(int i=0;i<n;i++){
        if(mm<mas[i].second){
            mm=mas[i].second;
        }
    }
    cout << mm << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>

//#pragma comment(linker, "/STACK:10000000")

using namespace std;

//const int N = 1e5+10;
const int N = 100010;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen ("input.txt","r",stdin);
        //freopen ("output.txt","w",stdout);
    #endif

    int n,d;
    cin >> n >> d;
    pair<int,int> mas[N];

    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        mas[i].first=x;mas[i].second=y;
    }

    std::sort(mas,mas+n);
    long long sum=mas[0].second;
    long long mm=0,last=0,current=1;
    for(int i=1; /*i<n*/ ;i++){
        if(current>=n) break;
        if(mas[current].first - mas[last].first < d){
            sum+=mas[current].second;
            current++;
        }else{
            if(last+1 != current) {last++;}else {last++;current++;}
            mm=max(mm,sum);
            sum-=mas[last-1].second;
        }
    }

    mm=max(mm,sum);
    for(int i=0;i<n;i++){
        if(mm<mas[i].second){
            mm=mas[i].second;
        }
    }
    cout << mm << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>

//#pragma comment(linker, "/STACK:10000000")

using namespace std;

//const int N = 1e5+10;
const int N = 100010;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen ("input.txt","r",stdin);
        //freopen ("output.txt","w",stdout);
    #endif

    int n,d;
    cin >> n >> d;
    pair<int,int> mas[N];

    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        mas[i].first=x;mas[i].second=y;
    }

    std::sort(mas,mas+n);
    long long sum=mas[0].second;
    long long mm=0;
    for(int i=1;i<n;i++){
        if((mas[i].first-mas[i-1].first) <= d){
            sum+=mas[i].second;
        }else{
            mm=max(mm,sum);
            sum=0;
        }
    }
    mm=max(mm,sum);
    for(int i=0;i<n;i++){
        if(mm<mas[i].second){
            mm=mas[i].second;
        }
    }
    cout << mm << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>

//#pragma comment(linker, "/STACK:10000000")

using namespace std;

//const int N = 1e5+10;
const int N = 100010;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen ("input.txt","r",stdin);
        //freopen ("output.txt","w",stdout);
    #endif

    int n,d;
    cin >> n >> d;
    pair<int,int> mas[N];

    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        mas[i].first=x;mas[i].second=y;
    }

    std::sort(mas,mas+n);
    long long sum=mas[0].second;
    long long mm=0,last=0,current=1;
    for(int i=1; /*i<n*/ ;i++){
        if(current>=n) break;
        if(mas[current].first - mas[last].first < d){
            sum+=mas[current].second;
            current++;
        }else{
            mm=max(mm,sum);
            while(true){
                last++;
                if(last==current) { sum=0; break;}
                sum-=mas[last].second;
                if(mas[current].first - mas[last].first < d){
                    break;
                }
            }
        }
    }

    mm=max(mm,sum);
    for(int i=0;i<n;i++){
        if(mm<mas[i].second){
            mm=mas[i].second;
        }
    }
    cout << mm << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>

//#pragma comment(linker, "/STACK:10000000")

using namespace std;

//const int N = 1e5+10;
const int N = 100010;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen ("input.txt","r",stdin);
        //freopen ("output.txt","w",stdout);
    #endif

    int n,d;
    cin >> n >> d;
    pair<int,int> mas[N];

    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        mas[i].first=x;mas[i].second=y;
    }

    std::sort(mas,mas+n);
    long long sum=mas[0].second;
    long long mm=0;
    long long current=0;
    for(int i=1;i<n;i++){
        if((mas[i].first-mas[i-1].first) <= d ){
            sum+=mas[i].second;
            current+=(mas[i].first-mas[i-1].first);
            if(current>d) {
                sum=mas[i].second;
                current=0;
            }
        }else{
            mm=max(mm,sum);
            sum=0;
            sum+=mas[i].second;
        }
    }
    mm=max(mm,sum);
    for(int i=0;i<n;i++){
        if(mm<mas[i].second){
            mm=mas[i].second;
        }
    }
    cout << mm << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>

//#pragma comment(linker, "/STACK:10000000")

using namespace std;

//const int N = 1e5+10;
const int N = 100010;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen ("input.txt","r",stdin);
        //freopen ("output.txt","w",stdout);
    #endif

    int n,d;
    cin >> n >> d;
    pair<int,int> mas[N];

    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        mas[i].first=x;mas[i].second=y;
    }

    std::sort(mas,mas+n);
    long long sum=mas[0].second;
    long long mm=0;
    for(int i=1;i<n;i++){
        if((mas[i].first-mas[i-1].first) < d){
            sum+=mas[i].second;
        }else{
            mm=max(mm,sum);
            sum=0;
            sum+=mas[i].second;
        }
    }
    mm=max(mm,sum);
    for(int i=0;i<n;i++){
        if(mm<mas[i].second){
            mm=mas[i].second;
        }
    }
    cout << mm << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>

//#pragma comment(linker, "/STACK:10000000")

using namespace std;

//const int N = 1e5+10;
const int N = 100010;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen ("input.txt","r",stdin);
        //freopen ("output.txt","w",stdout);
    #endif

    int n,d;
    cin >> n >> d;
    pair<int,int> mas[N];

    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        mas[i].first=x;mas[i].second=y;
    }

    std::sort(mas,mas+n);
    long long sum=mas[0].second;
    long long mm=0,last=0,current=1;
    for(int i=1; /*i<n*/ ;i++){
        if(current>=n) break;
        if(mas[current].first - mas[last].first < d){
            sum+=mas[current].second;
            current++;
        }else{
            mm=max(mm,sum);
            while(true){
                last++;
                if(last==current) { sum=0; break;}
                sum-=mas[last-1].second;
                if(mas[current].first - mas[last].first < d){
                    break;
                }
            }
        }
    }

    mm=max(mm,sum);
    for(int i=0;i<n;i++){
        if(mm<mas[i].second){
            mm=mas[i].second;
        }
    }
    cout << mm << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>

//#pragma comment(linker, "/STACK:10000000")

using namespace std;

//const int N = 1e5+10;
const int N = 100010;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen ("input.txt","r",stdin);
        //freopen ("output.txt","w",stdout);
    #endif

    int n,d;
    cin >> n >> d;
    pair<int,int> mas[N];

    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        mas[i].first=x;mas[i].second=y;
    }

    std::sort(mas,mas+n);
    long long sum=mas[0].second;
    long long mm=0,last=0,current=1;
    for(int i=1; /*i<n*/ ;i++){
        if(current>=n) break;
        if(mas[current].first - mas[last].first < d){
            sum+=mas[current].second;
            current++;
        }else{
            if(last+1 != current) last++;else {last++;current++;}
            mm=max(mm,sum);
            sum=mas[last].second;
        }
    }

    mm=max(mm,sum);
    for(int i=0;i<n;i++){
        if(mm<mas[i].second){
            mm=mas[i].second;
        }
    }
    cout << mm << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>

//#pragma comment(linker, "/STACK:10000000")

using namespace std;

//const int N = 1e5+10;
const int N = 100010;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen ("input.txt","r",stdin);
        //freopen ("output.txt","w",stdout);
    #endif

    int n,d;
    cin >> n >> d;
    pair<int,int> mas[N];

    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        mas[i].first=x;mas[i].second=y;
    }

    std::sort(mas,mas+n);
    long long sum=mas[0].second;
    long long mm=0,last=0,current=1;
    for(int i=1; /*i<n*/ ;i++){
        if(current>=n) break;
        if(mas[current].first - mas[last].first < d){
            sum+=mas[current].second;
            current++;
        }else{
            if(last+1 != current) {last++; current = last+1;}else {last++;current++;}
            mm=max(mm,sum);
            sum=mas[last].second;
        }
    }

    mm=max(mm,sum);
    for(int i=0;i<n;i++){
        if(mm<mas[i].second){
            mm=mas[i].second;
        }
    }
    cout << mm << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>

//#pragma comment(linker, "/STACK:10000000")

using namespace std;

//const int N = 1e5+10;
const int N = 100010;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen ("input.txt","r",stdin);
        //freopen ("output.txt","w",stdout);
    #endif

    int n,d;
    cin >> n >> d;
    pair<int,int> mas[N];

    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        mas[i].first=x;mas[i].second=y;
    }

    std::sort(mas,mas+n);
    long long sum=mas[0].second;
    long long mm=0;
    long long last=mas[0].first;
    for(int i=1;i<n;i++){
        if((mas[i].first-last) < d ){
            sum+=mas[i].second;
            //current+=(mas[i].first-mas[i-1].first);
        }else{
            mm=max(mm,sum);
            sum=0;
            sum+=mas[i].second;
            last=mas[i].first;
        }
    }
    mm=max(mm,sum);
    for(int i=0;i<n;i++){
        if(mm<mas[i].second){
            mm=mas[i].second;
        }
    }
    cout << mm << endl;
    return 0;
}


#include<iostream>
#include<fstream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<string>
#include<stack>
#include<vector>
#include<set>
#include<iomanip>

using namespace std;

//big arrays' declaration here

void main(){
#if defined(_DEBUG)
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
	int n,d,i,j,summ,max=0;
cin>>n>>d;
int *a=new int[n];
int *b=new int[n];
for (i=0;i<n;i++)
	cin>>a[i]>>b[i];
for (i=0;i<n;i++)
{
	summ=0;
for (j=0;j<n;j++)
	if (abs(a[i]-a[j])<=d)
		summ=summ+b[j];
if (summ>max)
	max=summ;
}
cout<<max;

}


#include<iostream>
#include<fstream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<string>
#include<stack>
#include<vector>
#include<set>
#include<iomanip>
#include<stdio.h>
#include <math.h>
using namespace std;
struct MyStruct
{
	long long m;
	long long s;
};
MyStruct a[100005];
long long summ[100005];
struct my_comparer {
	bool operator()(const MyStruct & one, const MyStruct & two) const {
		return one.m < two.m;
	}
};
void main() {
#if defined(_DEBUG)
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
	long long n, d;
	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].m >> a[i].s;
	}
	sort(a, a + n, my_comparer());
	summ[0] = a[0].s;
	for (int i = 1; i <n; i++)
	{
		summ[i] = summ[i - 1] + a[i].s;
	}
	long long max = 0;
	for (int i = 0; i < n; i++)
	{
		long long start = i;
		long long end = n-1;
		while (start < end)
		{
			int m = (start + end) / 2;
			if (a[i].m + d < a[m].m)
			{
				end = m-1;
			}
			else
			{
				if (a[i].m + d > a[m].m)
				{
					start = m + 1;
				}
			}
		}
		if (a[end].m > a[i].m + d)
		{
			end--;
		}
		long long ss = summ[end] - summ[i]+a[i].s;
		if (ss > max)
			max = ss;
	}
	cout << max;
}


#include<iostream>
#include<fstream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<string>
#include<stack>
#include<vector>
#include<set>
#include<iomanip>
#include<stdio.h>
#include <math.h>
using namespace std;
struct MyStruct
{
	long long m;
	long long s;
};
MyStruct a[100005];
long long summ[100005];
struct my_comparer {
	bool operator()(const MyStruct & one, const MyStruct & two) const {
		return one.m < two.m;
	}
};
void main() {
#if defined(_DEBUG)
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
	long long n, d;
	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].m >> a[i].s;
	}
	sort(a, a + n, my_comparer());
	summ[0] = a[0].s;
	for (int i = 1; i <n; i++)
	{
		summ[i] = summ[i - 1] + a[i].s;
	}
	long long max = 0;
	for (int i = 0; i < n; i++)
	{
		long long start = i;
		long long end = n-1;
		while (start < end)
		{
			int m = (start + end) / 2;
			if (a[i].m + d < a[m].m)
			{
				end = m-1;
			}
			else
			{
				if (a[i].m + d > a[m].m)
				{
					start = m + 1;
				}
			}
		}
		long long ss = summ[end] - summ[i]+a[i].s;
		if (ss > max)
			max = ss;
	}
	cout << max;
}


#include<iostream>
#include<fstream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<string>
#include<stack>
#include<vector>
#include<set>
#include<iomanip>

using namespace std;

//big arrays' declaration here

void main(){
#if defined(_DEBUG)
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
	int n,d,i,j;
	unsigned long int summ,max=0;
cin>>n>>d;
int a[10];
int b[10];
for (i=0;i<n;i++)
	cin>>a[i]>>b[i];
for (i=0;i<n;i++)
{
	summ=0;
for (j=0;j<n;j++)
	if (abs(a[i]-a[j])<=d)
		summ=summ+b[j];
if (summ>max)
	max=summ;
}
cout<<max;

}


#include<iostream>
#include<fstream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<string>
#include<stack>
#include<vector>
#include<set>
#include<iomanip>
#include<stdio.h>
#include <math.h>
using namespace std;
struct MyStruct
{
	long long m;
	long long s;
};
MyStruct a[100005];
long long summ[100005];
struct my_comparer {
	bool operator()(const MyStruct & one, const MyStruct & two) const {
		return one.m < two.m;
	}
};
void main() {
#if defined(_DEBUG)
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
	long long n, d;
	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].m >> a[i].s;
	}
	sort(a, a + n, my_comparer());
	for (int i = 1; i <= n; i++)
	{
		summ[i] = summ[i - 1] + a[i - 1].s;
	}
	long long max = 0;
	for (int i = 0; i < n; i++)
	{
		long long start = i;
		long long end = n;
		while (start < end)
		{
			int m = (start + end) / 2;
			if (a[i].m + d < a[m].m)
			{
				end = m-1;
			}
			else
			{
				if (a[i].m + d > a[m].m)
				{
					start = m + 1;
				}
			}
		}
		long long ss = summ[end] - summ[i];
		if (ss > max)
			max = ss;
	}
	cout << max;
}


#include<iostream>
#include<fstream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<string>
#include<stack>
#include<vector>
#include<set>
#include<iomanip>

using namespace std;

//big arrays' declaration here
struct people{
	int a;
	int b;
};
struct Comparer{
    bool operator()(const people & one, const people & two) const
	{
		return one.a<two.a;
	}
};
void main(){
#if defined(_DEBUG)
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
	int n,d,i,j;
	unsigned __int64 summ,max=0;
cin>>n>>d;
people c[100001];

for (i=0;i<n;i++)
	cin>>c[i].a>>c[i].b;
sort(c,c+n,Comparer());
for (i=0;i<n;i++)
{
	summ=0;
for (j=i;j<n;j++)
	if (abs(c[i].a-c[j].a)<d)
		summ=summ+c[j].b;
if (summ>max)
	max=summ;
}
cout<<max;

}


#include<iostream>
#include<fstream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<string>
#include<stack>
#include<vector>
#include<set>
#include<iomanip>

using namespace std;

//big arrays' declaration here

void main(){
#if defined(_DEBUG)
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
	int n,d,i,j;
	double summ,max=0;
cin>>n>>d;
int a[10];
int b[10];
for (i=0;i<n;i++)
	cin>>a[i]>>b[i];
for (i=0;i<n;i++)
{
	summ=0;
for (j=0;j<n;j++)
	if (abs(a[i]-a[j])<=d)
		summ=summ+b[j];
if (summ>max)
	max=summ;
}
cout<<max;

}


#include<iostream>
#include<fstream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<string>
#include<stack>
#include<vector>
#include<set>
#include<iomanip>

using namespace std;

//big arrays' declaration here
struct people{
	int a;
	int b;
};
struct Comparer{
    bool operator()(const people & one, const people & two) const
	{
		return one.a<two.a;
	}
};
void main(){
#if defined(_DEBUG)
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
	int n,d,i,j;
	unsigned long int summ,max=0;
cin>>n>>d;
people c[100001];

for (i=0;i<n;i++)
	cin>>c[i].a>>c[i].b;
sort(c,c+n,Comparer());
for (i=0;i<n;i++)
{
	summ=0;
for (j=i;j<n;j++)
	if (abs(c[i].a-c[j].a)<d)
		summ=summ+c[j].b;
if (summ>max)
	max=summ;
}
cout<<max;

}


#include<iostream>
#include<fstream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<string>
#include<stack>
#include<vector>
#include<set>
#include<iomanip>

using namespace std;

//big arrays' declaration here

void main(){
#if defined(_DEBUG)
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
	int n,d,i,j;
	unsigned long int summ,max=0;
cin>>n>>d;
int a[10];
int b[10];
for (i=0;i<n;i++)
	cin>>a[i]>>b[i];
for (i=0;i<n;i++)
{
	summ=0;
for (j=0;j<n;j++)
	if (abs(a[i]-a[j])<d)
		summ=summ+b[j];
if (summ>max)
	max=summ;
}
cout<<max;

}


#include<iostream>
#include<fstream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<string>
#include<stack>
#include<vector>
#include<set>
#include<iomanip>
#include<stdio.h>
#include <math.h>
using namespace std;
struct MyStruct
{
	long long m;
	long long s;
};
MyStruct a[100005];
long long summ[100005];
struct my_comparer {
	bool operator()(const MyStruct & one, const MyStruct & two) const {
		return one.m < two.m;
	}
};
void main() {
#if defined(_DEBUG)
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
	long long n, d;
	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].m >> a[i].s;
	}
	sort(a, a + n, my_comparer());
	summ[0] = a[0].s;
	for (int i = 1; i <n; i++)
	{
		summ[i] = summ[i - 1] + a[i].s;
	}
	long long max = 0;
	for (int i = 0; i < n; i++)
	{
		long long start = i;
		long long end = n-1;
		while (start < end)
		{
			int m = (start + end) / 2;
			if (a[i].m + d < a[m].m)
			{
				end = m-1;
			}
			else
			{
				if (a[i].m + d > a[m].m)
				{
					start = m + 1;
				}
				else
				if (a[i].m + d == a[m].m)
				{
					start = m+1;
				}
			}
		}
		if (a[end].m > a[i].m + d)
		{
			end--;
		}
		long long ss = summ[end] - summ[i]+a[i].s;
		if (ss > max)
			max = ss;
	}
	cout << max;
}


#include<iostream>
#include<fstream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<string>
#include<stack>
#include<vector>
#include<set>
#include<iomanip>
#include<stdio.h>
#include <math.h>
using namespace std;
struct MyStruct
{
	long long m;
	long long s;
};
MyStruct a[100005];
long long summ[100005];
struct my_comparer {
	bool operator()(const MyStruct & one, const MyStruct & two) const {
		return one.m < two.m;
	}
};
void main() {
#if defined(_DEBUG)
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
	long long n, d;
	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].m >> a[i].s;
	}
	sort(a, a + n, my_comparer());
	summ[0] = a[0].s;
	for (int i = 1; i <n; i++)
	{
		summ[i] = summ[i - 1] + a[i].s;
	}
	long long max = 0;
	for (int i = 0; i < n; i++)
	{
		long long start = i;
		long long end = n-1;
		while (start < end)
		{
			int m = (start + end) / 2;
			if (a[i].m + d < a[m].m)
			{
				end = m-1;
			}
			else
			{
				if (a[i].m + d > a[m].m)
				{
					start = m + 1;
				}
				else
				if (a[i].m + d == a[m].m)
				{
					end = m - 1;
				}
			}
		}
		if (a[end].m >= a[i].m + d)
		{
			end--;
		}
		long long ss = summ[end] - summ[i]+a[i].s;
		if (ss > max)
			max = ss;
	}
	cout << max;
}


#include<iostream>
#include<algorithm>
using namespace std;
struct friends{
    int money;
    int friendship;

}arr[100005];

int cmp(friends a,friends b){
    if(a.money==b.money)
        return a.friendship<b.friendship;
    return a.money<b.money;

}
int main(){
    int n,d;
    cin>>n>>d;
    for(int i = 1;i <= n; i++){
        cin>>arr[i].money>>arr[i].friendship;
    }
    sort(arr+1,arr+n+1,cmp);
    long long result = 0,resultTemp = 0;
    for(int i = n; i > 0; i--){
        resultTemp = arr[i].friendship;
        for(int j = i - 1; arr[i].money - arr[j].money < d; j--){
            if(j<=0)
                break;
            resultTemp+=arr[j].friendship;
        }
        if(resultTemp>result)
            result = resultTemp;
    }

    cout<<result<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
struct friends{
    int money;
    int friendship;
    int mon_min;
}arr[100005];
long long dp[100005];
int cmp(friends a,friends b){
    if(a.money==b.money)
        return a.friendship<b.friendship;
    return a.money<b.money;

}
int main(){
    int n,d;
    cin>>n>>d;
    for(int i = 1;i <= n; i++){
        cin>>arr[i].money>>arr[i].friendship;
    }
    sort(arr+1,arr+n+1,cmp);
    long long  dpValue;
    for(int i = 1; i <= n; i++){
        dp[i] = arr[i].friendship;
        arr[i].mon_min = arr[i].money;
        for(int j = 1; j < i; j++){
            if(arr[i].money-arr[j].mon_min<d){
                dpValue = dp[j] + arr[i].friendship;
                if(dpValue>dp[i]){
                    dp[i] = dpValue;
                    arr[i].mon_min = arr[j].mon_min;
                }

            }

        }
    }
    long long result = 0;
    for(int i = 1; i <= n; i++){
        if(dp[i]>result)
            result = dp[i];
    }
    cout<<result<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
struct friends{
    int money;
    int friendship;

}arr[100005];

int cmp(friends a,friends b){
    if(a.money==b.money)
        return a.friendship<b.friendship;
    return a.money<b.money;

}
int main(){
    int n,d;
    cin>>n>>d;

    for(int i = 1;i <= n; i++){
        cin>>arr[i].money>>arr[i].friendship;
    }
    sort(arr+1,arr+n+1,cmp);
    long long  result = arr[1].friendship;
    int beg = 1,i = 1,lastI = 1;
    int begMon = arr[beg].money;
    for( i = beg+1;i<=n; i++){
        if(arr[i].money-begMon<d){
            result+=arr[i].friendship;
        }
        else
            break;
    }
    lastI = i;
    --i;
    long long temp, lastTemp = result;
    while(i!=n){
        temp = lastTemp - arr[beg].friendship;
        begMon = arr[++beg].money;
        for(i = beg+1;i <=n; i++){
            if(arr[i].money - begMon>=d)
                break;
        }
        for(int j = lastI; j < i; j++){
            temp+=arr[j].friendship;
        }
        lastTemp = temp;
        if(temp>result)
            result = temp;
        lastI = i;
        --i;
    }

    cout<<result<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
struct friends{
    int money;
    int friendship;
    int mon_min;
}arr[100005];
int dp[100005];
int cmp(friends a,friends b){
    if(a.money==b.money)
        return a.friendship<b.friendship;
    return a.money<b.money;

}
int main(){
    int n,d;
    cin>>n>>d;
    for(int i = 1;i <= n; i++){
        cin>>arr[i].money>>arr[i].friendship;
    }
    sort(arr+1,arr+n+1,cmp);
    int dpValue;
    for(int i = 1; i <= n; i++){
        dp[i] = arr[i].friendship;
        arr[i].mon_min = i;
        for(int j = 1; j < i; j++){
            if(arr[i].money-arr[j].mon_min<d){
                dpValue = dp[j] + arr[i].friendship;
                if(dpValue>dp[i]){
                    dp[i] = dpValue;
                    arr[i].mon_min = arr[j].money;
                }

            }

        }
    }
    int result = 0;
    for(int i = 1; i <= n; i++){
        if(dp[i]>result)
            result = dp[i];
    }
    cout<<result<<endl;
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main(){
    map <int, long long> friends;
    map <int, long long>::iterator j;
    map <int, long long>::iterator k;
    long long n, d;
    cin >> n >> d;
    for (int i = 0; i < n; ++i){
        long long a[2];
        cin >> a[0] >> a[1];
        friends[a[0]] += a[1];
    }
    long long max = 0, count = 0;
    j = friends.begin();
    for (k = j; k != friends.end(); ++k){
        if (k->first - j->first < d){
            count += k->second;
        }
        else{
            if (count > max){ max = count; }
            while (k->first - j->first < d){
                count -= j->second;
                ++j;
            }
        }
    }
    if (count > max){ max = count; }
    cout << max;
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main(){
    map <int, int> friends;
    map <int, int>::iterator j;
    map <int, int>::iterator k;
    int n, d;
    cin >> n >> d;
    for (int i = 0; i < n; ++i){
        int a[2];
        cin >> a[0] >> a[1];
        friends[a[0]] += a[1];
    }
    long long max = 0;
    for (j = friends.begin(); j != friends.end(); ++j){
        long long count = 0;
        for (k = j; k != friends.end(); ++k){
            if (k->first - j->first < d){
                count += k->second;
            }
            else{ break; }
        }
        if (count > max){ max = count; }
    }
    cout << max;
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main(){
    map <int, int> friends;
    map <int, int>::iterator j;
    map <int, int>::iterator k;
    int n, d;
    cin >> n >> d;
    for (int i = 0; i < n; ++i){
        int a[2];
        cin >> a[0] >> a[1];
        friends[a[0]] += a[1];
    }
    int max = 0;
    for (j = friends.begin(); j != friends.end(); ++j){
        int count = 0;
        for (k = j; k != friends.end(); ++k){
            if (k->first - j->first < d){
                count += k->second;
            }
            else{ break; }
        }
        if (count > max){ max = count; }
    }
    cout << max;
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main(){
    map <int, long long> friends;
    map <int, long long>::iterator j;
    map <int, long long>::iterator k;
    long long n, d;
    cin >> n >> d;
    for (int i = 0; i < n; ++i){
        long long a[2];
        cin >> a[0] >> a[1];
        friends[a[0]] += a[1];
    }
    long long max = 0, count = 0;
    j = friends.begin();
    for (k = j; k != friends.end(); ++k){
        if (k->first - j->first < d){
            count += k->second;
        }
        else{
            if (count > max){ max = count; }
            count -= j->second;
            ++j;
        }
    }
    if (count > max){ max = count; }
    cout << max;
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main(){
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    map <int, int> friends;
    map <int, int>::iterator j;
    map <int, int>::iterator k;
    int n, d;
    cin >> n >> d;
    for (int i = 0; i < n; ++i){
        int a[2];
        cin >> a[0] >> a[1];
        friends[a[0]] += a[1];
    }
    long long max = 0;
    for (j = friends.begin(); j != friends.end(); ++j){
        long long count = 0;
        for (k = j; k != friends.end(); ++k){
            if (k->first - j->first < d){
                count += k->second;
            }
            else{ break; }
        }
        if (count > max){ max = count; }
    }
    cout << max;
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main(){
    map <int, long long> friends;
    map <int, long long>::iterator j;
    map <int, long long>::iterator k;
    long long n, d;
    cin >> n >> d;
    for (int i = 0; i < n; ++i){
        long long a[2];
        cin >> a[0] >> a[1];
        friends[a[0]] += a[1];
    }
    long long max = 0, count = 0;
    j = friends.begin();
    for (k = j; k != friends.end(); ++k){
        if (k->first - j->first < d){
            count += k->second;
        }
        else{
            if (count > max){ max = count; }
            while (k->first - j->first >= d){
                count -= j->second;
                ++j;
            }
        }
    }
    if (count > max){ max = count; }
    cout << max;
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main(){
    map <int, long long> friends;
    map <int, long long>::iterator j;
    map <int, long long>::iterator k;
    long long n, d;
    cin >> n >> d;
    for (int i = 0; i < n; ++i){
        long long a[2];
        cin >> a[0] >> a[1];
        friends[a[0]] += a[1];
    }
    long long max = 0, count = 0;
    j = friends.begin();
    for (k = j; k != friends.end(); ++k){
        if (k->first - j->first < d){
            count += k->second;
        }
        else{
            if (count > max){ max = count; }
            while (k->first - j->first >= d){
                count -= j->second;
                ++j;
            }
            count += k->second;
        }
    }
    if (count > max){ max = count; }
    cout << max;
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main(){
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    map <int, long long> friends;
    map <int, long long>::iterator j;
    map <int, long long>::iterator k;
    long long n, d;
    cin >> n >> d;
    for (int i = 0; i < n; ++i){
        long long a[2];
        cin >> a[0] >> a[1];
        friends[a[0]] += a[1];
    }
    long long max = 0;
    for (j = friends.begin(); j != friends.end(); ++j){
        long long count = 0;
        for (k = j; k != friends.end(); ++k){
            if (k->first - j->first < d){
                count += k->second;
            }
            else{ break; }
        }
        if (count > max){ max = count; }
    }
    cout << max;
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main(){
    map <int, long long> friends;
    map <int, long long>::iterator j;
    map <int, long long>::iterator k;
    long long n, d;
    cin >> n >> d;
    for (int i = 0; i < n; ++i){
        long long a[2];
        cin >> a[0] >> a[1];
        friends[a[0]] += a[1];
    }
    long long max = 0;
    for (j = friends.begin(); j != friends.end(); ++j){
        long long count = 0;
        for (k = j; k != friends.end(); ++k){
            if (k->first - j->first < d){
                count += k->second;
            }
            else{ break; }
        }
        if (count > max){ max = count; }
    }
    cout << max;
    return 0;
}


#include<stdio.h>
int main()
{
    int a,b,i,d,c,n;
    a=1;b=2;
    scanf("%d",&n);
    for(i=1;i<100000000;i++)
    {
        c=(i*(i+1))/2;
        if(c<n)
            continue;
        else if(c==n)
        {
            d=1;
            break;
        }
        else if(c>n)
        {
            d=0;
            break;
        }
    }
    if(d==1)
        printf("YES");
    else printf("NO");
    return 0;
}


#include <stdio.h>
//#define DEBUG

int main(void) {
	#ifdef DEBUG
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int i, n, b, d, a,
	total = 0, to_empty = 0;

	scanf("%d%d%d", &n, &b, &d);

	for(i = 0; i < n; ++i) {
		scanf("%d", &a);
		if (a > b)
			continue;
		total += a;
		if (total > d) {
			total -= d;
			++to_empty;
		}
	}

	printf("%d", to_empty);

	return 0;
}


#include <stdio.h>
//#define DEBUG

int main(void) {
	#ifdef DEBUG
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int i, n, b, d, a, total = 0;
	long long to_empty = 0;

	scanf("%d%d%d", &n, &b, &d);

	for(i = 0; i < n; ++i) {
		scanf("%d", &a);
		if (a > b)
			continue;
		total += a;
		while (total > d) {
			total -= d;
			++to_empty;
		}
	}

	printf("%I64d", to_empty);

	return 0;
}


#include <stdio.h>
//#define DEBUG

int main(void) {
	#ifdef DEBUG
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int i, n, b, d, a, total = 0;
	long long to_empty = 0;

	scanf("%d%d%d", &n, &b, &d);

	for(i = 0; i < n; ++i) {
		scanf("%d", &a);
		if (a > b)
			continue;
		total += a;
		if (total > d) {
			total = 0;
			++to_empty;
		}
	}

	printf("%I64d", to_empty);

	return 0;
}


#include <stdio.h>
//#define DEBUG

int main(void) {
	#ifdef DEBUG
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int i, n, b, d, a, total = 0;
	long long to_empty = 0;

	scanf("%d%d%d", &n, &b, &d);

	for(i = 0; i < n; ++i) {
		scanf("%d", &a);
		if (a > b)
			continue;
		total += a;
		if (total > d) {
			total -= d;
			++to_empty;
		}
	}

	printf("%I64d", to_empty);

	return 0;
}


#include <stdio.h>

int main(void)
{
	int n=0;
	int b=0;
	int d=0;
	long int s=0;
	int Tmp=0;
	scanf("%i%i%i",&n,&b,&d);
	while (n>0)
	{
		scanf("%ld",&Tmp);
		if (Tmp<=b)
			s+=Tmp;
		n--;
	}
	printf("%ld", s/d);
	return 0;
}


#include <stdio.h>

int main(void)
{
	int n=0;
	int b=0;
	int d=0;
	long int s=0;
	int Tmp=0;
	scanf("%i%i%i",&n,&b,&d);
	while (n>0)
	{
		scanf("%i",&Tmp);
		if (Tmp<=b)
			s+=Tmp;
		n--;
	}
	printf("%ld", s/d-1*(s%d==0)*(s!=0));
	return 0;
}


#include <stdio.h>

int main(void)
{
	int n=0;
	int b=0;
	int d=0;
	long int s=0;
	int Tmp=0;
	scanf("%i%i%i",&n,&b,&d);
	while (n>0)
	{
		scanf("%ld",&Tmp);
		if (Tmp<=b)
			s+=Tmp;
		n--;
	}
	printf("%ld", s/d-1*(s%d==0));
	return 0;
}


#include <stdio.h>

int main(void)
{
	// your code goes here
	int n=0;
	int b=0;
	int d=0;
	long int s=0;
	int Tmp=0;
	int Result=0;
	scanf("%i%i%i",&n,&b,&d);
	while (n>0)
	{
		scanf("%i",&Tmp);
		if (Tmp<=b)
			s+=Tmp;
		if (s>d)
		{
			s=0;
			Result++;
		}
		n--;
	}
	printf("%ld", Result);
	return 0;
}


#include<stdio.h>
int main()
{
    int n,a,b,c,i,j,k,l=0,sum=0;
    scanf("%d %d %d",&n,&a,&b);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&c);
        if(c>a)
            {continue;}
        else
            {
            sum=sum+c;
            if(sum>b)
                {
                    l++;
                    sum=0;
                }
            }
    }
    printf("%d",l);
}


#include<stdio.h>
int main()
{
    int n,a,b,c,i,j,k,l=0,sum=0;
    scanf("%d %d %d",&n,&a,&b);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&c);
        if(c>a)
            continue;
        else
            {
            sum=sum+c;
            if(sum>b)
                {
                    l++;
                    sum=sum-b;
                }
            }
    }
    printf("%d",l);
}


#include<stdio.h>
int main()
{
    int n,a,b,c,i,j,k,l,sum=0;
    scanf("%d %d %d",&n,&a,&b);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&c);
        if(c>a)
            continue;
        else
            sum=sum+c;
    }
    if(sum>b)
    {
        l=sum/b;
        printf("%d",l);

    }
    else
    {
        printf("0");
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int [] a = new int [n];
        int b = input.nextInt();
        int d = input.nextInt();
        for (int i = 0; i < n; i++) {
            a[i]= input.nextInt();
        }
        int sum= 0;
        for (int i = 0; i < n; i++) {
            if(a[i]<=b){
                sum+=a[i];
            }
        }
            int x = sum/d;
        System.out.println(x);
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int [] a = new int [n];
        int b = input.nextInt();
        int d = input.nextInt();
        long sum= 0;
        for (int i = 0; i < n; i++) {
            a[i]= input.nextInt();
            if(a[i]<=b){
                sum+=a[i];
            }
        }

       long x = 0;
       if(sum>d){
           x=sum/d;
       }
        System.out.println(x);
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int [] a = new int [n];
        int b = input.nextInt();
        int d = input.nextInt();
        int sum= 0;
        for (int i = 0; i < n; i++) {
            a[i]= input.nextInt();
            if(a[i]<=b){
                sum+=a[i];
            }
        }

       int x = 0;
       if(sum>d){
           x=sum/d;
       }
        System.out.println(x);
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int a = 0;
        int x = 0;
        int b = input.nextInt();
        int d = input.nextInt();
        int sum= 0;
        for (int i = 0; i < n; i++) {
            a= input.nextInt();
            if(a<=b){
                sum+=a;
            }
            if(sum>d){
              x++;
              sum = 0;
        }
        }

        System.out.println(x);
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int a = 0;
        int x = 0;
        int b = input.nextInt();
        int d = input.nextInt();
        int sum= 0;
        for (int i = 0; i < n; i++) {
            a= input.nextInt();
            if(a<=b){
                sum+=a;
            }
            if(sum>d){
              x++;
        }
        }

        System.out.println(x);
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int [] a = new int [n];
        int b = input.nextInt();
        int d = input.nextInt();
        for (int i = 0; i < n; i++) {
            a[i]= input.nextInt();
        }
        int sum= 0;
        for (int i = 0; i < n; i++) {
            if(a[i]<=b){
                sum+=a[i];
            }
        }
       int x = 0;
       if(sum!=d){
           x=sum/d;
       }
        System.out.println(x);
    }
}


import java.util.Scanner;

public class Juicer {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int b = in.nextInt();
		int d = in.nextInt();
		in.nextLine();
		int w = 0, o=0, f=0;
		for (int i = 0; i < n; i++) {
			o=in.nextInt();
			if(b<o) {
				w+=o;
			}
			else {
				w+=o;
			}
			if(w>d){
				f++;
				w=0;
			}
		}
		if(w>d) f++;
		System.out.println(f);
	}

}


import java.util.Scanner;

public class Juicer {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int b = in.nextInt();
		int d = in.nextInt();
		in.nextLine();
		int w = 0, o=0, f=0;
		for (int i = 0; i < n; i++) {
			o=in.nextInt();
			if(w>d){
				f++;
				w=0;
			}
			else{
				if(b<o) {
					w+=b;
					continue;
				}
				else {
					w+=o;
				}
			}
		}
		if(w>d) f++;
		System.out.println(f);
	}

}


import java.util.Scanner;

public class Juicer {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int b = in.nextInt();
		int d = in.nextInt();
		in.nextLine();
		int w = 0, o=0, f=0;
		for (int i = 0; i < n; i++) {
			o=in.nextInt();
			if(w>d){
				f++;
				w=0;
			}
			else{
				if(b<o) continue;
				else {
					w+=o;
				}
			}
		}
		if(w>d) f++;
		System.out.println(f);
	}

}


import java.util.Scanner;

public class Juicer {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int b = in.nextInt();
		int d = in.nextInt();
		in.nextLine();
		int w = 0, o=0, f=0;
		for (int i = 0; i < n; i++) {
			o=in.nextInt();
			if(w>d){
				f++;
				w-=d;
			}
			else{
				if(b<o) continue;
				else {
					w+=o;
				}
			}
		}
		if(w>d) f++;
		System.out.println(f);
	}

}


import java.util.Scanner;

public class Juicer {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int b = in.nextInt();
		int d = in.nextInt();
		in.nextLine();
		int w = 0, o=0, f=0;
		for (int i = 0; i < n; i++) {
			o=in.nextInt();
			if(b>=o) {
				w+=o;
			}
			if(w>d){
				f++;
				w=0;
			}
		}
		if(w>d) f++;
		System.out.println(f);
	}

}


import java.util.Scanner;

public class Juicer {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int b = in.nextInt();
		int d = in.nextInt();
		in.nextLine();
		int w = 0, o=0, f=0;
		for (int i = 0; i < n; i++) {
			o=in.nextInt();
			if(w>=d){
				f++;
				w=0;
			}
			else{
				if(b<o) continue;
				else {
					w+=o;
				}
			}
		}
		if(w>d) f++;
		System.out.println(f);
	}

}


import java.lang.*;
import java.util.*;
import java.io.*;
        public class TestClass {
            public static void main(String args[] ) {
                Scanner s = new Scanner(System.in);
                		int n = s.nextInt();
                		int[] arr = new int[n];
                		int b=s.nextInt();
                		int d = s.nextInt();
                		int x=0;
                		int ans=0;
        for (int i = 0; i <= n; i++) {
            arr[i]=s.nextInt();
           if(arr[i]<=b ){
               x+=arr[i];
               if(x>d){
                   ans++;
                   x=0;
               }
           }

        }

        System.out.println(ans);
    }
        }


import java.lang.*;
 import java.util.*;
import java.io.*;
        public class TestClass {
            public static void main(String args[] ) {
                Scanner s = new Scanner(System.in);
                		int n = s.nextInt();
                		int b=s.nextInt();
                		int d = s.nextInt();
                		int x=0;
                		int ans=0;
        for (int i = 0; i <= n; i++) {
            int y=s.nextInt();
            x+=y;
           if(y<=b && x<=d){
               continue;
           }
           else if(y<=b && x>d){
               x=0;
               ans++;
           }
           else if(y>b){
               x=x-y;

           }
        }

        System.out.println(ans);
    }
        }


import java.lang.*;
import java.util.Scanner;
import java.util.*;
import java.io.*;
        public class TestClass {
            public static void main(String args[] ) {
                Scanner s = new Scanner(System.in);
                		int n = s.nextInt();
                		int[] arr = new int[n];
                		int b=s.nextInt();
                		int d = s.nextInt();
                		int x=0;
                		int ans=0;
        for (int i = 0; i < n; i++) {
            arr[i]=s.nextInt();
           if(arr[i]<=b ){
               x+=arr[i];
               if(x>d){
                   ans++;
                   x=0;
               }
           }

        }

        System.out.println(ans);
        s.close();
    }
        }


import java.lang.*;
import java.util.*;
import java.io.*;
        public class TestClass {
            public static void main(String args[] ) {
                Scanner s = new Scanner(System.in);
                		int n = s.nextInt();
                		int[] arr = new int[n];
                		int b=s.nextInt();
                		int d = s.nextInt();
                		int x=0;
                		int ans=0;
        for (int i = 0; i <= n; i++) {
            arr[i]=input.nextInt();
           if(arr[i]<=b ){
               x+=arr[i];
               if(x>d){
                   ans++;
                   x=0;
               }
           }

        }

        System.out.println(ans);
    }
        }


import java.lang.*;
import java.util.Scanner;
import java.util.*;
import java.io.*;
        public class TestClass {
            public static void main(String args[] ) {
                Scanner s = new Scanner(System.in);
                		int n = s.nextInt();
                		int[] arr = new int[n];
                		int b=s.nextInt();
                		int d = s.nextInt();
                		int x=0;
                		int ans=0;
        for (int i = 0; i <= n; i++) {
            arr[i]=s.nextInt();
           if(arr[i]<=b ){
               x+=arr[i];
               if(x>d){
                   ans++;
                   x=0;
               }
           }

        }

        System.out.println(ans);
        s.close();
    }
        }


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        StringBuilder s=new StringBuilder();
        long n = Reader.nextLong(), b = Reader.nextLong(), d = Reader.nextLong(), m, cnt = 0, sum = 0;
        while(n-- >0) {
            m = Reader.nextInt();
            if(m <= b) {
                sum += m;
                if(sum == d)
                    sum = 0;
                else if(sum > d) {
                    sum %= d;
                    cnt++;
                }
            }
        }
        s.append(cnt).append('\n');
        System.out.print(s);
    }
}

class Reader {

    static StringTokenizer tokenizer;
    static BufferedReader reader;

    public static void init(InputStream input) throws UnsupportedEncodingException {
        reader=new BufferedReader(new InputStreamReader(input,"UTF-8"));
        tokenizer=new StringTokenizer("");
    }

    public static String next() throws IOException {
        while(!tokenizer.hasMoreTokens())
            tokenizer=new StringTokenizer(reader.readLine());
        return tokenizer.nextToken();
    }

    public static String nextLine() throws IOException {
        return reader.readLine();
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        StringBuilder s=new StringBuilder();
        long n = Reader.nextLong(), b = Reader.nextLong(), d = Reader.nextLong(), m, cnt = 0, sum = 0;
        while(n-- >0) {
            m = Reader.nextInt();
            if(m <= b) {
                sum += m;
                if(sum > d) {
                    if(sum % d == 0)
                        cnt += sum / d - 1;
                    else cnt += sum / d;
                    sum %= d;
                }
            }
        }
        s.append(cnt).append('\n');
        System.out.print(s);
    }
}

class Reader {

    static StringTokenizer tokenizer;
    static BufferedReader reader;

    public static void init(InputStream input) throws UnsupportedEncodingException {
        reader=new BufferedReader(new InputStreamReader(input,"UTF-8"));
        tokenizer=new StringTokenizer("");
    }

    public static String next() throws IOException {
        while(!tokenizer.hasMoreTokens())
            tokenizer=new StringTokenizer(reader.readLine());
        return tokenizer.nextToken();
    }

    public static String nextLine() throws IOException {
        return reader.readLine();
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args)throws IOException, URISyntaxException {
        Reader.init(System.in);
        StringBuilder s=new StringBuilder();
        long n = Reader.nextLong(), b = Reader.nextLong(), d = Reader.nextLong(), sum = 0, cur, cnt = 0;
        while(n-- > 0)
            if((cur = Reader.nextLong()) <= b) {
                sum += cur;
                if(sum > d) {
                    sum = 0;
                    cnt++;
                }
            }
        s.append(cnt).append('\n');
        System.out.print(s);
    }
}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) throws UnsupportedEncodingException {
        reader = new BufferedReader(
                     new InputStreamReader(input, "UTF-8") );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static String nextLine() throws IOException {
        return reader.readLine();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }

    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        StringBuilder s=new StringBuilder();
        long n = Reader.nextLong(), b = Reader.nextLong(), d = Reader.nextLong(), m, sum = 0, cnt = 0;
        while(n-- >0) {
            m = Reader.nextLong();
            if(m <= b) {
                sum += m;
                if(sum == d)
                    sum = 0;
                else if(sum > d) {
                    cnt++;
                    sum = 0;
                }
            }
        }
        s.append(cnt).append('\n');
        System.out.print(s);
    }
}

class Reader {

    static StringTokenizer tokenizer;
    static BufferedReader reader;

    public static void init(InputStream input) throws UnsupportedEncodingException {
        reader=new BufferedReader(new InputStreamReader(input,"UTF-8"));
        tokenizer=new StringTokenizer("");
    }

    public static String next() throws IOException {
        while(!tokenizer.hasMoreTokens())
            tokenizer=new StringTokenizer(reader.readLine());
        return tokenizer.nextToken();
    }

    public static String nextLine() throws IOException {
        return reader.readLine();
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        StringBuilder s=new StringBuilder();
        long n = Reader.nextLong(), b = Reader.nextLong(), d = Reader.nextLong(), m, sum = 0;
        while(n-- >0) {
            m = Reader.nextLong();
            if(m <= b)
                sum += m;
        }
        long c = sum % d == 0 ? 0 : 1;
        sum = sum / d - 1;
        if(sum < 0)
            sum = 0;
        s.append(sum + c).append('\n');
        System.out.print(s);
    }
}

class Reader {

    static StringTokenizer tokenizer;
    static BufferedReader reader;

    public static void init(InputStream input) throws UnsupportedEncodingException {
        reader=new BufferedReader(new InputStreamReader(input,"UTF-8"));
        tokenizer=new StringTokenizer("");
    }

    public static String next() throws IOException {
        while(!tokenizer.hasMoreTokens())
            tokenizer=new StringTokenizer(reader.readLine());
        return tokenizer.nextToken();
    }

    public static String nextLine() throws IOException {
        return reader.readLine();
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}


import java.util.*;

public class solution{

    public static void Main(String[] args){
    Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int size=scan.nextInt();
        int waster=scan.nextInt();
        int sum=0;
        int counter=0;
        for(int i=0;i<n;i++)
        {
            int x=scan.nextInt();
           if(x<=size)
             {
                 sum+=x;
                 if(sum>waster)
                 {
                     counter++;
                     sum=0;
                 }
             }
        }
        System.out.println(counter);
    }
}


import java.util.*;

public class solution{

    public static void Main(String[] args){
               Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int size=scan.nextInt();
        int waster=scan.nextInt();
        int sum=0;
        int counter=0;
        for(int i=0;i<n;i++)
        {
            int x=scan.nextInt();
           if(x<=size)
             {
                 sum+=x;
                 if(sum>waster)
                 {
                     counter++;
                     sum=0;
                 }
             }
        }
        System.out.print(counter);
    }
}


import java.util.Scanner;

public class solution{

    public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int size=scan.nextInt();
        int waster=scan.nextInt();
        int sum=0;
        int counter=0;
        for(int i=0;i<n;i++)
        {
            int x=scan.nextInt();
           if(x<=size)
             {
                 sum+=x;
                 if(sum>waster)
                 {
                     counter++;
                     sum=0;
                 }
             }
        }
        System.out.println(counter);
    }
}


import java.util.*;

public class solution{

    public static void Main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int size=scan.nextInt();
        int waster=scan.nextInt();
        int sum=0;
        int counter=0;
        for(int i=0;i<n;i++)
        {
            int x=scan.nextInt();
           if(x<=size)
             {
                 sum+=x;
                 if(sum>waster)
                 {
                     counter++;
                     sum=0;
                 }
             }
        }
        System.out.print(counter);
    }
}


import java.util.*;

public class solution{

    public static void Main(String[] args){
               Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int size=scan.nextInt();
        int waster=scan.nextInt();
        int sum=0;
        int counter=0;
        for(int i=0;i<n;i++)
        {
            int x=scan.nextInt();
           if(x<=size)
             {
                 sum+=x;
                 if(sum>waster)
                 {
                     counter++;
                     sum=0;
                 }
             }
        }
        System.out.println(counter);
    }
}


import java.util.Scanner;
public class solution{
    public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int size=scan.nextInt();
        int waster=scan.nextInt();
        int sum=0;
        int counter=0;
        for(int i=0;i<n;i++)
        {
           int x=scan.nextInt();

           if(x<=size)
             {
                 sum+=x;
                 if(sum>waster)
                 {
                     counter++;
                     sum=0;
                 }
             }
        }
        System.out.print(counter);
    }
}


import java.util.*;

public class solution{

    public static  void Main(String args[]){
        Scanner scan=new Scanner(System.in);
        int OrangeS[]=new int[scan.nextInt()];
        int size=scan.nextInt();
        int waster=scan.nextInt();
        int sum=0;
        int counter=0;
        for(int i=0;i<OrangeS.length;i++)
           if(OrangeS[i]<=size)
             {
                 sum+=OrangeS[i];
                 if(sum>waster)
                 {
                     counter++;
                     sum=0;
                 }
             }

        System.out.print(counter);
    }
}


import java.util.*;

public class solution{

    public static void Main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int OrangeS[]=new int[n];
        int size=scan.nextInt();
        int waster=scan.nextInt();
        int sum=0;
        int counter=0;
        for(int i=0;i<OrangeS.length;i++)
           if(OrangeS[i]<=size)
             {
                 sum+=OrangeS[i];
                 if(sum>waster)
                 {
                     counter++;
                     sum=0;
                 }
             }

        System.out.println(counter);
    }
}


//package acm;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author adMath.min
 */
import java.math.*;

public class Acm {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int d = sc.nextInt();
        int sum = 0;
        int s = 0;
        int r = 0;

        while (x > 0) {
            r = sc.nextInt();

        if(r<=y) {
                  sum += r;
                if (sum > d) {

                    s+=sum/d;
                    sum=sum%d;

                }

            }
            x--;
        }
        System.out.println(s);
    }
}


//package acm;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author adMath.min
 */
import java.math.*;

public class Acm {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
   int y=sc.nextInt();
   int d=sc.nextInt();
   int sum=0;
   int s=0;
    int r=0;
   while(x>0){
      r=sc.nextInt();
         s+=r/d;
   sum+=r%d;

   x--;}
        System.out.println(r==d?0:sum/d+s);
        }
    }


//package acm;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author adMath.min
 */
import java.math.*;

public class Acm {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int d = sc.nextInt();
        int sum = 0;
        int s = 0;
        int r = 0;
        while (x > 0) {
            r = sc.nextInt();

            sum += r % d;
if(x%2==0){
   s += r / d;
   s++;
 sum=0;

}
            x--;
        }
        System.out.println(r == d ? 0 : (sum / d) + s);
    }
}


//package acm;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author adMath.min
 */
import java.math.*;

public class Acm {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt() - 1;
        int y = sc.nextInt();
        int d = sc.nextInt();
        int sum = 0;
        int s = 0;
        int r = 0;
        r = sc.nextInt();

        sum += r;
        while (x > 0) {
            r = sc.nextInt();
            if (sum + r > d) {
                s++;
            }

            sum = 0;

            x--;
        }
        System.out.println(s);
    }
}


//package acm;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author adMath.min
 */
import java.math.*;

public class Acm {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int d = sc.nextInt();
        int sum = 0;
        int s = 0;
        int r = 0;

        while (x > 0) {
            r = sc.nextInt();

        if(r<=y) {
                  sum += r;
                if (sum > d) {

                    s+=sum/d;
                    sum=0;

                }

            }
            x--;
        }
        System.out.println(s);
    }
}


//package acm;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author adMath.min
 */
import java.math.*;

public class Acm {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt() - 1;
        int y = sc.nextInt();
        int d = sc.nextInt();
        int sum = 0;
        int s = 0;
        int r = 0;
        r = sc.nextInt();

        sum += r;
        while (x > 0) {
            r = sc.nextInt();
            if (sum + r > d) {
                s++;
            }

            sum =sum%d;

            x--;
        }
        System.out.println(s);
    }
}


//package acm;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author adMath.min
 */
import java.math.*;

public class Acm {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int d = sc.nextInt();
        int sum = 0;
        int s = 0;
        int r = 0;
        while (x > 0) {
            r = sc.nextInt();

            sum += r % d;
if(x%2==0){
   s += r / d;

}
            x--;
        }
        System.out.println(r == d ? 0 : (sum / d) + s);
    }
}


//package acm;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author adMath.min
 */
import java.math.*;

public class Acm {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt() - 1;
        int y = sc.nextInt();
        int d = sc.nextInt();
        int sum = 0;
        int s = 0;
        int r = 0;
        r = sc.nextInt();

        sum += r;
        while (x > 0) {

            for (int i = 0; i <= r; i++) {

                sum += 1;

                if (sum == d) {

                    s++;
                    sum = 0;

                }
            }
            x--;
        }
        System.out.println(r == d ? 0 : (sum / d) + s);
    }
}


//package acm;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author adMath.min
 */
import java.math.*;

public class Acm {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
   int y=sc.nextInt();
   int d=sc.nextInt();
   int sum=0;
   while(x>0){
   sum+=sc.nextInt();

   x--;}
        System.out.println(sum/d==d?0:sum/d);
        }
    }


//package acm;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author adMath.min
 */
import java.math.*;

public class Acm {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt() - 1;
        int y = sc.nextInt();
        int d = sc.nextInt();
        int sum = 0;
        int s = 0;
        int r = 0;
        r = sc.nextInt();

        sum += r;
        while (x > 0) {

            for (int i = 0; i <= r; i++) {

                sum += r;

                if (sum>= d) {

                    s++;
                    sum%=d;

                }
            }
            x--;
        }
        System.out.println(r == d ? 0 : (sum / d) + s);
    }
}


//package acm;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author adMath.min
 */
import java.math.*;

public class Acm {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
   int y=sc.nextInt();
   int d=sc.nextInt();
   int sum=0;
   while(x>0){
   sum+=sc.nextInt();

   x--;}
        System.out.println(sum/d);
        }
    }


//package acm;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author adMath.min
 */
import java.math.*;

public class Acm {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int d = sc.nextInt();
        int sum = 0;
        int s = 0;
        int r = 0;

        while (x > 0) {
            r = sc.nextInt();

        if(r<=y) {
                  sum += r;
                if (sum > d) {

                    s++;
                    sum=0;

                }

            }
            x--;
        }
        System.out.println(s);
    }
}


//package acm;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author adMath.min
 */
import java.math.*;

public class Acm {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt() - 1;
        int y = sc.nextInt();
        int d = sc.nextInt();
        int sum = 0;
        int s = 0;
        int r = 0;
        r = sc.nextInt();

        sum += r;
        while (x > 0) {

             s+=(sum+ r)/d;

                    sum = 0;

            x--;
        }
        System.out.println(r == d ? 0 : (sum / d) + s);
    }
}