getting TLE, any help

```
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
//#pragma GCC optimize("Ofast")
// #pragma GCC optimize "trapv"
#define ll long long
#define lld long double
int main() {
// your code goes here
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lld t;
cin>>t;
for(int T=1;T<=t;T++)
{
//cout<<"Case #"<<T<<": ";
ll n,m;
cin>>n>>m;
ll arr[n+1];
int ans=INT_MAX;
for(int i=1;i<=n;i++)
cin>>arr[i];
ll pref[n+1];
pref[0]=0;
for(int i=1;i<=n;i++)
pref[i]=(pref[i-1]+arr[i])%m;
for(int i=0;i<=n;i++)
{
for(int j=i;;j=(j-1)&i)
{
if(i+j<n && (i&j)==j)
{
int r=n-i;
int l=j+1;
ll sum1 = pref[l-1];
ll sum2 = pref[r];
ll sum = sum2-sum1;
if(sum<0)
sum+=m;
// cout<<i<<" "<<j<<" "<<l<<" "<<r<<"\n";
if(sum%m==0)
{
ans=min(ans, __builtin_popcount(i));
break;
//cout<<l<<" "<<r<<"\n";
}
}
if(j==0)
break;
}
}
if(ans==INT_MAX)
cout<<"-1\n";
else
cout<<ans<<"\n";
}
}
```