# coinStack-q4
# Exs for Section 65, Q.4, p.231, p.280
# input:  3 or 5
# GOTO version not translated

def printCoins(x, i):
  for j in range(len(x)):
    if x[j]:
      print("H", end=' ')
    else:
      print("T", end=' ')
    if (j == i):
      print("|", end = ' ')
  print()

n = int(input("n=? "))
x = [True]*n
i = 0
steps = 0
allHeads = False
while not allHeads:
  print(f"{steps:2}: ", end='')
  printCoins(x, i)
  x[0:i+1] = reversed(x[0:i+1])
  for j in range(i+1):
    x[j] = not x[j]
  steps += 1
  allHeads = all(coin for coin in x)
  i = (i+1)%n;
print(f"{steps:2}: ", end='')
printCoins(x, i)
