Why does it fulfill only 3 test cases although output is correct?

include
#include
using namespace std;
int main() {
int n,a[100],i,q,x,j,b[100],sum=0;
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
cin>>q;
for(i=1;i<=q;i++)
{
cin>>x;
if(x>=0&&x<n)
{
for(j=0;j<n;j++)
b[j]=a[j];
for(j=0;j<n;j++)
{
if(j>=x)
a[j]+=b[j-x];
else if(j<x)
a[j]+=b[n+j-x];
}
/for(j=0;j<n;j++)
cout<<a[j]<<" ";
cout<<endl;
/
if(i==q)
{
for(j=0;j<n;j++)
sum+=a[j];
cout<<sum;
}
}

}
return 0;

}

hi @muskanrathore01_4aab76aa7dafc189
refer this -->

#include<iostream>
#include<vector>
using namespace std;
int main() {
    int n;
    cin>>n;
    vector<int> v;
    for(int i=0;i<n;i++){
        int no;
        cin>>no;
        v.push_back(no);
    }
    int q;
    cin>>q;
    while(q--){
        int x;
        cin>>x;
        vector<int> temp = v;
        for(int i=0;i<n;i++){
            temp[i] = v[i] + v[(i-x+n)%n];
        }
        v = temp;
    }

    long long int sum = 0;
    for(int i=0;i<n;i++){
        sum = (sum + v[i])%1000000007;
    }
    cout<<sum<<endl;
}

This code also doesn’t work and has many syntax errors

hi @muskanrathore01_4aab76aa7dafc189
i don’t think there is any syntax errors in the code i shared as it is working fine… also i tried the code on all the 3 test cases individually, its working fine and giving the correct o/p… if still on submission it shows error, then there might be some compiler issues…

This is the error it is showing: #include<iostream> | ^ main.cpp:9:9: error: #include expects “FILENAME” or 9 | #include<vector> | ^ main.cpp: In function ‘int main()’: main.cpp:13:5: error: ‘cin’ was not declared in this scope 13 | cin>>n; | ^~~ main.cpp:1:1: note: ‘std::cin’ is defined in header ‘’; did you forget to ‘#include ’? +++ |+#include 1 | /****************************************************************************** main.cpp:13:9: error: ‘gt’ was not declared in this scope 13 | cin>>n; | ^~ main.cpp:14:5: error: ‘vector’ was not declared in this scope 14 | vector<int> v; | ^~~~~~ main.cpp:1:1: note: ‘std::vector’ is defined in header ‘’; did you forget to ‘#include ’? +++ |+#include 1 | /****************************************************************************** main.cpp:14:12: error: ‘lt’ was not declared in this scope 14 | vector<int> v; | ^~ main.cpp:14:23: error: ‘v’ was not declared in this scope 14 | vector<int> v; | ^ main.cpp:15:23: error: expected ‘)’ before ‘;’ token 15 | for(int i=0;i<n;i++){ | ~ ^ | ) main.cpp:15:24: error: ‘i’ was not declared in this scope 15 | for(int i=0;i<n;i++){ | ^ main.cpp:25:23: error: ‘gt’ declared as reference but not initialized 25 | vector<int> temp = v; | ^~ main.cpp:25:27: error: ‘temp’ was not declared in this scope 25 | vector<int> temp = v; | ^~~~ main.cpp:26:27: error: expected ‘)’ before ‘;’ token 26 | for(int i=0;i<n;i++){ | ~ ^ | ) main.cpp:33:23: error: expected ‘)’ before ‘;’ token 33 | for(int i=0;i<n;i++){ | ~ ^ | ) main.cpp:36:5: error: ‘cout’ was not declared in this scope 36 | cout<<sum<<endl; | ^~~~ main.cpp:36:5: note: ‘std::cout’ is defined in header ‘’; did you forget to ‘#include ’? main.cpp:36:28: error: ‘endl’ was not declared in this scope 36 | cout<<sum<<endl; | ^~~~ main.cpp:1:1: note: ‘std::endl’ is defined in header ‘’; did you forget to ‘#include ’? +++ |+#include

hi @muskanrathore01_4aab76aa7dafc189
code is working fine…

ok the code you gave earlier in text was coming in this format:

#include&lt;iostream&gt;
#include&lt;vector&gt;
using namespace std;
int main() {
    int n;
    cin&gt;&gt;n;
    vector&lt;int&gt; v;
    for(int i=0;i&lt;n;i++){
        int no;
        cin&gt;&gt;no;
        v.push_back(no);
    }
    int q;
    cin&gt;&gt;q;
    while(q--){
        int x;
        cin&gt;&gt;x;
        vector&lt;int&gt; temp = v;
        for(int i=0;i&lt;n;i++){
            temp[i] = v[i] + v[(i-x+n)%n];
        }
        v = temp;
    }

    long long int sum = 0;
    for(int i=0;i&lt;n;i++){
        sum = (sum + v[i])%1000000007;
    }
    cout&lt;&lt;sum&lt;&lt;endl;
}

This image one is working fine. Btw can you explain what was the main error in my original code?

hi @muskanrathore01_4aab76aa7dafc189
Actually i couldn’t make out our logic… this was a simple code and main part was just

temp[i] = v[i] + v[(i-x+n)%n];

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.