# Help me in solving CS2023_404 problem

### My issue

i don’t understand why my code is giving wrong answer even though its similar to the one shown in solution

### My code

``````#include<bits/stdc++.h>
using namespace std;
#define ll     long long

ll MOD  = 1e9+7;

ll mathpow(ll a, ll n){
if(n<0) return 0;
ll res = 1;
while(n){
if(n%2){
res*=a;
n--;
}else{
a*=a;
n/=2;
}
}
return res;
}

void solve()
{
int n;
cin>>n;
string s;
cin>>s;

vector<ll> pref(n),pref_4(n);

pref[0] = (s[0]=='*');
pref_4[0] = (s[0]=='4');

for(int i=1; i<n; i++){
pref[i] = pref[i-1]+ (s[i]=='*');
pref_4[i] = pref_4[i-1]+ (s[i]=='4');
}

ll ans = 0;
for(int i=1; i<n; i++){
if(s[i]!='4'){
ll left_4 = pref_4[i-1];
ll right_4 = pref_4[n-1]-pref_4[i];

ll left = pref[i-1];
ll right = pref[n-1]-pref[i];

ll lefts = ((mathpow(2,left)*left_4)%MOD+ (left*mathpow(2,left-1))%MOD)%MOD;
ll rights = ((mathpow(2,right)*right_4)%MOD+(right*mathpow(2,right-1))%MOD)%MOD;

ans += (lefts*rights)%MOD;

ans%=MOD;
}
}
cout<<ans<<endl;

}

int main()
{
int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
``````

Problem Link: CS2023_404 Problem - CodeChef

#include
using namespace std;

int main() {
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
int a[n];
int i;
for(i=0;i<=n-1;i++)
{
cin>>a[i];
}
int b[n];
for(i=0;i<=n-1;i++)
{
cin>>b[i];
}
int d=0;
int c=0;
int w=0;
for(i=0;i<=n-1;i++)
{
if(a[i]!=0)
{
d++;
}
if(a[i]==0||i==n-1)
{
if(d>c)
{
c=d;
}
d=0;
}
}
d=0;
for(i=0;i<=n-1;i++)
{
if(b[i]!=0)
{
d++;
}
if(b[i]==0||i==n-1)
{
if(d>w)
{
w=d;
}
d=0;
}
}
// cout<<c<<w<<“\n”;
if(c>w)
{
cout<<“Om”<<“\n”;
}
if(c==w)
{
cout<<“Draw”<<“\n”;
}
if(w>c)
{
}
}
return 0;
}
here i wrote a simple code to your problem while your code seems too complicated

#include
using namespace std;

int main() {
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
int a[n];
int i;
for(i=0;i<=n-1;i++)
{
cin>>a[i];
}
int b[n];
for(i=0;i<=n-1;i++)
{
cin>>b[i];
}
int d=0;
int c=0;
int w=0;
for(i=0;i<=n-1;i++)
{
if(a[i]!=0)
{
d++;
}
if(a[i]==0||i==n-1)
{
if(d>c)
{
c=d;
}
d=0;
}
}
d=0;
for(i=0;i<=n-1;i++)
{
if(b[i]!=0)
{
d++;
}
if(b[i]==0||i==n-1)
{
if(d>w)
{
w=d;
}
d=0;
}
}
// cout<<c<<w<<“\n”;
if(c>w)
{
cout<<“Om”<<“\n”;
}
if(c==w)
{
cout<<“Draw”<<“\n”;
}
if(w>c)
{