Language: C++

#pragma GCC optimise("Ofast,unroll-loops,no-stack-protector,fast-math");
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")
          
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
          
using namespace std;
using namespace __gnu_pbds;
          
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
          
using matrix = vector<vector<ll>>;
template<typename T>
using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
          
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).begin(), (x).rend()
//#define int long long
          
void FAST_IO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.setf(ios::fixed);
    //cout.precision(20);
    #ifndef _offline
    //freopen("trains.in", "r", stdin);
    //freopen("trains.out", "w", stdout);
    #endif
}

signed main() {
    FAST_IO();
    int n;
    cin >> n;
    vector<pii> ans;
    if (n % 2 == 1) {
        vector<pii> pairs;
        for (int a = 1; ; ++a) {
            int b = n - a;
            if (b < a) {
                break;
            }
            pairs.push_back({a, b});
        }
        for (int i = 0; i < pairs.size(); ++i) {
            for (int j = i + 1; j < pairs.size(); ++j) {
                ans.emplace_back(pairs[i].first, pairs[j].first);
                ans.emplace_back(pairs[i].first, pairs[j].second);
                ans.emplace_back(pairs[i].second, pairs[j].first);
                ans.emplace_back(pairs[i].second, pairs[j].second);
            }
        }
        for (int i = 1; i < n; ++i) {
            ans.emplace_back(i, n);
        }
    }
    else {
        vector<pii> pairs;
        for (int a = 1; ; ++a) {
            int b = n + 1 - a;
            if (b < a) {
                break;
            }
            pairs.push_back({a, b});
        }
        for (int i = 0; i < pairs.size(); ++i) {
            for (int j = i + 1; j < pairs.size(); ++j) {
                ans.emplace_back(pairs[i].first, pairs[j].first);
                ans.emplace_back(pairs[i].first, pairs[j].second);
                ans.emplace_back(pairs[i].second, pairs[j].first);
                ans.emplace_back(pairs[i].second, pairs[j].second);
            }
        }
    }
    cout << ans.size() << '\n';
    for (auto &[x, y] : ans) {
        cout << x << ' ' << y << '\n';
    } 
    return 0;
}

Compiler output:
In file included from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:4:
/usr/include/c++/14/bits/allocator.h: In destructor 'std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int> > >::_Vector_impl::~_Vector_impl()':
/usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = std::pair<int, int>]': target specific option mismatch
  182 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:132:14: note: called from here
  132 |       struct _Vector_impl
      |              ^~~~~~~~~~~~