LearnToCP
Sign in

Navigation

HomeRoadmapProblemsAbout Us

Theory

Contest Knowledge
Selecting an IDE
Basics
Your First ProgramData types and IOC++ syntaxModuloFunctionsVectorsMatricesTime Complexity
Sorting
SortingCounting sortRadix Sort
Optimization Techniques
Two PointersSum of numbers 1 to nPrefix sumBinary SearchGreedyBinary Search FunctionsBinary Search by AnswerDivide and Conquer
Binary Numbers
Binary NumbersNumbers in codeBitwise OperationsBitmasks
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of EratosthenesModified Sieve
Data Structures
StringsStackQueueMapsSetsPriority QueueCustom Criteria for FunctionsSegment TreesFenwick TreesSparse TablesUnion Find
Combinatorics
Addition PrincipleMultiplication PrincipleCombinatoric ObjectsInclusion Exclusion Principle
Geometry
Geometry BasicsVectorsCross and Dot ProductLinesPolygonsAnglesPoint in PolygonDistances and Intersection PointsConvex HullCircles
Recursion
PointersRecursionGenerating Combinatoric Objects
Dynamic Programming
About DPTree DPBitmask DPDigit DP
Graph Theory
GraphsDFS and BFSShortest PathsTreesTopological SortingDijkstra's AlgorithmMinimum Spanning TreesShortest Path Algorithms
Advanced Graph Theory
BiconnectivityStrongly Connected ComponentsBipartite GraphGraph FlowAugmenting PathsFlow - Minimum Cut DualityHeavy-Light DecompositionCentroid Decomposition
Advanced Data Structures
2D and 3D Segment TreesLazy PropagationImplicit Segment TreesPersistent Segment TreesLowest Common AncestorTrieBalanced Binary Search TreesMo's Algorithm

No Adjacent Ones

EasyProblem #49
Time LimitMemoryInputOutputTAGS
1 s64 MBstdinstdout
#recursion

Don't worry about Time Complexity for this problem

A hotel corridor has n rooms in a row. Every room is either empty or occupied, and the manager has one rule: two occupied rooms may never be next to each other.

Write down 0 for an empty room and 1 for an occupied one, and every allowed arrangement of the corridor becomes an array of n digits in which no two 1s stand side by side.

Print all of them.

The arrangements must come out in increasing order, reading each array as a number - so the all-empty corridor is first, and the arrangement starting with the most occupied rooms at the front is last.

Input

The only line of input contains a single integer n - the number of rooms.

Output

Print every allowed arrangement on its own line, as n digits separated by single spaces, in the order described above.

Example

Input
4
Output
0 0 0 0
0 0 0 1
0 0 1 0
0 1 0 0
0 1 0 1
1 0 0 0
1 0 0 1
1 0 1 0

There are eight arrangements for n=4. Arrays like 0 1 1 0 and 1 1 0 0 are missing because they put two occupied rooms next to each other.

Constraints

1≤n≤20

Submit your solution

Sign in to submit your solution and track your progress.

Sign in