Language: C++

#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

ld getdis(vector<ld>&l, vector<ld>&r) {
	ld sum = 0;
	for (int i = 0; i < 3; ++i) {
		sum += (l[i] - r[i])*(l[i] - r[i]);
	}
	return sqrt(sum);
}


struct po {
	int index;
	vector<ld> coors;
	po(int _d):coors(_d) {
		index = -1;
	}
	po(int _index, vector<ld>_coors) :index(_index), coors(_coors) {

	}
	po() {}
};
ld getdis(po&lpo, po&rpo) {
	return getdis(lpo.coors, rpo.coors);
}
template<class T>
class axisSorter {
	int k;
public:
	axisSorter(int _k) : k(_k) {}
	bool operator()(const T &a, const T &b) {
		return a.coors[k] < b.coors[k];
	}
};

template<class T, int Dim = 3>
struct kdtree {
public:
	T midpo;
	vector<T>pos;
	kdtree<T> *ltree, *rtree;
	int depth;
	int axis;
	kdtree(const T &p_) :val(p_), ltree(nullptr), rtree(nullptr) {

	}

	kdtree(vector<T>&ps_, const int& l, const int& r, const int depth_ = 0) : ltree(nullptr), rtree(nullptr), depth(depth_), axis(depth%Dim) {
		init(ps_, l, r);
	}
	vector<T>query(const T & amin, const T&amax) {
		vector<T>ans;
		bool aok = true;
		for (int i = 0; i < Dim; ++i) {
			if (amin.coors[i] <= val.coors[i] && val.coors[i] <= amax.coors[i]) {

			}
			else {
				aok = false;
				break;
			}
		}
		if (aok) {
			ans.emplace_back(val);
		}
		axisSorter<T> as(axis);
		if (as(midpo, amax) || val.coors[axis] == amax.coors[axis]) {
			if (rtree != nullptr) {
				vector<T>tans(rtree->query(amin, amax));
				ans.insert(ans.end(), tans.begin(), tans.end());
			}
		}
		if (as(amin, midpo) || val.coors[axis] == amin.coors[axis]) {
			if (ltree != nullptr) {
				vector<T>tans(ltree->query(amin, amax));
				ans.insert(ans.end(), tans.begin(), tans.end());
			}
		}
		return ans;
	}
	pair<pair<int,int>,ld> getmindis() {
		ld ansnum = 1e18;
		pair<int, int>ansp;
		if (ltree != nullptr) {
			auto p =ltree->getmindis();
			if (ansnum > p.second) {
				ansnum = p.second;
				ansp = p.first;
			}
		}
		if (rtree != nullptr) {
			auto p =  rtree->getmindis();
			if (ansnum > p.second) {
				ansnum = p.second;
				ansp = p.first;
			}
		}

		vector<po>lpos,rpos;
		ld axisvalue = midpo.coors[axis];
		if (ltree != nullptr) {
			for (auto po : ltree->pos) {
				if (po.coors[axis]>axisvalue - sqrt(ansnum)) {
					lpos.emplace_back(po);
				}
			}
		}
		if (rtree != nullptr) {
			for (auto po : rtree->pos) {
				if (po.coors[axis]<axisvalue + sqrt(ansnum)) {
					rpos.emplace_back(po);
				}
			}
		}
		for (auto lpo : lpos) {
			for (auto rpo : rpos) {
				ld dis = getdis(lpo, rpo);
				if (ansnum > dis) {
					ansnum = dis;
					ansp = make_pair(lpo.index, rpo.index);
				}
			}
			{
				ld dis = getdis(lpo, midpo);
				if (ansnum > dis) {
					ansnum = dis;
					ansp = make_pair(lpo.index, midpo.index);
				}
			}
		}
		for (auto rpo : rpos) {
			ld dis = getdis(midpo, rpo);
			if (ansnum > dis) {
				ansnum = dis;
				ansp = make_pair( midpo.index,rpo.index);
			}
		}
		return make_pair(ansp, ansnum);
		
	}
private:
	void init(vector<T>&ps, const int& l, const int& r) {
		if (l >= r) {
			return;
		}
		sort(ps.begin() + l, ps.begin() + r, axisSorter<T>(axis));
		const int mid = (l + r) / 2;
		midpo = ps[mid];
		pos = vector<T>(ps.begin() + l, ps.begin() + r);
		
		ltree = make_kdtree(ps, l, mid, depth + 1);
		rtree = make_kdtree(ps, mid + 1, r, depth + 1);
	}

};


