Problem:
Score : 700 points

Problem Statement

You are given an integer N. Determine if there exists a tree with 2N vertices numbered 1 to 2N satisfying the following condition, and show one such tree if the answer is yes.

Assume that, for each integer i between 1 and N (inclusive), Vertex i and N+i have the weight i. Then, for each integer i between 1 and N, the bitwise XOR of the weights of the vertices on the path between Vertex i and N+i (including themselves) is i.

Constraints

N is an integer.

1 \leq N \leq 10^{5}

Input

Input is given from Standard Input in the following format:

N

Output

If there exists a tree satisfying the condition in the statement, print Yes; otherwise, print No.
Then, if such a tree exists, print the 2N-1 edges of such a tree in the subsequent 2N-1 lines, in the following format:

a_{1} b_{1}
\vdots
a_{2N-1} b_{2N-1}

Here each pair (a_i, b_i) means that there is an edge connecting Vertex a_i and b_i. The edges may be printed in any order.

Sample Input 1

3

Sample Output 1

Yes
1 2
2 3
3 4
4 5
5 6

The sample output represents the following graph:

Sample Input 2

1

Sample Output 2

No

There is no tree satisfying the condition.

Solution in Rust (1.42.0) (judge verdict: Wrong Answer)

use std::collections::BTreeSet;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    if n < 3 {
        println!("No");
        return;
    }

    let mut total_xor = 0;
    for i in 1..=n {
        total_xor ^= i;
    }

    if total_xor == 0 {
        for i in 2..=n {
            sc.write(format!("{} {}\n", i - 1, i));
            sc.write(format!("{} {}\n", i - 1 + n, i + n));
        }
        sc.write(format!("{} {}\n", n, n + 1));
        return;
    }

    let mut xor_edges = BTreeSet::new();
    if total_xor.count_ones() == 1 {
        if total_xor == n {
            println!("No");
            return;
        }

        if total_xor == 1 {
            assert!(n >= 3);
            xor_edges.insert(2);
            xor_edges.insert(3);
        } else {
            xor_edges.insert(total_xor + 1);
            xor_edges.insert(1);
        }
    } else {
        for i in 0..64 {
            let k = 1 << i;
            if k & total_xor == 0 {
                continue;
            }
            assert!(k <= n);
            xor_edges.insert(k);
        }
    }

    sc.write("Yes\n");
    let mut ans = vec![total_xor];
    for &i in xor_edges.iter() {
        assert!(i != total_xor && i <= n && i > 0);
        ans.push(i);
    }
    for i in 1..=n {
        if i != total_xor && !xor_edges.contains(&i) {
            ans.push(i);
        }
    }
    for &i in xor_edges.iter() {
        ans.push(i + n);
    }
    for i in 1..=n {
        if i != total_xor && !xor_edges.contains(&i) {
            ans.push(i + n);
        }
    }
    for i in 1..ans.len() {
        sc.write(format!("{} {}\n", ans[i - 1], ans[i]));
    }

    let edge_last = *xor_edges.iter().next_back().unwrap();
    sc.write(format!("{} {}\n", edge_last, total_xor + n));
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}