You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.

One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.

If there exists no such matrix then output -1.


-----Input-----

The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 10^6).


-----Output-----

If the answer exists then output resulting matrix. Otherwise output -1.


-----Examples-----
Input
2 1

Output
1 0 
0 0 

Input
3 2

Output
1 0 0 
0 1 0 
0 0 0 

Input
2 5

Output
-1

Difficulty: MEDIUM
Tags: Constructive algorithms

Starter code:

Solutions:
import math, string, itertools, collections, re, fractions, array, copy
import bisect
import heapq
from itertools import chain, dropwhile, permutations, combinations
from collections import deque, defaultdict, OrderedDict, namedtuple, Counter, ChainMap

def VI():
	return list(map(int, input().split()))

def I():
	return int(input())

def LIST(n, m=None):
	return [0] * n if m is None else [[0] * m for i in range(n)]

def ELIST(n):
	return [[] for i in range(n)]

def MI(n=None, m=None):
	if n is None:
		(n, m) = VI()
	arr = LIST(n)
	for i in range(n):
		arr[i] = VI()
	return arr

def MS(n=None, m=None):
	if n is None:
		(n, m) = VI()
	arr = LIST(n)
	for i in range(n):
		arr[i] = input()
	return arr

def MIT(n=None, m=None):
	if n is None:
		(n, m) = VI()
	a = MI(n, m)
	arr = LIST(m, n)
	for (i, l) in enumerate(a):
		for (j, x) in enumerate(l):
			arr[j][i] = x
	return arr

def main(info=0):
	(n, k) = VI()
	if k > n * n:
		print('-1')
	else:
		m = [['0' for _ in range(n)] for _ in range(n)]
		(i, j) = (0, 0)
		for i in range(n):
			for j in range(i, n):
				if k == 0:
					break
				if i == j:
					m[i][j] = '1'
					k -= 1
				else:
					if k == 1:
						continue
					m[i][j] = '1'
					m[j][i] = '1'
					k -= 2
			if k == 0:
				break
		for l in m:
			print(' '.join(l))

def __starting_point():
	main()
__starting_point()


import sys
(n, k) = map(int, input().split())
matrix = [[0] * n for _ in range(n)]
(i1, j1, i2, j2) = (0, 0, 0, 0)
for i in range(n):
	for j in range(n):
		if matrix[i][j]:
			continue
		if i == j and k < 1 or (i != j and k < 2):
			break
		matrix[i][j] = matrix[j][i] = 1
		k -= 1 if i == j else 2
for i in range(n):
	if matrix[i][i] == 0 and k:
		matrix[i][i] = 1
		k -= 1
if k:
	print(-1)
else:
	for row in matrix:
		print(*row)


(n, k) = map(int, input().split(' '))
if k > n ** 2:
	print(-1)
elif k == n ** 2:
	a = [['1'] * n for i in range(n)]
	for i in range(n):
		a[i] = ' '.join(a[i])
		print(a[i])
else:
	a = [['0'] * n for i in range(n)]
	c = 0
	i = 0
	b = True
	while b and i < n:
		for j in range(n):
			if i == j:
				if c + 1 > k:
					continue
				a[i][j] = '1'
				c += 1
			elif a[j][i] != '1':
				if c + 2 > k:
					continue
				a[i][j] = '1'
				a[j][i] = '1'
				c += 2
			if c == k:
				b = False
				break
		i += 1
	for i in range(n):
		a[i] = ' '.join(a[i])
		print(a[i])


(n, k) = map(int, input().split())
if n * n < k:
	print(-1)
else:
	arr = [[0 for _ in range(n)] for _ in range(n)]
	cnt = 0
	for i in range(n):
		if cnt < k:
			arr[i][i] = 1
			cnt += 1
		for j in range(i + 1, n):
			if cnt <= k - 2:
				arr[i][j] = 1
				arr[j][i] = 1
				cnt += 2
	for r in arr:
		print(' '.join(map(str, r)))


def main(n, k):
	total = n * n
	if total < k:
		print(-1)
		return
	m = [[0] * n for _ in range(n)]
	fill(m, n, k)
	print_m(m)

def fill(m, n, k):
	for i in range(n):
		for j in range(i, n):
			if k == 0:
				return
			if i == j:
				m[i][j] = 1
				k -= 1
			elif k == 1:
				m[i + 1][i + 1] = 1
				k = 0
				return
			else:
				m[i][j] = 1
				m[j][i] = 1
				k -= 2

def print_m(m):
	for row in m:
		print(' '.join(map(str, row)))
(n, k) = [int(x) for x in input().split()]
main(n, k)


(n, k) = map(int, input().split())
if k > n * n:
	print(-1)
else:
	m = [[0] * n for i in range(n)]
	i = 0
	while k > 0 and i < n:
		j = i
		while k > 0 and j < n:
			if i == j:
				m[i][j] = 1
				k -= 1
			elif k >= 2:
				m[i][j] = 1
				m[j][i] = 1
				k -= 2
			j += 1
		i += 1
	for row in m:
		print(*row)


(N, K) = map(int, input().split())
if K > N * N:
	exit(print(-1))
G = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
	if K == 0:
		break
	G[i][i] = 1
	K -= 1
	for j in range(i + 1, N):
		if K <= 1:
			break
		(G[i][j], G[j][i]) = (1, 1)
		K -= 2
for i in range(N):
	print(' '.join((str(v) for v in G[i])))


import sys
import math
(n, k) = map(int, input().split())
ans = [[0 for i in range(n)] for i in range(n)]
row = 0
col = 0
scol = 0
while row < n:
	col = scol
	while col < n:
		if col == row and k > 0:
			ans[row][col] = 1
			k -= 1
		elif k > 0:
			if k >= 2:
				ans[row][col] = 1
				ans[col][row] = 1
				k -= 2
		col += 1
	row += 1
	scol += 1
