Account
GitHubFeedback
Drafts and results saved on this device
Submit on CSES.fi
CSES Problemset/Introductory Problems

Gray Code

#2205
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

Time limit:1.00 s
Memory limit:512 MB
Unsolved
Download Tests (.zip)

A Gray code is a list of all 2n2^n bit strings of length nn, where any two successive strings differ in exactly one bit (i.e., their Hamming distance is one).

Your task is to create a Gray code for a given length nn.

Input

The only input line has an integer nn.

Output

Print 2n2^n lines that describe the Gray code. You can print any valid solution.

Constraints
  • 1≤n≤161 \le n \le 16
Sample Test Cases (1)
Example 1ID: sample-1
Input
2
Expected Output
00
01
11
10
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|1 line, 0 chars
Test Bench
Download .zip
Input (stdin)
2
Expected Output
00
01
11
10