Skip to main content
Back to problems
Codeforces
Easy
Matrices
Arrays
Math
Levko and Table

Construct an n×nn \times n table of positive integers whose diagonal sum is exactly kk, with all other cells set to $1$.

Acceptance 0%
Problem Statement

You are given two integers nn and kk. Build an n×nn \times n table of positive integers such that:

  • the sum of the main diagonal equals exactly kk,
  • every other cell contains $1$.

If multiple tables are possible, any valid one is acceptable.

This is a straightforward construction problem: the only values you are free to choose are the nn diagonal cells, while all non-diagonal cells are fixed to $1$.

Input Format

  • The first line contains two integers nn and kk.

Output Format

  • Print an n×nn \times n table of positive integers.
  • The sum of the diagonal elements must be exactly kk.
  • All off-diagonal elements must be $1$.

Constraints

  • 1n1 \le n
  • knk \ge n
  • All printed values must be positive integers.

If exact original contest limits are unknown, treat the task as requiring a valid constructive output for arbitrary feasible nn and kk.

Examples
Sample cases returned by the problem API.

Example 1

Input

3 7

Output

2 1 1
1 2 1
1 1 3

Explanation

The diagonal sum is 2+2+3=72+2+3=7, and every non-diagonal cell is $1$.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.