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=[int(i) for i in input().split()]

if H%h==0 and W%w==0:
        print("No")
elif W%w!=0:
        print("Yes")
        for y in range(H):
                for x in range(W):
                        if x!=0:
                                print(" ",end="")
                        if (x%w)!=(w-1):
                                print(100000,end="")
                        else:
                                print(-100000*(w-1)-1,end="")
                print()
else:
        print("Yes")
        for y in range(H):
                for x in range(W):
                        if x!=0:
                                print(" ",end="")
                        if (y%h)!=(h-1):
                                print(100000,end="")
                        else:
                                print(-100000*(h-1)-1,end="")
                print()

Solution (Python):

H, W, h, w = map(int, input().split())
if W % w == 0 and H % h == 0:
    print('No')
else:
    swapped = False
    if W % w == 0:
        H, W, h, w, swapped = W, H, w, h, True
    a = [ [ 0 for _ in range(W) ] for _ in range(H) ]
    for y in range(H):
        for x in range(0, W, w):
            a[y][x] = W
        for x in range(w - 1, W, w):
            a[y][x] = - W - 1
    if swapped:
        H, W, h, w = W, H, w, h
        b = a
        a = [ [ 0 for _ in range(W) ] for _ in range(H) ]
        for y in range(H):
            for x in range(W):
                a[y][x] = b[x][y]
    print('Yes')
    for y in range(H):
        print(*a[y])

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

Solution (Python):
import sys
H,W,h,w=map(int,input().split())
if H%h==0 and W%w==0:
  print("No")
elif H%h!=0:
  print("Yes")
  p=100000*(h-1)-1
  q=-100000
  L=int(H/h)
  for l in range(L):
    for i in range(W):
      print(p, end = ' ')
    print("")
    for i in range(h-1):
      for i in range(W):
        print(q, end = ' ')
      print("")
  for i in range(W):
    print(p, end = ' ')
  print("")
  for i in range(H-L*h-1):
    for i in range(W):
      print(q, end = ' ')
else:
  print("Yes")
  p=100000*(w-1)-1
  q=-100000
  L=int(W/w)
  s=([p]+[q]*(w-1))*L+[p]+[q]*(W-L*w-1)
  for j in range(H):
    for i in range(W):
      print(s[i], end= " ")
    print("")

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    H,W,h,w = LI()
    f = False
    if H % h == 0 and W % w == 0:
        return 'No'
    if W % w == 0:
        H,W,h,w = W,H,w,h
        f = True

    p = 10**6*(w-1) - 1
    m = -(10**6)
    a = []
    for i in range(W):
        if i % w == 0:
            a.append(p)
        else:
            a.append(m)
    aa = [a] * H
    r = aa
    if f:
        r = [[aa[i][j] for i in range(H)] for j in range(W)]

    return 'Yes\n' + '\n'.join(' '.join(map(str,t)) for t in r)


print(main())

Solution (Python):

import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    H, W, h, w = ILI()
    return H, W, h, w


def solve(H, W, h, w):
    if H % h == 0 and W % w == 0:
        return False, None
    else:
        matrix = [[10 ** 3] * W for __ in range(H)]
        val = - (h * w * 1000) + 999
        for _h in range(h - 1, H, h):
            for _w in range(w - 1, W, w):
                matrix[_h][_w] = val

    return True, matrix


def main():
    params = read()
    ans_bool, matrix = solve(*params)
    if ans_bool:
        print("Yes")
        for row in matrix:
            print(" ".join(map(str, row)))
    else:
        print("No")


if __name__ == "__main__":
    main()

Solution (Python):
H,W,h,w=map(int,raw_input().split())
ans=[[1000]*W for _ in xrange(H)]
for i in xrange(h-1,H,h):
    for j in xrange(w-1,W,w):
        ans[i][j]=-(h*w-1)*1000-1
s=0
for i in xrange(H):
    for j in xrange(W):
        s+=ans[i][j]
if s>0:
    print "Yes"
    for i in xrange(H):
        for j in xrange(W):
            print ans[i][j],
        print
else:
    print "No"

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

def solve(H, W, h, w):
    if (W % w == 0 and H % h == 0):
        return False, []
    if (W % w == 0):
        return True, solve_vertical(H, W, h, w)
    return True, solve_horizontal(H, W, h, w)