//[l..r)
template<class T>
kdtree<T> *make_kdtree(vector<T>&ps_, const int& l, const int& r, const int& depth = 0) {
	if (l >= r)return nullptr;
	else {
		return new kdtree<T>(ps_, l, r, depth);
	}
}

vector<ld>getunit(vector<int>v) {
	vector<ld>unit;
	ld len = 0;
	for (auto a : v) {
		len += a*a;
		unit.emplace_back(ld(a));
	}
	len = sqrt(len);
	for (auto&u : unit) {
		u /= len;
	}
	return unit;
}

int main() {
	while (1) {
		int M, N, S, W; cin >> M >> N >> S >> W;
		if (!M&&!N&&!S&&!W)break;
		vector<po>pos;
		vector<vector<int>>memo;
		{
			int nx, ny, nz;
			for (int i = 0; i < M; ++i) {
				cin >> nx >> ny >> nz;

				po p(i, getunit(vector<int>{nx, ny, nz}));
				memo.push_back(vector<int>{nx,ny,nz} );
				pos.emplace_back(p);
			}
			int g = S;
			for (int i = M; i < M + N; ++i) {
				nx = (g / 7) % 100 + 1;
				ny = (g / 700) % 100 + 1;
				nz = (g / 70000) % 100 + 1;
				po p(i, getunit(vector<int>{nx, ny, nz}));
				memo.push_back(vector<int>{nx, ny, nz});
				if (g % 2 == 0)g = g / 2;
				else g = (g / 2) ^ W;
				pos.emplace_back(p);
			}
		}
		sort(pos.begin(), pos.end(), [](const po&l, const po&r) {
			ld dis = 0;
			for (int i = 0; i < 3; ++i) {
				if (abs(l.coors[i] - r.coors[i])> eps)return l.coors[i] < r.coors[i];
			}
			return l.index < r.index;
		});
		{
			vector<po>newpos;
			for (int i = 0; i < pos.size(); ++i) {
				if (newpos.empty())newpos.push_back(pos[i]);
				else {
					auto backpo(newpos.back());
					if (getdis(backpo, pos[i]) < eps) {
						continue;
					}
					else {
						newpos.push_back(pos[i]);
					}
				}
			}
			pos = newpos;
		}
		auto tree = make_kdtree(pos, 0, pos.size(), 0);
		auto ansp = tree->getmindis();
		for (int i = 0; i < 3; ++i) {
			if (memo[ansp.first.first][i]>memo[ansp.first.second][i]) {
				swap(ansp.first.first, ansp.first.second);
				break;
			}
			else if (memo[ansp.first.first][i] == memo[ansp.first.first][i]) {
				continue;
			}
			else {
				break;
			}
		}
		//cout << ansp.first.first << " " << ansp.first.second << endl;
		for (int i = 0; i < 3; ++i) {
			cout << memo[ansp.first.first][i] << " ";
		}
		for (int i = 0; i < 3; ++i) {
			cout << memo[ansp.first.second][i];
			if (i == 2)cout << endl;
			else cout << " ";
		}
		
	}
	return 0;
}

Compiler output:
a.cc: In constructor 'kdtree<T, Dim>::kdtree(const T&)':
a.cc:50:30: error: class 'kdtree<T, Dim>' does not have any field named 'val'
   50 |         kdtree(const T &p_) :val(p_), ltree(nullptr), rtree(nullptr) {
      |                              ^~~
a.cc: In member function 'std::vector<_Tp> kdtree<T, Dim>::query(const T&, const T&)':
a.cc:61:46: error: 'val' was not declared in this scope
   61 |                         if (amin.coors[i] <= val.coors[i] && val.coors[i] <= amax.coors[i]) {
      |                                              ^~~
a.cc:70:42: error: 'val' was not declared in this scope
   70 |                         ans.emplace_back(val);
      |                                          ^~~
a.cc:73:40: error: 'val' was not declared in this scope
   73 |                 if (as(midpo, amax) || val.coors[axis] == amax.coors[axis]) {
      |                                        ^~~
a.cc:79:40: error: 'val' was not declared in this scope
   79 |                 if (as(amin, midpo) || val.coors[axis] == amin.coors[axis]) {
      |                                        ^~~