Algorithm


B. Present from Lena
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:


          0
        0 1 0
      0 1 2 1 0
    0 1 2 3 2 1 0
  0 1 2 3 4 3 2 1 0
0 1 2 3 4 5 4 3 2 1 0
  0 1 2 3 4 3 2 1 0
    0 1 2 3 2 1 0
      0 1 2 1 0
        0 1 0
          0

Your task is to determine the way the handkerchief will look like by the given n.

Input

The first line contains the single integer n (2 ≤ n ≤ 9).

Output

Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.

Examples
input
Copy
2
output
Copy
    0
0 1 0
0 1 2 1 0
0 1 0
0
input
Copy
3
output
Copy
      0
0 1 0
0 1 2 1 0
0 1 2 3 2 1 0
0 1 2 1 0
0 1 0
0



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <iostream>
#include <cstdio>

int main(){
    int n; scanf("%d", &n);
    for(int row = 0; row <= 2*n ; row++){ 
        for(int col = 0; col <= 2*n; col++){
            int modRow = std::min(row, 2*n - row);
            if(col >= n - modRow && col <= n + modRow){printf("%d ", std::min(col + modRow - n, n + modRow - col));}
            else{printf("  ");}
        }
        printf("\n");
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
2

Output

x
+
cmd
0
0 1 0
0 1 2 1 0
0 1 0
0
Advertisements

Demonstration


Codeforces Solution-B. Present from Lena-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+