Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to n, inclusive.

For permutation p = p0, p1, ..., pn, Polo has defined its beauty — number <image>.

Expression <image> means applying the operation of bitwise excluding "OR" to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is represented as "^" and in Pascal — as "xor".

Help him find among all permutations of integers from 0 to n the permutation with the maximum beauty.

Input

The single line contains a positive integer n (1 ≤ n ≤ 106).

Output

In the first line print integer m the maximum possible beauty. In the second line print any permutation of integers from 0 to n with the beauty equal to m.

If there are several suitable permutations, you are allowed to print any of them.

Examples

Input

4


Output

20
0 2 1 4 3
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;


public class ProblemC {

	public static void main(String[] args) throws IOException {
		
		ProblemC solver = new ProblemC();
		solver.init();
		solver.solve();
	}
	
	private void init() {
		
		
	}
	
	private void solve() throws IOException {
		 
		Reader in = new Reader(System.in); 
		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		
		int n = in.nextInt();
		int[] p = new int[n+1];
		solve(p, n);
		long r = 0;
		for (int i = 0; i <= n; i++) {
			r += i ^ p[i];
		}
		out.println(r);
		for (int k : p) {
			out.print(k + " ");
		}
		out.println();
		out.flush();
		out.close();
	}
	
	private void solve(int[] p, int n) {
		if (n <= 0) return;
		int from = findFrom(n);
		int down = from;
		while (n > down) {
			if (Integer.bitCount(n) == 1) {
				p[n] = n - 1;
				p[n-1] = n;
				n -= 2;
			} else {
				p[n] = down;
				p[down] = n;
				n--;
				down++;
			}
		}
		solve(p, Math.min(n, from-1));
	}

	private int findFrom(int n) {
		if (n == 1) return 0;
		if (Integer.bitCount(n) == 1) return 1;
		
		int stop = Integer.highestOneBit(n);
		int mask = 0;
		int bit = 1;
		while (bit != stop) {
			if ((bit & n) == 0) mask |= bit;
			bit <<= 1;
		}
		return mask;
	}

	private static class Reader {
		
	    BufferedReader reader;
	    StringTokenizer tokenizer;
	
	    /** call this method to initialize reader for InputStream */
	    Reader(InputStream input) {
	        reader = new BufferedReader(
	                     new InputStreamReader(input) );
	        tokenizer = new StringTokenizer("");
	    }
	
	    /** get next word */
	    public String next() throws IOException {
	        while ( ! tokenizer.hasMoreTokens() ) {
	            //TODO add check for eof if necessary
	            tokenizer = new StringTokenizer(
	                   reader.readLine() );
	        }
	        return tokenizer.nextToken();
	    }
	
	    public int nextInt() throws IOException {
	        return Integer.parseInt( next() );
	    }
	    
	    public double nextDouble() throws IOException {
	        return Double.parseDouble( next() );
	    }
	    
	    public long nextLong() throws IOException {
	    	return Long.parseLong(next());
	    }
	}

}
