#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 5 ; //size of the array
int a[5] = {6,7,3,2,2};
int dp[n+1]={0}; //dp array
int i = 0 ;
while(i<=n-1){
if(i==0){
dp[i] = a[i] ;
}
else{
dp[i] = a[i] + dp[i-1];
}
i++;
}
int q = 4 ; //number of queries
int w[4] = {0,3,4,2}; //query array
i = 0 ;
while(i<=q-1){
int query;query = w[i];
cout<<dp[query]; //answering each query in O(1)
cout<<endl;
i++;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgICBpbnQgbiA9IDUgOyAvL3NpemUgb2YgdGhlIGFycmF5IAogICAgaW50IGFbNV0gPSB7Niw3LDMsMiwyfTsgCgogICAgaW50IGRwW24rMV09ezB9OyAvL2RwIGFycmF5IAogICAgaW50IGkgPSAwIDsgCiAgICB3aGlsZShpPD1uLTEpewogICAgICAgIGlmKGk9PTApewogICAgICAgICAgICBkcFtpXSA9IGFbaV0gOyAKICAgICAgICB9CiAgICAgICAgZWxzZXsKICAgICAgICAgICAgZHBbaV0gPSBhW2ldICsgZHBbaS0xXTsKICAgICAgICB9CiAgICAgICAgaSsrOwogICAgfQogICAgaW50IHEgPSA0IDsgLy9udW1iZXIgb2YgcXVlcmllcyAKICAgIGludCB3WzRdID0gezAsMyw0LDJ9OyAvL3F1ZXJ5IGFycmF5IAogICAgaSA9IDAgOyAKICAgIHdoaWxlKGk8PXEtMSl7CiAgICAgICAgaW50IHF1ZXJ5O3F1ZXJ5ID0gd1tpXTsKICAgICAgICBjb3V0PDxkcFtxdWVyeV07IC8vYW5zd2VyaW5nIGVhY2ggcXVlcnkgaW4gTygxKSAKICAgICAgICBjb3V0PDxlbmRsOwogICAgICAgIGkrKzsKICAgICAgIH0KICAgIHJldHVybiAwOwp9