Problem:
B: 累積差
問題
えびちゃんは最近「るいせきわ」のお勉強をして、数列 $(a_1, a_2, \dots, a_N)$ およびある整数 $L$, $R$ に対して $a_L+a_{L+1}+\dots+a_R$ を高速に求められるようになりました。
ここで、和ではなく差を求めることはできないか気になってきたえびちゃんのために、それを高速に処理するプログラムを書いてあげてください。より形式的には、数列 $(a_1, a_2, \dots, a_N)$ と整数 $L$, $R$ に対して $a_L-a_{L+1}-\dots-a_R$ を求めてください。
入力形式
$N$ $Q$
$a_1$ $a_2$ ... $a_N$
$L_1$ $R_1$
...
$L_Q$ $R_Q$
数列の長さ $N$ とクエリの個数 $Q$ が一行目に与えられ、数列 $a_i$ が二行目に与えられる。
続く $Q$ 行では一行あたり一組の $L$, $R$ が与えられる。
制約
$2 \leq N \leq 2\times 10^5$
$1 \leq Q \leq 2\times 10^5$
$1 \leq L_i < R_i \leq N$ ($1 \leq i \leq Q$)
$1 \leq a_i \leq 10^9$ ($1 \leq i \leq N$)
入力は全て整数である
出力形式
各クエリ $L$, $R$ に対して $a_L-a_{L+1}-\dots-a_R$ を一行ずつ出力してください。
入力例 1
5 2
1 4 3 5 2
1 4
2 3
出力例 1
-11
1
$1-4-3-5 = -11$ および $4-3 = 1$ です。
入力例 2
8 9
1 9 2 3 7 3 6 5
1 5
5 6
1 8
2 5
4 8
1 6
2 4
3 4
7 8
出力例 2
-20
4
-34
-3
-18
-23
4
-1
1

Submitted solutions:

code_snippet: #include<bits/stdc++.h>

using namespace std;


void acc() {
    int n, q;
    cin >> n >> q;
    vector<long long > pref(n + 1),v(n+1);
    for (int i = 1; i <= n; i++) {
        cin >>v[i] ;
    }
    for (int i = 1 ; i<=n ; i++){
        pref[i]+=pref[i-1]+v[i] ;
    }
    while (q--) {
        int l, r;
        cin >> l >> r;
        cout <<v[l]-pref[r]+pref[l] <<'\n';
    }

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
        acc();
}
accuracy: 1
time_ms: 40
memory_kb: 6212
final_rank: 6

code_snippet: #include <bits/stdc++.h>

using namespace std;
//make -f ../makefile SRC=

/*
*/
//------------------------------------------------------------------------------
bool DEBUG = false;

const int MAX_N = 200000;
static int64_t vect[MAX_N];
static int64_t P[MAX_N];


//------------------------------------------------------------------------------
void init(int N)
{ 
    P[0] = vect[0];
    for (int i=1; i<N; i++) P[i] = vect[i] + P[i-1];
    if (DEBUG) {printf("vect: "); for (int i=0; i<N; ++i) printf("%ld ",vect[i]); printf("\n");}
    if (DEBUG) {printf("P: "); for (int i=0; i<N; ++i) printf("%ld ",P[i]); printf("\n");}
}

//------------------------------------------------------------------------------
int64_t query(int N, int L, int R)
{ 
    if (L == R) return vect[L];
    return vect[L] - P[R] + P[L];
}

//------------------------------------------------------------------------------
int main()
{
    //DEBUG = true;
    //--------------------------------------------------------------------------
    int N, K, L, R, num;
    num = scanf("%d %d ", &N, &K);
    for (int n=0; n<N; ++n) num = scanf("%ld ", &vect[n]);
    init(N);

    for (int k=0; k<K; ++k)
    {
        num = scanf("%d %d ", &L, &R);
        int64_t res = query(N, L-1, R-1);
        printf("%ld\n", res);
    }
    
    return 0;
}

//------------------------------------------------------------------------------
accuracy: 1
time_ms: 50
memory_kb: 6692
final_rank: 8

code_snippet: #include<iostream>
using namespace std;

typedef long long ll;

ll sa[200001];
ll a[200001];

int main(){
    ll n,q,l,r;
    ll i,ans;

    cin >> n >> q;

    sa[0] = 0;

    for(i=1;i<=n;i++){
        cin >> a[i];
        sa[i] = a[i] + sa[i-1];
    }

    for(i=0;i<q;i++){
        cin >> l >> r;

        ans = a[l] - (sa[r] - sa[l]);

        cout << ans << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 320
memory_kb: 6216
final_rank: 19

code_snippet: #include<bits/stdc++.h>

using namespace std;

void func(){
  int n;
  int q;
  cin >> n >> q;
  using ll = long long;
  vector<ll> line(n);
  for(auto &i:line)cin >> i;
  vector<ll> sums(n+1,0);
  for(int i=0;i<n;++i){
    sums[i+1] = sums[i] + line[i];
  }
  for(int i=0;i<q;++i){
    int l;
    int r;
    cin >> l >> r;
    --l;
    --r;
    ll ans = line[l] - (sums[r+1] - sums[l+1]);
    cout << ans << endl;
  }
}

int main(){
  func();
}
accuracy: 1
time_ms: 250
memory_kb: 6280
final_rank: 16

code_snippet: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)

using namespace std;
using ll = long long ;
using P = pair<int,int>;
const int mod = 998244353;
const int inf = (1<<30);

const int dy[4] = {-1,0,0,1};
const int dx[4] = {0,-1,1,0};

int main(){
    int n,q;cin>>n>>q;
    vector<long long> A(n), B(n+1);
    for(int i = 0; n > i; i++){
       cin>>A[i]; 
    }
    for(int i = 1; n >= i; i++){
        B[i] = B[i-1]+A[i-1];     
    }
    for(int i = 0; q > i; i++){
        int l,r;cin>>l>>r;l--;r--;
        cout << A[l] - (B[r+1]-B[l+1]) << endl;
    }
}
accuracy: 1
time_ms: 250
memory_kb: 6252
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int N, Q; cin >> N >> Q;
    vector<ll> A(N);
    for (auto& a : A) cin >> a;
    vector<ll> S(N + 1);
    for (int i = 0 ; i < N ; i++) {
        S[i + 1] = S[i] - A[i];
    }
    for (int i = 0 ; i < Q ; i++) {
        int l, r; cin >> l >> r;
        l--;
        ll ans = S[r] - S[l] + 2 * A[l];
        cout << ans << endl; 
    }
}
accuracy: 1
time_ms: 250
memory_kb: 6280
final_rank: 16

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 3186.cc: Cumulative Difference
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N];
ll ass[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n, qn;
  scanf("%d%d", &n, &qn);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  for (int i = 0; i < n; i++) ass[i + 1] = ass[i] + as[i];

  while (qn--) {
    int l, r;
    scanf("%d%d", &l, &r); l--;

    ll v = as[l] - (ass[r] - ass[l + 1]);
    printf("%lld\n", v);
  }
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 5296
final_rank: 3

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=9167167167167167167;
const int INF=100000000;
const ll mod=998244353;
#define rep(i,a) for (int i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}



void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int N,Q;
	cin>>N>>Q;
	vector<ll> A(N+1);
	rep(i,N) cin>>A[i+1];
	rep(i,N) A[i+1]=A[i]+A[i+1];
	rep(i,Q){
		int l,r;
		cin>>l>>r;
		cout<<A[l]-A[l-1]-A[r]+A[l]<<"\n";
	}
}
accuracy: 1
time_ms: 40
memory_kb: 4544
final_rank: 1

