# -*- coding: utf-8 -*-
num_of_cards = int(raw_input("Enter the number of cards you wish to use: "))
print "the max number is", (2**num_of_cards - 1)


def is_bit_on(bit_pos, number):
  return (number & (1 << bit_pos)) != 0

# Create the cards:
cards = []
for i in range(num_of_cards):
  card = []
  for num in range(2**num_of_cards):
    if is_bit_on(i,num):
      card.append(num);
  cards.append(card)

# print the cards nicely!

# there are 2**(num_of_cards-1) numbers in a card. Let the number of rows
# be close to the square root of this number
num_of_rows = 2**int((num_of_cards-1)/2)
numbers_in_col = 2**(num_of_cards-1) / num_of_rows
len_of_num = len(str(2**num_of_cards - 1))

for card in cards:
  for i in range(0,len(card), numbers_in_col):
    row_str = []
    for j in range(numbers_in_col):
      formatstr = "%" + str(len_of_num) + "d"
      row_str.append(formatstr % (card[i+j],))
    print " ".join(row_str)
  print ""