Help in mexum april Lunchtime

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;
}

you have to break the loop when you encounter first element which has frequency zero
as it will be the ans for all remaining sub sets.
and also v*(mul[i-1]*i) is overflowing

take a look at this
I have changed this and got AC
https://www.codechef.com/viewsolution/32293430

1 Like

Got WA due to that . Lesson Don’t forget the basics