if k == 0:
	for i in range(n):
		for j in range(n):
			print(ans[i][j], end=' ')
		print()
else:
	print(-1)


(n, k) = map(int, input().split())
if k > n * n:
	print(-1)
else:
	tab = [[0] * n for _ in range(n)]
	for i in range(n):
		if k < 2:
			break
		for j in range(i, n):
			tab[i][j] = 1
			if i != j:
				k -= 2
			else:
				k -= 1
			if k < 2:
				break
	if k > 0:
		for i in range(n):
			if tab[i][i] == 0:
				tab[i][i] = 1
				break
	for i in range(n):
		for j in range(i):
			tab[i][j] = tab[j][i]
	for line in tab:
		print(' '.join(map(str, line)))


(n, k) = map(int, input().split())
matrica = [['0'] * n for i in range(n)]
if n ** 2 < k:
	print(-1)
else:
	for i in range(n):
		if k > 0:
			matrica[i][i] = '1'
			k -= 1
		else:
			break
		for j in range(i + 1, n):
			if k > 1:
				matrica[i][j] = '1'
				matrica[j][i] = '1'
				k -= 2
			else:
				break
	for i in range(n):
		for j in range(n):
			print(matrica[i][j], ' ', end='')
		print('')


from sys import stdin, stdout

def ri():
	return list(map(int, stdin.readline().split()))
(n, k) = ri()
if k > n * n:
	print(-1)
	return
m = [[0 for _ in range(n)] for __ in range(n)]
for i in range(n):
	if k == 1:
		m[i][i] = 1
		k -= 1
		break
	if k == 0:
		break
	m[i][i] = 1
	k -= 1
	for j in range(i + 1, n):
		if k == 1:
			m[i + 1][i + 1] = 1
			k -= 1
			break
		if k == 0:
			break
		m[i][j] = 1
		m[j][i] = 1
		k -= 2
for i in range(n):
	print(*m[i])


(n, k) = map(int, input().split())
if n * n < k:
	print('-1')
	exit()
mat = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
	if not k:
		break
	mat[i][i] = 1
	k = k - 1
	for j in range(i + 1, n):
		if k <= 1:
			break
		mat[i][j] = 1
		mat[j][i] = 1
		k = k - 2
for i in range(n):
	print(*mat[i])


import math
import re
(n, k) = list(map(int, input().split()))
if k > n * n:
	print(-1)
	return
