Problem p03438 (python)

Fixed submission:
N = int(input())
A = input()
ai = A.split()
B = input()
bi = B.split()
i = 0
a = []
b = []
for i in range(N):
    a.append(int(ai[i]))
    b.append(int(bi[i]))

i = 0
asum = 0
bsum = 0
for i in range(N):
    asum += a[i]
    bsum += b[i]

c = True
j = 0
if asum > bsum:
    print("No")
    c = False
elif asum == bsum:
    for j in range(N):
        if a[j] != b[j]:
            print("No")
            c = False
            break
    if c:
        print("Yes")
        c = False
else:
    k = 0
    Da = 0
    Db = 0
    d = bsum - asum 
    while Da <= d and Db <= d:
        dab = 0
        if a[k] < b[k]:
            dab = b[k] - a[k]
            if dab // 2 == 0:
                Da += 1
                a[k] += 2
            else:
                Da += dab // 2
                a[k] += (dab // 2) * 2 
        elif a[k] == b[k]:
            k += 1
        else:
            dab = a[k] - b[k]
            Db += dab
            b[k] += dab
        if k == N:
            break
if c:
    for j in range(N):
        if a[j] != b[j]:
            print("No")
            c = False
            break
    if c:
        if (d - Da) * 2 == (d - Db) * 1:
            print("Yes")
        else:
            print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
A = input()
ai = A.split()
B = input()
bi = B.split()
i = 0
a = []
b = []
for i in range(N):
    a.append(int(ai[i]))
    b.append(int(bi[i]))

i = 0
asum = 0
bsum = 0
for i in range(N):
    asum += a[i]
    bsum += b[i]

c = True
j = 0
if asum > bsum:
    print("No")
    c = False
elif asum == bsum:
    for j in range(N):
        if a[j] != b[j]:
            print("No")
            c = False
            break
    if c:
        print("Yes")
        c = False
else:
    k = 0
    Da = 0
    Db = 0
    d = bsum - asum 
    while Da < d and Db < d:
        if a[k] < b[k]:
            Da += (b[k] - a[k]) // 2
            a[k] += ((b[k] - a[k]) // 2) * 2 
        elif a[k] == b[k]:
            k += 1
        else:
            Db += a[k] - b[k]
            b[k] += a[k] - b[k]
        if k == N:
            break
if c:
    for j in range(N):
        if a[j] != b[j]:
            print("No")
            c = False
            break
    if c:
        if (N - Da) * 2 == (N - Db) * 1:
            print("Yes")
        else:
            print("No")N = int(input())
A = input()
ai = A.split()
B = input()
bi = B.split()
i = 0
a = []
b = []
for i in range(N):
    a.append(int(ai[i]))
    b.append(int(bi[i]))

i = 0
asum = 0
bsum = 0
for i in range(N):
    asum += a[i]
    bsum += b[i]

c = True
j = 0
if asum > bsum:
    print("No")
    c = False
elif asum == bsum:
    for j in range(N):
        if a[j] != b[j]:
            print("No")
            c = False
            break
    if c:
        print("Yes")
        c = False
else:
    k = 0
    Da = 0
    Db = 0
    d = bsum - asum 
    while Da < d and Db < d:
        if a[k] < b[k]:
            Da += (b[k] - a[k]) // 2
            a[k] += ((b[k] - a[k]) // 2) * 2 
        elif a[k] == b[k]:
            k += 1
        else:
            Db += a[k] - b[k]
            b[k] += a[k] - b[k]
        if k == N:
            break
if c:
    for j in range(N):
        if a[j] != b[j]:
            print("No")
            c = False
            break
    if c:
        if (N - Da) * 2 == (N - Db) * 1:
            print("Yes")
        else:
            print("No")