This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n = 2;
vector<pair<int,int>> ans;
void build(vector<int> par, ll k, bool neg) {
    if (k == 1) {
        if (neg) {
            vector<int> newpar = {n + 1, n + 2};
            n += 2;
            for (auto &i : par) {
                for (auto &j : newpar) {
                    ans.emplace_back(i, j);
                }
            }
            build(newpar, 1, neg ^ 1);
            return;
        }
        for (auto &i : par) {
            ans.emplace_back(i, 2);
        }
        return;
    }
    vector<int> newpar = {n + 1, n + 2, n + 3};
    n += 3;
    for (auto &i : par) {
        for (auto &j : newpar) {
            ans.emplace_back(i, j);
        }
    }
    build(newpar, k >> 1, neg ^ 1);
    if (k & 1) {
        if (par.size() == 1) {
            ans.emplace_back(1, n);
            ans.emplace_back(n, 2);
            n++;
        } else {
            vector<int> newpar = {n + 1, n + 2};
            n += 2;
            for (auto &i : par) {
                for (auto &j : newpar) {
                    ans.emplace_back(i, j);
                }
            }
            build(newpar, 1, neg ^ 1);
        }
    }
}
void solve() {
    ll k;
    cin >> k;
    if (k == 0) {
        cout << "3 2\n1 2\n2 3\n";
        return;
    }
    bool neg = k > 0;
    build({1}, abs(k), neg);
    cout << n << " " << (int) ans.size() << '\n';
    for (int i = 0; i < (int) ans.size(); i++) {
        if (ans[i].first == 2 || ans[i].first == n) ans[i].first = n + 2 - ans[i].first;
        if (ans[i].second == 2 || ans[i].second == n) ans[i].second = n + 2 - ans[i].second;
        cout << ans[i].first << " " << ans[i].second << '\n';
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc = 1;
    //cin >> tc;
    while (tc--) {
        solve();
    }
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |