Under construction

Still being built. Things may change

Fast Travel Coloring

Time limit2sMemory limit256 MB

Summary
Color the edges of a complete graph with 7n vertices using n colors so that every vertex pair is joined by an edge of each color or by a two-edge path of that color.
Level

Hard9 of 10

Topics
Graph, Math, Implementation
Solved
No attempts yet

Problem

You are given a complete undirected graph with 7n7n vertices, where nn is a positive integer. Paint its edges in nn colors so that for each pair of vertices u,vu, v and each color cc, at least one of the following holds:

  • The edge between uu and vv has color cc.
  • There is a vertex ww such that both edges (u,w)(u, w) and (w,v)(w, v) have color cc.

Input

The only line of input contains a positive integer nn (7≤7n≤10007 \leq 7n \leq 1000).

Output

Number the colors from 1 to nn. Let ci,jc_{i,j} be 00 if i=ji = j, and the color of the edge (i,j)(i, j) otherwise (so ci,j=cj,ic_{i,j} = c_{j,i}). Print ci,jc_{i,j} in 7n7n lines of 7n7n numbers each.

A solution is guaranteed to exist.

Hint

The second sample corresponds to the following coloring. The two images below show the subgraph for each color.

Examples2

  1. Example 1

    Input
    1
    
    Expected output
    0 1 1 1 1 1 1
    1 0 1 1 1 1 1
    1 1 0 1 1 1 1
    1 1 1 0 1 1 1
    1 1 1 1 0 1 1
    1 1 1 1 1 0 1
    1 1 1 1 1 1 0
    
  2. Example 2

    Input
    2
    
    Expected output
    0 1 2 2 1 1 1 1 1 1 1 1 1 1
    1 0 1 2 2 2 2 2 2 2 2 2 2 2
    2 1 0 1 2 2 2 2 2 2 2 2 2 2
    2 2 1 0 1 1 1 1 1 1 1 1 1 1
    1 2 2 1 0 2 2 2 2 2 2 2 2 2
    1 2 2 1 2 0 1 1 1 1 1 1 1 1
    1 2 2 1 2 1 0 1 1 1 1 1 1 1
    1 2 2 1 2 1 1 0 1 1 1 1 1 1
    1 2 2 1 2 1 1 1 0 1 1 1 1 1
    1 2 2 1 2 1 1 1 1 0 1 1 1 1
    1 2 2 1 2 1 1 1 1 1 0 1 1 1
    1 2 2 1 2 1 1 1 1 1 1 0 1 1
    1 2 2 1 2 1 1 1 1 1 1 1 0 1
    1 2 2 1 2 1 1 1 1 1 1 1 1 0