Problem:
 Score : 700 points    Problem Statement You are given four integers: H , W , h and w ( 1 ≤ h ≤ H , 1 ≤ w ≤ W ).
Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:   The matrix has H rows and W columns.  Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).  The sum of all the elements of the matrix is positive.  The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.       Constraints  1 ≤ h ≤ H ≤ 500  1 ≤ w ≤ W ≤ 500         Input Input is given from Standard Input in the following format:  H  W  h  w       Output If there does not exist a matrix that satisfies all of the conditions, print No .  Otherwise, print Yes in the first line, and print a matrix in the subsequent lines in the following format:  a_{11}  ...  a_{1W}  :  a_{H1}  ...  a_{HW}   Here, a_{ij} represents the (i,\ j) element of the matrix.        Sample Input 1 3 3 2 2      Sample Output 1 Yes
1 1 1
1 -4 1
1 1 1  The sum of all the elements of this matrix is 4 , which is positive.
Also, in this matrix, there are four subrectangles with 2 rows and 2 columns as shown below. For each of them, the sum of all the elements inside is -1 , which is negative.          Sample Input 2 2 4 1 2      Sample Output 2 No       Sample Input 3 3 4 2 3      Sample Output 3 Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7

Solution (Python):
H, W, h, w = map(int, input().split())

if H % h == 0 and W % w == 0:
    print('No')
    exit()

big = 1000
mul = h*w-1
print('Yes')
for y in range(1, H+1):
    arr = []
    for x in range(1, W+1):
        if y % h == 0 and x % w == 0:
            arr.append(-(big*mul+1))
        else:
            arr.append(big)
    print(' '.join(map(str, arr)))

Solution (Python):
h, w, h0, w0 = map(int, input().split())
if h0 == w0 == 1:
    print("No")
    exit()
