Language: C++

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

// https://atcoder.jp/contests/abc135/submissions/6597565 を参考

int K;

// 終点からスタートして原点に近づいていく
// 1つ前の点を返す関数
pair<int, int> pre(int x, int y) {
    if(x > y){
        pair<int, int> p = pre(y, x);
        return {p.second, p.first)};
    }
    if(x < 0){
        pair<int, int> p = pre(-x, y);
        return {-p.first, p.second};
    }

    // 0 <= x <= y が保証される
    if(x + y == K) return {0, 0};
    if(x + y >= 2*K) return {x, y-K};

    // x+y < 2*K && x+y != K のとき, x+y-KとKの偶奇が一致していれば2回,
    // そうでなければ x'+y' < 2*K を満たす(x', y')を経由して3回で原点に行ける
    // 以下2回で行ける場合を考える
    // 図示すれば第二象限の (x', y') | y >= y', -x'+y' = K に移動できることがわかる
    // x'<=0, y'>= 0, -x'+y'=K, (y-y')+(x-x')=K をx'について解くと
    int x_next = (x + y - 2*K) / 2;
    // yは (y-y')+(x-x')=K が成り立つように決める
    int y_next = y + x - x_next - K;
    // 3回の場合もこれでx'+y' < 2*K を満たす
    return {x_next, y_next};
}

int main() {
    int X, Y;
    cin >> K >> X >> Y;

    // 到達不可能な場合
    if(!(K&1) && (X+Y)&1) {
        cout << "-1";
        return 0;
    }

    vector<pair<int, int>> ans;
    ans.reserve(X+Y);
    ans.push_back({X, Y});
    while(ans.back() != make_pair(0, 0)){
        auto t = pre(ans.back());
        ans.push_back(t);
    }

    cout << ans.size() << "\n";
    for (int i = ans.size()-1; i >= 0; --i) {
        cout << ans[i].first << " " << ans[i].second << "\n";
    }
    return 0;
}

Compiler output:
a.cc: In function 'std::pair<int, int> pre(int, int)':
a.cc:14:34: error: expected '}' before ')' token
   14 |         return {p.second, p.first)};
      |                ~                 ^
a.cc:14:34: error: expected ';' before ')' token
   14 |         return {p.second, p.first)};
      |                                  ^
      |                                  ;
a.cc:14:34: error: expected primary-expression before ')' token
a.cc: At global scope:
a.cc:16:5: error: expected unqualified-id before 'if'
   16 |     if(x < 0){
      |     ^~
a.cc:22:5: error: expected unqualified-id before 'if'
   22 |     if(x + y == K) return {0, 0};
      |     ^~
a.cc:23:5: error: expected unqualified-id before 'if'
   23 |     if(x + y >= 2*K) return {x, y-K};
      |     ^~
a.cc:30:19: error: 'x' was not declared in this scope
   30 |     int x_next = (x + y - 2*K) / 2;
      |                   ^
a.cc:30:23: error: 'y' was not declared in this scope; did you mean 'yn'?
   30 |     int x_next = (x + y - 2*K) / 2;
      |                       ^
      |                       yn
a.cc:32:18: error: 'y' was not declared in this scope; did you mean 'yn'?
   32 |     int y_next = y + x - x_next - K;
      |                  ^
      |                  yn
a.cc:32:22: error: 'x' was not declared in this scope
   32 |     int y_next = y + x - x_next - K;
      |                      ^
a.cc:34:5: error: expected unqualified-id before 'return'
   34 |     return {x_next, y_next};
      |     ^~~~~~
a.cc:35:1: error: expected declaration before '}' token
   35 | }
      | ^
a.cc: In function 'int main()':
a.cc:51:30: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'int'
   51 |         auto t = pre(ans.back());
      |                      ~~~~~~~~^~
      |                              |
      |                              __gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type {aka std::pair<int, int>}
a.cc:11:24: note:   initializing argument 1 of 'std::pair<int, int> pre(int, int)'
   11 | pair<int, int> pre(int x, int y) {
      |                    ~~~~^
a.cc: In function 'std::pair<int, int> pre(int, int)':
a.cc:15:5: warning: control reaches end of non-void function [-Wreturn-type]
   15 |     }
      |     ^