Page not loading? Try clicking here.
Placeholder

#2071

Pascal triangle 1s 64MB

Problems

What is a Pascal triangle? A Pascal triangle is a triangle in which each number is obtained by adding the values of the upper-left and upper-right positions, as shown in Table 1 below.

Write a program that, given the height 𝑛 of a Pascal triangle and a type π‘š, prints the triangle in the specified format.

Conditions

The appearance of the Pascal triangle depends on the type π‘š, as shown in Table 2.


Input

Two integers are given: the triangle height 𝑛 (1 ≀ 𝑛 ≀ 30) and the type π‘š (1 ≀ π‘š ≀ 3).


Output

Print the Pascal triangle according to the given height 𝑛 and type π‘š.

Separate numbers with a single space.


Example #1

5 1
1

1 1
1 2 1
1 3 3 1
1 4 6 4 1

Example #2

4 2
1 3 3 1
1 2 1
1 1
1

Example #3

6 3
1

5 1
10 4 1
10 6 3 1
5 4 3 2 1
1 1 1 1 1 1


Source

JUNGOL

You must sign in to write code.