x, y = h // h0, w // w0
a1cnt = h0 * w0 - 1
a1sum, a2sum = h * w - x * y, x * y
a1 = ((pow(10, 9) - 1) // a1cnt)
a2 = -(a1 * a1cnt + 1)
asum = a1 * a1sum + a2 * a2sum
print("Yes" if asum > 0 else "No")
if asum > 0:
    for i in range(1, h + 1):
        a = [0] * w
        for j in range(1, w + 1):
            a[j - 1] = a2 if i % h0 == j % w0 == 0 else a1
        print(*a)

Solution (Python):
H, W, h, w = map(int, input().split())
if H % h == 0 and W % w == 0:
    print("No")
else:
    print("Yes")
    ans = [[None] * W for i in range(H)]
    for i in range(H):
        for j in range(W):
            if i % h == h - 1 and j % w == w - 1:
                ans[i][j] = -1 * 1000 * (h * w - 1) - 1
            else:
                ans[i][j] = 1000
    for i in ans:
        print(*i)

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


H,W,h,w = MI()
q1,r1 = H//h,H % h
q2,r2 = W//w,W % w

if r1 == 0 and r2 == 0:
    print('No')
else:
    print('Yes')
    if r2 != 0:
        A = []
        for _ in range(q2):
            A += [2*10**6]*(w-1)+[-(2*10**6)*(w-1)-1]
        A += [2*10**6]*r2
        for _ in range(H):
            print(*A)
    else:
        for i in range(1,H+1):
            if i % h != 0:
                print(*([2*10**6]*W))
            else:
                print(*([-(2*10**6)*(h-1)-1]*W))

Solution (Python):

min2 = lambda x,y: x if x < y else y

def solve(H,W,h,w):

    if h == 1 and w == 1:
        return None

    res = [[0]*W for _ in range(H)]



    for i in range(0,W,w):
        for j in range(0,H,h):
            res[j][i] = 10**9-1
            if i+w-1 < W and j+h-1 < H:
                res[j+h-1][i+w-1] = -10**9

    s = sum(sum(l) for l in res)
    if s <= 0:
        return None
    else:
        return res




if __name__ == '__main__':
    H,W,h,w = map(int,input().split())
    res = solve(H,W,h,w)

    if res:
        print('Yes')
        print('\n'.join(' '.join(map(str,l)) for l in res))
    else:
        print('No')

Solution (Python):
H,W,h,w=map(int,input().split())
p=(10**9-1)//(max(h*w-1,1))
m=p*(h*w-1)+1
vec=[[p for i in range(W+1)] for j in range(H+1)]
sm=0
for i in range(1,H+1):
  for j in range(1,W+1):
    if i%h==0 and j%w==0:
      vec[i][j]=-m
    sm+=vec[i][j]
if sm<=0:
  print("No")
else:
  print("Yes")
  for i in range(1,H+1):
    for j in range(1,W+1):
      print(vec[i][j],end=" \n"[j==W])

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


H, W, h, w = map(int, input().split())
v = [[0]*W for _ in range(H)]
if H%h==0 and W%w==0:
    print("No")
else:
    for i in range(H//h):
        for j in range(W//w):
            v[(i+1)*h-1][(j+1)*w-1] = -10**9
    for i in range(H//h+1):
        for j in range(W//w+1):
            if i*h<H and j*w<W:
                v[(i)*h][(j)*w] = 10**9-1
    ss = sum(sum(vv) for vv in v)
    if ss>0:
        print("Yes")
        write("\n".join(" ".join(map(str, vv)) for vv in v))
    else:
        print("No")

Solution (Python):
H, W, h, w = map(int, input().split())
if H % h == 0 and W % w == 0:
    print('No')
    exit()
rem = H * W - (H - H % h) * (W - W % w)
x = (H // h * W // w) // rem + 1
a = [[x] * W for _ in range(H)]
for i in range(h-1, H, h):
    for j in range(w-1, W, w):
        a[i][j] = -(h * w - 1) * x - 1
print('Yes')
for row in a:
    print(*row)

Solution (Python):
H, W, h, w = map(int, input().split())
rem = H * W - (H - H % h) * (W - W % w)
if rem == 0:
    print('No')
    exit()
x = (H // h * W // w + rem) // rem
if abs(x) > 10**9 or abs(-(h * w - 1) * x - 1) > 10**9:
    print('No')
    exit()
print('Yes')
a = [[x] * W for _ in range(H)]
for i in range(h-1, H, h):
    for j in range(w-1, W, w):
        a[i][j] = -(h * w - 1) * x - 1
for row in a:
    print(*row)

Solution (Python):
H,W,h,w = map(int,input().split())

if(H%h==0)&(W%w==0):
    print('No')
    exit()

print('Yes')

if(W%w!=0):
    base = [1000] * (w-1) + [-1000 * (w-1) -1]
    col = []
    for i in range(1 + W//w):
        col = col + base
    col = col[:W]
    for i in range(H):
        print(' '.join(map(str,col)))

else:
    base = [1000] * (h-1) + [-1000 * (h-1) -1]
    row = []
    for i in range(1 + H//h):
        row = row + base
    row = row[:H]
    for i in row:
        col = [i] * W
        print(' '.join(map(str,col)))

Solution (Python):
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H, W, h, w = map(int, read().split())

def f(H, W, h, w):
    if H % h == 0 and W % w == 0:
        print('No')
        return
    K = 100_000_000
    base = np.zeros((h, w), np.int64)
    base[0, 0] = K
    base[-1, -1] = -(K + 1)
    A = np.tile(base, ((H + h) // h, (W + w) // w))[:H, :W]
    print('Yes')
    for row in A:
        print(' '.join(map(str, row.tolist())))

f(H, W, h, w)

Solution (Python):
import sys
H,W,h,w=map(int,input().split())
if W%w==0 and H%h==0:
  print('No')
  sys.exit()
print('Yes')
if W%w!=0:
  m=[]
  a=str(1000*(w-1))
  b=str(-1001)
  for i in range(W):
    if i%w==0:
      m.append(a)
    else:
      m.append(b)
  s=' '.join(m)
  for i in range(H):
    print(s)
else:
  m1=' '.join([str(1000*(h-1))]*W)
  m2=' '.join([str(-1001)]*W)
  for i in range(H):
    if i%h==0:
      print(m1)
    else:
      print(m2)

Solution (Python):
H,W,h,w=map(int,input().split())
if H%h==0 and W%w==0:
    print("No")
else:
    c=10**9
    ans=[[(c-1)//(h*w-1) for i in range(W)] for j in range(H)]
    for i in range(H):
        for j in range(W):
            if (i+1)%h==0 and (j+1)%w==0:
                ans[i][j]=-c
    if sum(ans[i][j] for i in range(H) for j in range(W))>0:
        print("Yes")
        for i in range(H):
            print(*ans[i])
    else:
        print("No")

Solution (Python):
import sys
input = sys.stdin.readline
H, W, h, w = map(int, input().split())
unit = 10 ** 9 - 1
c = H * W
for i in range(h - 1, H, h):
  for j in range(w - 1, W, w): c -= 1
if c == 0:
  print("No")
  exit(0)
res = [[unit // c] * W for _ in range(H)]
for i in range(h - 1, H, h):
  for j in range(w - 1, W, w): res[i][j] = -(unit // c * (h * w - 1) + 1)
if sum([sum(r) for r in res]) > 0:
  print("Yes")
  for r in res: print(*r)
else: print("No")

Solution (Python):
H, W, h, w = map(int, input().split())
if H%h == W%w == 0:
  print('No')
  exit(0)
print('Yes')
f = 0
a, b = W, w
if not W%w:
  f = 1
  a, b = H, h
l = [0]*(a+1)
l[1] = 10**6
for i in range(2, a+1):
  if i >= b:
    l[i] = l[i-b] - 1
  else:
    l[i] = l[i-1] - 1
assert(l[-1] > 0)
g = [l[i+1] - l[i] for i in range(a)]
if f:
  for x in g:
    print(*([x]*W))
else:
  for _ in range(H):
    print(*g)

Solution (Python):
def main():
    H, W, h, w = map(int, input().split())
    p = 4000
    q = h*w-1
    a = [[p]*W for _ in [0]*H]
    for i in range(H//h):
        for j in range(W//w):
            a[(i+1)*h-1][(j+1)*w-1] = -p*q-1
    if sum([sum(i) for i in a]) <= 0:
        print("No")
    else:
        print("Yes")
        for i in a:
            print(*i)


main()

Solution (Python):
def compose(W, w):
  A = [0]*W
  S = [0]*(W+1)
  S[W%w] = 1000
  for j in range(W-w+1):
    S[j+w] = S[j] - 1
  for j in range(W):
    A[j] = S[j+1] - S[j]
    
  return A

H, W, h, w = map(int, input().split())

if H%h == 0 and W%w == 0:
  print("No")
else:
  print("Yes")
  if W%w:
    S = compose(W, w)
    for _ in range(H):
      print(*S)
  else:
    S = compose(H, h)
    for i in range(H):
      print(*[S[i] for _ in range(W)])

Solution (Python):
H, W, h, w = map(int, input().split())
a = [[0] * W for i in range(H)]
INF = 10**9

for i in range(H):
	for j in range(W):
		if i % h == h - 1 and j % w == w - 1:
			a[i][j] = -INF
		elif i % h == 0 and j % w == 0:
			a[i][j] = INF - 1
if sum([sum(line) for line in a]) > 0:
	print("Yes")
	for i in range(H):
		print(*a[i])
else:
	print("No")

Solution (Python):
def solve(W,w):
    A=[1]*W
    for i in range(W-1,w-1,-1):
        A[i-w]=A[i]+1
    A[w-1::w]=[-i for i in range(1,W//w+1)]
    for i in range(W-2,-1,-1):
        A[i+1]-=A[i]
    return A

H,W,h,w=map(int, input().split())
if W%w:
    print("Yes")
    A=solve(W,w)
    for _ in range(H):
        print(*A)
elif H%h:
    print("Yes")
    A=solve(H,h)
    for i in range(H):
        print(*[A[i]]*W)
else:
    print("No")

Solution (Python):
H,W,h,w=map(int,input().split())
if H%h==0 and W%w==0:
    print("No")
    quit()
else:
    print("Yes")
m=-10**9
p=(-m-1)//(h*w-1)  
ans=[[m if i%h==0 and j%w==0 else p for j in range(1,W+1)] for i in range(1,H+1)]
for i in ans:
    print(" ".join(map(str,i)))

Solution (Python):
H, W, h, w = map(int, input().split())

if h == w == 1 :
  print('No')

else :
  a = (10 ** 9 - 1) // (h * w - 1)
  ret = [[a] * W for _ in range(H)]
  for y in range(h - 1, H, h) :
    for x in range(w - 1, W, w) :
      ret[y][x] = - a * (h * w - 1) - 1

  s = 0
  for y in range(H) :
    s += sum(ret[y])
    
  if s > 0 :
    print('Yes')
    for r in ret :
      print(*r)
  else :
    print('No')

Solution (Python):


H,W,h,w = map(int,input().split())

lis = [[600] * W for i in range(H)]

for i in range(H):

    for j in range(W):

        if i % h == h-1 and j % w == w-1:
            lis[i][j] = -600 * (h * w - 1) - 1

s = 0

for i in range(H):
    s += sum(lis[i])

if s <= 0:
    print ("No")

else:
    print ("Yes")
    for i in lis:
        
        print (" ".join(map(str,i)))

Solution (Python):
H,W,h,w = map(int,input().split())
if not (H%h or W%w):
  print("No")
  exit()
if H%h:
  flg = "tate"
  n = H
  r = h
else:
  flg = "yoko"
  n = W
  r = w
ans = []
if r%2 == 0:
  s = r//2
  for i in range(n):
    if (i//s)%2 == 0:
      ans.append(2000)
    else:
      ans.append(-2001)
else:
  for i in range(n):
    if (i%r) < r//2+1:
      ans.append(2000)
    else:
      ans.append(-(int(2000/(r//2)*(r//2+1)))-1)
print("Yes")
if flg == "tate":
  for i in range(H):
    print(*([ans[i]]*W))
else:
  for i in range(H):
    print(*ans)

Solution (Python):
H, W, sh, sw = map(int, input().split())

if H%sh == 0 and W%sw == 0:
    print("No")
else:
    print("Yes")
    state = [[1]*W for _ in range(H)]
    INF = 10**9
    for h in range(H):
        for w in range(W):
            if w%sw == sw-1 and h%sh == sh-1:
                state[h][w] = -INF
            elif w%sw == 0 and h%sh == 0:
                state[h][w] = INF - (sh*sw-1)
    for h in range(H):
        print(" ".join([str(a) for a in state[h]]))

Solution (Python):
H, W, h, w = map(int, input().split())

grid = [[0] * W for _ in range(H)]
inf = 10**9
for i in range(H):
    for j in range(W):
        if i%h == h-1 and j%w == w-1:
            grid[i][j] = -inf
        elif i%h == 0 and j%w == 0:
            grid[i][j] = inf-1

if sum([sum(line) for line in grid]) > 0:
    print('Yes')
    for i in range(H):
        print(*grid[i])
else:
    print('No')

Solution (Python):
def examA():
    Alpha = [chr(i) for i in range(97, 97+26)]
    S = SI(); N = len(S)
    ans = -1
    for i in range(N):
        for s in Alpha:
            cur = [s for s in S]
            for l in range(i):
                for k in range(N-1):
                    if cur[k+1]==s:
                        cur[k]=s
 
            if len(Counter(cur[:N-i]))==1:
                ans = i
                break
        if ans>=0:
            break
    print(ans)
    return

def examB():
    N = I()
    A = LI()
    d = defaultdict(int)
    for a in A:
        d[a] +=1
    l = min(d); r = max(d)
    ans = "Yes"
    if l>=N:
        ans = "No"
    if r-l>1:
        ans = "No"
    if d[l]>l:
        ans = "No"
    if (r-d[l])*2+d[l]>N:
        ans = "No"
    if r==l and (N-l==1 or N//2>=l):
        ans = "Yes"
    print(ans)
    return

def examC():
    H, W, h, w = LI()
    judge = (H%h)+(W%w)
    if judge==0:
        print("No")
        return
    print("Yes")
    now = H//h+W//w
    neg = -(h*w-1)*now-1
    A = [[now]*W for _ in range(H)]
    for i in range(1,1+H//h):
        for j in range(1,1+W//w):
            A[i*h-1][j*w-1] = neg
    for v in A:
        print(" ".join(map(str,v)))
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

def main():
    H, W, h, w = map(int, input().split())
    if H % h == 0 and W % w == 0:
        print("No")
    elif H % h == 0:
        print("Yes")
        ans = [[0 for _ in range(W)] for _ in range(H)]
        for i in range(H):
            for j in range(0, W, w):
                ans[i][j] = 99999
                if j + w - 1 < W:
                    ans[i][j + w - 1] = -100000
        for a in ans:
            print(*a)
    else:
        print("Yes")
        ans = [[0 for _ in range(W)] for _ in range(H)]
        for i in range(W):
            for j in range(0, H, h):
                ans[j][i] = 99999
                if j + h - 1 < H:
                    ans[j + h - 1][i] = -100000
        for a in ans:
            print(*a)


if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    H,W,h,w = LI()
    if W%w != 0:
        s = [0]+[100000]*(w-1)
        for i in range(W-w+1):
            s.append(s[-w]-1)
        a = [s[i]-s[i-1] for i in range(1,W+1)]
        print("Yes")
        for i in range(H):
            print(*a)
    elif H%h != 0:
        H,W,h,w = W,H,w,h
        s = [0]+[100000]*(w-1)
        for i in range(W-w+1):
            s.append(s[-w]-1)
        a = [s[i]-s[i-1] for i in range(1,W+1)]
        print("Yes")
        ans = [[a[i]]*H for i in range(W)]
        for i in range(W):
            print(*ans[i])
    else:
        print("No")
    return


if __name__ == "__main__":
    solve()

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict


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


def main():
	H, W, h, w = getlist()
	L = [[1] * W for i in range(H)]
	if h * w != 1:
		x = (10 ** 9 - 1) // (h * w - 1)
		for i in range(H):
			for j in range(W):
				L[i][j] = x
	for i in range(H // h):
		for j in range(W // w):
			L[(i + 1) * h - 1][(j + 1) * w - 1] = - 10 ** 9
	s = 0
	for i in range(H):
		for j in range(W):
			s += L[i][j]
	if s < 0:
		print("No")
		return
	
	print("Yes")
	for i in range(H):
		print(" ".join(list(map(str, L[i]))))

if __name__ == '__main__':
	main()

Solution (Python):
H, W, h, w = [ int(v) for v in input().split() ]
if H % h == 0 and W % w == 0:
    print("No")
else:
    print("Yes")
    grid = [ [ -h*w*1000+999 if i % h == h-1 and j % w == w-1 else 1000 for j in range(W) ] for i in range(H) ]
    for i in grid:
        print(*i)

Solution (Python):
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


H, W, A, B = list(map(int, sys.stdin.readline().split()))
if H % A == 0 and W % B == 0:
    
    print('No')
    exit()



def cumsum(S, s):
    ret = np.zeros(S + 1, dtype=int)
    n = 0
    for i in range(0, len(ret), s):
        ret[i] = n
        n -= 1
    for a in range(1, s):
        n = 1e7
        for i in range(a, len(ret), s):
            ret[i] = n
            n -= 1
    return ret


print('Yes')
if H % A != 0:
    col = np.diff(cumsum(H, A))
    ans = np.tile(col, W).reshape(W, H).T
else:
    col = np.diff(cumsum(W, B))
    ans = np.tile(col, H).reshape(H, W)
print('\n'.join(map(lambda r: ' '.join(r), ans.astype(str))))

Solution (Python):
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

H, W, A, B = list(map(int, sys.stdin.readline().split()))
if H % A == 0 and W % B == 0:
    print('No')
    exit()

print('Yes')
MAX = 998244353
ans = np.full((H, W), MAX // (A * B - 1), dtype=int)
if A > 1 and B > 1:
    ans[np.meshgrid(np.arange(A - 1, H, A), np.arange(B - 1, W, B))] = -MAX-1
elif A == 1:
    ans[:, np.arange(B - 1, W, B)] = -MAX-1
else:
    ans[np.arange(A - 1, H, A), :] = -MAX-1
print('\n'.join(map(lambda r: ' '.join(r), ans.astype(str))))

Solution (Python):
H, W, h, w = map(int, input().split())

if H % h == 0 and W % w == 0:
    print("No")
    quit()

print("Yes")

def solve(H, W, h, w):
    S = [0] * (W + 1)
    S[W % w] = 1 + W // w
    for i in range(w, W + 1):
        S[i] = S[i - w] - 1
    return [[S[i + 1] - S[i] for i in range(W)]] * H

if W % w != 0:
    A = solve(H, W, h, w)
else:
    A = [r for r in zip(*solve(W, H, w, h))]

for a in A:
    print(*a)

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    H,W,h,w = map(int,input().split())
    if H*W-(H//h)*(W//w)*w*h == 0:
        print("No")
    else:
        if W%w != 0:
            ans = [0 for _ in range(W)]
            co = [0 for _ in range(W+1)]
            for i in range(1,w):
                co[i] = (W-i)//w+1
            for i in range(w,W+1):
                co[i] = co[i-w]-1
            for i in range(W):
               ans[i] = co[i+1]-co[i]
            print("Yes")
            for i in range(H):
                print(*ans)
        else:
            ans = [0 for _ in range(H)]
            co = [0 for _ in range(H+1)]
            for i in range(1,h):
                co[i] = (H-i)//h+1
            for i in range(h,H+1):
                co[i] = co[i-h]-1
            for i in range(H):
               ans[i] = co[i+1]-co[i]
            print("Yes")
            for i in range(H):
                print(*list(ans[i] for _ in range(W)))

if __name__ == "__main__":
    main()

Solution (Python):
H,W,h,w = map(int,input().split())
if H%h or W%w:
    print("Yes")
    a = (10**9)//(h*w)
    ans = [[a]*W for _ in [0]*H]
    for i in range(h-1,H,h):
        for j in range(w-1,W,w):
            ans[i][j] = -a*(h*w-1)-1
    for out in ans:
        print(*out)
else:
    print("No")

Solution (Python):
H, W, h, w = map(int, input().split())
if H % h == 0 and W % w == 0:
    print("No")
else:
    print("Yes")
    k = 1000000
    R = [[0]*W for i in range(H)]
    for i in range(0, H, h):
        for j in range(0, W, w):
            R[i][j] += k
            if i+h-1 < H:
                R[i+h-1][j] += k
            if j+w-1 < W:
                R[i][j+w-1] += k
            if i+h-1 < H and j+w-1 < W:
                R[i+h-1][j+w-1] -= 3*k+1
    for r in R:
        print(*r)

Solution (Python):
import sys
input = sys.stdin.readline

H,W,h,w = map(int,input().split())

if H%h == 0 and W%w == 0:
    print('No')
    exit()

x,y = H//h, W//w
s = x*y + 1
t = (h*w-1) * s + 1

import numpy as np
grid = np.full((H+1, W+1), s, dtype=np.int32)
grid[::h,::w] = -t
grid = grid[1:,1:]

print('Yes')
for row in grid:
    print(' '.join(row.astype(str)))

Solution (Python):
H, W, a, b = map(int, input().split())

if H%a or W%b:
    print('Yes')
    k = (H//a) * (W//b)
    x = k+2
    ansss = [[0]*(W) for _ in range(H)]
    for i in range(H//a):
        for j in range(W//b):
            ansss[(i+1)*a-1][(j+1)*b-1] = -x
    for i in range(-(-H//a)):
        for j in range(-(-W//b)):
            ansss[i*a][j*b] = x-1
    print('\n'.join([' '.join(map(str, anss)) for anss in ansss]))
else:
    print('No')

Solution (Python):
H, W, a, b = map(int, input().split())

if H%a or W%b:
    print('Yes')
    accAs = [0]
    if H%a:
        N, c = H, a
        k = -(-H // a)
    else:
        N, c = W, b
        k = -(-W // b)
    for i in range(k):
        accAs += [k-i]*(c-1) + [-i-1]
    As = []
    for i in range(N):
        As.append(accAs[i+1]-accAs[i])
    if H%a:
        for i in range(H):
            print(' '.join(map(str, [As[i]]*W)))
    else:
        for _ in range(H):
            print(*As)
else:
    print('No')

Solution (Python):
H,W,h,w=map(int,input().split())
if W%w!=0:
    print("Yes")
    s=[0 for i in range(W+1)]
    s[W%w]=1+W//w
    for i in range(w,W+1):
        s[i]=s[i-w]-1
    a=[s[i]-s[i-1] for i in range(1,W+1)]
    ans=[[str(a[i]) for i in range(W)] for j in range(H)]
    for line in ans:
        print(" ".join(line))
elif H%h!=0:
    print("Yes")
    s=[0 for i in range(H+1)]
    s[H%h]=1+H//h
    for i in range(h,H+1):
        s[i]=s[i-h]-1
    a=[s[i]-s[i-1] for i in range(1,H+1)]
    ans=[[str(a[i]) for j in range(W)] for i in range(H)]
    for line in ans:
        print(" ".join(line))
else:
    print("No")

Solution (Python):
from sys import exit
H, W, h, w = map(int, input().split())
if not H % h and not W % w:
    print('No')
    exit()
print('Yes')
G = [[1000]*W for _ in range(H)]
if H % h:
    for i in range(H//h):
        t = (i+1)*h - 1 
        for j in range(W):
            G[t][j] = -(h-1)*1000 - 1
else:
    for i in range(W//w):
        t = (i+1)*w - 1
        for j in range(H):
            G[j][t] = -(w-1)*1000 - 1
for g in G:
    print(*g)

Solution (Python):
H, W, h, w = map(int, input().split())
A = [[0]*W for _ in range(H)]
P = 10**9-1
M = -10**9
for y in range(0, H, h):
    for x in range(0, W, w):
        A[y][x] = P
for y in range(h-1, H, h):
    for x in range(w-1, W, w):
        A[y][x] = M
s = sum(map(sum, A))
if s<=-1:
    print("No")
else:
    print("Yes")
    for a in A:
        print(*a)

Solution (Python):
H, W, h, w = map(int, input().split())
if H % h == 0 and W % w == 0:
	print("No")
elif h == 1:
	print("Yes")
	coef = 999999999 // (w-1)
	plus, minus = coef, -coef * (w-1) - 1
	for _ in range(H):
		print(*[minus if j%w == 0 else plus for j in range(1, W+1)])
elif w == 1:
	print("Yes")
	coef = 999999999 // (h-1)
	plus, minus = coef, -coef * (h-1) - 1
	for i in range(1, H+1):
		print(*[minus if i%h == 0 else plus for _ in range(W)])
else:
	print("Yes")
	coef = min(999999999 // ((h-1) * (w-1)), 1000000000 // (h+w-1))
	plus, minus = coef * (h+w-1), -coef * (h-1) * (w-1) - 1
	for i in range(1, H+1):
		if i%h != 0:
			print(*[minus if j%w == 0 else plus for j in range(1, W+1)])
		else:
			print(*[minus for _ in range(W)])

Solution (Python):
H, W, h, w = map(int, input().split())
if H % h == 0 and W % w == 0:
	print("No")
elif h == 1:
	print("Yes")
	coef = 999999999 // (w-1)
	plus, minus = coef, -coef * (w-1) - 1
	for _ in range(H):
		print(*[minus if j%w == 0 else plus for j in range(1, W+1)])
elif w == 1:
	print("Yes")
	coef = 999999999 // (h-1)
	plus, minus = coef, -coef * (h-1) - 1
	for i in range(1, H+1):
		print(*[minus if i%h == 0 else plus for _ in range(W)])
else:
	print("Yes")
	coef = min(999999999 // ((h-1) * (w-1)), 1000000000 // (h+w-1))
	plus, minus = coef * (h+w-1), -coef * (h-1) * (w-1) - 1
	for i in range(1, H+1):
		if i%h != 0:
			print(*[minus if j%w == 0 else plus for j in range(1, W+1)])
		else:
			print(*[minus for _ in range(W)])

Solution (Python):
H, W, h, w = map(int, input().split())
p = 1000
if H % h > 0 or W % w > 0:
    print("Yes")
    a = [ [p] * W for i in range(H) ]
    for i in range(h-1, H, h):
        for j in range(w-1, W, w):
            a[i][j] = - p * (h * w - 1) - 1
    for i in range(H):
        print(' '.join(map(str, a[i])))
else:
    print("No")

Solution (Python):
import sys
H,W,h,w=map(int,input().split())
rh=H%h
rw=W%w
qh=H//h
qw=W//w
if rh==0 and rw==0:
    print('No')
    sys.exit()
print('Yes')
dp=[[0]*W for i in range(H)]
for i in range(0,H,h):
    for j in range(0,W,w):
        dp[i][j]=10**9-1
for i in range(h-1,H,h):
    for j in range(w-1,W,w):
        dp[i][j]=-10**9
for i in range(H):
    print(' '.join(map(str,dp[i])))

Solution (Python):
H,W,h,w = map(int,input().split())
if H % h == 0 and W % w == 0:
  print("No")
else:
  print("Yes")
  ans = [[1000] * W for i in range(H)]
  num = 0
  for i in range(h-1,H,h):
    for j in range(w-1,W,w):
      ans[i][j] = -(h * w-1) * 1000-1
      num += 1
  for nu in ans:
    print(" ".join(map(str,nu)))

Solution (Python):
H,W,h,w=map(int,input().split())
if H%h==0 and W%w==0:
  print("No")
  exit()
print("Yes")
Base=[[0]*w for i in range(h)]
Base[0][0]=10000000
Base[-1][-1]=-10000001
M=[[0]*W for i in range(H)]
for i in range(H):
  for j in range(W):
    M[i][j]=str(Base[i%h][j%w])
for i in range(H):
  print(" ".join(M[i]))

Solution (Python):


import sys


input = sys.stdin.readline


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


def solve():
    H, W, h, w = inpl()

    if H % h == 0 and W % w == 0:
        print('No')
        return -1

    ans = [[1000] * W for _ in range(H)]
    cnt = 0
    for i in range(h - 1, H, h):
        for j in range(w - 1, W, w):
            ans[i][j] = -(h * w - 1) * 1000 - 1
            cnt += 1

    print('Yes')
    for row in ans:
        print(' '.join(map(str, row)))

    return 0


solve()

Solution (Python):
H, W, h, w=map(int, raw_input().split())
if H%h==0 and W%w==0:
	print "No"
	exit()
swapped=False
if not W%w:
	swapped=True
	H, W, h, w=W, H, w, h
a=[(([1000000]*(w-1)+[-1000000*(w-1)-1])*(W/w+1))[:W]]*H
if swapped:
	a=[[a[i][j] for i in range(H)] for j in range(W)]
print "Yes"
for row in a:
	for value in row:
		print value,
	print

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

H,W,h,w = inpl()
MAP = [[0]*W for i in range(H)]

pl = mn = 0
tmp = 0
for y in range(H):
	for x in range(W):
		if (y+1)%h==0 and (x+1)%w==0:
			MAP[y][x] -= (h*w-1)*1000 +1
			mn += 1
			tmp -= (h*w-1)*1000 +1
		else:
			MAP[y][x] = 1000
			pl += 1
			tmp += 1000

if tmp <= 0:
	print('No')
else:
	print('Yes')
	for m in MAP:
		print(' '.join(map(str,m)))

Solution (Python):

import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)
 
 
H, W, h, w = map(int, input().split())
yes, no = "Yes", "No"
 
if (H%h == 0) and (W%w == 0):
    print(no)
    exit()
 
print(yes)
 
unit = 1000
if (W%w != 0):
    for i in range(H):
        
        
        
        
        l = []
        for j in range(W):
            if j % w == w-1:
                l.append(str(-unit*(w-1)-1))
            else:
                l.append(str(unit))
        print(" ".join(l))
    exit()
if (H%h != 0):
    for i in range(H):
        if i%h == h-1:
            l = [str(-unit*(h-1)-1)] * W
        else:
            l = [str(unit)] * W
        print(" ".join(l))
    exit()
raise Exception("hogeeee")

Solution (Python):

import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


H, W, h, w = map(int, input().split())
yes, no = "Yes", "No"

if (H%h == 0) and (W%w == 0):
    print(no)
    exit()

print(yes)

unit = 1000
if (W%w != 0):
    for i in range(H):
        
        
        
        
        l = []
        for j in range(W):
            if j % w == w-1:
                l.append(str(-unit*(w-1)-1))
            else:
                l.append(str(unit))
        print(" ".join(l))
    exit()
if (H%h != 0):
    for i in range(H):
        if i%h == h-1:
            l = [str(-unit*(h-1)-1)] * W
        else:
            l = [str(unit)] * W
        print(" ".join(l))
    exit()
raise Exception("hogeeee")

Solution (Python):
def get_1d(H, h):
    ret = [0] * (H + 1)
    for s in range(h):
        for x, i in enumerate(range(s, H, h)):
            ret[i] = -x
    for x, i in enumerate(range(H, 0, -h)):
        ret[i] = x + 1
    return [x1 - x0 for x0, x1 in zip(ret, ret[1:])]


def solve(H, W, h, w):
    if H % h == 0 and W % w == 0:
        return False
    ans = []
    if H % h > 0:
        col = get_1d(H, h)
        ans.extend([x] * W for x in col)
    else:
        row = get_1d(W, w)
        ans.extend([row] * H)
    return ans


H, W, h, w = map(int, input().split())
ans = solve(H, W, h, w)
if ans == False:
    print('No')
else:
    print('Yes')
    for row in ans:
        print(*row)

Solution (Python):
H,W,h,w = map(int,input().split())
if H%h == 0 and W%w == 0:
    print('No')
    exit()
print('Yes')

n = 1000
if W%w:
    m = -((w-1)*n + 1)
    row = [m if i%w==w-1 else n for i in range(W)]
    for i in range(H):
        print(*row)
else:
    m = -((h-1)*n + 1)
    for i in range(H):
        if i%h == h-1:
            print(*([m] * W))
        else:
            print(*([n] * W))