a = [[0] * n for i in range(n)]
for i in range(n):
	if k == 0:
		break
	a[i][i] = 1
	k -= 1
	if k == 0:
		break
	elif k == 1:
		a[i + 1][i + 1] = 1
		break
	else:
		for j in range(i + 1, min(n, i + 1 + k // 2)):
			a[i][j] = 1
			a[j][i] = 1
			k -= 2
for i in range(n):
	print(' '.join(map(str, a[i])))


(n, k) = map(int, input().split())
mat = [[0] * n for i in range(n)]
for i in range(n):
	for j in range(n):
		if i == j and k > 0:
			mat[i][j] = 1
			k -= 1
		elif i < j and k > 1:
			mat[i][j] = mat[j][i] = 1
			k -= 2
if k > 0:
	print(-1)
	return
print('\n'.join((' '.join(map(str, e)) for e in mat)))


def show():
	for i in range(n):
		print(' '.join([str(s) for s in a[i]]))
(n, k) = [int(s) for s in input().split()]
a = [[0 for i in range(n)] for j in range(n)]
if k > n ** 2:
	print(-1)
elif k == 0:
	show()
else:
	for i in range(n):
		if k > 0:
			a[i][i] = 1
			k -= 1
			t = i
			while k >= 2 and t < n - 1:
				t += 1
				a[i][t] = 1
				a[t][i] = 1
				k -= 2
		else:
			break
	show()


def main():
	(n, k) = map(int, input().split())
	l = [['0'] * n for _ in range(n)]
	for (y, row) in enumerate(l):
		if not k:
			break
		k -= 1
		row[y] = '1'
		for x in range(y + 1, n):
			if k < 2:
				break
			k -= 2
			l[x][y] = row[x] = '1'
	if k:
		print(-1)
	else:
		for row in l:
			print(' '.join(row))
main()


(n, k) = map(int, input().split())
m = [['0'] * n for _ in range(n)]
for x in range(n):
	for y in range(x, n):
		if x == y and k >= 1:
			m[x][y] = '1'
			k -= 1
		elif k >= 2:
			m[x][y] = '1'
			m[y][x] = '1'
			k -= 2
if k > 0:
	print(-1)
else:
	print('\n'.join([' '.join(i) for i in m]))


(n, k) = map(int, input().split())
if n * n < k:
	print(-1)
	exit()
else:
	T = [[0] * n for i in range(n)]
	for i in range(n):
		for j in range(i, n):
			if k >= 1:
				if i == j:
					T[i][j] = 1
					k -= 1
				elif k >= 2:
					T[i][j] = 1
					T[j][i] = 1
					k -= 2
	for i in range(n):
		print(*T[i])


import sys

def solve():
	(n, k) = map(int, input().split())
	mat = [[0] * n for i in range(n)]
	for i in range(n):
		for j in range(i, n):
			if k == 0:
				break
			if i == j:
				mat[i][j] = 1
				k -= 1
			elif k > 1:
				mat[i][j] = mat[j][i] = 1
				k -= 2
	if k != 0:
		print(-1)
		return
	for mat_r in mat:
		print(*mat_r)

def __starting_point():
	solve()
__starting_point()


(n, k) = input().rstrip().split(' ')
(n, k) = (int(n), int(k))
a = [[0] * n for i in range(n)]
for i in range(n):
	for j in range(n):
		if j == i:
			if k > 0:
				a[i][j] = 1
				k -= 1
		elif j >= i and k > 1:
			a[i][j] = a[j][i] = 1
			k -= 2
if k != 0:
	print(-1)
else:
	for i in range(n):
		print(' '.join(map(str, a[i])))


from math import sqrt
(n, k) = map(int, input().split())
if k > n * n:
	print(-1)
else:
	a = n * n - k
	a2 = int(sqrt(a))
	if a == a2 ** 2:
		t = n - a2
		for _ in range(t):
			print('1 ' * n)
		for _ in range(n - t):
			print('1 ' * t + '0 ' * (n - t))
	else:
		t = n - a2 - 1
		for _ in range(t):
			print('1 ' * n)
		i = k - t * (2 * n - t)
		i0 = i % 2
		i1 = i // 2
		if i0 == 1:
			print('1 ' * (t + 1 + i1) + '0 ' * (n - t - 1 - i1))
			for _ in range(i1):
				print('1 ' * (t + 1) + '0 ' * (n - t - 1))
			for _ in range(n - t - 1 - i1):
				print('1 ' * t + '0 ' * (n - t))
		else:
			print('1 ' * (t + i1) + '0 ' * (n - t - i1))
			if i1 == 1:
				print('1 ' * t + '0 ' + '1 ' + '0 ' * (n - t - 2))
				for _ in range(n - t - 2):
					print('1 ' * t + '0 ' * (n - t))
			else:
				print('1 ' * (t + 2) + '0 ' * (n - t - 2))
				for _ in range(i1 - 2):
					print('1 ' * (t + 1) + '0 ' * (n - t - 1))
				for _ in range(n - t - i1):
					print('1 ' * t + '0 ' * (n - t))


(n, k) = map(int, input().strip().split(' '))
mat = []
for i in range(n):
	mat.append([0] * n)
for i in range(n):
	for j in range(i, n):
		if k > 1 and i != j:
			k -= 2
			(mat[i][j], mat[j][i]) = (1, 1)
		elif k > 0 and i == j:
			k -= 1
			mat[i][j] = 1
if k == 0:
	for i in range(n):
		for j in range(n - 1):
			print(mat[i][j], end=' ')
		print(mat[i][n - 1])
else:
	print(-1)


n = [int(i) for i in input().split()]
if n[1] > n[0] * n[0]:
	print(-1)
else:
	a = [[0 for i in range(n[0])] for j in range(n[0])]
	k = n[1]
	for i in range(n[0]):
		if k > 0:
			a[i][i] = 1
			k -= 1
		j = i + 1
		while k > 1 and j < n[0]:
			a[i][j] = 1
			a[j][i] = 1
			k -= 2
			j += 1
		if k == 1:
			a[i + 1][i + 1] = 1
			k -= 1
		if k < 1:
			break
	for i in range(n[0]):
		for j in range(n[0]):
			print(a[i][j], end=' ')
		print()


(n, k) = map(int, input().split())
if n * n < k:
	print(-1)
else:
	arr = [[0] * n for i in range(n)]
	if k != 0:
		arr[0][0] = 1
		k -= 1
	i = 0
	j = 1
	while k > 1 and i < n - 1:
		arr[i][j] = 1
		arr[j][i] = 1
		j += 1
		if i == j - 1:
			k -= 1
		else:
			k -= 2
		if j == n:
			i += 1
			j = i
	i = 1
	while k != 0 and i < n:
		if arr[i][i] == 0:
			arr[i][i] = 1
			k -= 1
		i += 1
	for i in range(n):
		print(*arr[i])


def maximal_binary_matrix(n, k):
	matrix = [[0] * n for _ in range(n)]
	for i in range(n):
		for j in range(i, n):
			if i == j and k >= 1:
				matrix[i][j] = 1
				k -= 1
			elif k >= 2:
				matrix[i][j] = 1
				matrix[j][i] = 1
				k -= 2
	return matrix if k == 0 else None
(n, k) = map(int, input().split())
m = maximal_binary_matrix(n, k)
if m:
	for row in m:
		print(*row)
else:
	print(-1)


import sys
import math

def IO():
	sys.stdin = open('pyinput.txt', 'r')
	sys.stdout = open('pyoutput.txt', 'w')

def GCD(a, b):
	if b == 0:
		return a
	else:
		return GCD(b, a % b)

def LCM(a, b):
	return a * (b // GCD(a, b))

def scan(TYPE_1, TYPE_2=0):
	if TYPE_1 == int:
		return map(int, sys.stdin.readline().strip().split())
	elif TYPE_1 == float:
		return map(float, sys.stdin.readline().strip().split())
	elif TYPE_1 == list and TYPE_2 == float:
		return list(map(float, sys.stdin.readline().strip().split()))
	elif TYPE_1 == list and TYPE_2 == int:
		return list(map(int, sys.stdin.readline().strip().split()))
	elif TYPE_1 == str:
		return sys.stdin.readline().strip()
	else:
		print('ERROR!!!!')

def main():
	(n, k) = scan(int)
	if k > n * n:
		print(-1)
		return
	a = [[0 for i in range(n)] for j in range(n)]
	for i in range(n):
		for j in range(i, n):
			if a[i][i] == 0 and k > 0:
				a[i][i] = 1
				k -= 1
			if k > 1 and i != j:
				a[i][j] = a[j][i] = 1
				k -= 2
	for i in a:
		print(*i)
main()


(nu, k) = (int(i) for i in input().split())
x = 0
y = 0
z = 0
if k > nu ** 2:
	print(-1)
else:
	n = [[0] * nu for i in range(nu)]
	while k > 1:
		if x == 0:
			n[y][y] = 1
			k -= 1
			x += 1
			z = 1
		else:
			n[y][x + y] = 1
			n[x + y][y] = 1
			x += 1
			k -= 2
		if x + y == nu:
			x = 0
			y += 1
			z = 0
	if k == 1:
		y += z
		n[y][y] = 1
	for i in n:
		for j in i:
			print(j, end=' ')
		print()


def main():
	import sys
	readln = sys.stdin.readline
	try:
		while True:
			(n, k) = map(int, input().split())
			a = [['0'] * n for i in range(n)]
			i = j = 0
			while k > 0:
				if i == j:
					a[i][j] = '1'
					k -= 1
					j += 1
				elif k >= 2:
					a[i][j] = a[j][i] = '1'
					k -= 2
					j += 1
				elif i != n - 1:
					a[i + 1][i + 1] = '1'
					k = 0
				else:
					assert a[i][i] == '1'
					a[i][i] = '0'
					a[i][j] = a[j][i] = '1'
					k = 0
				if j == n:
					i += 1
					if i == n and k > 0:
						print(-1)
						break
					j = i
			else:
				for row in a:
					print(' '.join(row))
	except EOFError:
		pass
main()


str_params = input()
params = [int(s) for s in str_params.split(' ')]
n = params[0]
k = params[1]
part = 0
if k > n ** 2:
	print('%d\n' % -1)
else:
	matr = [[0 for x in range(n)] for y in range(n)]
	i = 1
	while part < k:
		matr[i - 1][i - 1] = 1
		part = part + 1
		j = i
		while (k - part > 1) & (j < n):
			matr[i - 1][j] = 1
			matr[j][i - 1] = 1
			j = j + 1
			part = part + 2
		i = i + 1
	for row in matr:
		print(' '.join(map(str, row)))
	print()


(n, k) = map(int, input().split())
tab = [[0 for x in range(n)] for y in range(n)]
for i in range(n):
	for j in range(i, n):
		if i != j:
			if k >= 2:
				tab[i][j] = 1
				tab[j][i] = 1
				k = k - 2
		elif k >= 1:
			tab[i][j] = 1
			k = k - 1
if k > 0:
	print(-1)
else:
	for i in range(n):
		for j in range(n):
			print(tab[i][j], end=' ')
		print('')


(n, k) = map(int, input().split())
if k > n * n:
	print(-1)
else:
	b = [[0] * n for i in range(n)]
	c = 0
	i = 0
	j = 0
	t = -1
	while c < k:
		if i == j:
			b[i][j] = 1
			c += 1
			j += 1
			t = 0
		elif j == n:
			i += 1
			j = i
			t = 1
		else:
			b[i][j] = 1
			b[j][i] = 1
			j += 1
			c += 2
			t = 2
	if c == k:
		p = ''
		for q in range(n):
			for w in range(n):
				p += str(b[q][w]) + ' '
			print(p)
			p = ''
	else:
		if t == 0:
			j -= 1
		if t == 1:
			i -= 1
			j = n - 1
		if t == 2:
			j -= 1
		b[i][j] = 0
		b[j][i] = 0
		b[i + 1][i + 1] = 1
		p = ''
		for q in range(n):
			for w in range(n):
				p += str(b[q][w]) + ' '
			print(p)
			p = ''


nums = input().split()
n = int(nums[0])
k = int(nums[1])
m = [[0] * n for _ in range(n)]
if k > n * n:
	print(-1)
else:
	for i in range(n):
		for j in range(i, n):
			d = 2 if i != j else 1
			if k >= d:
				k -= d
				m[i][j] = 1
				m[j][i] = 1
			elif k == 0:
				pass
			else:
				m[i + 1][i + 1] = 1
	for i in range(n):
		for j in range(n):
			print(m[i][j], end=' ')
		print('\n', end='')


(n, k) = map(int, input().split())
x = [0 for i in range(n)]
ans = [x.copy() for i in range(n)]
for i in range(n):
	for j in range(i, n):
		if i == j and k - 1 >= 0:
			ans[i][j] = 1
			k -= 1
		elif i != j and k - 2 >= 0:
			ans[j][i] = 1
			ans[i][j] = 1
			k -= 2
if k != 0:
	print(-1)
else:
	for i in range(n):
		print(*ans[i])


def A():
	(n, k) = [int(i) for i in input().split()]
	new = [[0] * n for i in range(n)]
	count = 0
	for i in range(n, 0, -1):
		if k <= 0:
			break
		k -= 1
		new[count][n - i] = 1
		if k <= 0:
			break
		for j in range(n - i + 1, n):
			if k - 2 >= 0:
				k -= 2
				new[count][j] = 1
				new[j][count] = 1
			else:
				break
		if k <= 0:
			break
		count += 1
	if k > 0:
		print('-1')
	else:
		for i in new:
			for j in i:
				print(j, end=' ')
			print()
A()


(n, k) = map(int, input().split())
if n * n < k:
	print(-1)
else:
	mat = []
	a = []
	t = n
	for i in range(t):
		for i in range(t):
			a.append(0)
		mat.append(a)
		a = []
	for i in range(t):
		for j in range(t):
			if i != j and k > 1:
				if mat[i][j]:
					continue
				else:
					mat[i][j] = 1
					mat[j][i] = 1
					k -= 2
			elif i == j and k:
				mat[i][j] = 1
				k -= 1
	for i in range(t):
		for j in range(t - 1):
			print('%d' % mat[i][j], end=' ')
		print(mat[i][t - 1])


import sys
input = sys.stdin.readline

def pprint(mat):
	for r in mat:
		print(' '.join(r))
(n, k) = map(int, input().split())
mat = [['0'] * n for _ in range(n)]
N = n
if n ** 2 < k:
	print(-1)
	sys.exit()
else:
	num_cells = 2 * n - 1
	rc = 0
	while num_cells > 0 and num_cells <= k:
		for x in range(rc, N):
			mat[x][rc] = '1'
			mat[rc][x] = '1'
		rc += 1
		k -= num_cells
		n -= 1
		num_cells = 2 * n - 1
	if k == 0:
		pprint(mat)
		sys.exit()
	elif k % 2 == 0:
		mat[rc + 1][rc + 1] = '1'
		k -= 1
for x in range(rc, rc + k // 2 + 1):
	mat[x][rc] = '1'
	mat[rc][x] = '1'
pprint(mat)


def is_available(i, j):
	return i < n and j < n and (matrix[i][j] == 0)
(n, k) = list(map(int, input().split()))
if k > n * n:
	print(-1)
else:
	matrix = []
	for i in range(n):
		matrix.append([0] * n)
	if k % 2 == 1:
		matrix[0][0] = 1
		k -= 1
	for i in range(n):
		for j in range(n):
			if k == 0:
				i = n
				break
			if matrix[i][j] == 1:
				continue
			if i == j:
				matrix[i + 1][j + 1] = matrix[i][j] = 1
			else:
				matrix[i][j] = matrix[j][i] = 1
			k -= 2
	print('\n'.join([' '.join(map(str, row)) for row in matrix]))


(n, k) = [int(x) for x in input().split()]
if k > n * n:
	print('-1')
else:
	res = [[0 for _ in range(n)] for _ in range(n)]
	for i in range(n):
		for j in range(n):
			if i > j:
				res[i][j] = res[j][i]
			elif i == j:
				if k > 0:
					res[i][j] = 1
					k -= 1
			elif k > 1:
				res[i][j] = 1
				k -= 2
	for i in range(n):
		print(' '.join((str(res[i][j]) for j in range(n))))


s = input()
n = int(s.split(' ')[0])
k = int(s.split(' ')[1])
arr = []
for i in range(n):
	arr.append([0] * n)
if k > n * n:
	print(-1)
else:
	l = 0
	for i in range(n):
		for j in range(n):
			if arr[i][j] == 0:
				if l < k:
					if i == j:
						arr[i][j] = 1
						l += 1
					elif l < k - 1:
						arr[i][j] = 1
						arr[j][i] = 1
						l += 2
	for i in range(n):
		for j in range(n):
			print(arr[i][j], end=' ')
		print()


def maxim():
	(n, k) = map(int, input().strip().split())
	if k < 0:
		print(-1)
		return
	if k > n ** 2:
		print(-1)
		return
	a = [[0 for _ in range(n)] for _ in range(n)]
	for i in range(n):
		if k >= 1:
			a[i][i] = 1
			k -= 1
		for j in range(i + 1, n):
			if k >= 2:
				a[i][j] = 1
				a[j][i] = 1
				k -= 2
			elif k >= 1:
				break
	if k > 0:
		print(-1)
		return
	for i in range(n):
		b = [str(i) for i in a[i]]
		b = ' '.join(b)
		print(b)
maxim()


(n, k) = map(int, input().split())
if n * n < k:
	print(-1)
	exit()
a = []
for i in range(n):
	a += [[0] * n]
row = 0
col = 0
while k >= 2:
	a[row][col] = 1
	k -= 1
	if row != col:
		a[col][row] = 1
		k -= 1
	col += 1
	if col >= n:
		row += 1
		col = row
if k == 1:
	if col != row:
		row += 1
		col = row
	a[row][row] = 1
for row in a:
	print(*row)


import sys
[n, k] = map(int, input().strip().split())
if k > n * n:
	print(-1)
	sys.exit(0)
a = [[0 for _ in range(n)] for __ in range(n)]
for i in range(n):
	if k >= 1:
		a[i][i] = 1
		k -= 1
	for j in range(i + 1, n):
		if k >= 2:
			a[i][j] = a[j][i] = 1
			k -= 2
for row in a:
	print(' '.join(map(str, row)))


r = lambda : int(input())
ra = lambda : [*map(int, input().split())]
p = lambda a: print('{:.6f}'.format(a))
(n, k) = ra()
a = [[0 for j in range(n)] for i in range(n)]
if k > n ** 2:
	print(-1)
else:
	while k > 0:
		for i in range(n):
			if k > 0:
				a[i][i] = 1
				k -= 1
			for j in range(i + 1, n):
				if k <= 1:
					break
				else:
					a[i][j] = 1
					a[j][i] = 1
					k -= 2
	for i in a:
		print(*i)


(n, k) = [int(i) for i in input().split()]
if k > n ** 2:
	print(-1)
	exit()
a = [[0 for z in range(n)] for i in range(n)]
for i in range(n):
	if k == 0:
		break
	a[i][i] = 1
	k -= 1
	for j in range(i + 1, n):
		if k == 1 or k == 0:
			break
		a[i][j] = a[j][i] = 1
		k -= 2
print('\n'.join((' '.join([str(j) for j in i]) for i in a)))


def main():
	(n, k) = map(int, input().split())
	if k > n ** 2:
		print(-1)
		return
	A = [[0] * n for _ in range(n)]
	i = 0
	j = 0
	while k > 1:
		A[i][j] = 1
		k -= 1
		j += 1
		while k > 1 and j < n:
			A[i][j] = 1
			A[j][i] = 1
			j += 1
			k -= 2
		i += 1
		j = i
	if k == 1:
		A[i][j] = 1
	for i in range(n):
		for j in range(n):
			print(A[i][j], end=' ')
		print()
main()


(n, k) = list(map(int, input().split()))
ans = None
if k > n ** 2:
	print(-1)
elif k == n ** 2:
	ans = [[1] * n for arr in range(n)]
	for i in range(n):
		print(' '.join((j for j in map(str, ans[i]))))
elif k == 0:
	ans = [[0] * n for arr in range(n)]
	for i in range(n):
		print(' '.join((j for j in map(str, ans[i]))))
else:
	ans = [[0] * n for arr in range(n)]
	for i in range(n - 1, 0, -1):
		loc = n - i - 1
		k -= 1
		ans[loc][loc] = 1
		if k >= 2 * i:
			for j in range(loc + 1, n):
				ans[loc][j] = ans[j][loc] = 1
			if k == 2 * i:
				break
			k -= 2 * i
		else:
			if k % 2 == 1:
				ans[loc + 1][loc + 1] = 1
				k -= 1
			for j in range(loc + 1, loc + 1 + k // 2):
				ans[loc][j] = ans[j][loc] = 1
			break
	for i in range(n):
		print(' '.join((j for j in map(str, ans[i]))))


(n, k) = map(int, input().split())
if k > n ** 2:
	print(-1)
	exit(0)
m = []
for _ in range(n):
	m.append([0] * n)
for y in range(n):
	if k < 2:
		break
	for x in range(y, n):
		if k < 2:
			break
		if x == y:
			m[y][x] = 1
			k -= 1
		else:
			m[y][x] = 1
			m[x][y] = 1
			k -= 2
if k == 1:
	for i in range(n):
		if m[i][i] == 0:
			m[i][i] = 1
			break
for y in range(n):
	for x in range(n):
		print(m[y][x], end=' ')
	print()


(n, k) = map(int, input().split())
if k > n ** 2:
	exit(print(-1))
else:
	a = [[0] * n for i in range(n)]
	for i in range(n):
		for j in range(i, n):
			if i != j and k == 1:
				a[i + 1][i + 1] = 1
				k -= 1
			elif i == j and k > 0:
				a[i][j] = 1
				k -= 1
			elif k >= 2:
				a[i][j] = 1
				a[j][i] = 1
				k -= 2
			elif k == 0:
				break
for i in a:
	print(*i)


(n, k) = list(map(int, input().split()))
a = [[0 for j in range(n)] for i in range(n)]
if n * n < k:
	print(-1)
	return
for i in range(n):
	cur = 2 * (n - i) - 1
	if cur <= k:
		k -= cur
		for j in range(i, n):
			a[i][j] = 1
			a[j][i] = 1
	else:
		if k == 0:
			break
		if k == 1:
			a[i][i] = 1
			break
		for j in range(i, i + (k + 1) // 2):
			a[i][j] = 1
			a[j][i] = 1
		if not k % 2:
			a[i + 1][i + 1] = 1
		break
for i in a:
	print(*i)


def print_matrix(a):
	for row in a:
		for el in row:
			print(el, end=' ')
		print()
(n, k) = [int(x) for x in input().split()]
if k > n * n:
	print(-1)
else:
	cur_line = 0
	a = [[0] * n for i in range(n)]
	while k > 0:
		mx = 2 * (n - cur_line) - 1
		mx = min(k, mx)
		if mx % 2 == 0:
			mx -= 1
		for i in range(mx // 2 + 1):
			a[cur_line + i][cur_line] = 1
			a[cur_line][cur_line + i] = 1
		k -= mx
		cur_line += 1
	print_matrix(a)


(n, k) = map(int, input().split())

def doit(n, l, k):
	k -= l
	t = []
	for i in range(1, n + 1):
		s = []
		for j in range(1, n + 1):
			if i == j:
				if i <= l:
					s.append('1')
				else:
					s.append('0')
			elif i > j:
				s.append(t[j - 1][i - 1])
			elif k > 0:
				s.append('1')
				k -= 2
			else:
				s.append('0')
		t.append(s)
	for i in t:
		print(' '.join(i))
if k > n ** 2:
	print(-1)
elif k % 2 == 0:
	for i in range(0, n + 1, 2):
		if k <= i * (2 * n - i):
			doit(n, i, k)
			break
else:
	for i in range(1, n + 1, 2):
		if k <= i * (2 * n - i):
			doit(n, i, k)
			break


(n, k) = map(int, input().split())
a = []
for i in range(n):
	a.append(['0'] * n)
for i in range(n):
	for j in range(i, n):
		if i == j:
			if k > 0:
				a[i][j] = '1'
				k -= 1
		elif k > 1:
			(a[i][j], a[j][i]) = ('1', '1')
			k -= 2
if k > 0:
	print(-1)
else:
	print('\n'.join([' '.join(x) for x in a]))


(n, k) = map(int, input().split())
a = []
for _ in range(n):
	a.append([0] * n)

def process():
	d = 0
	m = 0
	while m < k and d < n:
		a[d][d] = 1
		m += 1
		for i in range(d + 1, n):
			if m + 2 > k:
				break
			a[i][d] = 1
			a[d][i] = 1
			m += 2
		d += 1
	return m == k
if not process():
	print('-1')
	exit()
for i in range(n):
	for j in range(n):
		print(a[i][j], end=' ' if j < n - 1 else '\n')


class CodeforcesTask803ASolution:

	def __init__(self):
		self.result = ''
		self.n_k = []

	def read_input(self):
		self.n_k = [int(x) for x in input().split(' ')]

	def process_task(self):
		if self.n_k[0] ** 2 < self.n_k[1]:
			self.result = '-1'
		else:
			matrix = [[0] * self.n_k[0] for x in range(self.n_k[0])]
			to_place = self.n_k[1]
			x = 0
			y = 0
			while to_place:
				if x == y:
					matrix[x][y] = 1
					to_place -= 1
				elif to_place > 1:
					matrix[x][y] = 1
					matrix[y][x] = 1
					to_place -= 2
				x += 1
				if x >= self.n_k[0]:
					y += 1
					x = y
			self.result = '\n'.join([' '.join([str(x) for x in row]) for row in matrix])

	def get_result(self):
		return self.result
Solution = CodeforcesTask803ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def SieveOfEratosthenes(n):
	prime = []
	primes = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if primes[p] == True:
			prime.append(p)
			for i in range(p * p, n + 1, p):
				primes[i] = False
		p += 1
	return prime

def primefactors(n):
	fac = []
	while n % 2 == 0:
		fac.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 2):
		while n % i == 0:
			fac.append(i)
			n = n // i
	if n > 1:
		fac.append(n)
	return fac

def factors(n):
	fac = set()
	fac.add(1)
	fac.add(n)
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			fac.add(i)
			fac.add(n // i)
	return list(fac)

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x
(n, k) = map(int, input().split())
if k > n * n:
	print(-1)
else:
	mat = [[0] * n for i in range(n)]
	for i in range(n):
		if k == 0:
			break
		mat[i][i] = 1
		k -= 1
		for j in range(i + 1, n):
			if k > 1:
				mat[i][j] = 1
				mat[j][i] = 1
				k -= 2
	for i in mat:
		print(*i)


(n, k) = input('').split()
n = int(n)
k = int(k)
arr = [[0 for x in range(n)] for y in range(n)]
for i in range(n):
	for j in range(n):
		if arr[i][j] == arr[j][i] == 0:
			if i == j and k > 0:
				arr[i][j] = 1
				k = k - 1
			if i != j and k > 1:
				arr[i][j] = 1
				arr[j][i] = 1
				k = k - 2
if k == 0:
	lines = []
	for row in arr:
		lines.append(' '.join((str(x) for x in row)))
	print('\n'.join(lines))
else:
	print('-1')


from sys import stdin, exit
(n, k) = map(int, stdin.readline().split())
if k > n * n:
	print(-1)
	exit(0)
a = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
	for f in range(n):
		if a[i][f] == 1:
			continue
		if k == 0:
			break
		if i == f or k > 1:
			(a[i][f], a[f][i]) = (1, 1)
			k -= 1 + int(i != f)
print('\n'.join((' '.join(map(str, i)) for i in a)))


import sys

def printAllZero(n):
	for i in range(n):
		print('0 ' * n)

def printMatrix(onesInColRow):
	n = len(onesInColRow)
	for row in range(n):
		line = ''
		for col in range(row):
			if onesInColRow[col] > 0:
				line += '1 '
				onesInColRow[col] -= 1
			else:
				line += '0 '
		onesInCurrRow = 0
		if onesInColRow[row] >= 1:
			onesInCurrRow += 1
			onesInColRow[row] -= 1
		half = onesInColRow[row] // 2
		onesInCurrRow += half
		onesInColRow[row] -= half
		line += '1 ' * onesInCurrRow
		zeroesInCurrRow = n - (row + onesInCurrRow)
		line += '0 ' * zeroesInCurrRow
		print(line)
(n, k) = [int(i) for i in input().split(' ')]
if k < 0 or k > n * n:
	print(-1)
	sys.exit()
onesInColRow = [0] * n
for row in range(n):
	if k == 0:
		break
	rowLen = n - row
	maxOnes = rowLen * 2 - 1
	if k >= maxOnes:
		onesInColRow[row] = maxOnes
		k -= maxOnes
	else:
		maxOnesAvailableForRow = k
		if k % 2 == 0:
			maxOnesAvailableForRow = k - 1
		onesInColRow[row] = maxOnesAvailableForRow
		k -= maxOnesAvailableForRow
printMatrix(onesInColRow)


import sys, math, queue
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
(n, k) = map(int, input().split())
if k > n * n:
	print(-1)
	exit()
a = [[0 for i in range(n)] for i in range(n)]
if k == 1:
	a[0][0] = 1
if k <= 1:
	for ai in a:
		print(*ai)
	exit()
for i in range(n):
	if k >= 2:
		a[i][i] = 1
		k -= 1
	elif k == 1:
		a[i][i] = 1
		break
	elif k == 0:
		break
	for j in range(i + 1, n):
		if k < 2:
			break
		a[i][j] = 1
		a[j][i] = 1
		k -= 2
for ai in a:
	print(*ai)


import sys
(n, k) = map(int, input().split())
ans = [[0 for i in range(n)] for i in range(n)]
if k > n * n:
	print(-1)
	sys.exit()
cur = 0
j = 0
while k > 0:
	if k == 1:
		inc = 0
		if j > cur:
			inc = 1
		ans[cur + inc][cur + inc] = 1
		k -= 1
	else:
		ans[cur][j] = 1
		ans[j][cur] = 1
		k -= 2
		if cur == j:
			k += 1
		while ans[cur][j] == 1:
			j += 1
			if j == n:
				j = 0
				cur += 1
for i in range(n):
	print(*ans[i], sep=' ')


import sys
(n, k) = map(int, sys.stdin.readline().split())
ans = [[0] * n for i in range(n)]
for i in range(n):
	for j in range(i, n):
		if i != j:
			if k > 1:
				ans[i][j] = 1
				ans[j][i] = 1
				k -= 2
		elif k > 0:
			ans[i][j] = 1
			k -= 1
if k == 0:
	for i in range(n):
		print(*ans[i])
else:
	print(-1)


x = input()
y = list(x)
z = y.index(' ')
n = int(x[:z])
k = int(x[z + 1:])
h = [[0 for i in range(n)] for j in range(n)]
if k > n * n:
	print(-1)
if k <= n * n:
	for i in range(1, n + 1):
		u = 2 * n * i - i * i
		if u >= k:
			v = 2 * (i - 1) * n - (i - 1) * (i - 1)
			w = k - v
			g = i - 1
			break
	if g > 0:
		for i in range(g):
			for j in range(n):
				h[i][j] = 1
				h[j][i] = 1
		if w % 2 == 0:
			if w // 2 > 0:
				for i in range(1):
					for j in range(w // 2):
						h[i + g][j + g] = 1
						h[j + g][i + g] = 1
						h[g + 1][g + 1] = 1
		if w % 2 == 1:
			for i in range(1):
				for j in range(w // 2 + 1):
					h[i + g][j + g] = 1
					h[j + g][i + g] = 1
	if g == 0:
		if w % 2 == 0:
			if w // 2 > 0:
				for i in range(1):
					for j in range(w // 2):
						h[i][j + g] = 1
						h[j + g][i] = 1
						h[g + 1][g + 1] = 1
		if w % 2 == 1:
			for i in range(1):
				for j in range(w // 2 + 1):
					h[i + g][j + g] = 1
					h[j + g][i + g] = 1
	for i in range(n):
		for j in range(n):
			if j == n - 1:
				print(h[i][j])
			else:
				print(h[i][j], end=' ')


(n, k) = list(map(int, input().split()))
ks = k
l = []
for i in range(n):
	p = []
	for j in range(n):
		p.append(0)
	l.append(p)
if k > n ** 2:
	print(-1)
else:
	for i in range(n):
		for j in range(n):
			if k == 0:
				break
			if i == j:
				k -= 1
				l[i][j] = 1
			elif k > 1 and l[j][i] == 0:
				k -= 2
				l[i][j] = 1
				l[j][i] = 1
	ones = 0
	for row in l:
		ones += row.count(1)
	if ones != ks:
		print(-1)
	else:
		for i in l:
			s = ''
			for j in i:
				s += ' ' + str(j)
			print(s[1:])


def solve():
	(n, k) = [int(x) for x in input().split(' ')]
	grid = [[0 for i in range(n)] for j in range(n)]
	if k > n * n:
		print(-1)
	else:
		for i in range(n):
			if k == 0:
				break
			if k >= 1:
				for j in range(n):
					if k <= 1:
						break
					if grid[i][j] == 0:
						grid[i][j] = 1
						k -= 1
					if grid[j][i] == 0:
						grid[j][i] = 1
						k -= 1
			if k == 1:
				if grid[i][i] == 1:
					grid[i + 1][i + 1] = 1
				else:
					grid[i][i] = 1
				break
		for row in grid:
			print(*row)
solve()


def printM(M):
	for i in M:
		for j in i:
			print(j, end=' ')
		print()
(n, k) = input().split()
n = int(n)
k = int(k)
if k > n * n:
	print(-1)
	exit()
M = []
for i in range(n):
	M.append([0 for j in range(n)])
left = k
for i in range(n):
	if left == 0:
		printM(M)
		exit()
	M[i][i] = 1
	left -= 1
	for j in range(i + 1, n):
		if left == 0:
			printM(M)
			exit()
		if left == 1:
			M[i + 1][i + 1] = 1
			printM(M)
			exit()
		M[i][j] = M[j][i] = 1
		left -= 2
printM(M)


def do():
	(n, k) = map(int, input().split(' '))
	if k > n ** 2:
		print('-1')
		return
	res = [[0] * n for _ in range(n)]
	row = 0
	i = j = 0
	while i < n and k > 0:
		res[i][j] = 1
		res[j][i] = 1
		if i == j:
			k -= 1
		else:
			k -= 2
		i += 1
		if i == n or k == 1:
			row += 1
			i = j = row
	for line in res:
		print(' '.join(map(str, line)))
do()


import sys
import bisect
from bisect import bisect_left as lb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0

def hnbhai(tc):
	(n, k) = sd()
	mat = [[0 for i in range(n)] for j in range(n)]
	if n * n < k:
		print(-1)
		return
	for i in range(n):
		for j in range(n):
			if i == j and k > 0:
				mat[i][j] = 1
				k -= 1
			elif j > i and k > 1:
				mat[i][j] = 1
				mat[j][i] = 1
				k -= 2
	if k:
		print(-1)
		return
	for i in mat:
		print(*i)
for _ in range(1):
	hnbhai(_ + 1)


[n, k] = list(map(int, input().split()))
if n * n < k:
	print('-1')
	exit(0)
a = [[0 for j in range(n)] for i in range(n)]
p = 0
while k > 0:
	a[p][p] = 1
	k -= 1
	q = p + 1
	while k > 1 and q < n:
		a[p][q] = 1
		a[q][p] = 1
		k -= 2
		q += 1
	p += 1
for i in range(n):
	print(' '.join(map(str, a[i])))


def format(res):
	return '\n'.join([' '.join(line) for line in res])

def solution(n, k):
	if k > n ** 2:
		return -1
	res = [['0'] * n for _ in range(n)]
	for i in range(n):
		if k == 0:
			return format(res)
		else:
			res[i][i] = '1'
			k -= 1
			j = i + 1
			while j < n and k > 1:
				res[i][j] = res[j][i] = '1'
				k -= 2
				j += 1
	if k == 0:
		return format(res)
	return -1
(n, k) = [int(val) for val in input().split()]
print(solution(n, k))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from bisect import bisect_left
from collections import Counter
(n, k) = map(int, input().split())
if k > n ** 2:
	print(-1)
else:
	m = [[0] * n for i in range(n)]
	for i in range(n):
		if k <= 0:
			break
		m[i][i] = 1
		k -= 1
		for j in range(i + 1, n):
			if k >= 2:
				m[i][j] = 1
				m[j][i] = 1
				k -= 2
	for i in m:
		print(*i)


import sys
from bisect import bisect_left as lb
from collections import deque
from queue import PriorityQueue as pq
from math import *
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
mod = 10 ** 9 + 7
(n, k) = il()
if k > n * n:
	print(-1)
	exit(0)
a = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
	for j in range(n):
		if i == j and k > 0:
			a[i][j] = 1
			k -= 1
		elif j > i and k > 1:
			a[i][j] = 1
			a[j][i] = 1
			k -= 2
if k > 0:
	print(-1)
	exit(0)
for i in range(n):
	for j in range(n):
		print(a[i][j], end=' ')
	print()