I am getting a runtime error in sum infinite array...can anyone have a look?

vector<int> sumInRanges(vector<int> &arr, int n, vector<vector<long long>> &queries, int q) {
	const int M = 1e9+7;
    const int N = 1e5+10;
    
    vector<long long> pre;
    vector<int> answer;
    pre.push_back(0);
    pre.push_back(arr[0]);
    int d = 1;
    for(int i = 1;i<N;i++){
    	int p = i % n;
        pre.push_back((arr[p]+pre[d++])%M);
    }
    
    for(int i = 0;i<q;i++){
    	long long a = queries[i][1]  ;
        long long b = queries[i][0] - 1;
		answer.push_back((pre[a] - pre[b])%M);
    }
    return answer;
}