code_snippet: #pragma region header
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;

/* alias */
using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vf = vector<float>;
using vvf = vector<vf>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvll = vector<vll>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using qll = queue<ll>;
//仮想配列map<> https://code-database.com/knowledges/100
//優先度付きque https://atcoder.jp/contests/apg4b/tasks/APG4b_aa

/* define short */
#define MOD 1000000007
#define INF LLONG_MAX/32
#define elif else if
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mp make_pair
#define all(obj) (obj).begin(), (obj).end()
#define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/* REP macro */
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) reps(i, 1, n + 1)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define rrepd(i,n) for(ll i=n;i>=1;i--)

//小数点以下出力の時にmainに書く
// cout << fixed << setprecision(10);

#pragma endregion header

ll N;


vvll Graph;/*グラフ*/
// struct edge{ll to, cost;};
// vector<vector<edge>> Graph;
ll H, W; vs HW;/*HW .#*/



#pragma region fanction
#pragma region First Search
/*幅優先探索 vll dist(N,-1); Graphは隣接リスト*/
void bfs(vll &dist, ll fq, vvll Graph){
    dist[fq] = 0;
    deque<ll> que;que.pb(fq);
    ll v;
    while(!que.empty()){
        v = que.front();que.pop_front();

        for(ll nv:Graph[v]){
            if(dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            que.pb(nv);
        }
    }
}


/*distにsysxからの距離が入る　各重み1*/
/*HW幅優先探索 https://pyteyon.hatenablog.com/entry/2019/03/01/211133#%E6%B7%B1%E3%81%95%E5%84%AA%E5%85%88%E6%8E%A2%E7%B4%A2*/
/*vvll dist(H vll(W)); rep(h,H) rep(w,W) dist[h][w] = INF;*/
void HW_bfs(vvll &dist, ll sy, ll sx, vs HW){
    dist[sy][sx] = 0;
    deque<vll> que;
    que.pb({sy,sx});

    vll v;
    ll nowy, nowx, nexty,nextx;
    vvll dydx = {{1,0},{0,1},{-1,0},{0,-1}};

    //重み1ならpbしてd++ 重み0ならpfしてそのままdiseにd入れれば01bfs
    //que.back();que.pop_back()で深さ優先探索

    while(!que.empty()){
        v = que.front();que.pop_front();
        nowy = v[0]; nowx = v[1];
        for(vll dyx:dydx){
            nexty = nowy+dyx[0]; nextx = nowx+dyx[1];
            if(!(0 <= nexty && nexty < H && 0 <= nextx && nextx < W)) continue;
            if(HW[nexty][nextx] == '.' && dist[nexty][nextx] == INF){
                que.pb({nexty,nextx});
                dist[nexty][nextx] = dist[nowy][nowx] + 1;
            }
        }
    }
}

/*深さ優先探索 vll dist(N,-1); Graphは隣接リスト スタートのdistを0にすること！*/
void dfs(vll &dist, ll v, vvll &Graph){
    for(ll nv:Graph[v]){
        if(dist[nv] != -1) continue;
        dist[nv] = dist[v] + 1;
        dfs(dist,nv,Graph);
    }
}

//単一始点最短経路　ダイクストラ　O(MlogN)
//vector<vector<pll>> //Graph; fi:to se:cost
// Graph.resize(N);
// rep(i,M){
//     ll a,b,c; cin >> a >> b >> c;
//     a--;b--;
//     Graph[a].pb(pll(b,c));
//     Graph[b].pb(pll(a,c));
// }

vll dijkstra(ll start,vector<vector<pll>> &Graph){
    vll dist(N,INF);
    priority_queue<pll,vector<pll>,greater<pll>> que;
    dist[start] = 0;
    que.push(pll(dist[start],start));
    while (!que.empty()){
        pll p = que.top(); que.pop();
        ll v = p.second;
        if(dist[v] < p.first) continue;
        for(auto &e:Graph[v]){
            if(dist[e.first] > dist[v] + e.second){
                dist[e.first] = dist[v] + e.second;
                que.push(pll(dist[e.first],e.first));
            }
        }
    }

    return dist;
}

#pragma endregion First Search
#pragma region MOD
const ll nCkMax = 1e6;
vll fac(1,0),finv(1,0),inv(1,0);

void COMinit(){
    fac.resize(nCkMax);
    finv.resize(nCkMax);
    inv.resize(nCkMax);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(ll i=2;i<nCkMax;i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
/*a^n % mod p O(log N)*/
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}
/*a! mod p O(N)*/
ll modfac(ll n){
    ll ret = 1;
    rrep(i,n){
        ret *= i;
        ret %= MOD;
    }
    return ret;
}

/*nCk % mod 前処理O(N) クエリ処理O(1)*/
ll nCk(ll n, ll k){
    if(fac[0] != 1) COMinit();//初期化 O(N)
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll factorial(ll n){
    ll ans = 1;
    for (ll i = 1;i<=n;i++){
        ans = ans * i % MOD;
    }
    return ans;
}

ll nHk(ll n, ll k){
    return nCk(n+k-1,k);
}
#pragma endregion MOD
#pragma region enumeration
vvll make_n(vll v){
    vvll ret;
    vll tmp;
    ll n = v.size();
    do{
        tmp = {};
        rep(i,n) tmp.pb(v[i]);
        ret.pb(tmp);
    }while(next_permutation(all(v)));
    return ret;
}
/*nCk列挙 vvllなのに注意！*/
vvll make_C(ll n, ll r){
    vvll ret;
    vll tmp;
    vector<bool> v(n);
    fill(v.end() - r, v.end(), true);
    do {
        tmp = {};
        for (int i = 0; i < n; ++i) { 
            if (v[i]) tmp.pb(i);
        }
        ret.pb(tmp);
    } while (next_permutation(v.begin(), v.end()));
    //reverse(all(ret));
    return ret;
}
/*nPk列挙 nPnでn!列挙 この時順番通りになってる*/
vvll make_P(ll n, ll r){
    vvll C = make_C(n,r);
    vvll ret;
    vvll tmp;
    vll v;
    rep(i,C.size()){
        v = C[i];
        tmp = make_n(v);
        for(vll t:tmp) ret.pb(t);
    }
    return ret;
}

#pragma endregion enumeration
#pragma region array

/*一次元配列最大最小総和*/
ll vmax(vll array){
    ll Max = -INF;
    for(ll a:array) chmax(Max,a);
    return Max;
}

ll vmin(vll array){
    ll Min = INF;
    for(ll a:array) chmin(Min,a);
    return Min;
}

ll sum(vll &array){
    ll Sum = 0;
    for(ll a:array) Sum += a;
    return Sum;
}

/*累積和 先頭に0が追加されてる lからrまではret[r+1]-ret[l]*/
vll cumulatice_sum(vll &array){
    vll ret(array.size()+1,0);
    rep(i,array.size()) ret[i+1] = ret[i] + array[i];
    return ret;
}

/*重複消し*/
void list_set(vll &array){
    sort(all(array));
    array.erase(unique(all(array)),array.end());
}

/*vvllで格納されてる配列をkey番目の要素でソート*/
void vvllsort(vvll &array, ll key){
    sort(all(array),[&key](vll a,vll b){return a[key] < b[key];});
}

/*string Sに何個string Kが含まれるか 一文字でもいいけどcharじゃなくてstringにしてね*/
ll stringinstring(string &S,string K){
    ll ret = 0;
    rep(i,S.size()-K.size()+1){
        bool f = true;
        rep(j,K.size()) if(S[i+j] != K[j]) f=false;
        if(f) ret++;
    }
    return ret;
}
#pragma endregion array
#pragma region UnionFind
class UnionFind{
public:
    vector<ll> parent; //parent[i]はiの親
    vector<ll> siz; //素集合のサイズを表す配列(1で初期化)
    map<ll,vector<ll>> group; //集合ごとに管理する(key:集合の代表元、value:集合の要素の配列)
    ll n; //要素数
 
    //コンストラクタ
    UnionFind(ll n_):n(n_),parent(n_),siz(n_,1){ 
        //全ての要素の根が自身であるとして初期化
        for(ll i=0;i<n;i++){parent[i]=i;}
    }
 
    //データxの属する木の根を取得(経路圧縮も行う)
    ll root(ll x){
        if(parent[x]==x) return x;
        return parent[x]=root(parent[x]);//代入式の値は代入した変数の値なので、経路圧縮できる
    }
 
    //xとyの木を併合
    void unite(ll x,ll y){
        ll rx=root(x);//xの根
        ll ry=root(y);//yの根
        if(rx==ry) return;//同じ木にある時
        //小さい集合を大きい集合へと併合(ry→rxへ併合)
        if(siz[rx]<siz[ry]) swap(rx,ry);
        siz[rx]+=siz[ry];
        parent[ry]=rx;//xとyが同じ木にない時はyの根ryをxの根rxにつける
    }
 
    //xとyが属する木が同じかを判定
    bool same(ll x,ll y){
        ll rx=root(x);
        ll ry=root(y);
        return rx==ry;
    }
 
    //xの素集合のサイズを取得
    ll size(ll x){
        return siz[root(x)];
    }
 
    //素集合をそれぞれグループ化
    void grouping(){
        //経路圧縮を先に行う
        rep(i,n)root(i);
        //mapで管理する(デフォルト構築を利用)
        rep(i,n)group[parent[i]].pb(i);
    }
 
    //素集合系を削除して初期化
    void clear(){
        rep(i,n){parent[i]=i;}
        siz=vector<ll>(n,1);
        group.clear();
    }
};
#pragma endregion UnionFind
#pragma region bisect
/*二分探索*/
ll bisect_left(vll &array, ll key){
    return lower_bound(all(array),key) - array.begin();
}

ll bisect_right(vll &array, ll key){
    return upper_bound(all(array),key) - array.begin();
}

/*最長増加部分列*/
ll LIS(vll a){
    vll dp(a.size(),INF);
    rep(i,a.size()){
        dp[bisect_right(dp,a[i])] = a[i];
    }
    return bisect_left(dp,INF);
}
/*条件を満たす最大のokを返す　最小にしたいならokng逆にする solveを書き換えること!*/
bool solve(ll n){
    return true;
}

ll meguru_bisect(ll ok, ll ng){
    ll mid;
    while(abs(ok-ng) > 1){
        mid = (ok + ng) / 2;
        if(solve(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}
#pragma endregion bisect
#pragma region others

/* memo

二次元配列の90度回転
// i:j 
// j:N - i - 1


*/



/*普通のa^n*/
ll pow(ll a, ll n){
    ll res = 1;
    while (n > 0) {
        if (n & 1) res *= a;
        a *= a;
        n >>= 1;
    }
    return res;
}
/*最大公約数*/
ll gcd(ll x,ll y){
    if (x < y) swap(x,y);
    while (y > 0){
        ll r = x % y;
        x = y;
        y = r;
    }
    return x;
}

/*最小公倍数*/
ll lcm(ll x,ll y){
    return x * y / (gcd(x,y));
}

/*約数列挙*/
vll divisor(ll n){
    vll ret;
    for (ll i = 1; i * i <= n; i++){
        if (n % i == 0){
            ret.pb(i);
            if (i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

/*素因数分解*/
vll factorize(ll n){
    vll ret;
    while (n % 2 == 0){
        ret.pb(2);
        n /= 2;
    }
    ll f = 3;
    while (f * f <= n){
        if (n % f == 0){
            ret.pb(f);
            n /= f;
        }else f += 2;
    }
    if (n != 1) ret.pb(n);
    return ret;
}
const ll Eramax = 1e6+1;
vll Eratos(1,1);
void Erainit(){
    Eratos.resize(Eramax+1);
    rep(i,Eramax+1) Eratos[i] = i;
    for(ll i=2;i<Eramax;i++){
        if(Eratos[i] != i) continue;
        for(ll j=2*i;j<Eramax;j+=i) Eratos[j] = i;
    }
    Eratos[1] = -1;
}
//前処理型素因数分解　1e6以下を複数回やるならこっち
vll Era_factorize(ll n){
    if(Eratos[0] != 0) Erainit();
    vll ret = {};
    if(n==1) return ret;
    while(n!=1){
        ret.pb(Eratos[n]);
        n /= Eratos[n];
    }
    return ret;
}

#pragma endregion others
#pragma endregion fanction




int main() {
    ll Q; cin >> N >> Q;
    vll A(N); rep(i,N) cin >> A[i];
    vll Sum = cumulatice_sum(A);
    
    rep(i,Q){
        ll l,r; cin >> l >> r;
        r--;
        cout << A[l-1] - (Sum[r+1] - Sum[l]) << endl;
    }
    
}
accuracy: 1
time_ms: 250
memory_kb: 6300
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	int q; cin >> q;
	vector<ll> a(n);
	vector<ll> sum(n+1);
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum[i+1]=sum[i]+a[i];
	}
	while(q--){
		int l,r; cin >> l >> r;
		l--;
		printf("%lld\n",a[l]-(sum[r]-sum[l+1]));
	}
}
accuracy: 1
time_ms: 60
memory_kb: 5984
final_rank: 7

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n,q;
    cin >> n >> q;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    vector<long long int> csum(n+1, 0);
    for(int i=0; i<n; i++){
        csum[i+1] = csum[i]+a[i];
    }
    for(int i=0; i<q; i++){
        int l,r;
        cin >> l >> r;
        l--; r--;
        cout << a[l] -(csum[r+1]-csum[l+1]) << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 5472
final_rank: 10

code_snippet: #line 2 "/home/yuruhiya/programming/library/template/template.cpp"
#include <bits/stdc++.h>
#line 4 "/home/yuruhiya/programming/library/template/constants.cpp"
#include <string_view>
#line 7 "/home/yuruhiya/programming/library/template/constants.cpp"

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rfor(i, m, n) for (int i = (m); i >= (n); --i)
#define unless(c) if (!(c))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define range_it(a, l, r) (a).begin() + (l), (a).begin() + (r)

using namespace std;
using ll = long long;
using LD = long double;
using VB = vector<bool>;
using VVB = vector<VB>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VS = vector<string>;
using VD = vector<LD>;
using PII = pair<int, int>;
using VP = vector<PII>;
using PLL = pair<ll, ll>;
using VPL = vector<PLL>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQS = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000000;
constexpr long long inf_ll = 1000000000000000000ll, MOD = 1000000007;
constexpr long double PI = 3.14159265358979323846, EPS = 1e-12;
namespace CharacterClass {
	constexpr string_view
	    digit = "0123456789",
	    xdigit = "0123456789ABCDEFabcdef", lower = "abcdefghijklmnopqrstuvwxyz",
	    upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
	    alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
	    alnum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
	    word = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz",
	    punct = R"(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)",
	    graph =
	        R"(!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~)",
	    print =
	        R"( !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~)",
	    blank = " \t", space = " \t\n\r\f\v";
}  // namespace CharacterClass
#line 7 "/home/yuruhiya/programming/library/template/Input.cpp"
using namespace std;

#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#define fwrite_unlocked fwrite
#define fflush_unlocked fflush
#endif
class Scanner {
	static int gc() {
		return getchar_unlocked();
	}
	static char next_char() {
		char c;
		read(c);
		return c;
	}
	template <class T> static void read(T& v) {
		cin >> v;
	}
	static void read(char& v) {
		while (isspace(v = gc()))
			;
	}
	static void read(bool& v) {
		v = next_char() != '0';
	}
	static void read(string& v) {
		v.clear();
		for (char c = next_char(); !isspace(c); c = gc()) v += c;
	}
	static void read(int& v) {
		v = 0;
		bool neg = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c); c = gc()) v = v * 10 + (c - '0');
		if (neg) v = -v;
	}
	static void read(long long& v) {
		v = 0;
		bool neg = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c); c = gc()) v = v * 10 + (c - '0');
		if (neg) v = -v;
	}
	static void read(double& v) {
		v = 0;
		double dp = 1;
		bool neg = false, after_dp = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c) || c == '.'; c = gc()) {
			if (c == '.') {
				after_dp = true;
			} else if (after_dp) {
				v += (c - '0') * (dp *= 0.1);
			} else {
				v = v * 10 + (c - '0');
			}
		}
		if (neg) v = -v;
	}
	static void read(long double& v) {
		v = 0;
		long double dp = 1;
		bool neg = false, after_dp = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c) || c == '.'; c = gc()) {
			if (c == '.') {
				after_dp = true;
			} else if (after_dp) {
				v += (c - '0') * (dp *= 0.1);
			} else {
				v = v * 10 + (c - '0');
			}
		}
		if (neg) v = -v;
	}
	template <class T, class U> static void read(pair<T, U>& v) {
		read(v.first);
		read(v.second);
	}
	template <class T> static void read(vector<T>& v) {
		for (auto& e : v) read(e);
	}
	template <size_t N = 0, class T> static void read_tuple_impl(T& v) {
		if constexpr (N < tuple_size_v<T>) {
			read(get<N>(v));
			read_tuple_impl<N + 1>(v);
		}
	}
	template <class... T> static void read(tuple<T...>& v) {
		read_tuple_impl(v);
	}
	struct ReadVectorHelper {
		size_t n;
		ReadVectorHelper(size_t _n) : n(_n) {}
		template <class T> operator vector<T>() {
			vector<T> v(n);
			read(v);
			return v;
		}
	};
	struct Read2DVectorHelper {
		size_t n, m;
		Read2DVectorHelper(const pair<size_t, size_t>& nm) : n(nm.first), m(nm.second) {}
		template <class T> operator vector<vector<T>>() {
			vector<vector<T>> v(n, vector<T>(m));
			read(v);
			return v;
		}
	};

public:
	string read_line() const {
		string v;
		for (char c = gc(); c != '\n' && c != '\0'; c = gc()) v += c;
		return v;
	}
	template <class T> T read() const {
		T v;
		read(v);
		return v;
	}
	template <class T> vector<T> read_vector(size_t n) const {
		vector<T> a(n);
		read(a);
		return a;
	}
	template <class T> operator T() const {
		return read<T>();
	}
	int operator--(int) const {
		return read<int>() - 1;
	}
	ReadVectorHelper operator[](size_t n) const {
		return ReadVectorHelper(n);
	}
	Read2DVectorHelper operator[](const pair<size_t, size_t>& nm) const {
		return Read2DVectorHelper(nm);
	}
	void operator()() const {}
	template <class H, class... T> void operator()(H&& h, T&&... t) const {
		read(h);
		operator()(forward<T>(t)...);
	}

private:
	template <template <class...> class, class...> struct Multiple;
	template <template <class...> class V, class Head, class... Tail>
	struct Multiple<V, Head, Tail...> {
		template <class... Args> using vec = V<vector<Head>, Args...>;
		using type = typename Multiple<vec, Tail...>::type;
	};
	template <template <class...> class V> struct Multiple<V> { using type = V<>; };
	template <class... T> using multiple_t = typename Multiple<tuple, T...>::type;
	template <size_t N = 0, class T> void multiple_impl(T& t) const {
		if constexpr (N < tuple_size_v<T>) {
			auto& vec = get<N>(t);
			using V = typename remove_reference_t<decltype(vec)>::value_type;
			vec.push_back(read<V>());
			multiple_impl<N + 1>(t);
		}
	}

public:
	template <class... T> auto multiple(size_t h) const {
		multiple_t<T...> result;
		while (h--) multiple_impl(result);
		return result;
	}
} in;
#define inputs(T, ...) \
	T __VA_ARGS__;     \
	in(__VA_ARGS__)
#define ini(...) inputs(int, __VA_ARGS__)
#define inl(...) inputs(long long, __VA_ARGS__)
#define ins(...) inputs(string, __VA_ARGS__)
#line 7 "/home/yuruhiya/programming/library/template/Output.cpp"
#include <charconv>
#line 10 "/home/yuruhiya/programming/library/template/Output.cpp"
using namespace std;

struct BoolStr {
	const char *t, *f;
	BoolStr(const char* _t, const char* _f) : t(_t), f(_f) {}
} Yes("Yes", "No"), yes("yes", "no"), YES("YES", "NO"), Int("1", "0");
struct DivStr {
	const char *d, *l;
	DivStr(const char* _d, const char* _l) : d(_d), l(_l) {}
} spc(" ", "\n"), no_spc("", "\n"), end_line("\n", "\n"), comma(",", "\n"),
    no_endl(" ", "");
class Printer {
	BoolStr B{Yes};
	DivStr D{spc};

public:
	void print(int v) const {
		char buf[12]{};
		if (auto [ptr, e] = to_chars(begin(buf), end(buf), v); e == errc{}) {
			fwrite(buf, sizeof(char), ptr - buf, stdout);
		} else {
			assert(false);
		}
	}
	void print(long long v) const {
		char buf[21]{};
		if (auto [ptr, e] = to_chars(begin(buf), end(buf), v); e == errc{}) {
			fwrite(buf, sizeof(char), ptr - buf, stdout);
		} else {
			assert(false);
		}
	}
	void print(bool v) const {
		print(v ? B.t : B.f);
	}
	void print(vector<bool>::reference v) const {
		print(v ? B.t : B.f);
	}
	void print(char v) const {
		putchar_unlocked(v);
	}
	void print(const char* v) const {
		fwrite_unlocked(v, 1, strlen(v), stdout);
	}
	void print(double v) const {
		printf("%.20f", v);
	}
	void print(long double v) const {
		printf("%.20Lf", v);
	}
	template <class T> void print(const T& v) const {
		cout << v;
	}
	template <class T, class U> void print(const pair<T, U>& v) const {
		print(v.first);
		print(D.d);
		print(v.second);
	}
	template <class InputIterater>
	void print_range(const InputIterater& begin, const InputIterater& end) const {
		for (InputIterater i = begin; i != end; ++i) {
			if (i != begin) print(D.d);
			print(*i);
		}
	}
	template <class T> void print(const vector<T>& v) const {
		print_range(v.begin(), v.end());
	}
	template <class T, size_t N> void print(const array<T, N>& v) const {
		print_range(v.begin(), v.end());
	}
	template <class T> void print(const vector<vector<T>>& v) const {
		for (size_t i = 0; i < v.size(); ++i) {
			if (i) print(D.l);
			print(v[i]);
		}
	}

	Printer() = default;
	Printer(const BoolStr& _boolstr, const DivStr& _divstr) : B(_boolstr), D(_divstr) {}
	Printer& operator()() {
		print(D.l);
		return *this;
	}
	template <class H> Printer& operator()(H&& h) {
		print(h);
		print(D.l);
		return *this;
	}
	template <class H, class... T> Printer& operator()(H&& h, T&&... t) {
		print(h);
		print(D.d);
		return operator()(forward<T>(t)...);
	}
	template <class InputIterator>
	Printer& range(const InputIterator& begin, const InputIterator& end) {
		print_range(begin, end);
		print(D.l);
		return *this;
	}
	template <class T> Printer& range(const T& a) {
		range(a.begin(), a.end());
		return *this;
	}
	template <class... T> void exit(T&&... t) {
		operator()(forward<T>(t)...);
		std::exit(EXIT_SUCCESS);
	}
	Printer& flush() {
		fflush_unlocked(stdout);
		return *this;
	}
	Printer& set(const BoolStr& b) {
		B = b;
		return *this;
	}
	Printer& set(const DivStr& d) {
		D = d;
		return *this;
	}
	Printer& set(const char* t, const char* f) {
		B = BoolStr(t, f);
		return *this;
	}
} out;
#line 3 "/home/yuruhiya/programming/library/template/Step.cpp"
using namespace std;

template <class T> struct Step {
	using value_type = T;

	class iterator {
		value_type a, b, c;

	public:
		constexpr iterator() : a(value_type()), b(value_type()), c(value_type()) {}
		constexpr iterator(value_type _b, value_type _c, value_type _s)
		    : a(_b), b(_c), c(_s) {}
		constexpr iterator& operator++() {
			--b;
			a += c;
			return *this;
		}
		constexpr iterator operator++(int) {
			iterator tmp = *this;
			--b;
			a += c;
			return tmp;
		}
		constexpr const value_type& operator*() const {
			return a;
		}
		constexpr const value_type* operator->() const {
			return &a;
		}
		constexpr bool operator==(const iterator& i) const {
			return b == i.b;
		}
		constexpr bool operator!=(const iterator& i) const {
			return !(b == i.b);
		}
		constexpr value_type start() const {
			return a;
		}
		constexpr value_type size() const {
			return b;
		}
		constexpr value_type step() const {
			return c;
		}
	};
	constexpr Step(value_type b, value_type c, value_type s) : be(b, c, s) {}
	constexpr iterator begin() const {
		return be;
	}
	constexpr iterator end() const {
		return en;
	}
	constexpr value_type start() const {
		return be.start();
	}
	constexpr value_type size() const {
		return be.size();
	}
	constexpr value_type step() const {
		return be.step();
	}
	constexpr value_type sum() const {
		return start() * size() + step() * (size() * (size() - 1) / 2);
	}
	operator vector<value_type>() const {
		return to_a();
	}
	auto to_a() const {
		vector<value_type> result;
		result.reserve(size());
		for (auto i : *this) {
			result.push_back(i);
		}
		return result;
	}

private:
	iterator be, en;
};
template <class T> constexpr auto step(T a) {
	return Step<T>(0, a, 1);
}
template <class T> constexpr auto step(T a, T b) {
	return Step<T>(a, b - a, 1);
}
template <class T> constexpr auto step(T a, T b, T c) {
	return Step<T>(a, a < b ? (b - a - 1) / c + 1 : 0, c);
}
#line 8 "/home/yuruhiya/programming/library/template/Ruby.cpp"
using namespace std;

template <class F> struct Callable {
	F func;
	Callable(const F& f) : func(f) {}
};
template <class T, class F> auto operator|(const T& v, const Callable<F>& c) {
	return c.func(v);
}

struct Sort_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v), f);
			return v;
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const Sort_impl& c) {
		sort(begin(v), end(v));
		return v;
	}
} Sort;
struct SortBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v),
			     [&](const auto& i, const auto& j) { return f(i) < f(j); });
			return v;
		});
	}
} SortBy;
struct RSort_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(rbegin(v), rend(v), f);
			return v;
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const RSort_impl& c) {
		sort(rbegin(v), rend(v));
		return v;
	}
} RSort;
struct RSortBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v),
			     [&](const auto& i, const auto& j) { return f(i) > f(j); });
			return v;
		});
	}
} RSortBy;
struct Reverse_impl {
	template <class T> friend auto operator|(T v, const Reverse_impl& c) {
		reverse(begin(v), end(v));
		return v;
	}
} Reverse;
struct Unique_impl {
	template <class T> friend auto operator|(T v, const Unique_impl& c) {
		v.erase(unique(begin(v), end(v), end(v)));
		return v;
	}
} Unique;
struct Uniq_impl {
	template <class T> friend auto operator|(T v, const Uniq_impl& c) {
		sort(begin(v), end(v));
		v.erase(unique(begin(v), end(v)), end(v));
		return v;
	}
} Uniq;
struct Rotate_impl {
	auto operator()(int&& left) {
		return Callable([&](auto v) {
			int s = static_cast<int>(size(v));
			assert(-s <= left && left <= s);
			if (0 <= left) {
				rotate(begin(v), begin(v) + left, end(v));
			} else {
				rotate(begin(v), end(v) + left, end(v));
			}
			return v;
		});
	}
} Rotate;
struct Max_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) { return *max_element(begin(v), end(v), f); });
	}
	template <class T> friend auto operator|(T v, const Max_impl& c) {
		return *max_element(begin(v), end(v));
	}
} Max;
struct Min_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) { return *min_element(begin(v), end(v), f); });
	}
	template <class T> friend auto operator|(T v, const Min_impl& c) {
		return *min_element(begin(v), end(v));
	}
} Min;
struct MaxPos_impl {
	template <class T> friend auto operator|(T v, const MaxPos_impl& c) {
		return max_element(begin(v), end(v)) - begin(v);
	}
} MaxPos;
struct MinPos_impl {
	template <class T> friend auto operator|(T v, const MinPos_impl& c) {
		return min_element(begin(v), end(v)) - begin(v);
	}
} MinPos;
struct MaxBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto max_it = begin(v);
			auto max_val = f(*max_it);
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); max_val < val) {
					max_it = it;
					max_val = val;
				}
			}
			return *max_it;
		});
	}
} MaxBy;
struct MinBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto min_it = begin(v);
			auto min_val = f(*min_it);
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); min_val > val) {
					min_it = it;
					min_val = val;
				}
			}
			return *min_it;
		});
	}
} MinBy;
struct MaxOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto max_val = f(*begin(v));
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); max_val < val) {
					max_val = val;
				}
			}
			return max_val;
		});
	}
} MaxOf;
struct MinOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto min_val = f(*begin(v));
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); min_val > val) {
					min_val = val;
				}
			}
			return min_val;
		});
	}
} MinOf;
struct Count_impl {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) { return count(begin(v), end(v), val); });
	}
} Count;
struct CountIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) { return count_if(begin(v), end(v), f); });
	}
} CountIf;
struct Index_impl {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) -> optional<int> {
			auto result = find(begin(v), end(v), val);
			return result != end(v) ? optional(result - begin(v)) : nullopt;
		});
	}
} Index;
struct IndexIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) -> optional<int> {
			auto result = find_if(begin(v), end(v), f);
			return result != end(v) ? optional(result - begin(v)) : nullopt;
		});
	}
} IndexIf;
struct FindIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) -> optional<typename decltype(v)::value_type> {
			auto result = find_if(begin(v), end(v), f);
			return result != end(v) ? optional(*result) : nullopt;
		});
	}
} FindIf;
struct Sum_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			return accumulate(next(begin(v)), end(v), f(*begin(v)),
			                  [&](const auto& a, const auto& b) { return a + f(b); });
		});
	}
	template <class T> friend auto operator|(T v, const Sum_impl& c) {
		return accumulate(begin(v), end(v), typename T::value_type{});
	}
} Sum;
struct Includes {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) { return find(begin(v), end(v), val) != end(v); });
	}
} Includes;
struct IncludesIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) { return find_if(begin(v), end(v), f) != end(v); });
	}
} IncludesIf;
struct RemoveIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) {
			v.erase(remove_if(begin(v), end(v), f), end(v));
			return v;
		});
	}
} RemoveIf;
struct Each_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				f(i);
			}
		});
	}
} Each;
struct Select_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			using value_type = typename decltype(v)::value_type;
			vector<value_type> result;
			for (const auto& i : v) {
				if (f(i)) result.push_back(i);
			}
			return result;
		});
	}
} Select;
struct Map_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			using result_type = invoke_result_t<F, typename decltype(v)::value_type>;
			vector<result_type> result;
			result.reserve(size(v));
			for (const auto& i : v) {
				result.push_back(f(i));
			}
			return result;
		});
	}
} Map;
struct Indexed_impl {
	template <class T> friend auto operator|(const T& v, Indexed_impl& c) {
		using value_type = typename T::value_type;
		vector<pair<value_type, int>> result;
		result.reserve(size(v));
		int index = 0;
		for (const auto& i : v) {
			result.emplace_back(i, index++);
		}
		return result;
	}
} Indexed;
struct AllOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (!f(i)) return false;
			}
			return true;
		});
	}
} AllOf;
struct AnyOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (f(i)) return true;
			}
			return false;
		});
	}
} AnyOf;
struct NoneOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (f(i)) return false;
			}
			return true;
		});
	}
} NoneOf;

