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

bool isValid(ll mid,vector<ll>&nums,ll pos){
	//count the number of subarrays with sum mid
	ll count=0;
	ll st=0;
	ll n=nums.size();
	ll sum=0;
	for(int end=0;end<n;end++){
		sum+=nums[end];
	
		while(sum>mid){
			sum-=nums[st];
			st++;
		}
		
		count+=(end-st+1);
	}
	return count>=pos;
}

pair<ll,ll>countAndTotal(ll k,vector<ll>&nums){
	ll count=0;
	ll total=0;
	
	ll n=nums.size();
	vector<ll>pref(n+1,0);
	vector<ll>pp(n+1,0);//prefix of prefix it is used to calculate all teh left sums at O(1)
	//insted of the standard for loop
	
	for(int i=0;i<n;i++){
		pref[i+1]=pref[i]+nums[i];
	}
	
	//pp
	for(int i=0;i<=n;i++){
		pp[i]=((i>0)?pp[i-1]:0)+pref[i];
	}
	
	ll st=0;
	ll sum=0;
	for(int end=0;end<n;end++){
		sum+=nums[end];
		
		while(sum>k){
			sum-=nums[st];
			st++;
		}
		
		ll len=end-st+1;
		
		count+=len;
		
		ll left=(st>0)?pp[st-1]:0;
		total+=(pref[end+1]*len)-(pp[end]-left);
	}
	return {count,total};
	
}


ll solve(int pos,vector<ll>&nums){
	//first we have to find out what is teh element that comes in that pos
	//after that we have to find out the sum until that element
	int n=nums.size();
	ll st=0;
	ll end=accumulate(nums.begin(),nums.end(),0LL);
	ll ans=-1;
	while(st<=end){
		ll mid=st+(end-st)/2;
		
		if(isValid(mid,nums,pos)){
			ans=mid;
			end=mid-1;  
		}else{
			st=mid+1;
		}
	}
	pair<ll,ll>pr=countAndTotal(ans,nums);
	ll total=pr.second;
	ll count=pr.first;
	//because total is the all the subarrays sum and count is total subarrays
	//and pos is the cur pos we want so we are subtracting the extra eleemnts 
	//by the positions sum in it
	return total-((count-pos)*ans);
}

int main() {
	
	int n;
	cin>>n;
	vector<ll>nums(n);
	for(int i=0;i<n;i++){
		cin>>nums[i];
	}
	
//given queries we have to find the sum of them in rnage so sum(l-r)
//so pref[r]-pref[l-1];
    ll stPos;
    ll endPos;
    cin>>stPos>>endPos;
    
    cout<<solve(endPos,nums)-solve(stPos-1,nums)<<endl;
    return 0;
    
}