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.