I am debugging the following code for long . I have compared with AC solution with random cases and it worked . But still giving WA . I can write new code but i want to find my mistake . my solution is similar to the one in editorial .
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 998244353
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const ll N = 1e6;
ll a[N];
ll coun[N];
ll pref[N],mul[N],p2[N];
int main()
{
ll t,n,i,j,ans,val,temp,res,sum,v,mx;
p2[0]=1;
for(i=1;i<N;++i)
p2[i] = (p2[i-1]*2)%MOD; //calculation of powers of 2
cin>>t;
while(t--)
{
cin>>n;
for(i=0;i<=(n+70);++i)
coun[i]=pref[i]=mul[i]=0;
for(i=1;i<=n;++i)
{
cin>>a[i];
if(a[i]<N)
++coun[a[i]]; //saving the frequency
}
sum = 0;
res = 0;
mul[0]=1;
//cout<<n<<"\n";
for(i=1;i<=(n+1);++i)
{
pref[i] = (pref[i-1] + coun[i])%MOD;
v = ((n - pref[i])%MOD)%MOD;
v = p2[v];
res = (res + (v*(mul[i-1]*i)%MOD)%MOD)%MOD ;
v = (p2[coun[i]]-1)%MOD;
mul[i] = (v*mul[i-1])%MOD;
}
res = (res+MOD)%MOD;
cout<<res<<"\n";
return 0;
}