Problem:
Score : 1000 points

Problem Statement

We will call a string x good if it satisfies the following condition:

Condition: x can be represented as a concatenation of two copies of another string y of length at least 1.

For example, aa and bubobubo are good; an empty string, a, abcabcabc and abba are not good.

Eagle and Owl created a puzzle on good strings.
Find one string s that satisfies the following conditions. It can be proved that such a string always exists under the constraints in this problem.

1 ≤ |s| ≤ 200

Each character of s is one of the 100 characters represented by the integers 1 through 100.

Among the 2^{|s|} subsequences of s, exactly N are good strings.

Constraints

1 ≤ N ≤ 10^{12}

Input

Input is given from Standard Input in the following format:

N

Output

In the first line, print |s|, the length of s.
In the second line, print the elements in s in order, with spaces in between. Any string that satisfies the above conditions will be accepted.

Sample Input 1

7

Sample Output 1

4
1 1 1 1

There are two good strings that appear as subsequences of s: (1,1) and (1,1,1,1). There are six occurrences of (1,1) and one occurrence of (1,1,1,1), for a total of seven.

Sample Input 2

299

Sample Output 2

23
32 11 11 73 45 8 11 83 83 8 45 32 32 10 100 73 32 83 45 73 32 11 10

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

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

/**
 * Returns the least index of elements that are modified, wrapped with Some.
 * If the entire array is reversed, it returns None instead.
 * v's elements must be pairwise distinct.
 */
fn next_permutation<T: Ord>(v: &mut [T]) -> Option<usize> {
    let mut tail_dec: usize = 1;
    let n = v.len();
    while tail_dec < n {
        if v[n - tail_dec - 1] > v[n - tail_dec] {
            tail_dec += 1;
        } else {
            break;
        }
    }
    // v[n - tail_dec .. n] is strictly decreasing
    if tail_dec < n {
        let x = n - tail_dec - 1;
        let mut y = n;
        {
            let pivot = &v[x];
            for i in (n - tail_dec .. n).rev() {
                if v[i] > *pivot {
                    y = i;
                    break;
                }
            }
            assert!(y < n);
        }
        v.swap(x, y);
    }
    v[n - tail_dec .. n].reverse();
    if tail_dec < n {
        Some(n - tail_dec - 1)
    } else {
        None
    }
}


fn find_perm(k: i64, maxlen: usize) -> Option<Vec<usize>> {
    assert!(k < 200);
    // naive
    let k = k as usize;
    let mut n = ((k + 1).next_power_of_two() - 1).count_ones() as usize;
    if n <= 0 {
        n = 1;
    }
    while n <= 7 {
        let mut seq = vec![0; n];
        for i in 0 .. n {
            seq[i] = i;
        }
        while let Some(_) = next_permutation(&mut seq) {
            // check seq
            let mut cnt = 0;
            for bits in 1 .. 1 << n {
                let mut pool = Vec::new();
                for i in 0 .. n {
                    if (bits & 1 << i) != 0 {
                        pool.push(seq[i]);
                    }
                }
                let mut ok = true;
                for i in 0 .. pool.len() - 1 {
                    if seq[i] > seq[i + 1] { ok = false; break; }
                }
                if ok {
                    cnt += 1;
                }
            }
            //println!("cnt = {}, seq = {:?}", k, seq);
            if cnt == k {
                return Some(seq);
            }
        }
        n += 1;
    }
    if k > maxlen { return None; }
    let mut ret = vec![0; k];
    for i in 0 .. k {
        ret[i] = k - 1 - i;
    }
    Some(ret)
}

fn solve() {
    let mut n: i64 = get();
    let mut ans = Vec::new();
    let mut pos = 1;
    const INF: i64 = 1 << 60;
    while n > 0 {
        let mut mi: i64 = INF;
        let mut mink = 0;
        let mut mins = 0;
        let mut minvec = Vec::new();
        {
            let mut k = 1;
            while n >= (1 << k) - 1 {
                let s = ((n + 1) >> k) - 1;
                if s > 100 {
                    k += 1;
                    continue;
                }
                let vec = find_perm(s, k);
                if vec == None { k += 1; continue; }
                let vec = vec.unwrap();
                let vlen = vec.len();
                if vlen > k { k += 1; continue; }
                let rem = ((s + 1) << k) - 1;
                if n < rem {
                    k += 1;
                    continue;
                }
                if mi > n - rem {
                    mi = n - rem;
                    mink = k;
                    mins = s;
                    minvec = vec;
                }
                k += 1;
            }
        }
        assert!(mi != INF);
        assert!(mink > 0);
        let removal = ((mins as i64 + 1) << mink) - 1;
        n -= removal;
        for i in 0 .. mink {
            ans.push(pos + i);
        }
        for v in 0 .. minvec.len() {
            ans.push(pos + mink + v);
        }
        for i in 0 .. mink {
            ans.push(pos + i);
        }
        minvec.reverse();
        for &v in minvec.iter() {
            ans.push(pos + mink + v);
        }
        pos += mink + minvec.len();
    }
    // assert!(pos <= 101);

    println!("{}", ans.len());
    for i in 0 .. ans.len() {
        print!("{}{}", ans[i], if i == ans.len() - 1 { "\n" } else { " " });
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}