Problem p03429 (python)

Fixed submission:
n,m,a,b = list(map(int,input().split()))
ban = [["."]*m for i in range(n)]
aa = a
bb = b
if n%2 == 1 and m %2 == 1 and n>=3 and m>=3 and a>=2 and b>=2:
    aa-=2
    bb-=2
    ban[-3][-3] = "<"
    ban[-3][-2] = ">"
    ban[-3][-1] = "^"
    ban[-2][-3] = "^"
    ban[-2][-1] = "v"
    ban[-1][-3] = "v"
    ban[-1][-2] = "<"
    ban[-1][-1] = ">"
    for i in range(0,m-m%2-2,2):
        if aa == 0:
            break
        ban[-1][i] = "<"
        ban[-1][i+1] = ">"
        aa-=1
    for i in range(0,n-n%2-2,2):
        if bb == 0:
            break
        ban[i][-1] = "^"
        ban[i+1][-1] = "v"
        bb-=1
    n-=1
    m-=1
    yo = aa//2
    ta = bb//2
    yoa = aa%2
    taa = bb%2
    if n*m//4 -1 < yo+ta+yoa+taa:
        n+=1
        m+=1
        ban = [["."]*m for i in range(n)]
    else:
        tu = []
        for i in range(0,n,2):
            for j in range(0,m,2):
                tu.append([i,j])
        tu.pop()
        for i in range(yo+ta):
            x,y = tu[i]
            if i<yo:
                ban[x][y] = "<"
                ban[x+1][y] = "<"
                ban[x][y+1] = ">"
                ban[x+1][y+1] = ">"
            else:
                ban[x][y] = "^"
                ban[x+1][y] = "v"
                ban[x][y+1] = "^"
                ban[x+1][y+1] = "v"            
        if yoa and taa:
            x,y = tu[yo+ta]
            ban[x][y] = "<"
            ban[x][y+1] = ">"
            x,y = tu[yo+ta+1]
            ban[x][y] = "^"
            ban[x+1][y] = "v"
        elif yoa:
            x,y = tu[yo+ta]
            ban[x][y] = "<"
            ban[x][y+1] = ">"
        elif taa:
            x,y = tu[yo+ta]
            ban[x][y] = "^"
            ban[x+1][y] = "v"  
        print("YES")
        for i in ban:
            print("".join(i))
        exit()

if n%2 ==1:
    for i in range(0,m-m%2,2):
        if a == 0:
            break
        ban[-1][i] = "<"
        ban[-1][i+1] = ">"
        a-=1
    n-=1
if m%2 == 1:
    for i in range(0,n,2):
        if b == 0:
            break
        ban[i][-1] = "^"
        ban[i+1][-1] = "v"
        b-=1
    m-=1
if n%2 == 0 and m%2 == 0:
    yo = a//2
    ta = b//2
    yoa = a%2
    taa = b%2
    if n*m//4 < yo+ta+yoa+taa:
        print("NO")
        exit()
    tu = []
    for i in range(0,n,2):
        for j in range(0,m,2):
            tu.append([i,j])
    for i in range(yo+ta):
        x,y = tu[i]
        if i<yo:
            ban[x][y] = "<"
            ban[x+1][y] = "<"
            ban[x][y+1] = ">"
            ban[x+1][y+1] = ">"
        else:
            ban[x][y] = "^"
            ban[x+1][y] = "v"
            ban[x][y+1] = "^"
            ban[x+1][y+1] = "v"            
    if yoa and taa:
        x,y = tu[yo+ta]
        ban[x][y] = "<"
        ban[x][y+1] = ">"
        x,y = tu[yo+ta+1]
        ban[x][y] = "^"
        ban[x+1][y] = "v"
    elif yoa:
        x,y = tu[yo+ta]
        ban[x][y] = "<"
        ban[x][y+1] = ">"
    elif taa:
        x,y = tu[yo+ta]
        ban[x][y] = "^"
        ban[x+1][y] = "v"                      
print("YES")
for i in ban:
    print("".join(i))

Buggy submission (verdict: Runtime Error):
n,m,a,b = list(map(int,input().split()))
ban = [["."]*m for i in range(n)]
if n%2 ==1:
    for i in range(0,m,2):
        if a == 0:
            break
        ban[-1][i] = "<"
        ban[-1][i+1] = ">"
        a-=1
    n-=1
if m%2 == 1:
    for i in range(0,n,2):
        if b == 0:
            break
        ban[i][-1] = "^"
        ban[i+1][-1] = "v"
        b-=1
    m-=1
if n%2 == 0 and m%2 == 0:
    yo = a//2
    ta = b//2
    yoa = a%2
    taa = b%2
    if n*m//4 < yo+ta+yoa+taa:
        print("NO")
        exit()
    tu = []
    for i in range(0,n,2):
        for j in range(0,m,2):
            tu.append([i,j])
    for i in range(yo+ta):
        x,y = tu[i]
        if i<yo:
            ban[x][y] = "<"
            ban[x+1][y] = "<"
            ban[x][y+1] = ">"
            ban[x+1][y+1] = ">"
        else:
            ban[x][y] = "^"
            ban[x+1][y] = "v"
            ban[x][y+1] = "^"
            ban[x+1][y+1] = "v"            
    if yoa and taa:
        x,y = tu[yo+ta]
        ban[x][y] = "<"
        ban[x][y+1] = ">"
        x,y = tu[yo+ta+1]
        ban[x][y] = "^"
        ban[x+1][y] = "v"
    elif yoa:
        x,y = tu[yo+ta]
        ban[x][y] = "<"
        ban[x][y+1] = ">"
    elif taa:
        x,y = tu[yo+ta]
        ban[x][y] = "^"
        ban[x+1][y] = "v"                      
print("YES")
for i in ban:
    print(*i)