Language: C++

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

vector<pair<long long, long long>> solve(long long k, long long x, long long y) {
	// 全て同じ向きで行ける場合
	if (x % k == 0) {
		vector<pair<long long, long long>> L0;
		long long ex = x, ey = y;
		L0.push_back(make_pair(x, y));
		while (ex > 0) {
			L0.push_back(make_pair(ex, ey));
			ex -= k; ey -= k; if (ey < 0) ey = 0;
			if ((ex + ey) % 2 == 1) ey++;
		}
		return L0;
	}
	
	long long cx = 0, cy = 0;

	// 左向き 1 回
	vector<pair<long long, long long>> L1;
	cx = x - (x % k); cy = y - k;
	if ((cx + cy) % 2 == 0 && (cx > 0 || cy % k == 0)) {
		L1.push_back(make_pair(x, y));

		if (cx > 0) {
			long long ex = cx, ey = cy;
			while (ex > 0) {
				L1.push_back(make_pair(ex, ey));
				ex -= k; ey -= k; if (ey < 0) ey = 0;
				if ((ex + ey) % 2 == 1) ey++;
			}
		}
		else if (cy > 0) {
			while (cy > 0) { L1.push_back(make_pair(cx, cy)); cy -= k; }
		}
		else {
			while (cy < 0) { L1.push_back(make_pair(cx, cy)); cy += k; }
		}
	}

	// 右向き 1 回
	vector<pair<long long, long long>> L2;
	cx = x - (x % k) + k; cy = y - k;
	if ((cx + cy) % 2 == 0 && cx > 0) {
		L2.push_back(make_pair(x, y));
		long long ex = cx, ey = cy;
		while (ex > 0) {
			L2.push_back(make_pair(ex, ey));
			ex -= k; ey -= k; if (ey < 0) ey = 0;
			if ((ex + ey) % 2 == 1) ey++;
		}
	}

	// 左向き 2 回
	vector<pair<long long, long long>> L3;
	cx = x - (x % k); cy = y - k * 2;
	if ((cx + cy) % 2 == 0 && (cx > 0 || cy % k == 0)) {
		L3.push_back(make_pair(x, y));
		L3.push_back(make_pair(x - (k % 2), y - k));
		if (abs(y - k * 2) < abs(y)) cy = y - k * 2;
		else cy = y;

		if (cx > 0) {
			long long ex = cx, ey = cy;
			while (ex > 0) {
				L3.push_back(make_pair(ex, ey));
				ex -= k; ey -= k; if (ey < 0) ey = 0;
				if ((ex + ey) % 2 == 1) ey++;
			}
		}
		else if (cy > 0) {
			while (cy > 0) { L3.push_back(make_pair(cx, cy)); cy -= k; }
		}
		else {
			while (cy < 0) { L3.push_back(make_pair(cx, cy)); cy += k; }
		}
	}

	// 右向き 2 回
	vector<pair<long long, long long>> L4;
	cx = x - (x % k) + k; cy = y - k * 2;
	if ((cx + cy) % 2 == 0 && cx > 0) {
		L4.push_back(make_pair(x, y));
		L4.push_back(make_pair(x - (k % 2), y - k));
		if (abs(y - k * 2) < abs(y)) cy = y - k * 2;
		else cy = y;

		long long ex = cx, ey = cy;
		while (ex > 0) {
			L4.push_back(make_pair(ex, ey));
			ex -= k; ey -= k; if (ey < 0) ey = 0;
			if ((ex + ey) % 2 == 1) ey++;
		}
	}

	// まとめ
	vector<pair<long long, long long>> FinalAns;
	if (L1.size() > 0 && (FinalAns.size() == 0 || FinalAns.size() > L1.size())) FinalAns = L1;
	if (L2.size() > 0 && (FinalAns.size() == 0 || FinalAns.size() > L2.size())) FinalAns = L2;
	if (L3.size() > 0 && (FinalAns.size() == 0 || FinalAns.size() > L3.size())) FinalAns = L3;
	if (L4.size() > 0 && (FinalAns.size() == 0 || FinalAns.size() > L4.size())) FinalAns = L4;
	reverse(FinalAns.begin(), FinalAns.end());
	return FinalAns;
}

long long K, X, Y;

int main() {
	cin >> K >> X >> Y;
	
	if (K % 2 == 0 && (X + Y) % 2 != 0) {
		cout << "-1" << endl;
		return 0;
	}

	long long ax = X - Y, ay = X + Y;
	X = ax; Y = ay;

	bool v1 = false, v2 = false, v3 = false;
	if (X < 0) { v1 = true; X *= -1; }
	if (Y < 0) { v2 = true; Y *= -1; }
	if (X < Y) { v3 = true; swap(X, Y); }

	vector<pair<long long, long long>> ans = solve(K, X, Y);
	if (v3 == true) { for (int i = 0; i < ans.size(); i++) swap(ans[i].first, ans[i].second); }
	if (v2 == true) { for (int i = 0; i < ans.size(); i++) ans[i].second *= -1; }
	if (v1 == true) { for (int i = 0; i < ans.size(); i++) ans[i].first *= -1; }

	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++) {
		long long cx = ans[i].first, cy = ans[i].second;
		cout << (cx + cy) / 2 << " " << (cy - cx) / 2 << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'std::vector<std::pair<long long int, long long int> > solve(long long int, long long int, long long int)':
a.cc:104:9: error: 'reverse' was not declared in this scope
  104 |         reverse(FinalAns.begin(), FinalAns.end());
      |         ^~~~~~~