Under construction

Still being built. Things may change

Binary String Ordering

Time limit1sMemory limit64 MB

Summary
Print all 2^N binary strings of length N in the order given by the binary reflected Gray code formula i XOR floor(i/2).
Level

Easy3 of 10

Topics
Bit manipulation, Math, Implementation
Solved
No attempts yet

Problem

Nikola would not stop asking questions in math class, so his teacher gave the whole class this task.

There are 2N2^N binary strings of length NN. Print all 2N2^N of them, one per line, each string exactly once, so that the distance between every two neighboring lines is 1.

The distance between two binary strings is the number of positions where the corresponding digits differ. For example:

  • distance(111, 000) = 3 (the strings differ in the first, second and third positions)
  • distance(111100, 101010) = 3 (the strings differ in the second, fourth and fifth positions)
  • distance(110011, 110011) = 0

Many orderings satisfy the condition, so this problem accepts only one of them. Counting lines from 0, line ii holds i⊕⌊i/2⌋i \oplus \lfloor i/2 \rfloor written as an NN digit binary number, where ⊕\oplus is bitwise exclusive or and the number is padded on the left with '0'. That ordering is the binary reflected Gray code, and every two neighboring lines differ in exactly one digit.

Input

The first and only line contains NN, the length of the binary strings. (1≤N≤161 \le N \le 16)

Output

Print 2N2^N lines. Line ii (0≤i<2N0 \le i < 2^N) holds the NN digit binary representation of i⊕⌊i/2⌋i \oplus \lfloor i/2 \rfloor. Every line must consist of exactly NN digits, each '0' or '1'.

You may assume that at least one solution always exists.

Examples3

  1. Example 1

    Input
    1
    
    Expected output
    0
    1
    
  2. Example 2

    Input
    2
    
    Expected output
    00
    01
    11
    10
    
  3. Example 3

    Input
    3
    
    Expected output
    000
    001
    011
    010
    110
    111
    101
    100