#include <iostream>

int main() {
    int n;
    std::cin >> n;
    int a[n][n];

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            a[i][j] = i * j;
            std::cout << a[i][j] << " ";
        }
        std::cout << "\n";
    }

    int s = 0;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            s += a[i][j];
        }
        int avg = s / n;
        std::cout << avg << "\n";
        s = 0;
    }
}