Problem p03001 (python)

Fixed submission:
# -*- coding: utf-8 -*-

W, H, x, y = map(int, input().split())

count = 0
s = 0
if 2 * x == W and 2 * y == H:
    s = W * H / 2
    count = 4
else:

    if (x == 0 and y == 0) or (x == 0 and y == H) or (x == W and y == 0) or (x == W and y == H):
        s = W * H / 2
        count = 1
    elif (x == 0 and 2 * y == H) or (x == W and 2 * y == H) or (2 * x == W and y == 0) or (2 * x == W and y == H):
        s = W * H / 2
        count = 1
    else:
        if 2 * x == W:
            s = W * H / 2
            count = 1

        elif 2 * y == H:
            s = W * H / 2
            count = 1
        else:
            a = (H - 2 * y) / (2 * x - W)
            if a > 0:
                if ((H + a * x - y) / a) <= W and ((a * x - y) / a) >= 0:
                    s = (H**2 / 2 + H * (a * x - y)) / a
                    count += 1

                a *= -1
                if ((H + a * x - y) / a) >= 0 and ((a * x - y) / a) <= W:
                    s = (H**2 / 2 + H * (a * x - y)) / a
                    count += 1


            elif a < 0:
                s = a * (W**2) / 2 + (y - a * x) * W
                if (a * W + y - a * x) >= 0 and (y - a * x) <= H:
                    count += 1
                a *= -1
                if (a * W + y - a * x) <= H and (y - a * x) >= 0:
                    count += 1



if count == 1:
    print("{0:.6f}".format(abs(s)),0)
else:
    print("{0:.6f}".format(abs(s)),1)

Buggy submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())

count = 0
s = 0
if 2 * x == W and 2 * y == H:
    s = W * H / 2
    count = 4
else:

    if (x == 0 and y == 0) or (x == 0 and y == H) or (x == W and y == 0) or (x == W and y == H):
        s = W * H / 2
        count = 1
    elif (x == 0 and 2 * y == H) or (x == W and 2 * y == H) or (2 * x == W and y == 0) or (2 * x == W and y == H)
        s = W * H / 2
        count = 1
    else:
        if 2 * x == W:
            s = W * H / 2
            count = 1

        elif 2 * y == H:
            s = W * H / 2
            count = 1
        else:
            a = (H - 2 * y) / (2 * x - W)
            if a > 0:
                if ((H + a * x - y) / a) <= W and ((a * x - y) / a) >= 0:
                    s = (H**2 / 2 + H * (a * x - y)) / a
                    count += 2
            elif a < 0:
                s = a * (W**2) / 2 + (y - a * x) * W
                a *= -1
                if (a * W + y - a * x) <= H and (y - a * x) >= 0:
                    count += 2
if count == 1:
    print("{0:.6f}".format(s),0)
else:
    print("{0:.6f}".format(s),1)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

W, H, x, y = map(int, input().split())

count = 0
s = 0
if 2 * x == W and 2 * y == H:
    s = W * H / 2
    count = 4
else:

    if (x == 0 and y == 0) or (x == 0 and y == H) or (x == W and y == 0) or (x == W and y == H):
        s = W * H / 2
        count = 1
    elif (x == 0 and 2 * y == H) or (x == W and 2 * y == H) or (2 * x == W and y == 0) or (2 * x == W and y == H)
        s = W * H / 2
        count = 1
    else:        
        if 2 * x == W:
            s = W * H / 2
            count = 1

        elif 2 * y == H:
            s = W * H / 2
            count = 1
        else:
            a = (H - 2 * y) / (2 * x - W)
            if a > 0:
                if ((H + a * x - y) / a) <= W and ((a * x - y) / a) >= 0:
                    s = (H**2 / 2 + H * (a * x - y)) / a
                    count += 2
            elif a < 0:
                s = a * (W**2) / 2 + (y - a * x) * W
                a *= -1
                if (a * W + y - a * x) <= H and (y - a * x) >= 0:
                    count += 2
if count == 1:
    print("{0:.6f}".format(s),0)
else:
    print("{0:.6f}".format(s),1)