def solve_horizontal(H, W, h, w):
    return [solve_horizontal_core(W, w)] * H

def solve_horizontal_core(W, w):
    m, r = divmod(W, w)
    row = [0] * W
    row[0] = m + 1
    row[w - 1] = - m - 2
    for i in range(w, W):
        row[i] = row[i - w]
    return row

def solve_vertical(H, W, h, w):
    col = solve_horizontal_core(H, h)
    m = []
    for c in col:
        m.append([c] * W)
    return m

yesno, mat = solve(H, W, h, w)
if yesno:
    print('Yes')
    for row in mat:
        print(*row)
else:
    print('No')

Solution (Python):
H, W, h, w =list(map(int,input().split()))
INF = 10**10
mat = [[1000 for _ in range(H)] for _ in range(W)]

val =-h*w*1000+ 999
for h_new in range(h-1,H,h):
    for w_new in range(w-1,W,w):
        mat[w_new][h_new] = val

if (sum(sum(mat[j][i] for i in range(H)) for j in range(W)))< 0:
    print("No")
else:
    print("Yes")
    for i in range(H):
        for j in range(W):
            print(mat[j][i], end =" ")
        print("")

Solution (Python):
import sys




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


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


H, W, h, w = read_int_list()


def solve(H, W, h, w):
    if H % h == 0 and W % w == 0:
        return False, None
    a = [[0] * W for _ in range(H)]
    m = 10 ** 9 - 1
    M = m + 1
    for i in range(0, H, h):
        for j in range(0, W, w):
            a[i][j] = m
    for i in range(h - 1, H, h):
        for j in range(w - 1, W, w):
            a[i][j] = -M
    return True, a


possible, res = solve(H, W, h, w)
if possible:
    print('Yes')
    for row in res:
        print(' '.join(map(str, row)))
else:
    print('No')

Solution (Python):
h, w, hh, ww = [int(i) for i in input().split()]
area = [h*w, hh*ww]
m = (h//hh) * (w // ww)
a_inv = (area[0] / m - area[1])
if(a_inv <= 0):
    print("No")
else:
    print("Yes")
    a = a_inv ** -1
    if(int(a) < a):
        a = int(a) + 1
    else:
        a = int(a)
    b = (area[1] - 1) * a + 1
    while(b >= (area[0]/m - 1)*a):
        a += 1
        b = (area[1] - 1) * a + 1
    a = str(a)
    b = str(-b)
    for i in range(h):
        ret = [None]*w
        for j in range(w):
            if((i+1) % hh == 0 and (j+1) % ww == 0):
                ret[j] = b
            else:
                ret[j] = a
        print(" ".join(ret))

Solution (Python):
H,W,h,w = [int(x) for x in input().split(' ')]
if W % w != 0:
    r = W % w
    n = int(W/w)
    n = n+1
    print('Yes')
    for i in range(H):
        for k in range(W):
            if (k+1) % w == 0:
                print(-n*(w-1) - 1, end = '')
            else:
                print(n, end = '')
            if k == W-1:
                print()
            else:
                print(end = ' ')
elif H % h != 0:
    r = H % h
    n = int(H/h)
    n = n + 1
    print('Yes')
    store = 0
    for i in range(H):
        if (i+1) % h == 0:
            store = -n*(h-1) - 1
        else:
            store = n
        for k in range(W):
            if k == W-1:
                print(store)
            else:
                print(store, end=' ')
else:
    print('No')

Solution (Python):
H, W, h, w = map(int, raw_input().split())
f = (H / h) * (W / w)
m = H * W - f * h * w
if m == 0:
    print "No"
    quit()
t = (f + m - 1) / m + 1
a = [[t] * W for _ in xrange(H)]
k = t * (h * w - 1) + 1
s = H * W * t
for i in xrange(h - 1, H, h):
    for j in xrange(w - 1, W, w):
        a[i][j] = -k
        s -= k + 1
if s < 0:
    print "No"
else:
    print "Yes"
    for l in a:
        print " ".join(map(str, l))

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

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

blocks = (H//h) * (W//w)
left = H * W - blocks * h * w
offset = blocks // left + 1
v = [offset, -offset * (h * w - 1) - 1]

print("Yes")
for i in range(H):
    a = []
    for j in range(W):
        a.append(v[1 if i % h == h-1 and j % w == w-1 else 0])
    print(" ".join(list(map(str, a))))