struct Tally_impl {
	template <class F> auto operator()(size_t max_val) {
		return Callable([&](auto v) {
			vector<size_t> result(max_val);
			for (const auto& i : v) {
				result[static_cast<size_t>(i)]++;
			}
			return result;
		});
	}
	template <class T, class value_type = typename T::value_type>
	friend auto operator|(const T& v, Tally_impl& c) {
		map<value_type, size_t> result;
		for (const auto& i : v) {
			result[i]++;
		}
		return result;
	}
} Tally;

template <class T> auto operator*(const vector<T>& a, size_t n) {
	T result;
	for (size_t i = 0; i < n; ++i) {
		result.insert(result.end(), a.begin(), a.end());
	}
	return result;
}
auto operator*(string a, size_t n) {
	string result;
	for (size_t i = 0; i < n; ++i) {
		result += a;
	}
	return result;
}
template <class T, class U> auto& operator<<(vector<T>& a, const U& b) {
	a.insert(a.end(), all(b));
	return a;
}
template <class T> auto& operator<<(string& a, const T& b) {
	a.insert(a.end(), all(b));
	return a;
}
template <class T, class U> auto operator+(vector<T> a, const U& b) {
	a << b;
	return a;
}
template <class T> auto operator+(string a, const T& b) {
	a << b;
	return a;
}
#line 7 "/home/yuruhiya/programming/library/template/functions.cpp"
using namespace std;

