← Home
```go
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	var N int
	// If reading N fails, we stop.
	if _, err := fmt.Fscan(reader, &N); err != nil {
		return
	}

	grid := make([][]int, N)
	hasNonZero := false
	rMin, rMax := N, -1
	cMin, cMax := N, -1

	for i := 0; i < N; i++ {
		var s string
		fmt.Fscan(reader, &s)
		row := make([]int, N)
		for j := 0; j < N; j++ {
			val := int(s[j] - '0')
			row[j] = val
			if val > 0 {
				hasNonZero = true
				if i < rMin {
					rMin = i
				}
				if i > rMax {
					rMax = i
				}
				if j < cMin {
					cMin = j
				}
				if j > cMax {
					cMax = j
				}
			}
		}
		grid[i] = row
	}

	if !hasNonZero {
		fmt.Println("No")
		return
	}

	// Generate candidates for the rectangle coordinates (x1, y1) to (x2, y2)
	// Grid cell (r, c) corresponds to x in [c, c+1] and y in [N-1-r, N-r].
	
	// x1 candidates
	var x1Cand []int
	if cMin == 0 {
		x1Cand = []int{0, 1}
	} else {
		x1Cand = []int{cMin + 1}
	}

	// x2 candidates
	var x2Cand []int
	if cMax == N-1 {
		x2Cand = []int{N - 1, N}
	} else {
		x2Cand = []int{cMax}
	}

	// y1 candidates (bottom y)
	// rMax is the largest row index, corresponds to lowest y range [N-1-rMax, N-rMax]
	var y1Cand []int
	if rMax == N-1 {
		y1Cand = []int{0, 1}
	} else {
		y1Cand = []int{N - rMax}
	}

	// y2 candidates (top y)
	// rMin is the smallest row index, corresponds to highest y range [N-1-rMin, N-rMin]
	var y2Cand []int
	if rMin == 0 {
		y2Cand = []int{N - 1, N}
	} else {
		y2Cand = []int{N - 1 - rMin}
	}

	// Function to verify if a candidate rectangle produces the input grid
	check := func(x1, x2, y1, y2 int) bool {
		// Rectangle must have non-zero area
		if x1 >= x2 || y1 >= y2 {
			return false
		}
		
		for r := 0; r < N; r++ {
			for c := 0; c < N; c++ {
				// Corners of the cell (r, c)
				// BL: (c, N-1-r), BR: (c+1, N-1-r)
				// TL: (c, N-r),   TR: (c+1, N-r)
				corners := [][2]int{
					{c, N - 1 - r},
					{c + 1, N - 1 - r},
					{c, N - r},
					{c + 1, N - r},
				}
				count := 0
				for _, p := range corners {
					if p[0] >= x1 && p[0] <= x2 && p[1] >= y1 && p[1] <= y2 {
						count++
					}
				}
				if count != grid[r][c] {
					return false
				}
			}
		}
		return true
	}

	for _, x1 := range x1Cand {
		for _, x2 := range x2Cand {
			for _, y1 := range y1Cand {
				for _, y2 := range y2Cand {
					if check(x1, x2, y1, y2) {
						fmt.Println("Yes")
						return
					}
				}
			}
		}
	}

	fmt.Println("No")
}
```