#include <bits/stdc++.h>
using namespace std;
#define MAXN 2005
#define PII pair <int, int>
int arr [MAXN];
int dp[MAXN][3 * MAXN];
map <int, int> i, c;
int bc [MAXN * 3];
int findc [MAXN];
int main(){
    ios_base::sync_with_stdio(0);
    int n, k; cin >> n >> k;
    for (int g=1; g<=n; g++) cin >> arr[g];
    int lo = 0, hi = 2e9;
    while (hi > lo){
        int cnt = 1;
        int mid = (hi + lo)/2;
        c.clear();
        i.clear();
        memset(bc,0,sizeof(bc));
        for (int g=1; g<=n; g++) i[arr[g]] = 1, i[arr[g] + mid] = 1, i[arr[g] - mid] = 1;
        for (auto x = i.begin(); x!=i.end(); x++){
            bc[cnt] = x->first;
            c[x->first] = cnt++;
        }cnt--;
        memset(findc,0,sizeof(findc));
        for (int g=1; g<=n; g++) findc[g] = c[arr[g]];
        memset(dp, 0, sizeof(dp));
        for (int g=n; g>=1; g--){
            deque <PII> qu;
            int cur = 1;
            for (int y=1; y<=cnt; y++){
                while (cur<=n && bc[y]+mid>=bc[cur]){
                    int f = dp[g+1][cur];
                    while(qu.size() && qu.back().first>=f){
                        qu.pop_back();
                    }
                    qu.push_back(PII(f, cur));
                    cur++;
                }
                while (qu.size() && bc[qu[0].second]+mid < bc[y]){
                    qu.pop_front();
                }
                dp[g][y] = 2e9 + 5;
                if (abs(arr[g] - bc[y])<=mid){
                    dp[g][y] = dp[g+1][findc[g]];
                }
                if (qu.size()){
                    dp[g][y] = min(dp[g][y], 1 + qu[0].first);
                }
            }
        }
        if (dp[1][findc[1]] > k){
            lo = mid + 1;
        }
        else hi = mid;
    }
    cout << lo;
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define MAXN 2005
#define PII pair <int, int>
int arr [MAXN];
int dp[MAXN][3 * MAXN];
map <int, int> i;
unordered_map <int, int> c;
int bc [MAXN * 3];
int findc [MAXN];
main(){
    ios_base::sync_with_stdio(0);
    srand(time(0));
    int n, k;cin>>n>>k;
    for (int g=1; g<=n; g++) cin>>arr[g];
    int lo = 0, hi = 2e9;
    int cnt=1;
    for (int g=1; g<=n; g++) i[arr[g]] = 1;
        for (auto x = i.begin(); x!=i.end(); x++){
            bc[cnt] = x->first;
            c[x->first] = cnt++;
        }cnt--;
        for (int g=1; g<=n; g++) findc[g] = c[arr[g]];
    while (hi > lo){
        int mid = (hi + lo)/2;
        for (int g=n; g>=1; g--){
            deque <PII> qu;
            int cur = 1;
            for (int y=1; y<=cnt; y++){
                while (cur<=cnt && bc[y]+mid>=bc[cur]){
                    int f = dp[g+1][cur];
                    while(qu.size() && qu.back().first>=f){
                        qu.pop_back();
                    }
                    qu.push_back(PII(f, cur));
                    cur++;
                }
                while (qu.size() && bc[qu[0].second]+mid < bc[y]){
                    qu.pop_front();
                }
                dp[g][y] = 2e9 + 5;
                if (abs(arr[g] - bc[y])<=mid){
                    dp[g][y] = dp[g+1][findc[g]];
                }
                if (qu.size()){
                    dp[g][y] = min(dp[g][y], 1 + qu[0].first);
                }
            }
        }
        int answer = 2e9;
        for (int g=1; g<=cnt; g++){
            if (dp[1][g] < answer) answer = dp[1][g];
        }
        if (answer > k){
            lo = mid + 1;
        }
        else hi = mid;
    }
    cout << lo;
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define MAXN 2005
#define PII pair <int, int>
int arr [MAXN];
int dp[MAXN][3 * MAXN];
map <int, int> i;
unordered_map <int, int> c;
int bc [MAXN * 3];
int findc [MAXN];
main(){
    ios_base::sync_with_stdio(0);
    int n,k;cin>>n>>k;
    for (int g=1; g<=n; g++)cin>>arr[g];
    int lo = 0, hi = 2e9;
    while (hi > lo){
        int cnt = 1;
        int mid = (hi + lo)/2;
        i.clear();
        for (int g=1; g<=n; g++) i[arr[g]] = 1, i[arr[g] + mid] = 1, i[arr[g] - mid] = 1;
        for (auto x = i.begin(); x!=i.end(); x++){
            bc[cnt] = x->first;
            c[x->first] = cnt++;
        }cnt--;
        for (int g=1; g<=n; g++) findc[g] = c[arr[g]];
        for (int g=n; g>=1; g--){
            vector <PII> qu;
            int cur = 1;
            int z=0;
            for (int y=1; y<=cnt; y++){
                while (cur<=cnt && bc[y]+mid>=bc[cur]){
                    int f = dp[g+1][cur];
                    while(qu.size()>=z && qu.back().first>=f){
                        qu.pop_back();
                    }
                    qu.push_back(PII(f, cur));
                    cur++;
                }
                while (z<qu.size() && bc[qu[z].second]+mid < bc[y]){
                    z++;
                }
                dp[g][y] = 2e9+ 5;
                if (abs(arr[g] - bc[y])<=mid){
                    dp[g][y] = dp[g+1][findc[g]];
                }
                if (qu.size()>=z+1){
                    dp[g][y] = min(dp[g][y], 1 + qu[z].first);
                }
            }
        }
        int answer = 2e9;
        for (int g=1; g<=cnt; g++){
            if (dp[1][g] < answer) answer = dp[1][g];
        }
        if (answer > k){
            lo = mid + 1;
        }
        else hi = mid;
    }
    cout << lo;
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define MAXN 2005
#define PII pair <int, int>
int arr [MAXN];
int dp[MAXN][3 * MAXN];
map <int, int> i;
unordered_map <int, int> c;
int bc [MAXN * 3];
int findc [MAXN];
main(){
    ios_base::sync_with_stdio(0);
    int n,k;cin>>n>>k;
    for (int g=1; g<=n; g++)cin>>arr[g];
    int lo = 0, hi = 2e9;
    while (hi > lo){
        int cnt = 1;
        int mid = (hi + lo)/2;
        i.clear();
        for (int g=1; g<=n; g++) i[arr[g]] = 1, i[arr[g] + mid] = 1, i[arr[g] - mid] = 1;
        for (auto x = i.begin(); x!=i.end(); x++){
            bc[cnt] = x->first;
            c[x->first] = cnt++;
        }cnt--;
        for (int g=1; g<=n; g++) findc[g] = c[arr[g]];
        for (int g=n; g>=1; g--){
            vector <PII> qu;
            int cur = 1;
            int z=0;
            for (int y=1; y<=cnt; y++){
                while (cur<=cnt && bc[y]+mid>=bc[cur]){
                    int f = dp[g+1][cur];
                    while(qu.size()>z && qu.back().first>=f){
                        qu.pop_back();
                    }
                    qu.push_back(PII(f, cur));
                    cur++;
                }
                while (z<qu.size() && bc[qu[z].second]+mid < bc[y]){
                    z++;
                }
                dp[g][y] = 2e9+ 5;
                if (abs(arr[g] - bc[y])<=mid){
                    dp[g][y] = dp[g+1][findc[g]];
                }
                if (qu.size()>=z+1){
                    dp[g][y] = min(dp[g][y], 1 + qu[z].first);
                }
            }
        }
        int answer = 2e9;
        for (int g=1; g<=cnt; g++){
            if (dp[1][g] < answer) answer = dp[1][g];
        }
        if (answer > k){
            lo = mid + 1;
        }
        else hi = mid;
    }
    cout << lo;
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define int long long
#define MAXN 2005
#define PII pair <int, int>
int arr [MAXN];
int dp[MAXN][3 * MAXN];
map <int, int> i;
unordered_map <int, int> c;
int bc [MAXN * 3];
int findc [MAXN];
main(){
    ios_base::sync_with_stdio(0);
    int n, k; cin >> n >> k;
    for (int g=1; g<=n; g++) cin >> arr[g];
    int lo = 0, hi = 2e9;
    while (hi > lo){
        int cnt = 1;
        int mid = (hi + lo)/2;
        i.clear();
        for (int g=1; g<=n; g++) i[arr[g]] = 1, i[arr[g] + mid] = 1, i[arr[g] - mid] = 1;
        for (auto x = i.begin(); x!=i.end(); x++){
            bc[cnt] = x->first;
            c[x->first] = cnt++;
        }cnt--;
        for (int g=1; g<=n; g++) findc[g] = c[arr[g]];
        for (int g=n; g>=1; g--){
            deque <PII> qu;
            int cur = 1;
            for (int y=1; y<=cnt; y++){
                while (cur<=cnt && bc[y]+mid>=bc[cur]){
                    int f = dp[g+1][cur];
                    while(qu.size() && qu.back().first>=f){
                        qu.pop_back();
                    }
                    qu.push_back(PII(f, cur));
                    cur++;
                }
                while (qu.size() && bc[qu[0].second]+mid < bc[y]){
                    qu.pop_front();
                }
                dp[g][y] = 1e15 + 5;
                if (abs(arr[g] - bc[y])<=mid){
                    dp[g][y] = dp[g+1][findc[g]];
                }
                if (qu.size()){
                    dp[g][y] = min(dp[g][y], 1 + qu[0].first);
                }
            }
        }
        int answer = 1e15;
        for (int g=1; g<=cnt; g++){
            if (dp[1][g] < answer) answer = dp[1][g];
        }
        if (answer > k){
            lo = mid + 1;
        }
        else hi = mid;
    }
    cout << lo;
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define MAXN 2005
#define PII pair <int, int>
int arr [MAXN];
int dp[MAXN][3 * MAXN];
map <int, int> i;
unordered_map <int, int> c;
int bc [MAXN * 3];
int findc [MAXN];
main(){
    ios_base::sync_with_stdio(0);
    int n,k;cin>>n>>k;
    for (int g=1; g<=n; g++)cin>>arr[g];
    int lo = 0, hi = 2e9;
    while (hi > lo){
        int cnt = 1;
        int mid = (hi + lo)/2;
        i.clear();
        for (int g=1; g<=n; g++) i[arr[g]] = 1, i[arr[g] + mid] = 1, i[arr[g] - mid] = 1;
        for (auto x = i.begin(); x!=i.end(); x++){
            bc[cnt] = x->first;
            c[x->first] = cnt++;
        }cnt--;
        for (int g=1; g<=n; g++) findc[g] = c[arr[g]];
        for (int g=n; g>=1; g--){
            vector <PII> qu;
            int cur = 1;
            int z=0;
            for (int y=1; y<=cnt; y++){
                while (cur<=cnt && bc[y]+mid>=bc[cur]){
                    int f = dp[g+1][cur];
                    while(qu.size() && qu.back().first>=f){
                        qu.pop_back();
                    }
                    qu.push_back(PII(f, cur));
                    cur++;
                }
                while (z<qu.size() && bc[qu[z].second]+mid < bc[y]){
                    z++;
                }
                dp[g][y] = 2e9+ 5;
                if (abs(arr[g] - bc[y])<=mid){
                    dp[g][y] = dp[g+1][findc[g]];
                }
                if (qu.size()>=z+1){
                    dp[g][y] = min(dp[g][y], 1 + qu[z].first);
                }
            }
        }
        int answer = 2e9;
        for (int g=1; g<=cnt; g++){
            if (dp[1][g] < answer) answer = dp[1][g];
        }
        if (answer > k){
            lo = mid + 1;
        }
        else hi = mid;
    }
    cout << lo;
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define MAXN 2005
#define PII pair <int, int>
int arr [MAXN];
int dp[MAXN][3 * MAXN];
map <int, int> i;
unordered_map <int, int> c;
int bc [MAXN * 3];
int findc [MAXN];
main(){
    ios_base::sync_with_stdio(0);
    srand(time(0));
    int n = 2000, k = rand()%1000;
    for (int g=1; g<=n; g++) arr[g] = rand()*rand() * ((rand()%2)?(-1):(1));
    int lo = 0, hi = 2e9;
    int cnt=1;
    for (int g=1; g<=n; g++) i[arr[g]] = 1;
        for (auto x = i.begin(); x!=i.end(); x++){
            bc[cnt] = x->first;
            c[x->first] = cnt++;
        }cnt--;
        for (int g=1; g<=n; g++) findc[g] = c[arr[g]];
    while (hi > lo){
        int mid = (hi + lo)/2;
        for (int g=n; g>=1; g--){
            deque <PII> qu;
            int cur = 1;
            for (int y=1; y<=cnt; y++){
                while (cur<=cnt && bc[y]+mid>=bc[cur]){
                    int f = dp[g+1][cur];
                    while(qu.size() && qu.back().first>=f){
                        qu.pop_back();
                    }
                    qu.push_back(PII(f, cur));
                    cur++;
                }
                while (qu.size() && bc[qu[0].second]+mid < bc[y]){
                    qu.pop_front();
                }
                dp[g][y] = 2e9 + 5;
                if (abs(arr[g] - bc[y])<=mid){
                    dp[g][y] = dp[g+1][findc[g]];
                }
                if (qu.size()){
                    dp[g][y] = min(dp[g][y], 1 + qu[0].first);
                }
            }
        }
        int answer = 2e9;
        for (int g=1; g<=cnt; g++){
            if (dp[1][g] < answer) answer = dp[1][g];
        }
        if (answer > k){
            lo = mid + 1;
        }
        else hi = mid;
    }
    cout << lo;
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define int long long
#define MAXN 2005
#define PII pair <int, int>
int arr [MAXN];
int dp[MAXN][3 * MAXN];
map <int, int> i;
unordered_map <int, int> c;
int bc [MAXN * 3];
int findc [MAXN];
main(){
    ios_base::sync_with_stdio(0);
    int n,k;cin>>n>>k;
    for (int g=1; g<=n; g++)cin>>arr[g];
    int lo = 0, hi = 2e9;
    while (hi > lo){
        int cnt = 1;
        int mid = (hi + lo)/2;
        i.clear();
        for (int g=1; g<=n; g++) i[arr[g]] = 1, i[arr[g] + mid] = 1, i[arr[g] - mid] = 1;
        for (auto x = i.begin(); x!=i.end(); x++){
            bc[cnt] = x->first;
            c[x->first] = cnt++;
        }cnt--;
        for (int g=1; g<=n; g++) findc[g] = c[arr[g]];
        for (int g=n; g>=1; g--){
            vector <PII> qu;
            int cur = 1;
            int z=0;
            for (int y=1; y<=cnt; y++){
                while (cur<=cnt && bc[y]+mid>=bc[cur]){
                    int f = dp[g+1][cur];
                    while(qu.size() && qu.back().first>=f){
                        qu.pop_back();
                    }
                    qu.push_back(PII(f, cur));
                    cur++;
                }
                while (z<qu.size() && bc[qu[z].second]+mid < bc[y]){
                    z++;
                }
                dp[g][y] = 2e9+ 5;
                if (abs(arr[g] - bc[y])<=mid){
                    dp[g][y] = dp[g+1][findc[g]];
                }
                if (qu.size()>=z+1){
                    dp[g][y] = min(dp[g][y], 1 + qu[z].first);
                }
            }
        }
        int answer = 2e9;
        for (int g=1; g<=cnt; g++){
            if (dp[1][g] < answer) answer = dp[1][g];
        }
        if (answer > k){
            lo = mid + 1;
        }
        else hi = mid;
    }
    cout << lo;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MAXN 2005
#define PII pair <int, int>
int arr [MAXN];
int dp[MAXN][3 * MAXN];
map <int, int> i, c;
int bc [MAXN * 3];
int findc [MAXN];
main(){
    ios_base::sync_with_stdio(0);
    int n, k; cin >> n >> k;
    for (int g=1; g<=n; g++) cin >> arr[g];
    int lo = 0, hi = 2e9;
    while (hi > lo){
        int cnt = 1;
        int mid = (hi + lo)/2;
        c.clear();
        i.clear();
        memset(bc,0,sizeof(bc));
        for (int g=1; g<=n; g++) i[arr[g]] = 1, i[arr[g] + mid] = 1, i[arr[g] - mid] = 1;
        for (auto x = i.begin(); x!=i.end(); x++){
            bc[cnt] = x->first;
            c[x->first] = cnt++;
        }cnt--;
        memset(findc,0,sizeof(findc));
        for (int g=1; g<=n; g++) findc[g] = c[arr[g]];
        memset(dp, 0, sizeof(dp));
        for (int g=n; g>=1; g--){
            deque <PII> qu;
            int cur = 1;
            for (int y=1; y<=cnt; y++){
                while (cur<=cnt && bc[y]+mid>=bc[cur]){
                    int f = dp[g+1][cur];
                    while(qu.size() && qu.back().first>=f){
                        qu.pop_back();
                    }
                    qu.push_back(PII(f, cur));
                    cur++;
                }
                while (qu.size() && bc[qu[0].second]+mid < bc[y]){
                    qu.pop_front();
                }
                dp[g][y] = 1e15 + 5;
                if (abs(arr[g] - bc[y])<=mid){
                    dp[g][y] = dp[g+1][findc[g]];
                }
                if (qu.size()){
                    dp[g][y] = min(dp[g][y], 1 + qu[0].first);
                }
            }
        }
        if (dp[1][findc[1]] > k){
            lo = mid + 1;
        }
        else hi = mid;
    }
    cout << lo;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MAXN 2005
#define PII pair <int, int>
int arr [MAXN];
int dp[MAXN][3 * MAXN];
map <int, int> i, c;
int bc [MAXN * 3];
int findc [MAXN];
main(){
    ios_base::sync_with_stdio(0);
    int n, k; cin >> n >> k;
    for (int g=1; g<=n; g++) cin >> arr[g];
    int lo = 0, hi = 2e9;
    while (hi > lo){
        int cnt = 1;
        int mid = (hi + lo)/2;
        c.clear();
        i.clear();
        memset(bc,0,sizeof(bc));
        for (int g=1; g<=n; g++) i[arr[g]] = 1, i[arr[g] + mid] = 1, i[arr[g] - mid] = 1;
        for (auto x = i.begin(); x!=i.end(); x++){
            bc[cnt] = x->first;
            c[x->first] = cnt++;
        }cnt--;
        memset(findc,0,sizeof(findc));
        for (int g=1; g<=n; g++) findc[g] = c[arr[g]];
        memset(dp, 0, sizeof(dp));
        for (int g=n; g>=1; g--){
            deque <PII> qu;
            int cur = 1;
            for (int y=1; y<=cnt; y++){
                while (cur<=n && bc[y]+mid>=bc[cur]){
                    int f = dp[g+1][cur];
                    while(qu.size() && qu.back().first>=f){
                        qu.pop_back();
                    }
                    qu.push_back(PII(f, cur));
                    cur++;
                }
                while (qu.size() && bc[qu[0].second]+mid < bc[y]){
                    qu.pop_front();
                }
                dp[g][y] = 1e10 + 5;
                if (abs(arr[g] - bc[y])<=mid){
                    dp[g][y] = dp[g+1][findc[g]];
                }
                if (qu.size()){
                    dp[g][y] = min(dp[g][y], 1 + qu[0].first);
                }
            }
        }
        if (dp[1][findc[1]] > k){
            lo = mid + 1;
        }
        else hi = mid;
    }
    cout << lo;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define maxn 1007
using namespace std;

ll n,k;
ll a[maxn];
ll ans=1e16+7;
ll dp[maxn];

bool ok(ll x)
{
//	cout<<x<<endl;
//	memset(dp,0,sizeof(dp));//前i个的最小差值，第i个不动
	for(int i=1;i<=n;i++)
	{
		dp[i]=i-1;
		for(int j=1;j<i;j++)
		{
			if(abs(a[i]-a[j])<=(i-j)*x)
			{
				dp[i]=min(dp[i],dp[j]+(i-j-1));
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(dp[i]+(n-i)<=k)
		{
//			cout<<dp[i]<<" "<<(n-i)<<"****"<<endl;
			return 1;
		}
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
//	freopen("chaos.in","r",stdin);
//	freopen("chaos.out","w",stdout);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	{
		ll l=0,r=(1ll<<55);
		while(r-l>3)
		{
			ll mid=(l+r)/2;
			if(ok(mid)) r=mid;
			else l=mid;
		}
		for(ll i=l;i<=r;i++)
		{
			if(ok(i))
			{
				cout<<i;
				return 0;
			}
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define maxn 1007
using namespace std;

int n,k;
ll a[maxn];
ll ans=1e16+7;
ll dp[maxn];

bool ok(ll x)
{
//	cout<<x<<endl;
//	memset(dp,0,sizeof(dp));//前i个的最小差值，第i个不动
	for(int i=1;i<=n;i++)
	{
		dp[i]=i-1;
		for(int j=1;j<i;j++)
		{
			if(abs(a[i]-a[j])<=(i-j)*x)
			{
				dp[i]=min(dp[i],dp[j]+(i-j-1));
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(dp[i]+(n-i)<=k)
		{
//			cout<<dp[i]<<" "<<(n-i)<<"****"<<endl;
			return 1;
		}
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
//	freopen("chaos.in","r",stdin);
//	freopen("chaos.out","w",stdout);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	ll l=0,r=(1ll<<55);
	while(r-l>5)
	{
		ll mid=(l+r)/2;
		if(ok(mid)) r=mid;
		else l=mid;
	}
	for(int i=l;i<=r;i++)
	{
		if(ok(i))
		{
			cout<<i;
			return 0;
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define maxn 1007
using namespace std;

int n,k;
ll a[maxn];
int c[maxn];
ll ans=1e16+7;
int dp[maxn];

ll ck()
{
	ll maxx=0;
	for(int i=1;i<n;i++)
	{
		maxx=max(maxx,abs(a[i]-a[i+1]));
	}
	return maxx;
}

void dfs(int u,int lk)
{
//	cout<<u<<" "<<lk<<endl;
//	for(int i=1;i<=n;i++) cout<<a[i]<<" ";
//	cout<<endl;
	if(lk==0 || u>n)
	{
		ans=min(ans,ck());
		return;
	}
	else
	{
		if(lk)
		{
			if(u==1)
			{
				int xx=a[u];
				a[u]=a[u+1];
				dfs(u+1,lk-1);
				a[u]=xx;
				dfs(u+1,lk);
			}
			else if(u==n)
			{
				int xx=a[u];
				a[u]=a[u-1];
				dfs(u+1,lk-1);
				a[u]=xx;
			//	dfs(u+1,lk);
			}
			else
			{
				int xx=a[u];
				a[u]=a[u+1];
				dfs(u+1,lk-1);
				a[u]=a[u-1];
				dfs(u+1,lk-1);
				a[u]=(a[u+1]+a[u-1])/2;
				dfs(u+1,lk-1);
				a[u]=xx;
				dfs(u+1,lk);
			}
		}
	}
}

bool ok(int x)
{
//	cout<<x<<endl;
//	memset(dp,0,sizeof(dp));//前i个的最小差值，第i个不动
	for(int i=1;i<=n;i++)
	{
		dp[i]=i-1;
		for(int j=1;j<i;j++)
		{
			if(abs(a[i]-a[j])<=(i-j)*x)
			{
				dp[i]=min(dp[i],dp[j]+(i-j-1));
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(dp[i]+(n-i)<=k)
		{
//			cout<<dp[i]<<" "<<(n-i)<<"****"<<endl;
			return 1;
		}
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
//	freopen("chaos.in","r",stdin);
//	freopen("chaos.out","w",stdout);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	{
		int l=0,r=1e9;
		while(r-l>3)
		{
			int mid=(l+r)/2;
			if(ok(mid)) r=mid;
			else l=mid;
		}
		for(int i=l;i<=r;i++)
		{
			if(ok(i))
			{
				cout<<i;
				return 0;
			}
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define maxn 1007
using namespace std;

int n,k;
ll a[maxn];
ll ans=1e16+7;
ll dp[maxn];

ll ck()
{
	ll maxx=0;
	for(int i=1;i<n;i++)
	{
		maxx=max(maxx,abs(a[i]-a[i+1]));
	}
	return maxx;
}

void dfs(int u,int lk)
{
//	cout<<u<<" "<<lk<<endl;
//	for(int i=1;i<=n;i++) cout<<a[i]<<" ";
//	cout<<endl;
	if(lk==0 || u>n)
	{
		ans=min(ans,ck());
		return;
	}
	else
	{
		if(lk)
		{
			if(u==1)
			{
				int xx=a[u];
				a[u]=a[u+1];
				dfs(u+1,lk-1);
				a[u]=xx;
				dfs(u+1,lk);
			}
			else if(u==n)
			{
				int xx=a[u];
				a[u]=a[u-1];
				dfs(u+1,lk-1);
				a[u]=xx;
			//	dfs(u+1,lk);
			}
			else
			{
				int xx=a[u];
				a[u]=a[u+1];
				dfs(u+1,lk-1);
				a[u]=a[u-1];
				dfs(u+1,lk-1);
				a[u]=(a[u+1]+a[u-1])/2;
				dfs(u+1,lk-1);
				a[u]=xx;
				dfs(u+1,lk);
			}
		}
	}
}

bool ok(ll x)
{
//	cout<<x<<endl;
//	memset(dp,0,sizeof(dp));//前i个的最小差值，第i个不动
	for(int i=1;i<=n;i++)
	{
		dp[i]=i-1;
		for(int j=1;j<i;j++)
		{
			if(abs(a[i]-a[j])<=(i-j)*x)
			{
				dp[i]=min(dp[i],dp[j]+(i-j-1));
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(dp[i]+(n-i)<=k)
		{
//			cout<<dp[i]<<" "<<(n-i)<<"****"<<endl;
			return 1;
		}
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
//	freopen("chaos.in","r",stdin);
//	freopen("chaos.out","w",stdout);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	{
		ll l=0,r=1e16;
		while(r-l>3)
		{
			ll mid=(l+r)/2;
			if(ok(mid)) r=mid;
			else l=mid;
		}
		for(ll i=l;i<=r;i++)
		{
			if(ok(i))
			{
				cout<<i;
				return 0;
			}
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define maxn 2007
using namespace std;

int n,k;
ll a[maxn];
ll ans=1e16+7;
ll dp[maxn];

bool ok(ll x)
{
//	cout<<x<<endl;
//	memset(dp,0,sizeof(dp));//前i个的最小差值，第i个不动
	for(int i=1;i<=n;i++)
	{
		dp[i]=i-1;
		for(int j=1;j<i;j++)
		{
			if(abs(a[i]-a[j])<=(i-j)*x)
			{
				dp[i]=min(dp[i],dp[j]+(i-j-1));
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(dp[i]+(n-i)<=k)
		{
//			cout<<dp[i]<<" "<<(n-i)<<"****"<<endl;
			return 1;
		}
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
//	freopen("chaos.in","r",stdin);
//	freopen("chaos.out","w",stdout);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	ll l=0,r=(1ll<<55);
	while(r-l>5)
	{
		ll mid=(l+r)/2;
		if(ok(mid)) r=mid;
		else l=mid;
	}
	for(int i=l;i<=r;i++)
	{
		if(ok(i))
		{
			cout<<i;
			return 0;
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define maxn 1007
using namespace std;

ll n,k;
ll a[maxn];
ll ans=1e16+7;
ll dp[maxn];

bool ok(ll x)
{
//	cout<<x<<endl;
//	memset(dp,0,sizeof(dp));//前i个的最小差值，第i个不动
	for(int i=1;i<=n;i++)
	{
		dp[i]=i-1;
		for(int j=1;j<i;j++)
		{
			if(abs(a[i]-a[j])<=(i-j)*x)
			{
				dp[i]=min(dp[i],dp[j]+(i-j-1));
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(dp[i]+(n-i)<=k)
		{
//			cout<<dp[i]<<" "<<(n-i)<<"****"<<endl;
			return 1;
		}
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
//	freopen("chaos.in","r",stdin);
//	freopen("chaos.out","w",stdout);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	{
		ll l=0,r=1e16;
		while(r-l>3)
		{
			ll mid=(l+r)/2;
			if(ok(mid)) r=mid;
			else l=mid;
		}
		for(ll i=l;i<=r;i++)
		{
			if(ok(i))
			{
				cout<<i;
				return 0;
			}
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define maxn 1007
using namespace std;

int n,k;
ll a[maxn];
ll ans=1e16+7;
ll dp[maxn];

ll ck()
{
	ll maxx=0;
	for(int i=1;i<n;i++)
	{
		maxx=max(maxx,abs(a[i]-a[i+1]));
	}
	return maxx;
}

void dfs(int u,int lk)
{
//	cout<<u<<" "<<lk<<endl;
//	for(int i=1;i<=n;i++) cout<<a[i]<<" ";
//	cout<<endl;
	if(lk==0 || u>n)
	{
		ans=min(ans,ck());
		return;
	}
	else
	{
		if(lk)
		{
			if(u==1)
			{
				int xx=a[u];
				a[u]=a[u+1];
				dfs(u+1,lk-1);
				a[u]=xx;
				dfs(u+1,lk);
			}
			else if(u==n)
			{
				int xx=a[u];
				a[u]=a[u-1];
				dfs(u+1,lk-1);
				a[u]=xx;
			//	dfs(u+1,lk);
			}
			else
			{
				int xx=a[u];
				a[u]=a[u+1];
				dfs(u+1,lk-1);
				a[u]=a[u-1];
				dfs(u+1,lk-1);
				a[u]=(a[u+1]+a[u-1])/2;
				dfs(u+1,lk-1);
				a[u]=xx;
				dfs(u+1,lk);
			}
		}
	}
}

bool ok(int x)
{
//	cout<<x<<endl;
//	memset(dp,0,sizeof(dp));//前i个的最小差值，第i个不动
	for(int i=1;i<=n;i++)
	{
		dp[i]=i-1;
		for(int j=1;j<i;j++)
		{
			if(abs(a[i]-a[j])<=(i-j)*x)
			{
				dp[i]=min(dp[i],dp[j]+(i-j-1));
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(dp[i]+(n-i)<=k)
		{
//			cout<<dp[i]<<" "<<(n-i)<<"****"<<endl;
			return 1;
		}
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
//	freopen("chaos.in","r",stdin);
//	freopen("chaos.out","w",stdout);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	{
		ll l=0,r=1e16;
		while(r-l>3)
		{
			ll mid=(l+r)/2;
			if(ok(mid)) r=mid;
			else l=mid;
		}
		for(ll i=l;i<=r;i++)
		{
			if(ok(i))
			{
				cout<<i;
				return 0;
			}
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define maxn 1007
using namespace std;

int n,k;
ll a[maxn];
ll ans=1e16+7;
ll dp[maxn];

bool ok(ll x)
{
//	cout<<x<<endl;
//	memset(dp,0,sizeof(dp));//前i个的最小差值，第i个不动
	for(int i=1;i<=n;i++)
	{
		dp[i]=i-1;
		for(int j=1;j<i;j++)
		{
			if(abs(a[i]-a[j])<=(i-j)*x)
			{
				dp[i]=min(dp[i],dp[j]+(i-j-1));
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(dp[i]+(n-i)<=k)
		{
//			cout<<dp[i]<<" "<<(n-i)<<"****"<<endl;
			return 1;
		}
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
//	freopen("chaos.in","r",stdin);
//	freopen("chaos.out","w",stdout);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	{
		ll l=0,r=(1ll<<55);
		while(r-l>3)
		{
			ll mid=(l+r)/2;
			if(ok(mid)) r=mid;
			else l=mid;
		}
		for(int i=l;i<=r;i++)
		{
			if(ok(i))
			{
				cout<<i;
				return 0;
			}
		}
	}
	return 0;
}


//editor: Jan Tang
//problem:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
using namespace std;
#define set0(a) memset(a,0,sizeof(a));
#define CIN(a,n) for(int i=1;i<=n;i++) cin>>a[i];
typedef long long ll;
typedef unsigned long long ull;
const int Mod = 1e9+7;
const int maxn = 2005;
const int inf = 0x3f3f3f3f;
int k,n,dp[maxn], a[maxn];
bool check(ll x){
//dp[i]代表不改变第i个数的情况下前i-1个数最少需要改变的数的个数
	memset(dp, inf, sizeof(dp));
	dp[1] = 0;
	for(int i = 1; i < n; i++){
		for(int j = i+1; j <= n; j++){
			if(x * (j-i) >= a[j] - a[i]) dp[j] = min(dp[j], dp[i] + j-i-1);
		}
	}
	int ans = inf;
	for(int i = 1; i <= n; i++) ans = min(ans, dp[i]+n-i);

	if(ans<=k) return true;
	else return false;
}
/*==============================head==========================*/
int main(){
	while(scanf("%d%d",&n,&k)!=EOF){
		for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
		ll r = 2*inf, l = 0;
		while(l<r){
			ll mid = (r-l)/2 + l;
			if(check(mid)) r = mid;
			else l = mid+1;
		}
		cout << l << endl;
	}
	return 0;
}


//editor: Jan Tang
//problem:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
using namespace std;
#define set0(a) memset(a,0,sizeof(a));
#define CIN(a,n) for(int i=1;i<=n;i++) cin>>a[i];
typedef long long ll;
typedef unsigned long long ull;
const int Mod = 1e9+7;
const int maxn = 2005;
const int inf = 0x3f3f3f3f;
int k,n,dp[maxn], a[maxn];
bool check(ll x){
//	cout << x << endl;
	memset(dp, inf, sizeof(dp));
	dp[1] = 0;
	for(int i = 1; i < n; i++){
		for(int j = i+1; j <= n; j++){
			if(x * (j-i) >= a[j] - a[i]) dp[j] = min(dp[j], dp[i] + j-i-1);
		}
	}
	for(int i = 1; i <= n; i++) if(dp[i] == inf) dp[i] = dp[i-1] + 1;
//	for(int i = 1; i <=n; i++)printf("dp[%d] = %d\n", i, dp[i]);
	if(dp[n]<=k) return true;
	else return false;
}
/*==============================head==========================*/
int main(){
	while(scanf("%d%d",&n,&k)!=EOF){
		for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
		ll r = 2*inf, l = 0;
		while(l<r){
			ll mid = (r-l)/2 + l;
			if(check(mid)) r = mid;
			else l = mid+1;
		}
		cout << l << endl;
	}
	return 0;
}


//editor: Jan Tang
//problem:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
using namespace std;
#define set0(a) memset(a,0,sizeof(a));
#define CIN(a,n) for(int i=1;i<=n;i++) cin>>a[i];
typedef long long ll;
typedef unsigned long long ull;
const int Mod = 1e9+7;
const int maxn = 2005;
const int inf = 0x3f3f3f3f;
int k,n,dp[maxn], a[maxn];
bool check(ll x){
//dp[i]代表不改变第i个数的情况下前i-1个数最少需要改变的数的个数
//	cout << x << endl;
	for(int i = 1; i <= n; i++) dp[i] = i-1;

	for(int i = 1; i <= n; i++){
		for(int j = i+1; j <= n; j++){
			if(x * (j-i) >= abs(a[j] - a[i])) dp[j] = min(dp[j], dp[i] + j-i-1);
		}
//		printf("dp[%d] = %d\n", i, dp[i]);
	}
	int ans = inf;
	for(int i = 1; i <= n; i++) ans = min(ans, dp[i]+n-i);

	if(ans<=k) return true;
	else return false;
}
/*==============================head==========================*/
int main(){
	while(scanf("%d%d",&n,&k)!=EOF){
		for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
		ll r = 2*inf, l = 0;
		while(l<r){
			ll mid = (r-l)/2 + l;
			if(check(mid)) r = mid;
			else l = mid+1;
		}
		cout << r << endl;
	}
	return 0;
}


//editor: Jan Tang
//problem:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
using namespace std;
#define set0(a) memset(a,0,sizeof(a));
#define CIN(a,n) for(int i=1;i<=n;i++) cin>>a[i];
typedef long long ll;
typedef unsigned long long ull;
const int Mod = 1e9+7;
const int maxn = 2005;
const int inf = 0x3f3f3f3f;
int k,n,dp[maxn], a[maxn];
bool check(ll x){
//dp[i]代表不改变第i个数的情况下前i-1个数最少需要改变的数的个数
	memset(dp, inf, sizeof(dp));
	dp[1] = 0;
	for(int i = 1; i < n; i++){
		for(int j = i+1; j <= n; j++){
			if(x * (j-i) >= abs(a[j] - a[i])) dp[j] = min(dp[j], dp[i] + j-i-1);
		}
	}
	int ans = inf;
	for(int i = 1; i <= n; i++) ans = min(ans, dp[i]+n-i);

	if(ans<=k) return true;
	else return false;
}
/*==============================head==========================*/
int main(){
	while(scanf("%d%d",&n,&k)!=EOF){
		for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
		ll r = 2*inf, l = 0;
		while(l<r){
			ll mid = (r-l)/2 + l;
			if(check(mid)) r = mid;
			else l = mid+1;
		}
		cout << r << endl;
	}
	return 0;
}


//editor: Jan Tang
//problem:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
using namespace std;
#define set0(a) memset(a,0,sizeof(a));
#define CIN(a,n) for(int i=1;i<=n;i++) cin>>a[i];
typedef long long ll;
typedef unsigned long long ull;
const int Mod = 1e9+7;
const int maxn = 2005;
const int inf = 0x3f3f3f3f;
int k,n,dp[maxn], a[maxn];
bool check(ll x){
//dp[i]代表不改变第i个数的情况下前i-1个数最少需要改变的数的个数
//	cout << x << endl;
	memset(dp, inf, sizeof(dp));
	dp[1] = 0;
	for(int i = 1; i <= n; i++){
		dp[i] = i-1;
		for(int j = i+1; j <= n; j++){
			if(x * (j-i) >= abs(a[j] - a[i])) dp[j] = min(dp[j], dp[i] + j-i-1);
		}
//		printf("dp[%d] = %d\n", i, dp[i]);
	}
	int ans = inf;
	for(int i = 1; i <= n; i++) ans = min(ans, dp[i]+n-i);

	if(ans<=k) return true;
	else return false;
}
/*==============================head==========================*/
int main(){
	while(scanf("%d%d",&n,&k)!=EOF){
		for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
		ll r = 2*inf, l = 0;
		while(l<r){
			ll mid = (r-l)/2 + l;
			if(check(mid)) r = mid;
			else l = mid+1;
		}
		cout << r << endl;
	}
	return 0;
}


#include<iostream>
#include<map>
#include<algorithm>

using namespace std;

map<string, int> nombres;
map<int, string> desNames;

int main() {
    ios_base::sync_with_stdio(false);

    int n, d;
    cin >> n >> d;
    int countNames = 1;
    int matrixTimes[n][n];
    int occurs[n][n];
    int memo[n][n];

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            memo[i][j] = -1;
            occurs[i][j] = -1;
            matrixTimes[i][j] = -1;
        }
    }

    string ans = "";

    int valAns = 0;

    for (int k = 0; k < n; k++) {
        string firstName, secondName;
        int time;
        cin >> firstName >> secondName >> time;

        if (nombres[firstName] == 0) {
            nombres[firstName] = countNames;
            desNames[countNames] = firstName;
            countNames++;

        }
        if (nombres[secondName] == 0) {
            nombres[secondName] = countNames;
            desNames[countNames] = secondName;
            countNames++;

        }

        int i = nombres[firstName] - 1;
        int j = nombres[secondName] - 1;

        matrixTimes[i][j] = time;

        occurs[i][j] = 1;

        if (occurs[i][j] == 1 && occurs[j][i] == 1) {
            int time2 = matrixTimes[i][j];
            int time1 = matrixTimes[j][i];

            int value = time2 - time1;
            if (value > 0 && value <= d) {
                if (i < j)
                    memo[i][j] = 1;
                else
                    memo[j][i] = 1;
            }
        }

    }
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (memo[i][j] > 0) {
                valAns++;
                ans = ans + desNames[i+1] + " " + desNames[j+1] + "\n";
            }
        }
    }
    cout << valAns << "\n" << ans;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, d;
    int tt;
    string aa, bb;
    cin >> n >> d;
    vector<string> a;
    vector<string> b;
    vector<int> t;
    int f = 0;
    int rand =2;
    vector<pair<string, string>> friends;
    for(int i =0; i < n; i++)
    {
        cin >> aa >>bb >>tt;
        if(tt != 0)
        {
            a.push_back(aa);
            b.push_back(bb);
            t.push_back(tt);
        }
    }
    for(int i =0; i < a.size(); i++)
    {
        for(int j =0; j < a.size(); j++)
        {
            if(a[i] == b[j] && b[i] == a[j])
            {
                if(t[j] - t[i] <= d)
                {
                    //cout <<a[i]<<" "<<b[j]<<t[j] - t[i] << endl;
                    f += 1;
                    friends.push_back(make_pair(a[i], b[i]));
                    a.pop_back();
                    b.pop_back();
                    t.pop_back();
                }
                else
                {
                    a.pop_back();
                    b.pop_back();
                    t.pop_back();
                }
            }
        }
    }
    for(int i =0; i < friends.size(); i++)
    {
        for(int j = 0;j < friends.size();j++)
        {
            if(((friends[i].first == friends[j].second) && (friends[j].first == friends[i].second))||((friends[i].first == friends[j].first) && (friends[i].second == friends[j].second && (j != i))))
            {
                friends.erase(friends.begin()+j);
                f--;
                j = 0;
            }
        }
    }
    cout << f << endl;
    for(int i =0; i < friends.size(); i++)
    {
        cout <<friends[i].first<<" "<<friends[i].second<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, d;
    cin >> n >> d;
    string a[n], b[n];
    int t[n];
    int f = 0;
    int rand =2;
    vector<pair<string, string>> friends;
    for(int i =0; i < n; i++)
    {
        cin >> a[i] >>b[i] >>t[i];
    }
    for(int i =0; i < n; i++)
    {
        for(int j =0; j < n; j++)
        {
            if(a[i] == b[j])
            {
                if(t[j] - t[i] <= d)
                {
                    cout <<a[i]<<" "<<b[j]<<t[j] - t[i] << endl;
                    f += 1;
                    friends.push_back(make_pair(a[i], b[i]));
                    a[i] = a[i]+ to_string(rand++);
                    b[i] = a[i]+ to_string(rand++);
                    a[j] = a[i]+ to_string(rand++);
                    b[j] = a[i]+ to_string(rand++);
                }
                else
                {
                    a[i] = a[i]+ to_string(rand++);
                    b[i] = a[i]+ to_string(rand++);
                    a[j] = a[i]+ to_string(rand++);
                    b[j] = a[i]+ to_string(rand++);
                }
            }
        }
    }
    cout << f << endl;
    for(int i =0; i < friends.size(); i++)
    {
        cout << friends[i].first<<" "<<friends[i].second<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, d;
    cin >> n >> d;
    string a[n], b[n];
    int t[n];
    int f = 0;
    int rand =2;
    vector<pair<string, string>> friends;
    for(int i =0; i < n; i++)
    {
        cin >> a[i] >>b[i] >>t[i];
    }
    for(int i =0; i < n; i++)
    {
        for(int j =0; j < n; j++)
        {
            if(a[i] == b[j] && b[i] == a[j])
            {
                if(t[i] == 0)
                {
                    a[i] = a[i]+ to_string(rand++);
                    b[i] = a[i]+ to_string(rand++);
                }
                if(t[j] == 0)
                {
                    a[j] = a[i]+ to_string(rand++);
                    b[j] = a[i]+ to_string(rand++);
                }
                else if(t[j] - t[i] <= d)
                {
                    //cout <<a[i]<<" "<<b[j]<<t[j] - t[i] << endl;
                    f += 1;
                    friends.push_back(make_pair(a[i], b[i]));
                    a[i] = a[i]+ to_string(rand++);
                    b[i] = a[i]+ to_string(rand++);
                    a[j] = a[i]+ to_string(rand++);
                    b[j] = a[i]+ to_string(rand++);
                }
                else
                {
                    a[i] = a[i]+ to_string(rand++);
                    b[i] = a[i]+ to_string(rand++);
                    a[j] = a[i]+ to_string(rand++);
                    b[j] = a[i]+ to_string(rand++);
                }
            }
        }
    }
    cout << f << endl;
    for(int i =0; i < friends.size(); i++)
    {
        cout << friends[i].first<<" "<<friends[i].second<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, d;
    cin >> n >> d;
    string a[n], b[n];
    int t[n];
    int f = 0;
    int rand =2;
    vector<pair<string, string>> friends;
    for(int i =0; i < n; i++)
    {
        cin >> a[i] >>b[i] >>t[i];
    }
    for(int i =0; i < n; i++)
    {
        for(int j =0; j < n; j++)
        {
            if(a[i] == b[j])
            {
                if(t[i] == 0)
                {
                    a[i] = a[i]+ to_string(rand++);
                    b[i] = a[i]+ to_string(rand++);
                }
                if(t[j] == 0)
                {
                    a[j] = a[i]+ to_string(rand++);
                    b[j] = a[i]+ to_string(rand++);
                }
                else if(t[j] - t[i] <= d)
                {
                    //cout <<a[i]<<" "<<b[j]<<t[j] - t[i] << endl;
                    f += 1;
                    friends.push_back(make_pair(a[i], b[i]));
                    a[i] = a[i]+ to_string(rand++);
                    b[i] = a[i]+ to_string(rand++);
                    a[j] = a[i]+ to_string(rand++);
                    b[j] = a[i]+ to_string(rand++);
                }
                else
                {
                    a[i] = a[i]+ to_string(rand++);
                    b[i] = a[i]+ to_string(rand++);
                    a[j] = a[i]+ to_string(rand++);
                    b[j] = a[i]+ to_string(rand++);
                }
            }
        }
    }
    cout << f << endl;
    for(int i =0; i < friends.size(); i++)
    {
        cout << friends[i].first<<" "<<friends[i].second<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, d;
    cin >> n >> d;
    string a[n], b[n];
    int t[n];
    int f = 0;
    int rand =2;
    vector<pair<string, string>> friends;
    for(int i =0; i < n; i++)
    {
        cin >> a[i] >>b[i] >>t[i];
    }
    for(int i =0; i < n; i++)
    {
        for(int j =0; j < n; j++)
        {
            if(a[i] == b[j])
            {
                if(t[j] - t[i] <= d)
                {
                    //cout <<a[i]<<" "<<b[j]<<t[j] - t[i] << endl;
                    f += 1;
                    friends.push_back(make_pair(a[i], b[i]));
                    a[i] = a[i]+ to_string(rand++);
                    b[i] = a[i]+ to_string(rand++);
                    a[j] = a[i]+ to_string(rand++);
                    b[j] = a[i]+ to_string(rand++);
                }
                else
                {
                    a[i] = a[i]+ to_string(rand++);
                    b[i] = a[i]+ to_string(rand++);
                    a[j] = a[i]+ to_string(rand++);
                    b[j] = a[i]+ to_string(rand++);
                }
            }
        }
    }
    cout << f << endl;
    for(int i =0; i < friends.size(); i++)
    {
        cout << friends[i].first<<" "<<friends[i].second<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, d;
    int tt;
    string aa, bb;
    cin >> n >> d;
    vector<string> a;
    vector<string> b;
    vector<int> t;
    int f = 0;
    int rand =2;
    vector<pair<string, string>> friends;
    for(int i =0; i < n; i++)
    {
        cin >> aa >>bb >>tt;
        if(tt != 0)
        {
            a.push_back(aa);
            b.push_back(bb);
            t.push_back(tt);
        }
    }
    for(int i =0; i < a.size(); i++)
    {
        for(int j =0; j < a.size(); j++)
        {
            if(a[i] == b[j] && b[i] == a[j])
            {
                if(t[j] - t[i] <= d)
                {
                    //cout <<a[i]<<" "<<b[j]<<t[j] - t[i] << endl;
                    f += 1;
                    friends.push_back(make_pair(a[i], b[i]));
                    a.pop_back();
                    b.pop_back();
                    t.pop_back();
                }
                else
                {
                    a.pop_back();
                    b.pop_back();
                    t.pop_back();
                }
            }
        }
    }
    for(int i =0; i < friends.size(); i++)
    {
        for(int j = 0;j < friends.size();j++)
        {
            if((friends[i].first == friends[j].second && friends[j].first == friends[i].second)||(friends[i].first == friends[j].first && friends[i].second == friends[j].second) )
            {
                friends.erase(friends.begin()+j);
                f--;
            }
        }
    }
    cout << f << endl;
    for(int i =0; i < friends.size(); i++)
    {
        cout << friends[i].first<<" "<<friends[i].second<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, d;
    int tt;
    string aa, bb;
    cin >> n >> d;
    vector<string> a;
    vector<string> b;
    vector<int> t;
    int f = 0;
    int rand =2;
    vector<pair<string, string>> friends;
    for(int i =0; i < n; i++)
    {
        cin >> aa >>bb >>tt;
        if(tt != 0)
        {
            a.push_back(aa);
            b.push_back(bb);
            t.push_back(tt);
        }
    }
    for(int i =0; i < a.size(); i++)
    {
        for(int j =0; j < a.size(); j++)
        {
            if(a[i] == b[j] && b[i] == a[j])
            {
                if(t[j] - t[i] <= d)
                {
                    //cout <<a[i]<<" "<<b[j]<<t[j] - t[i] << endl;
                    f += 1;
                    friends.push_back(make_pair(a[i], b[i]));
                    a.pop_back();
                    b.pop_back();
                    t.pop_back();
                }
                else
                {
                    a.pop_back();
                    b.pop_back();
                    t.pop_back();
                }
            }
        }
    }
    for(int i =0; i < friends.size(); i++)
    {
        for(int j = 0;j < friends.size();j++)
        {
            if((friends[i].first == friends[j].second && friends[j].first == friends[i].second)||(friends[i].first == friends[j].first && friends[j].first == friends[j].second) )
            {
                friends.erase(friends.begin()+j);
                f--;
            }
        }
    }
    cout << f << endl;
    for(int i =0; i < friends.size(); i++)
    {
        cout << friends[i].first<<" "<<friends[i].second<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, d;
    cin >> n>> d;
    int t[n];
    string f[n], s[n];
    set<pair<string , string> > ans;

    for(int i=0;i<n;i++)
      cin >> f[i] >> s[i] >> t[i];

    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(t[j] - t[i] > d)
                break;
            else if(t[j] - t[i] > 0 && f[i] == s[j] && f[j] == s[i])
                ans.insert(make_pair(min(f[i],s[i]), max(f[i], s[i])));
        }
    }

    cout<<ans.size()<<endl;

    for(auto it = ans.begin(); it != ans.end(); it++)
        cout<< (*it).first << " " << (*it).second << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct message {
	string from, to;
	int time;
};

bool isFriends(message m1, message m2, int t) {
	if(m1.from == m2.to && m1.to == m2.from && abs(m1.time - m2.time) <= t && abs(m1.time - m2.time) > 0)
		return true;
	else return false;
}
vector <message> v;
map <pair <string, string>, bool> used;
vector <pair <string, string> > ans;

int main() {
	int n, d; cin >> n >> d;
	string a, b;
	int t;
	message m;
	for(int i = 1; i <= n; i++) {
		cin >> a >> b >> t;
		m.from = a;
		m.to = b;
		m.time = t;
		v.push_back(m);
	}

	for(int i = 0; i < v.size(); i++) {
		for(int j = 0; j < v.size(); j++) {
			if(isFriends(v[i], v[j], d) && !used[{v[i].from, v[i].to}] && !used[{v[j].from, v[i].to}]) {
				used[{v[i].from, v[j].from}] = 1;
				used[{v[j].from, v[i].from}] = 1;
				ans.push_back({v[i].from, v[i].to});
			}
		}
	}
	cout << ans.size() << endl;
	for(int i = 0; i < ans.size(); i++) {
		cout << ans[i].first << " " << ans[i].second << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//ifstream in("in.txt");
//ofstream out("out.txt");

struct message {
	string from, to;
	int time;
};

bool friends(message m1, message m2, int t) {
	if(m1.from == m2.to && m1.to == m2.from && abs(m1.time - m2.time) <= t)
		return true;
	else return false;
}

vector <message> v;
vector <pair <string, string> > ans;
int main() {
	int n, d; cin >> n >> d;
	message m;
	string a, b;
	int t;
	for(int i = 1; i <= n; i++) {
		cin >> a >> b >> t;
		m.from = a;
		m.to = b;
		m.time = t;
		v.push_back(m);
	}

	for(int i = 0; i < v.size(); i++) {
		for(int j = 0; j < v.size(); j++) {
			if(friends(v[i], v[j], d)) {
				ans.push_back({v[i].from, v[j].from});
				v.erase(v.begin() + i, v.begin() + i + 1);
				v.erase(v.begin() + j, v.begin() + j + 1);
			}
		}
	}
	cout << ans.size() << endl;
	for(int i = 0; i < ans.size(); i++)
		cout << ans[i].first << " " << ans[i].second << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//ifstream in("in.txt");
//ofstream out("out.txt");

struct message {
	string from, to;
	int time;
};

bool friends(message m1, message m2, int t) {
	if(m1.from == m2.to && m1.to == m2.from && abs(m1.time - m2.time) <= t && abs(m1.time - m2.time) > 0)
		return true;
	else return false;
}

vector <message> v;
set <pair <string, string> > ans;
int main() {
	int n, d; cin >> n >> d;
	message m;
	string a, b;
	int t;
	for(int i = 1; i <= n; i++) {
		cin >> a >> b >> t;
		m.from = a;
		m.to = b;
		m.time = t;
		v.push_back(m);
	}

	for(int i = 0; i < v.size(); i++) {
		for(int j = 0; j < v.size(); j++) {
			if(friends(v[i], v[j], d)) {
				ans.insert({v[i].from, v[j].from});
				v.erase(v.begin() + i);
				v.erase(v.begin() + j);
			}

		}
	}

	cout << ans.size() << endl;
	for(set <pair <int, int> >::iterator i = ans.begin(); i != ans.end(); i++) {
		cout << *i.first << " " << *i.second << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//ifstream in("in.txt");
//ofstream out("out.txt");

struct message {
	string from, to;
	int time;
};

bool friends(message m1, message m2, int t) {
	if(m1.from == m2.to && m1.to == m2.from && abs(m1.time - m2.time) <= t && abs(m1.time - m2.time) > 0)
		return true;
	else return false;
}

vector <message> v;
set <pair <string, string> > ans;
int main() {
	int n, d; cin >> n >> d;
	message m;
	string a, b;
	int t;
	for(int i = 1; i <= n; i++) {
		cin >> a >> b >> t;
		m.from = a;
		m.to = b;
		m.time = t;
		v.push_back(m);
	}

	for(int i = 0; i < v.size(); i++) {
		for(int j = 0; j < v.size(); j++) {
			if(friends(v[i], v[j], d) && ans.find({v[i].from, v[j].from}) == ans.end() && ans.find({v[j].from, v[i].from}) == ans.end()) {
				ans.insert({v[i].from, v[j].from});
				v.erase(v.begin() + i);
				v.erase(v.begin() + j);
			}

		}
	}

	cout << ans.size() << endl;
	for(set <pair <string, string> >::iterator i = ans.begin(); i != ans.end(); i++) {
		cout << (*i).first << " " << (*i).second << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//ifstream in("in.txt");
//ofstream out("out.txt");

struct message {
	string from, to;
	int time;
};

bool friends(message m1, message m2, int t) {
	if(m1.from == m2.to && m1.to == m2.from && abs(m1.time - m2.time) <= t)
		return true;
	else return false;
}

vector <message> v;
vector <pair <string, string> > ans;
int main() {
	int n, d; cin >> n >> d;
	message m;
	string a, b;
	int t;
	for(int i = 1; i <= n; i++) {
		cin >> a >> b >> t;
		m.from = a;
		m.to = b;
		m.time = t;
		v.push_back(m);
	}

	for(int i = 0; i < v.size(); i++) {
		for(int j = 0; j < v.size(); j++) {
			if(friends(v[i], v[j], d)) {
				ans.push_back({v[i].from, v[j].from});
				v.erase(v.begin() + i, v.begin() + i + 1);
				v.erase(v.begin() + j, v.begin() + j + 1);
			}
		}
	}

	for(int i = 0; i < ans.size(); i++)
		cout << ans[i].first << " " << ans[i].second << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//ifstream in("in.txt");
//ofstream out("out.txt");

struct message {
	string from, to;
	int time;
};

bool friends(message m1, message m2, int t) {
	if(m1.from == m2.to && m1.to == m2.from && abs(m1.time - m2.time) <= t && abs(m1.time - m2.time) > 0)
		return true;
	else return false;
}

vector <message> v;
vector <pair <string, string> > ans;
int main() {
	int n, d; cin >> n >> d;
	message m;
	string a, b;
	int t;
	for(int i = 1; i <= n; i++) {
		cin >> a >> b >> t;
		m.from = a;
		m.to = b;
		m.time = t;
		v.push_back(m);
	}

	for(int i = 0; i < v.size(); i++) {
		for(int j = 0; j < v.size(); j++) {
			if(friends(v[i], v[j], d)) {
				ans.push_back({v[i].from, v[j].from});
				v.erase(v.begin() + i);
				v.erase(v.begin() + j);
			}

		}
	}

	cout << ans.size() << endl;
	for(int i = 0; i < ans.size(); i++)
		cout << ans[i].first << " " << ans[i].second << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//ifstream in("in.txt");
//ofstream out("out.txt");

struct message {
	string from, to;
	int time;
};

bool friends(message m1, message m2, int t) {
	if(m1.from == m2.to && m1.to == m2.from && abs(m1.time - m2.time) <= t)
		return true;
	else return false;
}

vector <message> v;
vector <pair <string, string> > ans;
int main() {
	int n, d; cin >> n >> d;
	message m;
	string a, b;
	int t;
	for(int i = 1; i <= n; i++) {
		cin >> a >> b >> t;
		m.from = a;
		m.to = b;
		m.time = t;
		v.push_back(m);
	}

	for(int i = 0; i < v.size(); i++) {
		for(int j = 0; j < v.size(); j++) {
			if(friends(v[i], v[j], d)) {
				ans.push_back({v[i].from, v[j].from});
				v.erase(v.begin() + i, v.begin() + i + 1);
				v.erase(v.begin() + j, v.begin() + j + 1);
			}
		}
	}
	cout << ans.size();
	for(int i = 0; i < ans.size(); i++)
		cout << ans[i].first << " " << ans[i].second << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//ifstream in("in.txt");
//ofstream out("out.txt");

struct message {
	string from, to;
	int time;
};

bool friends(message m1, message m2, int t) {
	if(m1.from == m2.to && m1.to == m2.from && abs(m1.time - m2.time) <= t && abs(m1.time - m2.time) > 0)
		return true;
	else return false;
}

vector <message> v;
set <pair <string, string> > ans;
int main() {
	int n, d; cin >> n >> d;
	message m;
	string a, b;
	int t;
	for(int i = 1; i <= n; i++) {
		cin >> a >> b >> t;
		m.from = a;
		m.to = b;
		m.time = t;
		v.push_back(m);
	}

	for(int i = 0; i < v.size(); i++) {
		for(int j = 0; j < v.size(); j++) {
			if(friends(v[i], v[j], d)) {
				ans.insert({v[i].from, v[j].from});
				v.erase(v.begin() + i);
				v.erase(v.begin() + j);
			}

		}
	}

	cout << ans.size() << endl;
	for(set <pair <string, string> >::iterator i = ans.begin(); i != ans.end(); i++) {
		cout << (*i).first << " " << (*i).second << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//ifstream in("in.txt");
//ofstream out("out.txt");

struct message {
	string from, to;
	int time;
};

bool friends(message m1, message m2, int t) {
	if(m1.from == m2.to && m1.to == m2.from && abs(m1.time - m2.time) <= t && abs(m1.time - m2.time) > 0)
		return true;
	else return false;
}

vector <message> v;
vector <pair <string, string> > ans;
int main() {
	int n, d; cin >> n >> d;
	message m;
	string a, b;
	int t;
	for(int i = 1; i <= n; i++) {
		cin >> a >> b >> t;
		m.from = a;
		m.to = b;
		m.time = t;
		v.push_back(m);
	}

	for(int i = 0; i < v.size(); i++) {
		for(int j = 0; j < v.size(); j++) {
			if(friends(v[i], v[j], d)) {
				ans.push_back({v[i].from, v[j].from});
				v.erase(v.begin() + i, v.begin() + i + 1);
				v.erase(v.begin() + j, v.begin() + j + 1);
			}
		}
	}
	cout << ans.size() << endl;
	for(int i = 0; i < ans.size(); i++)
		cout << ans[i].first << " " << ans[i].second << endl;
	return 0;
}


#include<bits/stdc++.h>
#define lld long long int
#define faster ios_base::sync_with_stdio(false);cin.tie(0);
#define pr pair< string,string >
#define pi pair< int,int >

using namespace std;

int main(){

  int n,d;
  cin>>n>>d;
  map< pr,pi > process;

  set< pr > ans;
  for(int i=0;i<n;i++){
    int t;
    string a,b;
    cin>>a>>b>>t;
    pr x = make_pair(a,b),y=make_pair(b,a);
    if(process[x].first != t+1){
      process[x].second  = process[x].first;
      process[x].first = t+1;
    }
//    cout<<process[x]<<" "<<process[y]<<endl;
    if((process[y].first>0 && process[y].first < process[x].first && process[y].first +d>=process[x].first)||(process[y].second>0 && process[y].second < process[x].first && process[y].second +d>=process[x].first)){
      if(a>b) swap(a,b);
      ans.insert(make_pair(a,b));
    }
  }

  cout<<(int)ans.size()<<endl;
  set< pr >::iterator it;
  for(it = ans.begin();it!= ans.end();it++)cout<<(*it).first<<" "<<(*it).second<<endl;

}


#include<bits/stdc++.h>
#define lld long long int
#define faster ios_base::sync_with_stdio(false);cin.tie(0);
#define pr pair< string,string >

using namespace std;

int main(){

  int n,d;
  cin>>n>>d;
  map< pr,int > process;

  set< pr > ans;
  for(int i=0;i<n;i++){
    int t;
    string a,b;
    cin>>a>>b>>t;
    pr x = make_pair(a,b),y=make_pair(b,a);
    process[x] = t+1;
//    cout<<process[x]<<" "<<process[y]<<endl;
    if(process[y]>0 && process[x]<=process[y]+d){
      if(a>b) swap(a,b);
      ans.insert(make_pair(a,b));
    }
  }

  cout<<(int)ans.size()<<endl;
  set< pr >::iterator it;
  for(it = ans.begin();it!= ans.end();it++)cout<<(*it).first<<" "<<(*it).second<<endl;

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

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

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1000 + 47;

map<string, int> M;
string L[MAX];
int T[MAX][MAX];
int F[MAX][MAX];

int getInd(const string& a)
{
	if (M.find(a) == M.end())
	{
		int sz = SZ(M);
		M[a] = sz;
		L[sz] = a;
		return sz;
	}

	return M[a];
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n, d;
	cin >> n >> d;

	FOR(i, 0, 2 * n)
	{
		FOR(j, 0, 2 * n) T[i][j] = -INF;
	}

	int ans = 0;
	FOR(i, 0, n)
	{
		string a, b;
		int t;
		cin >> a >> b >> t;
		int v1 = getInd(a);
		int v2 = getInd(b);
		if (t - T[v2][v1] <= d)
		{
			if (!F[v1][v2])
			{
				F[v1][v2] = F[v2][v1] = 1;
				ans++;
			}
		}

		T[v1][v2] = t;
	}

	cout << ans << endl;
	FOR(i, 0, n)
	{
		FOR(j, 0, i)
		{
			if (!F[i][j]) continue;
			cout << L[i] << " " << L[j] << "\n";
		}
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

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

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2000 + 47;

map<string, int> M;
string L[MAX];
int T[MAX][MAX];
int F[MAX][MAX];

int getInd(const string& a)
{
	if (M.find(a) == M.end())
	{
		int sz = SZ(M);
		M[a] = sz;
		L[sz] = a;
		return sz;
	}

	return M[a];
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n, d;
	cin >> n >> d;

	FOR(i, 0, 2 * n)
	{
		FOR(j, 0, 2 * n) T[i][j] = -INF;
	}

	int ans = 0;
	FOR(i, 0, n)
	{
		string a, b;
		int t;
		cin >> a >> b >> t;
		int v1 = getInd(a);
		int v2 = getInd(b);
		if (t - T[v2][v1] > 0 && t - T[v2][v1] <= d)
		{
			if (!F[v1][v2])
			{
				F[v1][v2] = F[v2][v1] = 1;
				ans++;
			}
		}

		T[v1][v2] = t;
	}

	cout << ans << endl;
	FOR(i, 0, n)
	{
		FOR(j, 0, i)
		{
			if (!F[i][j]) continue;
			cout << L[i] << " " << L[j] << "\n";
		}
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

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

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1000 + 47;

map<string, int> M;
string L[MAX];
int T[MAX][MAX];
int F[MAX][MAX];

int getInd(const string& a)
{
	if (M.find(a) == M.end())
	{
		int sz = SZ(M);
		M[a] = sz;
		L[sz] = a;
		return sz;
	}

	return M[a];
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n, d;
	cin >> n >> d;

	FOR(i, 0, 2 * n)
	{
		FOR(j, 0, 2 * n) T[i][j] = -INF;
	}

	int ans = 0;
	FOR(i, 0, n)
	{
		string a, b;
		int t;
		cin >> a >> b >> t;
		int v1 = getInd(a);
		int v2 = getInd(b);
		if (t - T[v2][v1] > 0 && t - T[v2][v1] <= d)
		{
			if (!F[v1][v2])
			{
				F[v1][v2] = F[v2][v1] = 1;
				ans++;
			}
		}

		T[v1][v2] = t;
	}

	cout << ans << endl;
	FOR(i, 0, n)
	{
		FOR(j, 0, i)
		{
			if (!F[i][j]) continue;
			cout << L[i] << " " << L[j] << "\n";
		}
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

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

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2000 + 47;

struct Item
{
	int a, b, t;
	Item() {}
	Item(int a1, int b1, int t1)
	{
		a = a1;
		b = b1;
		t = t1;
	}
};
map<string, int> M;
string L[MAX];
int F[MAX][MAX];
Item A[MAX];

int getInd(const string& a)
{
	if (M.find(a) == M.end())
	{
		int sz = SZ(M);
		M[a] = sz;
		L[sz] = a;
		return sz;
	}

	return M[a];
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n, d;
	cin >> n >> d;

	FOR(i, 0, n)
	{
		string a, b;
		int t;
		cin >> a >> b >> t;
		int v1 = getInd(a);
		int v2 = getInd(b);
		A[i] = Item(v1, v2, t);
	}

	FOR(i, 0, n)
	{
		FOR(j, i + 1, n)
		{
			if (A[i].a == A[j].b && A[i].b == A[j].a && A[j].t - A[i].t > 0 && A[j].t - A[i].t <= d)
			{
				F[A[i].a][A[i].b] = F[A[i].b][A[i].a] = 1;
			}
		}
	}

	int ans = 0;
	FOR(i, 0, SZ(M))
	{
		FOR(j, 0, i)
		{
			if (F[i][j]) ans++;
		}
	}

	cout << ans << "\n";
	FOR(i, 0, SZ(M))
	{
		FOR(j, 0, i)
		{
			if (!F[i][j]) continue;
			cout << L[i] << " " << L[j] << "\n";
		}
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

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

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2000 + 47;

map<string, int> M;
string L[MAX];
int T[MAX][MAX];
int F[MAX][MAX];

int getInd(const string& a)
{
	if (M.find(a) == M.end())
	{
		int sz = SZ(M);
		M[a] = sz;
		L[sz] = a;
		return sz;
	}

	return M[a];
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n, d;
	cin >> n >> d;

	FOR(i, 0, 2 * n)
	{
		FOR(j, 0, 2 * n) T[i][j] = -INF;
	}

	int ans = 0;
	FOR(i, 0, n)
	{
		string a, b;
		int t;
		cin >> a >> b >> t;
		int v1 = getInd(a);
		int v2 = getInd(b);
		if (t - T[v2][v1] > 0 && t - T[v2][v1] <= d)
		{
			if (!F[v1][v2])
			{
				F[v1][v2] = F[v2][v1] = 1;
				ans++;
			}
		}

		T[v1][v2] = t;
	}

	cout << ans << endl;
	FOR(i, 0, SZ(M))
	{
		FOR(j, 0, i)
		{
			if (!F[i][j]) continue;
			cout << L[i] << " " << L[j] << "\n";
		}
	}
}


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

struct info{string s;int t;}I;
int main()
{
    int n,d,total=0,i;
    string s;
    multimap<string,info>M,M1;
    multimap<string,info>::iterator it,it1,it2;
    cin>>n>>d;
    for(i=0;i<n;i++)
    {
        cin>>s>>I.s>>I.t;
        M.insert(pair<string,info>(s,I));
    }
    for(it=M.begin();it!=M.end();it++)
    {
        if((it1=M.find(it->second.s))!=M.end())
            if(it1->second.t-it->second.t>0&&it1->second.t-it->second.t<=d)

                if(((it2=M1.find(it1->second.s))==M1.end())&&((it2=M1.find(it1->first))==M1.end()))
                {
                    total++;
                    I.s=it1->second.s;I.t=it->second.t;
                    M1.insert(pair<string,info>(it1->first,I));
                }
    }
    cout<<total<<endl;
    for(it=M1.begin();it!=M1.end();it++)
        cout<<it->first<<" "<<it->second.s<<endl;
    return 0;
}


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

struct info{string s;int t;}I;
int main()
{
    int n,d,total=0,i;
    string s;
    multimap<string,info>M,M1;
    multimap<string,info>::iterator it,it1,it2;
    cin>>n>>d;
    for(i=0;i<n;i++)
    {
        cin>>s>>I.s>>I.t;
        M.insert(pair<string,info>(s,I));
    }
    for(it=M.begin();it!=M.end();it++)
    {
        if((it1=M.find(it->second.s))!=M.end())
            if(it1->second.s==it->first)
            if(it1->second.t-it->second.t>0&&it1->second.t-it->second.t<=d)

                if(((it2=M1.find(it1->second.s))==M1.end())&&((it2=M1.find(it1->first))==M1.end()))
                {
                    total++;
                    I.s=it1->second.s;I.t=it->second.t;
                    M1.insert(pair<string,info>(it1->first,I));
                }
    }
    cout<<total<<endl;
    for(it=M1.begin();it!=M1.end();it++)
        cout<<it->first<<" "<<it->second.s<<endl;
    return 0;
}


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

struct info{string s,t;int T;}I;
int main()
{
    int n,d,i,j,k,total=0;
    cin>>n>>d;
    vector<info>V,V1;
    for(i=0;i<n;i++)
    {
        cin>>I.s>>I.t>>I.T;
        V.push_back(I);
    }
    for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
    {
        if(V[i].t==V[j].s&&V[j].t==V[i].s)
            if(V[j].T-V[i].T>0&&V[j].T-V[i].T<=d)
            {
                int flag=0;
                for(k=0;k<V1.size();k++)
                    if((V[j].s==V1[k].s&&V1[k].t==V[j].t)||(V[j].s==V1[k].t&&V1[k].s==V[j].t))
                    {
                        flag=1;
                        break;
                    }
                if(flag==0)
                {
                    total++;
                    I.s=V[j].s;
                    I.t=V[j].t;
                    I.T=1;
                    V1.push_back(I);
                }
            }
    }
    cout<<total<<endl;
    for(i=0;i<V1.size();i++)
        cout<<V1[i].s<<" "<<V1[i].t<<endl;
    return 0;
}


#include <iostream>
#include<sstream>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
typedef long long ll;

using namespace std;
map<pair<string, string>,vector<int>>list;
map<pair<string, string>, vector<bool>>visited;

int n, d,x,y,ans=0;
string f, t;
vector<string>from;
vector<string>to;

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

	for (ll i = 0; i < n; i++)
	{
		cin >> f >> t >> x;
		pair<string, string>p = pair<string, string>(f, t);
		list[p].push_back(x);
		visited[p].push_back(0);
	}
		for (map<pair<string, string>, vector<int>>::iterator it = list.begin(); it != list.end(); ++it)
	{
		for (int i = 0; i < it->second.size(); i++)
		{
			pair<string, string>To = pair<string, string>(it->first.second, it->first.first);
			x = it->second[i];
			if ((list.count(To)))
			{
				int sz = list[To].size();
				int ln = visited[To].size();
				if (sz < ln-1 || ((0 == visited[To][0]) && ln==sz))
				{
					int j;
					if (sz < ln - 1)
						j = sz - ln - 1;
					else
						j = 0;

					y = list[To][j];
					x = abs(x - y);

					if (x <= d &&x > 0)
					{
						visited[To].push_back(1);
						visited[it->first].push_back(1);
						from.push_back(it->first.first);
						to.push_back(it->first.second);
						ans++;
					}
				}
			}
		}
			x = 0;

	}
	cout << ans<<endl;
	for (int i = 0; i < from.size(); i++)
	{
		cout << from[i] << " " << to[i] << endl;
	}
	return 0;
}


#include <iostream>
#include<sstream>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
typedef long long ll;

using namespace std;
map<string,pair<string, int>>list;
map<string,bool>visited;

int n, d,x,y,ans=0;
string f, t;
vector<string>from;
vector<string>to;
int main()
{
	cin >> n >> d;

	for (ll i = 0; i < n; i++)
	{
		cin >> f >> t >> x;
		list[f] = pair<string, int>(t, x);
		visited[f] = 0;
	}
	for (map<string, pair<string, int>>::iterator it = list.begin(); it != list.end(); ++it)
	{
		x=it->second.second;
		visited[it->first] = 1;
		if (list.count(it->first) && (0 == visited[it->second.first]))
		{
			visited[it->second.first] = 1;
			y = list[it->second.first].second;
			x = abs(x - y);
			if (x <= d &&x > 0)
			{
				from.push_back(it->first);
				to.push_back(it->second.first);
				ans++;
			}
		}
			x = 0;
	}
	cout << ans<<endl;
	for (int i = 0; i < from.size(); i++)
	{
		cout << from[i] << " " << to[i] << endl;
	}
	return 0;
}


#include <iostream>
#include<sstream>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
typedef long long ll;

using namespace std;
string s[1001], r[1001];
ll t[1001];
ll n, d;
set <pair<string, string>>ans;

int main()
{
	cin >> n >> d;
	for (ll i = 0; i < n; i++) cin >> s[i] >> r[i] >> t[i];
	for (ll i = 0; i < n; i++)
	{

		for (ll j = i + 1; j < n; j++)
		{
				if ((abs(t[i] - t[j]) <= d) && (abs(t[i] - t[j])>0))
				if ((s[i] == r[j]) && (s[j] == r[i]))
				{
					if (s[i] > r[i])
						ans.insert(pair<string, string>(s[i], r[i]));
					else
						ans.insert(pair<string, string>(r[i], s[i]));
				}
		}

	}
	cout << ans.size() << endl;
	set<pair<string, string>>::iterator it;
	for (it = ans.begin(); it != ans.end(); it++)
	{
		cout << it->first << " " << it->second << endl;
	}
	return 0;
}


#include <iostream>
#include<sstream>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
typedef long long ll;

using namespace std;
map<string,pair<string, int>>list;
map<string,bool>visited;

int n, d,x,y,ans=0;
string f, t;
vector<string>from;
vector<string>to;
int main()
{
	cin >> n >> d;

	for (ll i = 0; i < n; i++)
	{
		cin >> f >> t >> x;
		list[f] = pair<string, int>(t, x);
		visited[f] = 0;
	}
	for (map<string, pair<string, int>>::iterator it = list.begin(); it != list.end(); ++it)
	{
		x=it->second.second;
		visited[it->first] = 1;
		if (list.count(it->first) && (0 == visited[it->second.first]))
		{

			y = list[it->second.first].second;
			x = abs(x - y);
			if ((list[it->second.first].first==it->first)&&x <= d &&x > 0)
			{
				visited[it->second.first] = 1;
				from.push_back(it->first);
				to.push_back(it->second.first);
				ans++;
			}
		}
			x = 0;
	}
	cout << ans<<endl;
	for (int i = 0; i < from.size(); i++)
	{
		cout << from[i] << " " << to[i] << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define FF              freopen("input.txt" , "r" , stdin);
#define sf              scanf
#define pf              printf
#define fs              first
#define se              second
#define pb              push_back
#define ins             insert
#define Lb              lower_bound
#define Up              upper_bound
#define INF             (1<<30)
#define mem(a,b)        memset(a, b, sizeof(a))
#define MAX             100010
#define MAXR            100010
#define MAXC            100010

typedef long long ll;

const double PI = 2.0 * acos(0.0);
const double eps = 1e-9;

template < class T > T Abs(T x) { return x > 0 ? x : -x; }
template < class T > string toString(T n) { ostringstream ost; ost << n; ost.flush() ; return ost.str(); }
template < class T > inline T gcd(T a,T b) { if(a < 0) return gcd(-a,b); if(b < 0)return gcd(a,-b); return (b == 0) ? a : gcd(b ,a % b); }
template < class T > inline T lcm(T a,T b) { if(a < 0) return lcm(-a,b); if(b < 0)return lcm(a,-b); return a * (b / gcd(a , b)); }
template < class T > inline T sqr(T n) { return n * n; }
template < class T > T power(T n, int p)
{
    if(!p) return 1;
    else
    {
        T sum = sqr( power( n ,  p >> 1) );
        if(p & 1) sum =  n;
        return sum;
    }
}

//ll bigmod(ll num , ll p , ll mod)
//{
//    ll sum = 1 , temp = num;
//    while(p)
//    {
//        if(p & 1) sum = (sum * temp) % mod;
//        temp = (temp * temp) % mod; p = p >> 1;
//    }
//    return sum;
//}

/// S , E  , N , W
//int one [] = {1 ,0,-1, 0};
//int two [] = {0 ,1, 0,-1};
///S , SE , E , NE , N , NW , W , SW
//int one [] = {1 ,1 ,0,-1,-1,-1, 0, 1};
//int two [] = {0 ,1 ,1 ,1, 0,-1,-1,-1};
///Knight Direction
//int one[]={2 ,1 ,-1,-2,-2,-1, 1, 2};
//int two[]={1 ,2 , 2, 1,-1,-2,-2,-1};

struct node{

    string a , b;
    node(string x , string y) {a = x; b = y;}
    bool operator < (const node &t) const {
        return t.a > a;
    }
};

map < node , int > person;
set < node > vis;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(false);
    int n , d , cn;
    string x , y;
    cin >> n >> d;
    for(int i = 0; i < n ; ++i)
    {
        cin >> x >> y >> cn ;
        person[node(x , y)] = cn;
    }
    for(auto it = person.begin() ; it != person.end() ; ++it)
    {
        x = it->first.a;
        y = it->first.b;
        if(person.find(node(x , y)) != person.end() && person.find(node(y , x)) != person.end())
        {
            int n = abs(person[node(x , y)] - person[node(y , x)]);
            if(n > 0 && n <= d && vis.find(node(y , x)) == vis.end()) vis.insert(node(x , y));
        }
    }
    cout << vis.size() << endl;
    for(auto it = vis.begin() ; it != vis.end() ; ++it)
    {
        cout << (*it).a << " " << (*it).b << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pf printf
#define sf scanf

struct node {
    string a , b ;
    int cost ;
    node(){}
    node(string x , string y , int z)
    {
        a = x ; b = y; cost = z;
    }
};

vector < node > ve;
set < pair < string , string > > se;

int main()
{
   // freopen("input.txt" , "r" , stdin);
    int n , d , temp ;
    string x , y ;
    cin >> n >> d;
    for(int i = 0 ; i < n ; ++i)
    {
        cin >> x >> y >> temp;
        ve.push_back(node(x , y , temp));
    }
    for(int i = 0 ; i < n ; ++i)
    {
        for(int j = 0 ; j < n ; ++j)
        {
            if( i == j ) continue;
            temp = abs(ve[i].cost - ve[j].cost);
            if(ve[i].a == ve[j].b && ve[j].a == ve[i].b && temp > 0 && temp <= d)
            {
                x = max( ve[i].a , ve[i].b);
                y = min( ve[i].a , ve[i].b);
                if( se.find(make_pair(y , x)) == se.end() ) se.insert(make_pair(y , x));
            }
        }
    }
    cout << (int) se.size() << endl;
    for(auto x : se) cout << x.first << " " << x.second << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define FF              freopen("input.txt" , "r" , stdin);
#define sf              scanf
#define pf              printf
#define fs              first
#define se              second
#define pb              push_back
#define ins             insert
#define Lb              lower_bound
#define Up              upper_bound
#define INF             (1<<30)
#define mem(a,b)        memset(a, b, sizeof(a))
#define MAX             100010
#define MAXR            100010
#define MAXC            100010

typedef long long ll;

const double PI = 2.0 * acos(0.0);
const double eps = 1e-9;

template < class T > T Abs(T x) { return x > 0 ? x : -x; }
template < class T > string toString(T n) { ostringstream ost; ost << n; ost.flush() ; return ost.str(); }
template < class T > inline T gcd(T a,T b) { if(a < 0) return gcd(-a,b); if(b < 0)return gcd(a,-b); return (b == 0) ? a : gcd(b ,a % b); }
template < class T > inline T lcm(T a,T b) { if(a < 0) return lcm(-a,b); if(b < 0)return lcm(a,-b); return a * (b / gcd(a , b)); }
template < class T > inline T sqr(T n) { return n * n; }
template < class T > T power(T n, int p)
{
    if(!p) return 1;
    else
    {
        T sum = sqr( power( n ,  p >> 1) );
        if(p & 1) sum =  n;
        return sum;
    }
}

//ll bigmod(ll num , ll p , ll mod)
//{
//    ll sum = 1 , temp = num;
//    while(p)
//    {
//        if(p & 1) sum = (sum * temp) % mod;
//        temp = (temp * temp) % mod; p = p >> 1;
//    }
//    return sum;
//}

/// S , E  , N , W
//int one [] = {1 ,0,-1, 0};
//int two [] = {0 ,1, 0,-1};
///S , SE , E , NE , N , NW , W , SW
//int one [] = {1 ,1 ,0,-1,-1,-1, 0, 1};
//int two [] = {0 ,1 ,1 ,1, 0,-1,-1,-1};
///Knight Direction
//int one[]={2 ,1 ,-1,-2,-2,-1, 1, 2};
//int two[]={1 ,2 , 2, 1,-1,-2,-2,-1};

map < pair < string , string >  , int > person;
set < pair < string , string > > vis;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(false);
    int n , d , cn;
    string x , y;
    cin >> n >> d;
    for(int i = 0; i < n ; ++i)
    {
        cin >> x >> y >> cn ;
        person[make_pair(x , y)] = cn;
    }
    for(auto it = person.begin() ; it != person.end() ; ++it)
    {
        x = it->first.first;
        y = it->first.second;
        if(person.find(make_pair(x , y)) != person.end() && person.find(make_pair(y , x)) != person.end())
        {
            int n = abs(person[make_pair(x , y)] - person[make_pair(y , x)]);
            if(n > 0 && n <= d && vis.find(make_pair(y , x)) == vis.end()) vis.insert(make_pair(x , y));
        }
    }
    cout << vis.size() << endl;
    for(auto it = vis.begin() ; it != vis.end() ; ++it)
    {
        cout << (*it).first << " " << (*it).second << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,k,t;
	string s1,s2;
	cin >> n >> k;
	vector<tuple<int,string,string> >vt;
	for(int i=0;i<n;i++){
		cin >> s1 >> s2  >> t;
		vt.push_back(make_tuple(t,s1,s2));
	}
	set<pair<string,string> >ans;
	sort(vt.begin(),vt.end());
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(get<0>(vt[i])==get<0>(vt[j]))continue;
			if(get<0>(vt[j])>get<0>(vt[i])+k)break;
			if(get<1>(vt[i])==get<2>(vt[j])&&get<2>(vt[i])==get<1>(vt[j])){
				string Min = min(get<1>(vt[i]),get<2>(vt[i]));
				string Max = max(get<1>(vt[i]),get<2>(vt[i]));
				ans.insert(make_pair(Min,Max));
			}
		}
	}
	cout << ans.size() << "\n";
	for(auto it:ans){
		cout << it.first << " " << it.second << "\n";
	}
}


#include<bits/stdc++.h>
using namespace std;
#define falze(n) 		memset(n,false,sizeof(n))
#define zero(n)			memset(n,0,sizeof(n))
#define init(n) 		memset(n,-1,sizeof(n))
#define REP(i,n) 		for(i=0;i<n;i++)
#define FOR(i,a,b) 		for(i=a;i<=b;i++)
#define FORD(i,a,b) 	for(i=a;i>=b;i--)
#define FOR2(i,a,b,c) 	for(i=a;i<=b;i+=c)
#define FORD2(i,a,b,c)	for(i=a;i>=b;i-=c)
#define mod(x,y) 		(((x%y)<0)?((x%y)+y):(x%y))
#define PB 				push_back
#define endll 			"\n"
#define INF 			0x3FFFFFFF
#define in(a,b)			substr(a,b-a+1) // INCLUSIVE
#define ff				first
#define ss				second
#define LEN(x)			((int)x.size())
#define mm				1000000007
#define check(x)		(((x%=mm)+=mm)%=mm)
typedef long long ll;
typedef pair<int,int> ii;

int n,m,len;

map<string ,int> id;
map<int , string> idtoname;
set<int> Adj[1010][1010];

void add(string s){
	if(id.count(s) == 0){
		id[s] = len;
		idtoname[len++] = s;
	}
}

set<ii> all;
set<ii> logs;

int main(){
	int i,j,k,t,a,b;
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);

	//freopen("input.in", "r",stdin);
	//freopen("output.out","w",stdout);

	int d;
	cin >> n >> d;

	len = 0;

	REP(i,n){
		string u,v;
		cin >> u >> v >> t;
		add(u); add(v);

		logs.insert(ii(min(id[u],id[v]), max(id[u],id[v])));
		all.insert(ii(id[u],id[v]));
		Adj[id[u]][id[v]].insert(t);
	}

	vector<ii> ans;

	for(ii cur:logs) if(all.count(ii(cur.ss,cur.ff))){
		int f = 0;
		for(auto cur2:Adj[cur.ff][cur.ss]){
			for(auto cur3:Adj[cur.ss][cur.ff]){
				if(abs(cur2-cur3) <= d)
					f = 1;
					break;

			}
			if(f) break;
		}
		if(f) ans.PB(cur);
	}
	cout << LEN(ans) << endll;
	for(auto cur:ans){
		cout << idtoname[cur.ff] << " " << idtoname[cur.ss] << endll;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define falze(n) 		memset(n,false,sizeof(n))
#define zero(n)			memset(n,0,sizeof(n))
#define init(n) 		memset(n,-1,sizeof(n))
#define REP(i,n) 		for(i=0;i<n;i++)
#define FOR(i,a,b) 		for(i=a;i<=b;i++)
#define FORD(i,a,b) 	for(i=a;i>=b;i--)
#define FOR2(i,a,b,c) 	for(i=a;i<=b;i+=c)
#define FORD2(i,a,b,c)	for(i=a;i>=b;i-=c)
#define mod(x,y) 		(((x%y)<0)?((x%y)+y):(x%y))
#define PB 				push_back
#define endll 			"\n"
#define INF 			0x3FFFFFFF
#define in(a,b)			substr(a,b-a+1) // INCLUSIVE
#define ff				first
#define ss				second
#define LEN(x)			((int)x.size())
#define mm				1000000007
#define check(x)		(((x%=mm)+=mm)%=mm)
typedef long long ll;
typedef pair<int,int> ii;

int n,m,len;

map<string ,int> id;
map<int , string> idtoname;
map<ii, set<int> > Adj;

void add(string s){
	if(id.count(s) == 0){
		id[s] = len;
		idtoname[len++] = s;
	}
}

set<ii> all;
set<ii> logs;

int main(){
	int i,j,k,t,a,b;
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);

	//freopen("input.in", "r",stdin);
	//freopen("output.out","w",stdout);

	int d;
	cin >> n >> d;

	len = 0;

	REP(i,n){
		string u,v;
		cin >> u >> v >> t;
		add(u); add(v);

		logs.insert(ii(min(id[u],id[v]), max(id[u],id[v])));
		all.insert(ii(id[u],id[v]));
		Adj[ii(id[u],id[v])].insert(t);
	}

	vector<ii> ans;

	for(ii cur:logs) if(all.count(ii(cur.ss,cur.ff))){
		int f = 0;
		for(auto cur2:Adj[ii(cur.ff,cur.ss)]){
			for(auto cur3:Adj[ii(cur.ss,cur.ff)]){
				if(abs(cur2-cur3) <= d and abs(cur2-cur3) > 0){
					f = 1;
					break;
				}

			}
			if(f) break;
		}
		if(f) ans.PB(cur);
	}
	cout << LEN(ans) << endll;
	for(auto cur:ans){
		cout << idtoname[cur.ff] << " " << idtoname[cur.ss] << endll;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define falze(n) 		memset(n,false,sizeof(n))
#define zero(n)			memset(n,0,sizeof(n))
#define init(n) 		memset(n,-1,sizeof(n))
#define REP(i,n) 		for(i=0;i<n;i++)
#define FOR(i,a,b) 		for(i=a;i<=b;i++)
#define FORD(i,a,b) 	for(i=a;i>=b;i--)
#define FOR2(i,a,b,c) 	for(i=a;i<=b;i+=c)
#define FORD2(i,a,b,c)	for(i=a;i>=b;i-=c)
#define mod(x,y) 		(((x%y)<0)?((x%y)+y):(x%y))
#define PB 				push_back
#define endll 			"\n"
#define INF 			0x3FFFFFFF
#define in(a,b)			substr(a,b-a+1) // INCLUSIVE
#define ff				first
#define ss				second
#define LEN(x)			((int)x.size())
#define mm				1000000007
#define check(x)		(((x%=mm)+=mm)%=mm)
typedef long long ll;
typedef pair<int,int> ii;

int n,m,len;

map<string ,int> id;
map<int , string> idtoname;
set<int> Adj[1010][1010];

void add(string s){
	if(id.count(s) == 0){
		id[s] = len;
		idtoname[len++] = s;
	}
}

set<ii> all;
set<ii> logs;

int main(){
	int i,j,k,t,a,b;
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);

	//freopen("input.in", "r",stdin);
	//freopen("output.out","w",stdout);

	int d;
	cin >> n >> d;

	len = 0;

	REP(i,n){
		string u,v;
		cin >> u >> v >> t;
		add(u); add(v);

		logs.insert(ii(min(id[u],id[v]), max(id[u],id[v])));
		all.insert(ii(id[u],id[v]));
		Adj[id[u]][id[v]].insert(t);
	}

	vector<ii> ans;

	for(ii cur:logs) if(all.count(ii(cur.ss,cur.ff))){
		int f = 0;
		for(auto cur2:Adj[cur.ff][cur.ss]){
			for(auto cur3:Adj[cur.ss][cur.ff]){
				if(abs(cur2-cur3) <= d and abs(cur2-cur3) > 0){
					f = 1;
					break;
				}

			}
			if(f) break;
		}
		if(f) ans.PB(cur);
	}
	cout << LEN(ans) << endll;
	for(auto cur:ans){
		cout << idtoname[cur.ff] << " " << idtoname[cur.ss] << endll;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,t;
    cin >> n >> t;
    string s1[n],s2[n];
    int k = 0,zn[n];
    bool metk[n];
    string ot[n][2];
    for (int i = 0;i < n;i++)
    {
        cin >> s1[i] >> s2[i] >> zn[i];
        metk[i] = 0;
    }
    for(int i = 0;i < n;i++)
        if (metk[i] == 0)
        {
            for (int j = i + 1;j < n;j++)
                if (s1[i] == s2[j] && s2[i] == s1[j] && abs(zn[i] - zn[j]) <= t && abs(zn[i] - zn[j])!= 0)
                {
                    metk[i] = 1;
                    metk[j] = 1;
                    ot[k][0] = s1[i];
                    ot[k][1] = s2[i];
                    k++;
                }
        }
    cout << k << endl;
    for(int i = 0;i < k;i++)
        cout << ot[i][0] << " " << ot[i][1] << endl;
}


#include<set>
#include<iostream>
using namespace std;
typedef pair<string,string> P;
string a[1010],b[1010];
set<P> S;
int N,d,t[1010];
main(){
	cin>>N>>d;
	for(int i=0;i<N;++i)
		cin>>a[i]>>b[i]>>t[i];
	for(int i=0;i<N;++i)
		for(int j=i+1;j<N;++j)
			if(a[i]==b[j]&&a[j]==b[i]&&t[j]>t[i]&&t[j]-t[i]<=d)
				S.insert(P(min(a[i],a[j]),max(b[i],b[j])));
	cout<<S.size();
	for(typeof(S.begin())i=S.begin();i!=S.end();++i)
		cout<<endl<<i->first<<' '<<i->second;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<string,string> p;
int main(){set<p>s;long n,k,i,j;
    cin>>n>>k;string a[n],b[n];long t[n];
    for(i=0;i<n;i++)cin>>a[i]>>b[i]>>t[i];
    for(i=0;i<n;i++)
        for(j=i+1;j<n;j++)
            if(a[i]==b[j]&&a[j]==b[i]&&t[j]-t[i]<=k&&t[j]-t[i])
                s.insert(p(max(b[i],b[j]),min(a[i],a[j])));
    cout<<s.size()<<endl;
    set<p>::iterator it=s.begin();
    for(;it!=s.end();++it) cout<<(it->first)<<' '<<(it->second)<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,t;
    cin >> n >> t;
    string s1[n],s2[n];
    int k = 0,zn[n];
    bool metk[n];
    string ot[n][2];
    for (int i = 0;i < n;i++)
    {
        cin >> s1[i] >> s2[i] >> zn[i];
        metk[i] = 0;
    }
    for(int i = 0;i < n;i++)
        if (metk[i] == 0)
        {
            for (int j = i + 1;j < n;j++)
                if (s1[i] == s2[j] && s2[i] == s1[j] && abs(zn[i] - zn[j]) <= t)
                {
                    metk[i] = 1;
                    metk[j] = 1;
                    ot[k][0] = s1[i];
                    ot[k][1] = s2[i];
                    k++;
                }
        }
    cout << k << endl;
    for(int i = 0;i < k;i++)
        cout << ot[i][0] << " " << ot[i][1] << endl;
}


#include<bits/stdc++.h>
using namespace std;
set < pair <string,string> >ans;
int t[1003],i,n,d;
string a[1003],b[1003];
main()
{
    scanf("%d%d",&n,&d);
    for (i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>t[i];
    for (i=1;i<=n;i++)
        for (int j=i+1;j<=n;j++)
            if (a[i]==b[j]&&t[i]<t[j]&&t[j]-t[i]<=d)
    {
        ans.insert(make_pair(min(a[i],b[i]),max(a[i],b[i])));
    }
    cout<<ans.size()<<'\n';
   for (set <pair<string,string> >::iterator it=ans.begin();it!=ans.end();it++)
        cout<<it->first<<' '<<it->second<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
set < pair <string,string> >ans;
int t[1003],i,n,d;
string a[1003],b[1003];
main()
{
    scanf("%d%d",&n,&d);
    for (i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>t[i];
    for (i=1;i<=n;i++)
        for (int j=i+1;j<=n;j++)
            if (a[i]==b[j]&&b[i]==a[j]&&t[i]<t[j]&&t[j]-t[i]<=d)
    {
        ans.insert(make_pair(min(a[i],b[i]),max(a[i],b[i])));
    }
    cout<<ans.size()<<'\n';
   for (set <pair<string,string> >::iterator it=ans.begin();it!=ans.end();it++)
        cout<<it->first<<' '<<it->second<<'\n';
}


#include<set>
#include<iostream>
using namespace std;
typedef pair<string,string> P;
string a[1010],b[1010];
set<P> S;
int N,d,t[1010];
main(){
    cin>>N>>d;
    for(int i=0;i<N;++i)
        cin>>a[i]>>b[i]>>t[i];
    for(int i=0;i<N;++i)
        for(int j=i+1;j<N;++j)
            if(a[i]==b[j]&&a[j]==b[i]&&t[j]>t[i]&&t[j]-t[i]<=d)
                S.insert(P(min(a[i],a[j]),max(b[i],b[j])));
    cout<<S.size();
    for(typeof(S.begin())i=S.begin();i!=S.end();++i)
        cout<<endl<<i->first<<' '<<i->second;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <stdio.h>
using namespace std;
int c,d,n,k,i,m,j,x=1,y,z,X,Y;
main(){
	cin>>n>>d;
	string s[n],a[n],s1[n],s2[n];int b[n];
	for(i=0;i<n;i++) cin>>s[i]>>a[i]>>b[i];
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(s[i]==a[j] && a[i]==s[j] && b[j]-b[i]>0 && b[j]-b[i]<=d){
				for(k=0;k<x;k++){
				if(s[i]==s1[k]||s[i]==s2[k])continue; else{
				s1[x]=s[i];
				s2[x]=a[i];
				x++;
				}
				}
			}
		}
	}
	cout<<x-1<<endl;
	for(i=1;i<x;i++)cout<<s1[i]<<" "<<s2[i]<<endl;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <stdio.h>
using namespace std;
int d,n,i=1,k,m,j,x,y,z;
main(){
	cin>>n>>d;
	string a[n],b[n],s[n];
	int c[n];
	for(i=0;i<n;i++)	cin>>a[i]>>b[i]>>c[i];
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			if(a[i]==b[j]&&b[i]==a[j]&&c[j]-c[i]>0&&c[j]-c[i]<=d){s[k]=a[i]+" "+b[i];k++;a[i]='1';b[i]='1';a[j]='2';b[j]='2';}
		}
	}
	cout<<k<<endl;
	for(i=0;i<k;i++)cout<<s[i]<<endl;

}


#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
using namespace std;

struct la
{
	char a[30], b[30];
	int num;
}ax[1000+5];

vector<la> pp;
int main()
{
	int n, d;
	scanf("%d%d", &n, &d);
	int i, j, k;
	for (i = 0; i < n; i++) scanf("%s%s%d", &ax[i].a, &ax[i].b, &ax[i].num);

	int cnt = 0;
	for (i = 0; i < n; i++)
	{
		int ok = 1;
		for (int j = 0; j < n;j++)
			if (strcmp(ax[i].a, ax[j].b) == 0 && strcmp(ax[i].b, ax[j].a) == 0 && ax[i].a[0]!=0)
			{
				if (ax[j].num - ax[i].num <= d && ax[j].num - ax[i].num > 0 )
				{
					//cnt++;
					for (k = 0; k < 30; k++)
					{
						//ax[i].a[k] = ax[i].b[k] = 0;
						ax[j].a[k] = ax[j].b[k] = 0;
					}
					if (ok == 0) continue;
					cnt++;
					ok = 0;
					la q;
					strcpy(q.a, ax[i].a);
					strcpy(q.b, ax[i].b);
					pp.push_back(q);

				}
			}
	}
	printf("%d\n", cnt);
	for (i = 0; i < pp.size(); i++)
		printf("%s %s\n", pp[i].a, pp[i].b);
	//system("pause");

	return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
using namespace std;

struct la
{
	char a[30], b[30];
	int num;
}ax[10000+5];

vector<la> pp;

int main()
{
	int n, d;
	scanf("%d%d", &n, &d);
	int i, j, k;
	for (i = 0; i < n; i++) scanf("%s%s%d", &ax[i].a, &ax[i].b, &ax[i].num);

	int cnt = 0;
	for (i = 0; i < n; i++)
	{
		int ok = 1;
		for (int j = 0; j < n; j++)
		{
			if (strcmp(ax[i].a, ax[j].b) == 0 && strcmp(ax[i].b, ax[j].a) == 0)
			{
				if (ax[j].num - ax[i].num <= d && ax[j].num - ax[i].num > 0)
				{
					//cnt++;
					//cout << ax[i].num << " " << ax[j].num << endl;
					ax[i].num = -1000, ax[j].num = -1000;

					cnt++;
					ok = 0;
					la q;
					strcpy(q.a, ax[i].a);
					strcpy(q.b, ax[i].b);
					pp.push_back(q);

				}
			}
		}
	}

	for (i = 0; i < pp.size(); i++)
		for (j = i + 1; j < pp.size(); j++)
		{
			if (pp[j].a[0]!=0)
			if ((strcmp(pp[i].a, pp[j].a) == 0 && strcmp(pp[i].b, pp[j].b) == 0) || (strcmp(pp[i].b, pp[j].a) == 0 && strcmp(pp[i].a, pp[j].b) == 0))
			{
				cnt--;
				//	cout << "as" << endl;
				pp[j].a[0] = pp[j].b[0] = 0;
			}
		//	cout << ax[i].a << " " << ax[i].b << endl;
			//cout << ax[j].a << " " << ax[j].b << endl;
		}
	printf("%d\n", cnt);
	for (i = 0; i < pp.size(); i++)
		if(pp[i].a[0]!=0 || ax[i].b[0]!=0)printf("%s %s\n", pp[i].a, pp[i].b);
	//system("pause");

	return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
using namespace std;

struct la
{
    char a[30], b[30];
    int num;
}ax[1000+5];

vector<la> pp;
int main()
{
    int n, d;
    scanf("%d%d", &n, &d);
    int i, j, k;
    for (i = 0; i < n; i++) scanf("%s%s%d", &ax[i].a, &ax[i].b, &ax[i].num);

    int cnt = 0;
    for (i = 0; i < n; i++)
    {
        int ok = 1;
        for (int j = 0; j < n; j++)
        {
            if (strcmp(ax[i].a, ax[j].b) == 0 && strcmp(ax[i].b, ax[j].a) == 0)
            {
                if (ax[j].num - ax[i].num <= d && ax[j].num - ax[i].num > 0)
                {
                    //cnt++;
                    //cout << ax[i].num << " " << ax[j].num << endl;
                    ax[i].num = -1000, ax[j].num = -1000;

                    cnt++;
                    ok = 0;
                    la q;
                    strcpy(q.a, ax[i].a);
                    strcpy(q.b, ax[i].b);
                    pp.push_back(q);

                }
            }
        }
    }

    for (i = 0; i < pp.size(); i++)
        for (j = i + 1; j < pp.size(); j++)
        {
            if ((strcmp(pp[i].a, pp[j].a) == 0 && strcmp(pp[i].b, pp[j].b) == 0) || (strcmp(pp[i].b, pp[j].a) == 0 && strcmp(pp[i].a, pp[j].b) == 0))
            {
                cnt--;
                //  cout << "as" << endl;
                pp[j].a[0] = pp[j].b[0] = 0;
            }
        //  cout << ax[i].a << " " << ax[i].b << endl;
            //cout << ax[j].a << " " << ax[j].b << endl;
        }
    printf("%d\n", cnt);
    for (i = 0; i < pp.size(); i++)
        if(pp[i].a[0]!=0 || ax[i].b[0]!=0)printf("%s %s\n", pp[i].a, pp[i].b);
    //system("pause");

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define SZ(c) int(c.size())
#define MP make_pair

map <pair <string, string>, int> m;
map <pair <string, string>, int> :: iterator it;
set <pair <string, string> > ans;
set <pair <string, string> > :: iterator sit;

int main() {
    int n, d, t; scanf("%d %d", &n, &d);
    for (int i = 0; i < n; ++i) {
        string a, b; cin >> a >> b >> t;
        m[MP(a, b)] = t;
    }
    for (it = m.begin(); it != m.end(); ++it) {
        if (m.count(MP(it->first.second, it->first.first)) &&
                abs(m[MP(it->first.second, it->first.first)] - it->second) <= d) {
            ans.insert(MP(min(it->first.second, it->first.first), max(it->first.second, it->first.first)));
        }
    }
    printf("%d\n", SZ(ans));
    for (sit = ans.begin(); sit != ans.end(); ++sit) {
        cout << sit->first << " " << sit->second << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ALL(c) c.begin(), c.end()
#define SZ(c) int(c.size())
#define MP make_pair
#define N 1001

int t[N];
string a[N], b[N];

int main() {
    int n, d; scanf("%d %d", &n, &d);
    for (int i = 0; i < n; ++i) cin >> a[i] >> b[i] >> t[i];
    vector <pair <string, string> > ans;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (a[i] == b[j] && b[i] == a[j] && t[j] - t[i] <= d && t[j] - t[i] > 0) {
                ans.push_back(MP(min(a[i], b[i]), max(a[i], b[i])));
            }
        }
    }
    sort(ALL(ans));
    ans.resize(unique(ALL(ans)) - ans.begin());
    cout << SZ(ans) << endl;
    for (int i = 0; i < SZ(ans); ++i) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ALL(c) c.begin(), c.end()
#define SZ(c) int(c.size())
#define MP make_pair
#define N 1001

int t[N];
string a[N], b[N];

int main() {
    int n, d; scanf("%d %d", &n, &d);
    for (int i = 0; i < n; ++i) cin >> a[i] >> b[i] >> t[i];
    vector <pair <string, string> > ans;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (a[i] == b[j] && b[i] == a[j] && t[j] - t[i] <= d) {
                ans.push_back(MP(min(a[i], b[i]), max(a[i], b[i])));
            }
        }
    }
    sort(ALL(ans));
    ans.resize(unique(ALL(ans)) - ans.begin());
    cout << SZ(ans) << endl;
    for (int i = 0; i < SZ(ans); ++i) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

# define ll long long

ll n, d, t[1010];
vector <pair <string, string> > ans;
string  a[1010], b[1010];

int main() {
    cin >> n >> d;
    for(int i = 1;i <= n;i++) {
        cin >> a[i] >> b[i] >> t[i];
    }
    for(int i = 1;i <= n;i++) {
        for(int j = i + 1;j <= n;j++) {
            if(a[j] == b[i] && b[j] == a[i] && abs(t[j] - t[i]) <= d) {
                ans.push_back({a[i], b[i]});
                break;
            }
        }
    }
    cout << ans.size() << '\n';
    for(int i = 0;i < ans.size();i++) {
        cout << ans[i].first << " " << ans[i].second << '\n';
    }
}