template <class T = long long> constexpr T TEN(size_t n) {
	T result = 1;
	for (size_t i = 0; i < n; ++i) result *= 10;
	return result;
}
template <class T, class U,
          enable_if_t<is_integral_v<T> && is_integral_v<U>, nullptr_t> = nullptr>
constexpr auto div_ceil(T n, U m) {
	return (n + m - 1) / m;
}
template <class T, class U> constexpr auto div_ceil2(T n, U m) {
	return div_ceil(n, m) * m;
}
template <class T> constexpr T triangle(T n) {
	return (n & 1) ? (n + 1) / 2 * n : n / 2 * (n + 1);
}
template <class T> constexpr T nC2(T n) {
	return (n & 1) ? (n - 1) / 2 * n : n / 2 * (n - 1);
}
template <class T, class U> constexpr auto middle(const T& l, const U& r) {
	return l + (r - l) / 2;
}
template <class T, class U, class V>
constexpr bool in_range(const T& v, const U& lower, const V& upper) {
	return lower <= v && v < upper;
}
template <class T, enable_if_t<is_integral_v<T>, nullptr_t> = nullptr>
constexpr bool is_square(T n) {
	T s = sqrt(n);
	return s * s == n || (s + 1) * (s + 1) == n;
}
template <class T = long long> constexpr T BIT(int b) {
	return T(1) << b;
}
template <class T> constexpr int BIT(T x, int i) {
	return (x & (1 << i)) ? 1 : 0;
}
template <class T, class U, enable_if_t<is_integral_v<U>, nullptr_t> = nullptr>
constexpr T Pow(T a, U n) {
	assert(n >= 0);
	T result = 1;
	while (n > 0) {
		if (n & 1) {
			result *= a;
			n--;
		} else {
			a *= a;
			n >>= 1;
		}
	}
	return result;
}
template <class T, class U, enable_if_t<is_integral_v<U>, nullptr_t> = nullptr>
constexpr T Powmod(T a, U n, T mod) {
	assert(n >= 0);
	if (a > mod) a %= mod;
	T result = 1;
	while (n > 0) {
		if (n & 1) {
			result = result * a % mod;
			n--;
		} else {
			a = a * a % mod;
			n >>= 1;
		}
	}
	return result;
}
template <class T> bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> int sz(const T& v) {
	return v.size();
}
template <class T, class U> int lower_index(const T& a, const U& v) {
	return lower_bound(all(a), v) - a.begin();
}
template <class T, class U> int upper_index(const T& a, const U& v) {
	return upper_bound(all(a), v) - a.begin();
}
template <class T> auto Slice(const T& v, size_t i, size_t len) {
	return i < v.size() ? T(v.begin() + i, v.begin() + min(i + len, v.size())) : T();
}
template <class T, class U = typename T::value_type> U Gcdv(const T& v) {
	return accumulate(next(v.begin()), v.end(), U(*v.begin()), gcd<U, U>);
}
template <class T, class U = typename T::value_type> U Lcmv(const T& v) {
	return accumulate(next(v.begin()), v.end(), U(*v.begin()), lcm<U, U>);
}
namespace internal {
	template <class T, size_t N> auto make_vector(vector<int>& sizes, const T& init) {
		if constexpr (N == 1) {
			return vector(sizes[0], init);
		} else {
			int size = sizes[N - 1];
			sizes.pop_back();
			return vector(size, make_vector<T, N - 1>(sizes, init));
		}
	}
}  // namespace internal
template <class T, size_t N>
auto make_vector(const int (&sizes)[N], const T& init = T()) {
	vector s(rbegin(sizes), rend(sizes));
	return internal::make_vector<T, N>(s, init);
}
#line 9 "/home/yuruhiya/programming/library/template/template.cpp"
#if __has_include(<library/dump.hpp>)
#include <library/dump.hpp>
#define LOCAL
#else
#define dump(...) ((void)0)
#endif

