Codechef problem ...fast

#include
using namespace std;

int main() {
// your code goes here
long long int n,q,l,r,sum,diff;
cin >> n;
long long int a[n];
for(int i=0;i<n;i++ ){
cin >> a[i];
}

cin >> q;

int d;
for(int i=0;i<q;i++) {
    cin >> l >> r  >> d;
    sum=0;
    diff=0;
    for(int j=0;j<n;j++) {
        
        diff=r-j*d;
        if(diff >=l) {
            sum=sum+a[diff-1];
        }
    }
    
    cout << sum << endl;
    
}




return 0;

}

how to reduce its time complexity?? please anyone fast