Help me in solving ATBO problem

My issue

if n = 6,
a = {1,2,3,4,5,6}
b = {15,-5,-9,2,3,15}
it is giving its answer as NO as by the most popular explained code.
but the answer can be YES by performing the operation first on index 3, then array becomes 1, 2 ,12,-5,-4,15 then performing operation on index 2 then array becomes 1,9,5,-12,3,15
then performing operation on index 1 then array becomes 15,-5,-9,2,3,15

This code is the most popular explained code

t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    
    solved=True
    for i in range(n-3):
        
        gap = b[i]-a[i]
        
        if gap==0:
            continue
        
        else:
            if gap != a[i+1]+a[i+2]:
                print("NO")
                solved=False
                break
            else:
                l,m,n,o=a[i],a[i+1],a[i+2],a[i+3]
                
                m=-1*a[i+2]
                n=-1*a[i+1]
                o=a[i+1]+a[i+2]+a[i+3]
                
                a[i+1],a[i+2],a[i+3] = m,n,o
    if a[-1]!=b[-1] or a[-2]!=b[-2] or a[-3]!=b[-3]:
        if solved:
            solved=False
            print("NO")
    if solved:
        print("YES")

Problem Link: Operating on A Practice Coding Problem - CodeChef

2 Likes