Building for the UN

Interview

Time limit3sMemory limit128 MB

Summary
Print a fixed two-floor n by n grid where the lower floor's rows and upper floor's columns each represent a labeled country, satisfying a connectivity and adjacency construction.
Level

Easy3 of 10

Topics
Implementation, Simulation, Matrix
Solved
No attempts yet

Statement

The United Nations is going to construct a new headquarters shaped like a rectangular box. The building is made of several identical rectangular floors stacked one on top of another. Every floor is a rectangular grid of the same size, and every cell of the grid is one office.

Two offices are adjacent when they lie on the same floor and share a wall, or when one sits directly on top of the other (the ceiling of the lower office is the floor of the upper one).

The building must host nn national missions. Each country receives a set of offices, and the offices belonging to one country must form a connected region: from any office of a country you can reach every other office of the same country by stepping between adjacent offices of that country.

Because any two countries may want to negotiate privately behind a shared wall or ceiling, every pair of countries must own at least one pair of adjacent offices.

Such a building always exists. So that the answer is unique, you must output the specific valid building described in the Output section.

Input

A single line with one integer nn (1≤n≤501 \le n \le 50) — the number of countries.

Output

Construct the building exactly as follows, then print it.

  • The building has height 22 (two floors), and each floor is an n×nn \times n grid: nn rows, each of nn characters.
  • Label the countries with the first nn characters of the sequence A,B,…,Z,a,b,…,zA, B, \dots, Z, a, b, \dots, z (all uppercase letters first, then all lowercase letters). Call these labels c1,c2,…,cnc_1, c_2, \dots, c_n.
  • Lower floor: every office in row ii belongs to country ii, so row ii is the character cic_i repeated nn times.
  • Upper floor: every office in column jj belongs to country jj, so every row equals c1c2…cnc_1 c_2 \dots c_n.

First print three integers hh, ww, and ll — the height, width, and length of the building; here h=2h = 2 and w=l=nw = l = n. Then print the lower floor as nn lines of nn characters, print one empty line, and print the upper floor as nn lines of nn characters.

Examples3

  1. Example 1

    Input
    1
    
    Expected output
    2 1 1
    A
    
    A
    
  2. Example 2

    Input
    2
    
    Expected output
    2 2 2
    AA
    BB
    
    AB
    AB
    
  3. Example 3

    Input
    4
    
    Expected output
    2 4 4
    AAAA
    BBBB
    CCCC
    DDDD
    
    ABCD
    ABCD
    ABCD
    ABCD