template <class T> constexpr T oj_local(const T& oj, const T& local) {
#ifndef LOCAL
	return oj;
#else
	return local;
#endif
}
#line 3 "/home/yuruhiya/programming/library/Utility/CulSum.cpp"
#include <type_traits>
#line 5 "/home/yuruhiya/programming/library/Utility/CulSum.cpp"
using namespace std;

template <class T> class CulSum {
public:
	using value_type = T;
	using data_type = vector<value_type>;

private:
	size_t n;
	data_type data;

public:
	CulSum() = default;
	CulSum(const data_type& a) : n(a.size()), data(n + 1) {
		for (size_t i = 0; i < n; ++i) {
			data[i + 1] = data[i] + a[i];
		}
	}
	template <class U, class F, enable_if_t<is_integral_v<U>, nullptr_t> = nullptr>
	CulSum(const U& _n, F f) : n(_n), data(n + 1) {
		for (size_t i = 0; i < n; ++i) {
			data[i + 1] = data[i] + static_cast<value_type>(f(i));
		}
	}
	template <class U, class F, enable_if_t<!is_integral_v<U>, nullptr_t> = nullptr>
	CulSum(const U& a, F f)
	    : CulSum(a.size(), [a, f](size_t i) -> value_type { return f(a[i]); }) {}
	size_t size() const {
		return n;
	}
	value_type at(size_t i) const {
		return operator()(i, i + 1);
	}
	// [l, r)
	value_type operator()(size_t l, size_t r) const {
		l = min(l, n);
		r = min(r, n);
		return l > r ? 0 : data[r] - data[l];
	}
	// [0, r)
	value_type operator()(size_t r) const {
		r = min(r, n);
		return data[r];
	}
	const data_type& get_data() const {
		return data;
	}
};
#line 3 "a.cpp"

