Buggy python submission (verdict: Runtime Error):
def main():
    h, w, a, b = map(int, input().split())
    r = [w - a] * h
    c = [h - b] * w
    t = [[0] * w for _ in range(h)]
    br = False
    for x in range(h, -1, -1):
        for y in range(w, -1, -1):
            if a * x + (w - a) * (h - x) == b * y + (h - b) * (w - y):
                br = True
                break
        if br: break
    else:
        print("No")
        exit()
    for i in range(x):
        r[h - 1 - i] = a
    for i in range(y):
        c[w - 1 - i] = b
    for i in range(h):
        j = 0
        while r[i] > 0:
            if c[j] == 0:
                j += 1
                continue
            t[i][j] = 1
            r[i] -= 1
            c[j] -= 1
            j += 1
    for x in t:
        print(*x, sep="")

main()


Fixed submission:
from heapq import *

def main():
    h, w, a, b = map(int, input().split())
    r = []
    c = []
    t = [[0] * w for _ in range(h)]
    br = False
    for x in range(h + 1):
        for y in range(w + 1):
            if a * (h - x) + (w - a) * x == b * (w - y) + (h - b) * y:
                br = True
                break
        if br: break
    else:
        print("No")
        exit()
    for i in range(x):
        heappush(r, [-w + a, i])
    for i in range(x, h):
        heappush(r, [-a, i])
    for j in range(y):
        heappush(c, [-h + b, j])
    for j in range(y, w):
        heappush(c, [-b, j])
    while r:
        e0, i = heappop(r)
        tmp = []
        for _ in range(-e0):
            e1, j = heappop(c)
            t[i][j] = 1
            if -e1 > 1: tmp.append([e1 + 1, j])
        for l in tmp:
            heappush(c, l)
    for x in t:
        print(*x, sep="")

main()

Buggy python submission (verdict: Runtime Error):
def main():
    h, w, a, b = map(int, input().split())
    r = [w - a] * h
    c = [h - b] * w
    t = [[0] * w for _ in range(h)]
    for y in range(w, -1, -1):
        x = (b * y + (h - b) * (w - y) - h * (w - a)) / (2 * a - w)
        if int(x) == x and 0 <= x <= h:
            x = int(x)
            break
    else:
        print("No")
        exit()
    for i in range(x):
        r[h - 1 - i] = a
    for i in range(y):
        c[w - 1 - i] = b
    for i in range(h):
        j = 0
        while r[i] > 0:
            if c[j] == 0:
                j += 1
                continue
            t[i][j] = 1
            r[i] -= 1
            c[j] -= 1
            j += 1
    for x in t:
        print(*x, sep="")

main()


Fixed submission:
from heapq import *

def main():
    h, w, a, b = map(int, input().split())
    r = []
    c = []
    t = [[0] * w for _ in range(h)]
    br = False
    for x in range(h + 1):
        for y in range(w + 1):
            if a * (h - x) + (w - a) * x == b * (w - y) + (h - b) * y:
                br = True
                break
        if br: break
    else:
        print("No")
        exit()
    for i in range(x):
        heappush(r, [-w + a, i])
    for i in range(x, h):
        heappush(r, [-a, i])
    for j in range(y):
        heappush(c, [-h + b, j])
    for j in range(y, w):
        heappush(c, [-b, j])
    while r:
        e0, i = heappop(r)
        tmp = []
        for _ in range(-e0):
            e1, j = heappop(c)
            t[i][j] = 1
            if -e1 > 1: tmp.append([e1 + 1, j])
        for l in tmp:
            heappush(c, l)
    for x in t:
        print(*x, sep="")

main()