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.*;
import java.util.*;

public class Main {
	static PrintWriter out = new PrintWriter(new BufferedWriter(
			new OutputStreamWriter(System.out)));

	public static void main(String[] args) throws IOException {
		Scan scan = new Scan();
		int n = scan.nextInt();
		int ans[] = new int[n + 1];
		Arrays.fill(ans, -1);
		ans[0] = 0;
		for (int i = n; i > 0; i--) {
			if (ans[i] != -1)
				continue;
			int tmp = i;
			int l = 0;
			int count = 0;
			while(tmp>0){
				if((tmp&1)==0)
					l+=1<<count;
				count++;
				tmp = tmp>>1;
			}
			// System.out.println(l+" "+i);
			ans[i] = l;
			ans[l] = i;
		}
		long res = 0;
		for (int i = 0; i <= n; i++)
			res += (long)(ans[i] ^ i);
		out.println(res);
		for (int x : ans)
			out.print(x + " ");
		out.flush();

	}
}

class Scan {

	BufferedReader buffer;
	StringTokenizer tok;

	Scan() {
		buffer = new BufferedReader(new InputStreamReader(System.in));
	}

	boolean hasNext() {
		while (tok == null || !tok.hasMoreElements()) {
			try {
				tok = new StringTokenizer(buffer.readLine());
			} catch (Exception e) {
				return false;
			}
		}
		return true;
	}

	String next() {
		if (hasNext())
			return tok.nextToken();
		return null;
	}

	String nextLine() {
		String s = null;
		try {
			s = buffer.readLine();
		} catch (Exception e) {
			return null;
		}
		return s;
	}

	char nextChar() {
		try {
			return ((char) buffer.read());
		} catch (Exception e) {
		}
		return '\0';
	}

	int nextInt() {
		return Integer.parseInt(next());
	}

	long nextLong() {
		return Long.parseLong(next());
	}

	double nextDouble() {
		return Double.parseDouble(next());
	}
}