int main() {
	ini(n, q);
	VL a = in[n];
	CulSum<ll> sum(a);
	rep(i, q) {
		int l = in--, r = in;
		out(a[l] - sum(l + 1, r));
	}
}
accuracy: 1
time_ms: 10
memory_kb: 6148
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define irep(i,a,b) for(int i=int(a);i<(int)b;++i)
#define rrep(i,a,b) for(int i=int(a);i>=(int)b;--i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll,ll>>>
#define vpl vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define pb push_back
#define se second
#define fi first
#define all(v) v.begin(),v.end()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

using namespace std;

template<typename T> istream& operator>>(istream&i,v(T)&v){rep(j,v.size())i>>v[j];return i;}
template<typename T> string join(const v(T)&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T> ostream& operator<<(ostream&o,const v(T)&v){if(v.size())o<<join(v);return o;}



using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

const ll mod = 1e9 + 7; //998244353;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


ll modpow(ll a,ll b){
    if(b == 0){
        return 1;
    }
    if(b%2 == 0){
        ll tmp = modpow(a,b/2);
        return tmp*tmp%mod;
    }else{
        return modpow(a,b-1)*a%mod;
    }

}



int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n,q;
    cin >> n >> q;
    vl a(n),asum(n+1);
    rep(i,n){
        cin >> a[i];
        asum[i+1] = asum[i] + a[i];
    }

    vl ans;
    rep(i,q){
        int l,r;
        cin >> l >> r;
        ll s = -asum[r]+asum[l] + a[l-1];
        ans.pb(s);
    }

    rep(i,ans.size())cout << ans[i] << endl;
    return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 8340
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
#include <cstdint>
#include <string>
#include <sstream>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using P = pair<int,int>;
const int INF=1001001001;
const int mod =1e9+7;

int main() {
  int N,Q;cin>>N>>Q;
  vector<int>a(N+1);
  for(int i=1;i<=N;i++){cin>>a[i];}
  vector<ll>sum(N+1);
  for(int i=1;i<=N;i++){sum[i]=sum[i-1]+a[i];}
  for(int i=0;i<Q;i++){
    int L,R;cin>>L>>R;
    cout<<a[L]-(sum[R]-sum[L])<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 5492
final_rank: 11

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 9223372036854775807
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 200005

int N,num_query;
ll A[SIZE];

int main(){

	scanf("%d %d",&N,&num_query);

	A[0] = 0;
	for(int i = 1; i <= N; i++){

		scanf("%lld",&A[i]);
		A[i] += A[i-1];
	}

	int left,right;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d %d",&left,&right);

		printf("%lld\n",(A[left]-A[left-1])-(A[right]-A[left]));
	}

	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 4776
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)

using namespace std;
typedef long long ll;

const int INTINF = INT_MAX >> 1;

int main(){

	int N, Q;
	cin  >> N >> Q;
	vector<ll> v(N), H(N+1);
	rep(i, N){
		cin >> v[i];
		H[i+1] = H[i] - v[i];

	}
	rep(i, Q){
		int a, b; cin >> a >>  b;
		cout << - H[a-1] + H[b] + v[a-1] * 2 << endl;
	}

    return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 6204
final_rank: 13

code_snippet: #include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main() { 
    int n, q;
    cin >> n >> q;
    vector<ll> rui;
    ll total = 0;
    rui.push_back(0);
    rep(i, n){
        ll a;
        cin >> a;
        total += a;
        rui.push_back(total);
    }
    rep(i, q){
        ll l, r;
        cin >> l >> r;
        cout << rui[l] - rui[l-1] - (rui[r] - rui[l]) << endl;
    }
    return 0; 
}
accuracy: 1
time_ms: 240
memory_kb: 5212
final_rank: 9

code_snippet: #include<iostream>
#include<vector>
#include<string>

using namespace std;

#define int long long
#define endl "\n"

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N, Q;
  vector<int> a, sum;

  cin>>N>>Q;

  a.resize(N);
  sum.resize(N+1);

  for(int i = 0;  i < N; i++){
    cin>>a[i];

    sum[i+1] += sum[i] + a[i];
  }

  for(int i =0; i < Q; i++){
    int L, R;

    cin>>L>>R;

    L--, R--;

    int s = sum[R+1] - sum[L+1];

    cout<<a[L]-s<<endl;
  }

  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 6000
final_rank: 5

code_snippet: #include <bits/stdc++.h>
#ifdef _DEBUG
#include "_DEBUG.hpp"
#endif
#define int long long
using namespace std;
using P = pair<int, int>;
const int inf = 1LL << 60;
const int mod = 1e9 + 7;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

template <class T>
vector<T> make_vec(size_t a) {
  return vector<T>(a);
}

template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template <class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
  t = v;
}

template <class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v) {
  for (auto &e : t) fill(e, v);
}

signed main() {
  
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  cin >> a;

  vector<int> imos(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    imos[i] = imos[i-1] + a[i-1];
  }

  for(int i = 0; i < q; i++){
    int l, r;
    cin >> l >> r;
    int ans = a[l-1] - (imos[r] - imos[l]);
    cout << ans << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 6240
final_rank: 14

code_snippet: /**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n, q; cin >> n >> q;
    vector<int> a(n);
    vector<int> sum(n + 1, 0);
    rep(i, n) {
        cin >> a[i];
        sum[i + 1] = sum[i] + a[i];
    }
    rep(_, q) {
        int l, r; cin >> l >> r;
        -- l;
        cout << a[l] - (sum[r] - sum[l + 1]) << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 6000
final_rank: 12