test case running , but showing wrong answer on submission

Problem Code: JAGAM

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
long int n,z1,z2;
cin>>n>>z1>>z2;
long int arr[n];
bool flag1=false,flag2=false;
for(int i=0;i<n;i++) cin>>arr[i];

   for(int i=0;i<n;i++)
   {
       if(arr[i]==z1||arr[i]==z2||arr[i]==-z1||arr[i]==-z2)
       {
           cout<<"1"<<"\n";
           flag1=true;
           break;
       }
   }
      if (flag1!=true)
       {
           for(int j=0;j<n;j++)
           {
           for(int i=0;i<n;i++)
            {
            if((arr[i]+arr[j]==z1||arr[i]+arr[j]==z2||arr[i]+arr[j]==-z1||arr[i]+arr[j]==-z2||arr[i]-arr[j]==z1||arr[i]-arr[j]==z2||arr[i]-arr[j]==-z1||arr[i]-arr[j]==-z2)&&flag2!=true)
            {
                cout<<"2"<<"\n";
                flag2=true;
                break;
                break;
            }
       }}}
       if (flag1!=true&&flag2!=true) cout<<"0"<<"\n";
       else continue;
   }
    
    
    
}