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

int n, num[400000], maxx, minn, mim, mam;
long long ans;

void reedInp(int x) {
    for (int i = 0; i < n; i++)
        cin >> num[i];
}

int check(int x, int y) {
    if (maxx < x) {
        maxx = x;
        mam = y;
    }
    if (minn > x && x) {
        minn = x;
        mim = y;
    }
}

void cnt(int x[]) {
    maxx = 0, minn = 10001;
    for (int i = 0; i < n; i++)
        check(x[i], i);
    ans += (minn + maxx) * (minn + maxx);
    x[mam] = x[mim] = 0;
}

int main() {
    cin >> n;
    reedInp(n);
    for (int i = 0; i < n / 2; i++)
        cnt(num);
    cout << ans;
}


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

int n, num[400000], maxx, minn, ans, mim, mam;

void reedInp(int x) {
    for (int i = 0; i < n; i++)
        cin >> num[i];
}

int check(int x, int y) {
    if (maxx < x) {
        maxx = x;
        mam = y;
    }
    if (minn > x && x) {
        minn = x;
        mim = y;
    }
}

void cnt(int x[]) {
    maxx = 0, minn = 1001;
    for (int i = 0; i < n; i++)
        check(x[i], i);
    ans += (minn + maxx) * (minn + maxx);
    x[mam] = x[mim] = 0;
}

int main() {
    cin >> n;
    reedInp(n);
    for (int i = 0; i < n / 2; i++)
        cnt(num);
    cout << ans;
}


#include<bits/stdc++.h>
using namespace std;
#define ioS            ios::sync_with_stdio(false);cin.tie(0);
#define li             long int
#define ll             long li
#define ull            unsigned ll
#define pi             pair<int,int>
#define vi             vector<int>
#define vli            vector<li>
#define vll           vector<ll>
#define vvi            vector<vector<int>>
#define pb             push_back
#define mp             make_pair
#define forn(i,s,n)    for(auto i=s;i<n;++i)
#define forr(i,s,n)    for(auto i=s;i>=n;--i)
const ll mx = 1e9+2;
void solve(int test)
{
    int n;
    cin>>n;
    vli a(n);
    forn(i,0,n) cin>>a[i];
    sort(a.begin(),a.end());
    li s = 0;
    forn(i,0,n/2)
        s+=(a[i]+a[n-1-i])*(a[i]+a[n-1-i]);
    cout<<s<<endl;
}
int32_t main()
{
    ioS
    int t;
    // cin>>t;
    // forn(i,1,t+1)
        solve(0);
}


#include<bits/stdc++.h>
using namespace std;
#define ioS            ios::sync_with_stdio(false);cin.tie(0);
#define li             long int
#define ll             long li
#define ull            unsigned ll
#define pi             pair<int,int>
#define vi             vector<int>
#define vli            vector<li>
#define vll           vector<ll>
#define vvi            vector<vector<int>>
#define pb             push_back
#define mp             make_pair
#define forn(i,s,n)    for(auto i=s;i<n;++i)
#define forr(i,s,n)    for(auto i=s;i>=n;--i)
const ll mx = 1e9+2;
void solve(int test)
{
    int n;
    cin>>n;
    vli a(n);
    forn(i,0,n) cin>>a[i];
    sort(a.begin(),a.end());
    li s = 0;
    forn(i,0,n/2)
        s+=(0l+a[i]+a[n-1-i])*(0l+a[i]+a[n-1-i]);
    cout<<s<<endl;
}
int32_t main()
{
    ioS
    int t;
    // cin>>t;
    // forn(i,1,t+1)
        solve(0);
}


#include<bits/stdc++.h>
using namespace std;
#define ioS            ios::sync_with_stdio(false);cin.tie(0);
#define li             long int
#define ll             long li
#define ull            unsigned ll
#define pi             pair<int,int>
#define vi             vector<int>
#define vli            vector<li>
#define vll           vector<ll>
#define vvi            vector<vector<int>>
#define pb             push_back
#define mp             make_pair
#define forn(i,s,n)    for(auto i=s;i<n;++i)
#define forr(i,s,n)    for(auto i=s;i>=n;--i)
const ll mx = 1e9+2;
void solve(int test)
{
    int n;
    cin>>n;
    vll a(n);
    forn(i,0,n) cin>>a[i];
    sort(a.begin(),a.end());
    ll s = 0;
    forn(i,0,n/2)
        s+=(a[i]+a[n-1-i])*(a[i]+a[n-1-i]);
    cout<<s<<endl;
}
int32_t main()
{
    ioS
    int t;
    // cin>>t;
    // forn(i,1,t+1)
        solve(0);
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll a,b,c[1234567],d,e,i,j,n;
	map<ll,ll> m;
	string s;
	cin>>a;
	for(i=1;i<=a;i++){
		cin>>c[i];
	}
	ll ans=0;
	sort(c+1,c+a+1);
	for(i=1;i<=a/2;i++){
		d=c[i]+c[a+1-i];
		ans+=d*d;
	}
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,c[4000005],ans=0,d,e,i,j,n;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>c[i];
	}
	d=n;
	sort(c+1,c+n+1);
	for(i=1;i<=n/2;i++){
		ans+=(c[i]+c[d])*(c[i]+c[d]);
		d--;
	}
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,c[100005],ans=0,d,e,i,j,n;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>c[i];
	}
	d=n;
	sort(c+1,c+n+1);
	for(i=1;i<=n/2;i++){
		ans+=(c[i]+c[d])*(c[i]+c[d]);
		d--;
	}
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int n;
int a[1<<19];
long long AnswerProblem;
int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    for (int i=1;i<=n;i++)
    {
        int i2=n+1;i2-=i;
        AnswerProblem+=a[i]*a[i2];
    }
    cout<<AnswerProblem<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
int a[1<<19];
long long AnswerProblem;
int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    for (int i=1;i<=n;i++)
    {
        int i2=n+1;i2-=i;
        AnswerProblem+=(a[i]+a[i2])*(a[i]+a[i2]);
    }
    cout<<AnswerProblem/2<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int x[100010];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&x[i]);
    int s,f;
    scanf("%d %d",&s,&f);
    int l=f-s;
    ll sum=0;
    ll maxsum=0;
    for(int i=1;i<=l;i++)
        sum+=x[i];
    maxsum=sum;
    int maxans=l;
    ll ysj=n;
    for(int i=l+1;i<=n;i++)
    {
        sum+=x[i];
        sum-=x[i-l];
        if(sum>maxsum)
        {
            ll tmp=f-i;
            if(tmp<=0) tmp+=n;
                maxsum=sum;
                ysj=tmp;
        }
        else if(sum==maxsum)
        {
            ll tmp=f-i;
            if(tmp<=0) tmp+=n;
             if(tmp<ysj)   ysj=tmp;
        }
    }
    printf("%lld",ysj);
    return 0;
}


#include<cstdio>
#include<algorithm>
typedef long long LL;
const int N=100005;
int n;
int a[N];
int S,F;
int main()
{
	scanf("%d",&n);
	for (int u=1;u<=n;u++)	scanf("%d",&a[u]);
	for (int u=1;u<=n;u++) a[u+n]=a[u];
	n*=2;
	scanf("%d%d",&S,&F);
	int now=0;
	int ans=0,ans1;
	int L=1,R=0;//哪些地方可以比赛
	for (int u=1;u<=n;u++)//在这个时间
	{
		int last=R;
		while (true)
		{
			int rr=R+1;
			int tt=(rr+u-1)%n;
			if (tt==0) tt=n;
			if (tt<F&&tt>=S)
			{
				now+=a[rr];
				R=rr;
				if (R==last+n) break;
			}
			else break;
		}
		while (L!=R)
		{
			int ll=L+1;
			int tt=(ll+u-1)%n;
			if (tt==0) tt=n;
			if (tt>=F||tt<S)
			{
				now-=a[ll];
				L=ll;
			}
			else break;
		}
		now=0;
		for (int i=1;i<=n;i++)
		{
			int tt=(i+u-1)%n;
			if (tt==0) tt=n;
			if (tt<F&&tt>=S) now+=a[i];
		}
		if (now>ans)
		{
			ans=now;
			ans1=u;
		}
	}
	printf("%d\n",ans1);
	return 0;
}


#include<cstdio>
#include<algorithm>
typedef long long LL;
const int N=100005;
int n;
int a[N];
int S,F;
int main()
{
	scanf("%d",&n);
	for (int u=1;u<=n;u++)	scanf("%d",&a[u]);
	for (int u=1;u<=n;u++) a[u]+=a[u-1];
	scanf("%d%d",&S,&F);
	int now=0;
	int ans=0,ans1;
	int L=1,R=0;//哪些地方可以比赛
	for (int u=1;u<=n;u++)//在这个时间
	{
		int last=R;
		while (true)
		{
			int rr=R+1;
			int tt=(rr+u-1)%n;
			if (tt==0) tt=n;
			if (tt<F&&tt>=S)
			{
				now+=a[rr];
				R=rr;
				if (R==last)
				{
					printf("%d\n",u);
					return 0;
				}
			}
			else break;
		}
		while (L!=R)
		{
			int ll=L+1;
			int tt=(ll+u-1)%n;
			if (tt==0) tt=n;
			if (tt>=F||tt<S)
			{
				now-=a[ll];
				L=ll;
			}
			else break;
		}
		now=0;
		for (int i=1;i<=n;i++)
		{
			int tt=(i+u-1)%n;
			if (tt==0) tt=n;
			if (tt<F&&tt>=S) now+=a[i];
		}
		if (now>ans)
		{
			ans=now;
			ans1=u;
		}
	}
	printf("%d\n",ans1);
	return 0;
}


#include<cstdio>
#include<algorithm>
typedef long long LL;
const int N=100005;
int n;
int a[N];
int S,F;
int main()
{
	scanf("%d",&n);
	for (int u=1;u<=n;u++)	scanf("%d",&a[u]);
	scanf("%d%d",&S,&F);
	int now=0;
	for (int u=S;u<F;u++) now=now+a[u];
	int l=S,r=F-1;
	int ans=now,ans1=1;
	for (int u=2;u<=n;u++)
	{
		now=now-a[r];
		r--;r=r+n;r%=n;if (r==0) r=n;
		l--;l=l+n;l%=n;if (l==0) l=n;
		now=now+a[l];
		if (now>ans)
		{
			ans=now;
			ans1=u;
		}
	}
	printf("%d\n",ans1);
	return 0;
}


#include<cstdio>
#include<algorithm>
typedef long long LL;
const int N=100005;
int n;
int a[N];
int S,F;
int main()
{
	scanf("%d",&n);
	for (int u=1;u<=n;u++)	scanf("%d",&a[u]);
	scanf("%d%d",&S,&F);
	int ans=0,ans1;
	int now=0;
	for (int u=S;u<F;u++) now=now+a[u];
	int l=S,r=F-1;
	for (int u=2;u<=n;u++)
	{
		now=now-a[r];
		r--;r=r+n;r%=n;if (r==0) r=n;
		l--;l=l+n;l%=n;if (l==0) l=n;
		now=now+a[l];
	/*	printf("%d %d\n",l,r);
		printf("YES:%d %d\n",u,now);*/
		if (now>ans)
		{
			ans=now;
			ans1=u;
		}
	}
	printf("%d\n",ans1);
	return 0;
}


#include<cstdio>
#include<algorithm>
typedef long long LL;
const int N=100005;
int n;
int a[N];
int S,F;
int main()
{
	scanf("%d",&n);
	for (int u=1;u<=n;u++)	scanf("%d",&a[u]);
	scanf("%d%d",&S,&F);
	int now=0;
	int ans=0,ans1;
	int L=1,R=0;//哪些地方可以比赛
	for (int u=1;u<=n;u++)//在这个时间
	{
		while (true)
		{
			int rr=R+1;
			int tt=(rr+u-1)%n;
			if (tt==0) tt=n;
				if (tt<F&&tt>=S)
				{
					now+=a[rr];
					R=rr;
				}
			else break;
		}
		while (true)
		{
			int ll=L+1;
			int tt=(ll+u-1)%n;
			if (tt==0) tt=n;
			if (tt>=F||tt<S)
			{
					now-=a[ll];
					L=ll;
				}
			else break;
		}
		now=0;
		for (int i=1;i<=n;i++)
		{
			int tt=(i+u-1)%n;
			if (tt==0) tt=n;
			//printf("%d %d %d\n",u,i,tt);
			if (tt<F&&tt>=S) now+=a[i];
		}
	//	printf("%d %d\n",u,now);
		if (now>ans)
		{
			ans=now;
			ans1=u;
		}
	}
	printf("%d\n",ans1);
	return 0;
}


//In the name of Allah

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

#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define TL ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int MX=1e5+100,INF=1e18,INF2=-1e18,D=1e9+7;
int n , arr[MX] ,s , f ,dif ,con,big,sum;
int32_t main(){
    TL
    cin>>n;
    for(int i=0 ; i<n  ; i++){
        cin>>arr[i];
    }
    cin>>s>>f;
    dif=f-s;
    for(int i=0 ; i<dif ; i++){
        sum+= arr[i];
    }
    con=(s-1+dif-1)%n;
    big=sum;
    for(int i=1 ; i<n ;i++){
        sum+=(arr[(i+dif-1)%n]-arr[i-1]);
        if(sum>big){
            big=sum;
            con=(i+s-1+dif-1)%n;
        }
        if(sum==big && (con+dif+s-2)%n>(i+dif+s-2)%n){
            big=sum;
            con=i;
        }
    }
    cout<<(con+dif+s-2)%n+1<<endl;
    return 0;
}


//In the name of Allah

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

#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define TL ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int MX=1e5+100,INF=1e18,INF2=-1e18,D=1e9+7;
int n , arr[MX] ,s , f ,dif ,con,big,sum;
int32_t main(){
    TL
    cin>>n;
    for(int i=0 ; i<n  ; i++){
        cin>>arr[i];
    }
    cin>>s>>f;
    dif=f-s;
    for(int i=0 ; i<dif ; i++){
        sum+= arr[i];
        con=0;
        big=sum;
    }
    for(int i=1 ; i<n ;i ++){
        sum+=(arr[(i+dif-1)%n]-arr[i-1]);
        if(sum>big){
            big=sum;
            con=i;
        }
    }
    cout<<con+dif<<endl;
    return 0;
}


//In the name of Allah

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

#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define TL ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int MX=1e5+100,INF=1e18,INF2=-1e18,D=1e9+7;
int n , arr[MX] ,s , f ,dif ,con,big,sum;
int32_t main(){
    TL
    cin>>n;
    for(int i=0 ; i<n  ; i++){
        cin>>arr[i];
    }
    cin>>s>>f;
    dif=f-s;
    if(dif==n){
        cout<<1<<endl;
        return 0;
    }
    for(int i=0 ; i<dif ; i++){
        sum+= arr[i];
    }
    con=0;
    big=sum;
    for(int i=1 ; i<n ;i ++){
        sum+=(arr[(i+dif-1)%n]-arr[i-1]);
        if(sum>big){
            big=sum;
            con=i;
        }
        if(sum==big && (con+dif+s-2)%n>(i+dif+s-2)%n){
            big=sum;
            con=i;
        }
    }
    cout<<(con+dif+s-2)%n+1<<endl;
    return 0;
}


//In the name of Allah

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

#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define TL ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int MX=1e5+100,INF=1e18,INF2=-1e18,D=1e9+7;
int n , arr[MX] ,s , f ,dif ,con,big,sum;
int32_t main(){
    TL
    cin>>n;
    for(int i=0 ; i<n  ; i++){
        cin>>arr[i];
    }
    cin>>s>>f;
    dif=f-s;
    for(int i=0 ; i<dif ; i++){
        sum+= arr[i];
        con=0;
        big=sum;
    }
    for(int i=1 ; i<n ;i ++){
        sum+=(arr[i+dif-1%n]-arr[i-1]);
        if(sum>big){
            big=sum;
            con=i;
        }
    }
    cout<<con+dif<<endl;
    return 0;
}


//In the name of Allah

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

#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define TL ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int MX=1e5+100,INF=1e18,INF2=-1e18,D=1e9+7;
int n , arr[MX] ,s , f ,dif ,con,big,sum;
int32_t main(){
    TL
    cin>>n;
    for(int i=0 ; i<n  ; i++){
        cin>>arr[i];
    }
    cin>>s>>f;
    dif=f-s;
    for(int i=0 ; i<dif ; i++){
        sum+= arr[i];
    }
    con=(s-1+dif-1)%n;
    big=sum;
    for(int i=1 ; i<n ;i++){
        sum+=(arr[(i+dif-1)%n]-arr[i-1]);
        if(sum>big){
            big=sum;
            con=(i+s-1+dif-1)%n;
        }
        else if(sum==big && (con+dif+s-2)%n>(i+dif+s-2)%n){
            big=sum;
            con=(i+s-1+dif-1)%n;
        }
    }
    con++;
    cout<<con<<endl;
    return 0;
}


//In the name of Allah

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

#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define TL ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int MX=1e5+100,INF=1e18,INF2=-1e18,D=1e9+7;
int n , arr[MX] ,s , f ,dif ,con,big,sum;
int32_t main(){
    TL
    cin>>n;
    for(int i=0 ; i<n  ; i++){
        cin>>arr[i];
    }
    cin>>s>>f;
    dif=f-s;
    for(int i=0 ; i<dif ; i++){
        sum+= arr[i];
    }
    con=0;
    big=sum;
    for(int i=1 ; i<n ;i++){
        sum+=(arr[(i+dif-1)%n]-arr[i-1]);
        if(sum>big){
            big=sum;
            con=i;
        }
    }
    if(s-con==0){
        cout<<n<<endl;
        return 0;
    }
    cout<<(s-con+n-1)%n+1<<endl;
    return 0;
}


//In the name of Allah

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

#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define TL ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int MX=1e5+100,INF=1e18,INF2=-1e18,D=1e9+7;
int n , arr[MX] ,s , f ,dif ,con,big,sum;
int32_t main(){
    TL
    cin>>n;
    for(int i=0 ; i<n  ; i++){
        cin>>arr[i];
    }
    cin>>s>>f;
    dif=f-s;
    for(int i=0 ; i<dif ; i++){
        sum+= arr[i];
        con=0;
        big=sum;
    }
    for(int i=1 ; i<n ;i ++){
        sum+=(arr[i+dif-1]-arr[i-1]);
        if(sum>big){
            big=sum;
            con=i;
        }
    }
    cout<<con+dif<<endl;
    return 0;
}


//In the name of Allah

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

#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define TL ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int MX=1e5+100,INF=1e18,INF2=-1e18,D=1e9+7;
int n , arr[MX] ,s , f ,dif ,con,big,sum;
int32_t main(){
    TL
    cin>>n;
    for(int i=0 ; i<n  ; i++){
        cin>>arr[i];
    }
    cin>>s>>f;
    dif=f-s;
    if(dif==n){
        cout<<1<<endl;
        return 0;
    }
    for(int i=0 ; i<dif ; i++){
        sum+= arr[i];
    }
    con=0;
    big=sum;
    for(int i=1 ; i<n ;i ++){
        sum+=(arr[(i+dif-1)%n]-arr[i-1]);
        if(sum>big){
            big=sum;
            con=i;
        }
        if(sum==big && (con+dif-1)%n>(i+dif-1)%n){
            big=sum;
            con=i;
        }
    }
    cout<<(con+dif-1)%n+s<<endl;
    return 0;
}


//In the name of Allah

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

#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define TL ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int MX=1e5+100,INF=1e18,INF2=-1e18,D=1e9+7;
int n , arr[MX] ,s , f ,dif ,con,big,sum;
int32_t main(){
    TL
    cin>>n;
    for(int i=0 ; i<n  ; i++){
        cin>>arr[i];
    }
    cin>>s>>f;
    dif=f-s;
    for(int i=0 ; i<dif ; i++){
        sum+= arr[i];
    }
    con=0;
    big=sum;
    for(int i=1 ; i<n ;i++){
        sum+=(arr[(i+dif-1)%n]-arr[i-1]);
        if(sum>big){
            big=sum;
            con=i;
        }
        else if(sum==big && (con+dif+s-2)%n>(i+dif+s-2)%n){
            big=sum;
            con=i;
        }
    }
    cout<<(con+s-1+dif-1)%n+1<<endl;
    return 0;
}


//In the name of Allah

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

#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define TL ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int MX=1e5+100,INF=1e18,INF2=-1e18,D=1e9+7;
int n , arr[MX] ,s , f ,dif ,con,big,sum;
int32_t main(){
    TL
    cin>>n;
    for(int i=0 ; i<n  ; i++){
        cin>>arr[i];
    }
    cin>>s>>f;
    dif=f-s;
    if(dif==n){
        cout<<1<<endl;
        return 0;
    }
    for(int i=0 ; i<dif ; i++){
        sum+= arr[i];
    }
    con=0;
    big=sum;
    for(int i=1 ; i<n ;i ++){
        sum+=(arr[(i+dif-1)%n]-arr[i-1]);
        if(sum>big){
            big=sum;
            con=i;
        }
        if(sum==big && (con+dif-1)%n>(i+dif-1)%n){
            big=sum;
            con=i;
        }
    }
    cout<<(con+dif-1)%n+1<<endl;
    return 0;
}


//In the name of Allah

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

#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define TL ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int MX=1e5+100,INF=1e18,INF2=-1e18,D=1e9+7;
int n , arr[MX] ,s , f ,dif ,con,big,sum;
int32_t main(){
    TL
    cin>>n;
    for(int i=0 ; i<n  ; i++){
        cin>>arr[i];
    }
    cin>>s>>f;
    dif=f-s;
    for(int i=0 ; i<dif ; i++){
        sum+= arr[i];
    }
    con=0;
    big=sum;
    for(int i=1 ; i<n ;i++){
        sum+=(arr[(i+dif-1)%n]-arr[i-1]);
        if(sum>big){
            big=sum;
            con=i;
        }
        if(sum==big){
            if((s-con+n-1)%n>(s-i+n-1)%n){
                sum=big;
                con=i;
            }
        }
    }
    if(s-con==0){
        cout<<n<<endl;
        return 0;
    }
    cout<<(s-con+n-1)%n+1<<endl;
    return 0;
}


//In the name of Allah

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

#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define TL ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int MX=1e5+100,INF=1e18,INF2=-1e18,D=1e9+7;
int n , arr[MX] ,s , f ,dif ,con,big,sum;
int32_t main(){
    TL
    cin>>n;
    for(int i=0 ; i<n  ; i++){
        cin>>arr[i];
    }
    cin>>s>>f;
    dif=f-s;
    if(dif==n){
        cout<<1<<endl;
        return 0;
    }
    for(int i=0 ; i<dif ; i++){
        sum+= arr[i];
    }
    con=0;
    big=sum;
    for(int i=1 ; i<n ;i ++){
        sum+=(arr[(i+dif-1)%n]-arr[i-1]);
        if(sum>big){
            big=sum;
            con=i;
        }
    }
    cout<<con+dif<<endl;
    return 0;
}


//In the name of Allah

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

#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define TL ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int MX=1e5+100,INF=1e18,INF2=-1e18,D=1e9+7;
int n , arr[MX] ,s , f ,dif ,con,big,sum;
int32_t main(){
    TL
    cin>>n;
    for(int i=0 ; i<n  ; i++){
        cin>>arr[i];
    }
    cin>>s>>f;
    dif=f-s;
    for(int i=0 ; i<dif ; i++){
        sum+= arr[i];
    }
    con=(s-1+dif-1)%n;
    big=sum;
    for(int i=1 ; i<n ;i++){
        sum+=(arr[(i+dif-1)%n]-arr[i-1]);
        if(sum>big){
            big=sum;
            con=(i+s-1+dif-1)%n;
        }
        else if(sum==big && (con+dif+s-2)%n>(i+dif+s-2)%n){
            big=sum;
            con=i;
        }
    }
    con++;
    cout<<con<<endl;
    return 0;
}


//In the name of Allah

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

#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define TL ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int MX=1e5+100,INF=1e18,INF2=-1e18,D=1e9+7;
int n , arr[MX] ,s , f ,dif ,con,big,sum;
int32_t main(){
    TL
    cin>>n;
    for(int i=0 ; i<n  ; i++){
        cin>>arr[i];
    }
    cin>>s>>f;
    dif=f-s;
    if(dif==n){
        cout<<1<<endl;
        return 0;
    }
    for(int i=0 ; i<dif ; i++){
        sum+= arr[i];
    }
    con=0;
    big=sum;
    for(int i=1 ; i<n ;i ++){
        sum+=(arr[(i+dif-1)%n]-arr[i-1]);
        if(sum>big){
            big=sum;
            con=i;
        }
        if(sum==big && (con+dif)%n>(i+dif)%n){
            big=sum;
            con=i;
        }
    }
    cout<<(con+dif-1)%n+1<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int a[200001];

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

	for (int i = n+1; i <= 2*n; i++)
		a[i] += a[i-1];

	int s, f;
	cin >> s >> f;

	int r = f - s;
	int mx = 0;
	int mxi = 0;
	for (int i = 1; i <= 2*n - r + 1; i++) {
		int v = a[i+r-1] - a[i-1];
		if (v > mx) {
			mx = v;
			mxi = i;
		}
	}

	int t = (s - mxi + 1 + 2*n) %n;
	if (t == 0)
		t = n;
	cout << t << endl;
	return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int a[200001];

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

	for (int i = n+1; i <= 2*n; i++)
		a[i] += a[i-1];

	int s, f;
	cin >> s >> f;

	int r = f - s;
	int mx = 0;
	int mxi = 0;
	int mnt = 999999999;
	for (int i = 2; i <= 2*n - r + 1; i++) {
		int v = a[i+r-1] - a[i-1];

		int t = (s - i + 1 + 2*n) %n;

		if (t == 0)
			t = n;

		if (v > mx) {
			mx = v;
			mxi = i;
			mnt = t;
		} else if (v == mx) {
			mnt = min(mnt, t);
		}

	}

	cout << mnt << endl;
	return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int a[200001];

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

	for (int i = n+1; i <= 2*n; i++)
		a[i] += a[i-1];

	int s, f;
	cin >> s >> f;

	int r = f - s;
	int mx = 0;
	int mxi = 0;
	for (int i = 2; i <= 2*n - r + 1; i++) {
		int v = a[i+r-1] - a[i-1];
		if (v > mx) {
			mx = v;
			mxi = i;
		}
	}

	int t = (s - mxi + 1 + 2*n) %n;
	if (t == 0)
		t = n;
	cout << t << endl;
	return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int a[200001];

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

	for (int i = n+1; i <= 2*n; i++)
		a[i] += a[i-1];

	int s, f;
	cin >> s >> f;

	int r = f - s;
	int mx = 0;
	int mxi = 0;
	int mnt = 999999999;
	for (int i = 2; i <= 2*n - r + 1; i++) {
		int v = a[i+r-1] - a[i-1];
		if (v > mx) {
			mx = v;
			mxi = i;
		}

		int t = (s - mxi + 1 + 2*n) %n;

		if (t == 0)
			t = n;
		mnt = min(mnt, t);
	}

	cout << mnt << endl;
	return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int a[100001];

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

	int s, f;
	cin >> s >> f;

	int mx = 0;
	int mxi = 0;
	for (int i = 1; i <= n - (f-s-1); i++) {
		int v = a[i+(f-s-1)] - a[i-1];
		if (v > mx) {
			mx = v;
			mxi = i;
		}
	}

	int t = (s-mxi+n) % n;
	t += 1;
	cout << t << endl;
	return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int a[200001];

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

	for (int i = n+1; i <= 2*n; i++)
		a[i] += a[i-1];

	int s, f;
	cin >> s >> f;

	int r = f - s;
	int mx = 0;
	int mxi = 0;
	int mnt = 0;
	for (int i = 2; i <= 2*n - r + 1; i++) {
		int v = a[i+r-1] - a[i-1];
		if (v > mx) {
			mx = v;
			mxi = i;
		}

		int t = (s - mxi + 1 + 2*n) %n;

		if (t == 0)
			t = n;
		mnt = min(mnt, t);
	}

	cout << mnt << endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,s,f;
int w[100007];
int a[100007];
int change(int x)
{
	while(x>n)
	{
		x-=n;
	}
	while(x<=0)
	{
		x+=n;
	}
	return x;
}
int main(){
	int big=0;
	int keep=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	scanf("%d%d",&s,&f);
	w[s]+=a[1];
	w[f]-=a[1];
	printf("%d %d\n",s,f);
	for(int i=2;i<=n;i++)
	{
		s++;
		f++;
		if(s>n)
		{
			s-=n;
		}
		if(f>n)
		{
			f-=n;
		}
		if(s<f)
		{
			w[s]+=a[i];
			w[f]-=a[i];
		}
		else
		{
			w[s]+=a[i];
			w[1]+=a[i];
			w[f]-=a[i];
		}
	}
	for(int i=1;i<=n;i++)
	{
		w[i]+=w[i-1];
		if(w[i]>big)
		{
			big=w[i];
			keep=i;
		}
	}
	printf("%d",keep);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,s,f;
int w[100007];
int a[100007];
int main(){
	int big=0;
	int keep=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	w[s]+=a[1];
	w[f]-=a[1];
	printf("%d %d\n",s,f);
	for(int i=2;i<=n;i++)
	{
		s++;
		f++;
		if(s>n)
		{
			s-=n;
		}
		if(f>n)
		{
			f-=n;
		}
		if(s<f)
		{
			w[s]+=a[i];
			w[f]-=a[i];
		}
		else
		{
			w[s]+=a[i];
			w[1]+=a[i];
			w[f]-=a[i];
		}
	}
	for(int i=1;i<=n;i++)
	{
		w[i]+=w[i-1];
		if(w[i]>big)
		{
			big=w[i];
			keep=i;
		}
	}
	printf("%d",keep);
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int n,s,f,cnt,ans;
int w[100007];
int a[10007];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	scanf("%d%d",&s,&f);
	for(int i=1;i<=n;i++)
	{
		int x=s-i+1;
		int y=f-i+1;
		if(x<=0&&y>0)
		{
			w[x+n]+=a[i];
			w[1]+=a[i];
			w[y]-=a[i];
		}
		else if(x<1&&y<1)
		{
			w[x+n]+=a[i];
			w[y+n]-=a[i];
		}
		else
		{
			w[x]+=a[i];
			w[y]-=a[i];
		}
	}
	for(int i=1;i<=n;i++)
	{
		w[i]+=w[i-1];
		if(w[i]>ans)
		{
			ans=w[i];
			cnt=i;
		}
	}
	printf("%d",cnt);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,s,f;
int w[100007];
int a[100007];
int main(){
	int big=0;
	int keep=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	scanf("%d%d",&s,&f);
	w[s]+=a[1];
	w[f]-=a[1];
	for(int i=2;i<=n;i++)
	{
		s++;
		f++;
		if(s>n)
		{
			s-=n;
		}
		if(f>n)
		{
			f-=n;
		}
		if(s<f)
		{
			w[s]+=a[i];
			w[f]-=a[i];
		}
		else
		{
			w[s]+=a[i];
			w[1]+=a[i];
			w[f]-=a[i];
		}
	}
	for(int i=1;i<=n;i++)
	{
		w[i]+=w[i-1];
		if(w[i]>big)
		{
			big=w[i];
			keep=i;
		}
	}
	printf("%d",keep);
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int n,s,f,cnt,ans;
int w[100007];
int a[10007];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	scanf("%d%d",&s,&f);
	for(int i=1;i<=n;i++)
	{
		int x=s-i+1;
		int y=f-i+1;
		if(x<=0&&y>0)
		{
			w[x+n]+=a[i];
			w[1]+=a[i];
			w[y]-=a[i];
		}
		else if(x<1&&y<1)
		{
			w[x+n]+=a[i];
			w[y+n]-=a[i];
		}
		else
		{
			w[x]+=a[i];
			w[y]-=a[i];
		}
	}
	cnt=1;
	for(int i=1;i<=n;i++)
	{
		w[i]+=w[i-1];
		if(w[i]>ans)
		{
			ans=w[i];
			cnt=i;
		}
	}
	printf("%d",cnt);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,s,f;
int w[100007];
int a[100007];
int main(){
	int big=0;
	int keep=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	scanf("%d%d",&s,&f);
	w[s]+=a[1];
	w[f]-=a[1];
	printf("%d %d\n",s,f);
	for(int i=2;i<=n;i++)
	{
		s++;
		f++;
		if(s>n)
		{
			s-=n;
		}
		if(f>n)
		{
			f-=n;
		}
		if(s<f)
		{
			w[s]+=a[i];
			w[f]-=a[i];
		}
		else
		{
			w[s]+=a[i];
			w[1]+=a[i];
			w[f]-=a[i];
		}
	}
	for(int i=1;i<=n;i++)
	{
		w[i]+=w[i-1];
		if(w[i]>big)
		{
			big=w[i];
			keep=i;
		}
	}
	printf("%d",keep);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,s,f;
int w[100007];
int a[100007];
int main(){
	int big=0;
	int keep=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	scanf("%d%d",&s,&f);
	w[s]+=a[1];
	w[f]-=a[1];
	for(int i=2;i<=n;i++)
	{
		s--;
		f--;
		if(s<=0)
		{
			s+=n;
		}
		if(f<=0)
		{
			f+=n;
		}
		if(s<f)
		{
			w[s]+=a[i];
			w[f]-=a[i];
		}
		else
		{
			w[s]+=a[i];
			w[1]+=a[i];
			w[f]-=a[i];
		}
	}
	for(int i=1;i<=n;i++)
	{
		w[i]+=w[i-1];
		if(w[i]>big)
		{
			big=w[i];
			keep=i;
		}
	}
	printf("%d",keep);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
int a[3*maxn];
int main()
{
    int n;
    while(cin>>n)
    {
       for(int i=0;i<n;i++)
        {
            scanf("%d",a+i);
            a[i+n]=a[i];
        }

       int s,f;
       scanf("%d%d",&s,&f);

       int nd=f-s;
       int now=0;

       for(int i=0;i<nd;i++)
       {
           now+=a[i];
       }

       int da=nd-1;
       int res=now;
       for(int i=1;i<n;i++)
       {
           res=res-a[i]+a[(i+nd-1)%n];
           if(res>=now)
           {
               int tt=(i+nd-1)%n;
                 tt++;
               if(res==now)
               {
                   da=min(da,tt);
                   now=res;
                  continue;
               }

               da=tt;
               now=res;
           }
           //cout<<da<<endl;
       }

       cout<<da<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
int a[3*maxn];
int main()
{
    int n;
    while(cin>>n)
    {
       for(int i=0;i<n;i++)
        {
            scanf("%d",a+i);
            a[i+n]=a[i];
        }

       int s,f;
       scanf("%d%d",&s,&f);

       int nd=f-s;
       int now=0;
       for(int i=0;i<nd;i++)
       {
           now+=a[i];
       }

       int da=nd-1;
       for(int i=nd;i<2*n;i++)
       {
           int res;
           res=now+a[i]-a[i-nd];
           if(res>now)
           {
               da=i;
               now=res;
           }
           //cout<<da<<endl;
       }

       da++;
       da%=n;

       if(da==0)
        da=n;
       cout<<da<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
int a[3*maxn];
int main()
{
    int n;
    while(cin>>n)
    {
       for(int i=0;i<n;i++)
        {
            scanf("%d",a+i);
            a[i+n]=a[i];
        }

       int s,f;
       scanf("%d%d",&s,&f);

       int nd=f-s;
       int now=0;

       for(int i=0;i<nd;i++)
       {
           now+=a[i];
       }

       int da=nd-1;
       int res=now;
       for(int i=1;i<n;i++)
       {
           res=res-a[i]+a[(i+nd-1)%n];
           if(res>=now)
           {
               int tt=(i+nd-1)%n;
                 tt++;
               if(res==now)
               {
                   da=min(da,tt);
                   continue;
               }
               da=tt;
               now=res;
           }
           //cout<<da<<endl;
       }

       cout<<da<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
int a[3*maxn];
int main()
{
    int n;
    while(cin>>n)
    {
       for(int i=0;i<n;i++)
        {
            scanf("%d",a+i);
        }

       int s,f;
       scanf("%d%d",&s,&f);
       int nd=f-s;
       int now=0;
       for(int i=0;i<nd;i++)
       {
           now+=a[i];
       }

       int da=s;
       int res=now;
       for(int i=0;i<n;i++)
       {
           res=res-a[i]+a[(i+nd)%n];
           if(res>=now)
           {
               int tt=(s-i+n-1)%n;
                 if(tt==0)
                    tt=n;
               if(res==now)
               {
                   da=min(da,tt);
                   now=res;
                  continue;
               }

               da=tt;
               now=res;
           }
           //cout<<da<<endl;
       }

       cout<<da<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
int a[3*maxn];
int main()
{
    int n;
    while(cin>>n)
    {
       for(int i=0;i<n;i++)
        {
            scanf("%d",a+i);
            a[i+n]=a[i];
        }

       int s,f;
       scanf("%d%d",&s,&f);

       int nd=f-s;
       int now=0;

       for(int i=0;i<nd;i++)
       {
           now+=a[i];
       }

       int da=nd;
       int res=now;
       for(int i=0;i<n;i++)
       {
           res=res-a[i]+a[(i+nd)%n];
           if(res>=now)
           {
               int tt=(i+nd)%n;
                 tt++;
               if(res==now)
               {
                   da=min(da,tt);
                   now=res;
                  continue;
               }
               da=tt;
               now=res;
           }
           //cout<<da<<endl;
       }

       cout<<da<<endl;
    }

}


#include <cstdio>

inline int readin(){
	int x=0;char c;
	for(;(c=getchar())<'0'||c>'9';);
	for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-48,c=getchar());
	return x;
}

int a[200005];

int main(){
	int n=readin();
	for (int i=1;i<=n;i++) a[i]=a[i+n]=readin();
	int f=readin(),s=readin();
	int t=s-f,sum=0,l=1;
	for (int i=1;i<=t;i++) sum+=a[i];
	for (int i=1,j=t+1;i<n;i++,j++){
		int tmp=sum-a[i]+a[j];
		if (tmp>=sum) l=i+1;
		sum=tmp;
	}
	int ans=f-l<0?f-l+n:f-l;
	ans=(ans)%n+1;
	printf("%d",ans);
}


#include <cstdio>

inline int readin(){
	int x=0;char c;
	for(;(c=getchar())<'0'||c>'9';);
	for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-48,c=getchar());
	return x;
}

int a[200005];

int main(){
	int n=readin();
	for (int i=1;i<=n;i++) a[i]=a[i+n]=readin();
	int f=readin(),s=readin();
	int t=s-f,sum=0,l=1;
	for (int i=1;i<=t;i++) sum+=a[i];
	for (int i=1,j=t+1;i<n;i++,j++){
		int tmp=sum-a[i]+a[j];
		if (tmp>sum) l=i+1;
		sum=tmp;
	}
	int ans=f-l<0?f-l+n:f-l;
	ans=(ans)%n+1;
	printf("%d",ans);
}


#include <cstdio>

inline int readin(){
	int x=0;char c;
	for(;(c=getchar())<'0'||c>'9';);
	for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-48,c=getchar());
	return x;
}

int a[200005];

int main(){
	int n=readin();
	for (int i=1;i<=n;i++) a[i]=a[i+n]=readin();
	int f=readin(),s=readin();
	int t=s-f,sum=0,l=1;
	for (int i=1;i<=t;i++) sum+=a[i];
	for (int i=1,j=t+1;i<=n;i++,j++){
		int tmp=sum-a[i]+a[j];
		if (tmp>=sum) l=i+1;
		sum=tmp;
	}
	int ans=f-l<0?f-l+n:f-l;
	ans=(ans)%n+1;
	printf("%d",ans);
}


#include <cstdio>

inline int readin(){
	int x=0;char c;
	for(;(c=getchar())<'0'||c>'9';);
	for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-48,c=getchar());
	return x;
}

int a[200005];

int main(){
	int n=readin();
	for (int i=1;i<=n;i++) a[i]=a[i+n]=readin();
	int f=readin(),s=readin();
	int t=s-f,sum=0,l=1,max;
	for (int i=1;i<=t;i++) sum+=a[i];
	max=sum;
	for (int i=1,j=t+1;i<=n;i++,j++){
		int tmp=sum-a[i]+a[j];
		if (tmp>=max) l=i+1,max=tmp;
		sum=tmp;
	}
	int ans=f-l<0?f-l+n:f-l;
	ans=(ans)%n+1;
	printf("%d",ans);
}


#include <cstdio>

inline int readin(){
	int x=0;char c;
	for(;(c=getchar())<'0'||c>'9';);
	for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-48,c=getchar());
	return x;
}

int a[200005];

int main(){
	int n=readin();
	for (int i=1;i<=n;i++) a[i]=a[i+n]=readin();
	int f=readin(),s=readin();
	int t=s-f,sum=0,l=1,max;
	for (int i=1;i<=t;i++) sum+=a[i];
	max=sum;
	for (int i=1,j=t+1;i<=n;i++,j++){
		int tmp=sum-a[i]+a[j];
		if (tmp>max) l=i+1,l=(f-l<0?f-l+n:f-l)+1,max=tmp;else
			if (tmp==max){
				int p=i+1;
				p=(f-p<0?f-p+n:f-p)+1;
				if (p<l) l=p;
			}
		sum=tmp;
	}
	printf("%d",l);
}


#include <cstdio>
using namespace std;
const int N = 1e5+5;
int a[N],n;
int s,f;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    scanf("%d%d",&s,&f);
    int Max=0,ansId=f,sum,LastId;
    int len = f-s;
    for(int i=0;i<len;i++){
        int nId = (f-1-i+n)%n;
        Max += a[nId];
        LastId = nId;
    }
    sum = Max;
    for(int i=1;i<n;i++){
        int nId = ((f-1+i)%n+n)%n;
        sum += a[nId];
        sum -= a[LastId];
        LastId = (LastId+1) % n;
        if(sum > Max){
            Max = sum;
            ansId = nId+1;
        }
//        printf("%d --- %d\n",i,sum);
    }
    printf("%d\n",ansId);
    return 0;
}


#include <cstdio>
using namespace std;
const int N = 1e5+5;
int a[N];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int s,f;
    scanf("%d%d",&s,&f);
    int len = f-s;
    int nowLen = 0;
    int sum = 0;
    int ansTime = s;
    for(int i=0;i<len;i++){
        sum += a[i];
    }
//    printf("sum = %d\n",sum);
    for(int i=1;i<n;i++){
        int NewSum = sum-a[i-1]+a[(i+len-1)%n];
        --s;
        if(s == 0) s = n;
//        printf("nSum = %d,s = %d\n",NewSum,s);
        if(NewSum > sum){
            sum = NewSum;
            ansTime = s;
        }else if(NewSum == sum){
            if(s < ansTime){
                ansTime = s;
            }
        }
    }
    printf("%d\n",ansTime);
    return 0;
}


#include <cstdio>
using namespace std;
const int N = 1e5+5;
int a[N],n;
int s,f;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    scanf("%d%d",&s,&f);
    int Max=0,ansId=0+1,sum,LastId;
    int len = f-s;
    for(int i=0;i<len;i++){
        int nId = (0-i+n)%n;
        Max += a[nId];
        LastId = nId;
    }
    sum = Max;
    for(int i=1;i<n;i++){
        sum += a[i];
        LastId = (LastId+1) % n;
        sum -= a[LastId];
        if(sum > Max){
            Max = sum;
            ansId = i+1;
        }
    }
    printf("%d\n",ansId);
    return 0;
}


#include <cstdio>
using namespace std;
const int N = 1e5+5;
int a[N],n;
int s,f;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    scanf("%d%d",&s,&f);
    int Max=0,ansId=0+1,sum,LastId;
    int len = f-s;
    for(int i=0;i<len;i++){
        int nId = (0-i+n)%n;
        Max += a[nId];
        LastId = nId;
    }
    sum = Max;
    for(int i=1;i<n;i++){
        sum += a[i];
        sum -= a[LastId];
        LastId = (LastId+1) % n;
        if(sum > Max){
            Max = sum;
            ansId = i+1;
        }
    }
    printf("%d\n",ansId);
    return 0;
}


#include <cstdio>
using namespace std;
const int N = 1e5+5;
int a[N];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int s,f;
    scanf("%d%d",&s,&f);
    int len = f-s;
    int sum = 0;
    int ansTime = s;
    for(int i=0;i<len;i++){
        sum += a[i];
    }
    int Max = sum;
//    printf("sum = %d\n",sum);
    for(int i=1;i<n;i++){
        sum = sum-a[i-1]+a[(i+len-1)%n];
        --s;
        if(s == 0) s = n;
//        if(s == 8) {
//            printf("sum = %d,i = %d l = %d r = %d\n",sum,i,i-1,(i+len-1)%n);
//        }
//        printf("nSum = %d,s = %d\n",NewSum,s);
        if(sum > Max){
            Max = sum;
            ansTime = s;
        }else if(Max == sum){
            if(s < ansTime){
                ansTime = s;
            }
        }
    }
//    printf("%d\n",sum);
    printf("%d\n",ansTime);
    return 0;
}


#include <cstdio>
using namespace std;
const int N = 1e5+5;
int a[N],n;
int s,f;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    scanf("%d%d",&s,&f);
    s--;
    f--;
    int Max=0,ansId,sum,LastId;
    int len = f-s;
    for(int i=0;i<len;i++){
        int nId = ((0-i)%n+n)%n;
        Max += a[nId];
        LastId = nId;
    }
    ansId = s;
    sum = Max;
    for(int i=1;i<n;i++){
        int nId = ((0+i)%n+n)%n;
        sum += a[nId];
        sum -= a[LastId];
        LastId = (LastId+1) % n;
        if(sum > Max){
            Max = sum;
            ansId = ((s-i+1)%n+n)%n;
        }
//        printf("%d --- %d\n",i,sum);
    }
    printf("%d\n",ansId+1);

    return 0;
}

/**
10
7171 2280 6982 9126 9490 2598 569 6744 5754 1855
7 9
*/


#include <cstdio>
using namespace std;
const int N = 1e5+5;
int a[N],n;
int s,f;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    scanf("%d%d",&s,&f);
    s--;
    f--;
    int Max=0,ansId,sum,LastId;
    int len = f-s;
    for(int i=0;i<len;i++){
        int nId = ((0-i)%n+n)%n;
        Max += a[nId];
        LastId = nId;
    }
    ansId = s;
    sum = Max;
    for(int i=1;i<n;i++){
        int nId = ((0+i)%n+n)%n;
        sum += a[nId];
        sum -= a[LastId];
        LastId = (LastId+1) % n;
        if(sum > Max){
            Max = sum;
            ansId = ((s-i+1)%n+n)%n;
        }
//        printf("%d --- %d\n",i,sum);
    }
    if(ansId == 0) ansId = n;
    else ansId = ansId + 1;
    printf("%d\n",ansId);

    return 0;
}

/**
10
7171 2280 6982 9126 9490 2598 569 6744 5754 1855
7 9
*/


#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
#define INF (0x3f3f3f3f)
using namespace std;
const int maxn = 1e5+10;
int n,a[maxn],s,f;
int main() {
  cin>>n;
  for(int i=1;i<=n;++i) cin>>a[i];
  cin>>s>>f;
  int len=f-s;
  int sum=0,pos=s+len-1;
  for(int j=s+len-1;j>=s;--j) {
    sum+=a[j];
  }
  int ma=sum;
  for(int j=s+len-2;j>=s;--j) {
    sum=sum- a[j+1]+a[(j-len)%n+1+n];
    if(sum>=ma) {ma=sum, pos=j;}
  }
  for(int i=len+1;i<=n;++i) {
    sum = sum-a[i-len]+a[i];
    if(sum>ma) {ma=sum, pos=i;}
  }
  cout<<pos<<endl;
  return 0;
}


#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
#define INF (0x3f3f3f3f)
using namespace std;
const int maxn = 1e5+10;
int n,a[maxn],s,f;
int main() {
  cin>>n;
  for(int i=1;i<=n;++i) cin>>a[i];
  cin>>s>>f;
  int len=f-s;
  int s=0,pos=len;
  for(int j=len;j>=1;--j) {
    s+=a[j];
  }
  int ma=s;
  for(int j=len-1;j>=1;--j) {
    s=s- a[j+1]+a[(j-len)%n+1+n];
    if(s>=ma) {ma=s, pos=j;}
  }
  for(int i=len+1;i<=n;++i) {
    s = s-a[i-len]+a[i];
    if(s>ma) {ma=s, pos=i;}
  }
  cout<<pos<<endl;
  return 0;
}


#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
#define INF (0x3f3f3f3f)
using namespace std;
const int maxn = 1e5+10;
int n,a[maxn],s,f;
int main() {
  cin>>n;
  for(int i=1;i<=n;++i) cin>>a[i];
  cin>>s>>f;
  int len=f-s;
  int sum=0,pos=s+len-1;
  for(int j=s+len-1;j>=1;--j) {
    sum+=a[j];
  }
  int ma=sum;
  for(int j=s+len-2;j>=s;--j) {
    sum=sum- a[j+1]+a[(j-len)%n+1+n];
    if(sum>=ma) {ma=sum, pos=j;}
  }
  for(int i=len+1;i<=n;++i) {
    sum = sum-a[i-len]+a[i];
    if(sum>ma) {ma=sum, pos=i;}
  }
  cout<<pos<<endl;
  return 0;
}


#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
#define INF (0x3f3f3f3f)
using namespace std;
const int maxn = 1e5+10;
int n,a[maxn],s,f;
int main() {
  cin>>n;
  for(int i=1;i<=n;++i) cin>>a[i];
  cin>>s>>f;
  int ans=1,ps=s,pf=f-1,sum=0;
  for(int k=ps;k<=pf;k++) sum+=a[k];
  int mx=sum;
  for(int i=2;i<=n;++i) {
    sum-=a[pf];
    ps=(ps-2+n)%n+1,pf=(pf-2+n)%n+1;
    sum+=a[ps];
    if(sum>mx) mx=sum,ans=i;
  }
  cout<<ans<<endl;
  return 0;
}


#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
#define INF (0x3f3f3f3f)
using namespace std;
const int maxn = 1e5+10;
int n,a[maxn],s,f;
int main() {
  cin>>n;
  for(int i=1;i<=n;++i) cin>>a[i];
  cin>>s>>f;
  int len=f-s,sum=0;
  for(int i=1;i<=len;++i) sum+=a[i];
  int ma=sum,pos=len;
  for(int i=2;i<=n;++i) {
    sum = sum - a[i-1] + a[ (i+len-1) % (n+1) ];
    //cout<<ma<<" "<<sum<< " "<<a[i-1]<<" "<<a[(i+len-1)%n]<<endl;
    if(pos>(i+len-1)%(n+1) ) { if(ma<=sum) {ma=sum; pos=(i+len-1)%(n+1) ;} }
    else { if(ma<sum) { ma = sum; pos = (i+len-1)%(n+1) ; } }
  }
  cout<<pos<<endl;
  return 0;
}


#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
#define INF (0x3f3f3f3f)
using namespace std;
const int maxn = 1e5+10;
int n,a[maxn],s,f;
int main() {
  cin>>n;
  for(int i=1;i<=n;++i) cin>>a[i];
  cin>>s>>f;
  int len=f-s;
  int s=0,pos=len;
  for(int j=len;j>=1;--j) {
    s+=a[j];
  }
  int ma=s;
  for(int i=len+1;i<=n;++i) {
    s = s-a[i-len]+a[i];
    if(s>ma) {ma=s, pos=i;}
  }
  cout<<pos<<endl;
  return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int n,a[200005],s,f,len;
int sum,maxx,st;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=n+1;i<=n*2;i++)a[i]=a[i-n];
	scanf("%d%d",&s,&f);
	len=f-s;
	st=n;
	for(int i=1;i<=len;i++)sum+=a[i];
	for(int i=1;i<=n;i++)
	{
		if(maxx<sum){maxx=sum;st=i+len-1;}
		if(maxx==sum){st=min(st,i+len-1);}
		//printf("%d %d ",i,sum);
		sum-=a[i];
		sum+=a[i+len];
		//printf("%d %d\n",a[i],a[i+len]);
	}
	printf("%d",st);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int n,a[200005],s,f,len;
int sum,maxx,st;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=n+1;i<=n*2;i++)a[i]=a[i-n];
	scanf("%d%d",&s,&f);

	len=f-s;
	st=n;
	for(int i=1;i<=len;i++)sum+=a[i];
	for(int i=1;i<=n;i++)
	{
		if(maxx==sum){st=min(st,(s-i+n)%n+1);}
		if(maxx<sum){maxx=sum;st=(s-i+n)%n+1;}
		sum-=a[i];
		sum+=a[i+len];
	}
	printf("%d",st);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int n,a[200005],s,f,len;
int sum,maxx,st;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=n+1;i<=n*2;i++)a[i]=a[i-n];
	scanf("%d%d",&s,&f);
	len=f-s;
	st=n;
	for(int i=1;i<=len;i++)sum+=a[i];
	for(int i=1;i<=n;i++)
	{
		if(maxx==sum){st=max(st,i+len-1);}
		if(maxx<sum){maxx=sum;st=i+len-1;}
		sum-=a[i];
		sum+=a[i+len];
	}
	printf("%d",st);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int n,a[200005],s,f,len;
int sum,maxx,st;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=n+1;i<=n*2;i++)a[i]=a[i-n];
	scanf("%d%d",&s,&f);
	len=f-s;
	st=n;
	for(int i=1;i<=len;i++)sum+=a[i];
	for(int i=1;i<=n;i++)
	{
		if(maxx==sum){st=min(st,(s-i+n)%n+1);}
		if(maxx<sum){maxx=sum;st=(s-i+n)%n+1;}
		sum-=a[i];
		sum+=a[i+len];
	}
	printf("%d",st);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int n,a[200005],s,f,len;
int sum,maxx,st;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=n+1;i<=n*2;i++)a[i]=a[i-n];
	scanf("%d%d",&s,&f);
	len=f-s;
	st=n;
	for(int i=1;i<=len;i++)sum+=a[i];
	for(int i=1;i<=n;i++)
	{
		if(maxx<sum){maxx=sum;st=i+len-1;}
		//printf("%d %d ",i,sum);
		sum-=a[i];
		sum+=a[i+len];
		//printf("%d %d\n",a[i],a[i+len]);
	}
	printf("%d",st);
}


#include <bits/stdc++.h>

using namespace std;
#define CLR(a) memset(a, 0, sizeof(a))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define SZ(V) (int )V.size()
#define ALL(V) V.begin(), V.end()
#define RALL(V) V.rbegin(), V.rend()
#define FORN(i, n) for(LL i = 0; i < n; i++)
#define FORAB(i, a, b) for(LL i = a; i <= b; i++)
#define pll pair < long long int, long long int >
#define pii pair < int, int >
#define psi pair < string, int >
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD 1000000007LL

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef long long LL;

int main(){
    int n, s, f;
    cin >> n;
    vector < int > A(n),pre(n+1);
    pre[0] = 0;
    for(int i=0;i<n;i++){
        cin >> A[i];
        pre[i+1] = pre[i] + A[i];
    }
    cin >> s >> f;
    int maxTotal = INT_MIN,finalStart=1;
    for(int i=1;i<=n;i++){
        int start = i;
        int end = i + (f - s - 1);
        // cout << i << " " << start << " " << end << endl;
        int total = 0;
        if(end > n){
            end = end - n;
            // cout << "range " << start << " " << n << " " << end << endl;
            total += pre[n] - pre[start- 1];
            total += pre[end];
        }
        else{
            // cout << "range " << start << " " << end << endl;
            total += pre[end] - pre[start- 1];
        }
        // cout << total << " total " << maxTotal << endl;
        if(total > maxTotal){
            maxTotal = total;
            finalStart = i;
        }
    }
    if(finalStart == n){
        cout << finalStart << endl;
    }
    else{
        cout << finalStart + 1 << endl;
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define CLR(a) memset(a, 0, sizeof(a))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define SZ(V) (int )V.size()
#define ALL(V) V.begin(), V.end()
#define RALL(V) V.rbegin(), V.rend()
#define FORN(i, n) for(LL i = 0; i < n; i++)
#define FORAB(i, a, b) for(LL i = a; i <= b; i++)
#define pll pair < long long int, long long int >
#define pii pair < int, int >
#define psi pair < string, int >
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD 1000000007LL

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef long long LL;

int main(){
    int n, s, f;
    cin >> n;
    vector < int > A(n),pre(n+1);
    pre[0] = 0;
    for(int i=0;i<n;i++){
        cin >> A[i];
        pre[i+1] = pre[i] + A[i];
    }
    cin >> s >> f;
    int maxTotal = INT_MIN,finalStart=1;
    for(int i=1;i<=n;i++){
        int start = i;
        int end = i + (f - s - 1);
        // cout << i << " " << start << " " << end << endl;
        int total = 0;
        if(end > n){
            end = end - n;
            // cout << "range " << start << " " << n << " " << end << endl;
            total += pre[n] - pre[start- 1];
            total += pre[end];
        }
        else{
            // cout << "range " << start << " " << end << endl;
            total += pre[end] - pre[start- 1];
        }
        // cout << total << " total " << maxTotal << endl;
        if(total > maxTotal){
            maxTotal = total;
            finalStart = i;
        }
    }
    cout << finalStart + 1 << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define CLR(a) memset(a, 0, sizeof(a))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define SZ(V) (int )V.size()
#define ALL(V) V.begin(), V.end()
#define RALL(V) V.rbegin(), V.rend()
#define FORN(i, n) for(LL i = 0; i < n; i++)
#define FORAB(i, a, b) for(LL i = a; i <= b; i++)
#define pll pair < long long int, long long int >
#define pii pair < int, int >
#define psi pair < string, int >
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD 1000000007LL

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef long long LL;

int main(){
    int n, s, f;
    cin >> n;
    vector < int > A(n),pre(n+1);
    pre[0] = 0;
    for(int i=0;i<n;i++){
        cin >> A[i];
        pre[i+1] = pre[i] + A[i];
    }
    cin >> s >> f;
    int maxTotal = INT_MIN,finalStart=1,ans=n+1;
    for(int i=1;i<=n;i++){
        int start = i;
        int end = i + (f - s - 1);
        // cout << i << " " << start << " " << end << endl;
        int total = 0;
        if(end > n){
            end = end - n;
            // cout << "range " << start << " " << n << " " << end << endl;
            total += pre[n] - pre[start- 1];
            total += pre[end];
        }
        else{
            // cout << "range " << start << " " << end << endl;
            total += pre[end] - pre[start- 1];
        }
        // cout << total << " total " << maxTotal << endl;
        int newAns = s - i + 1;
        if(newAns < 1){
            newAns = newAns + n;
        }
        // cout << "new ans:" << newAns << endl;
        if(total == maxTotal){
            if(ans > newAns){
                ans = newAns;
                finalStart = i;
            }
        }
        else if(total >= maxTotal){
            maxTotal = total;
            ans = newAns;
            finalStart = i;
        }
    }
    cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define CLR(a) memset(a, 0, sizeof(a))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define SZ(V) (int )V.size()
#define ALL(V) V.begin(), V.end()
#define RALL(V) V.rbegin(), V.rend()
#define FORN(i, n) for(LL i = 0; i < n; i++)
#define FORAB(i, a, b) for(LL i = a; i <= b; i++)
#define pll pair < long long int, long long int >
#define pii pair < int, int >
#define psi pair < string, int >
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD 1000000007LL

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef long long LL;

int main(){
    int n, s, f;
    cin >> n;
    vector < int > A(n),pre(n+1);
    pre[0] = 0;
    for(int i=0;i<n;i++){
        cin >> A[i];
        pre[i+1] = pre[i] + A[i];
    }
    cin >> s >> f;
    int maxTotal = INT_MIN,finalStart=1;
    for(int i=1;i<=n;i++){
        int start = i;
        int end = i + (f - s - 1);
        // cout << i << " " << start << " " << end << endl;
        int total = 0;
        if(end > n){
            end = end - n;
            // cout << "range " << start << " " << n << " " << end << endl;
            total += pre[n] - pre[start- 1];
            total += pre[end];
        }
        else{
            // cout << "range " << start << " " << end << endl;
            total += pre[end] - pre[start- 1];
        }
        // cout << total << " total " << maxTotal << endl;
        if(total > maxTotal){
            maxTotal = total;
            finalStart = i;
        }
    }
    if(finalStart == n){
        cout << 1 << endl;
    }
    else{
        cout << finalStart + 1 << endl;
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define CLR(a) memset(a, 0, sizeof(a))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define SZ(V) (int )V.size()
#define ALL(V) V.begin(), V.end()
#define RALL(V) V.rbegin(), V.rend()
#define FORN(i, n) for(LL i = 0; i < n; i++)
#define FORAB(i, a, b) for(LL i = a; i <= b; i++)
#define pll pair < long long int, long long int >
#define pii pair < int, int >
#define psi pair < string, int >
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD 1000000007LL

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef long long LL;

int main(){
    int n, s, f;
    cin >> n;
    vector < int > A(n),pre(n+1);
    pre[0] = 0;
    for(int i=0;i<n;i++){
        cin >> A[i];
        pre[i+1] = pre[i] + A[i];
    }
    cin >> s >> f;
    int maxTotal = INT_MIN,finalStart=1;
    for(int i=1;i<=n;i++){
        int start = i;
        int end = i + (f - s - 1);
        // cout << i << " " << start << " " << end << endl;
        int total = 0;
        if(end > n){
            end = end - n;
            // cout << "range " << start << " " << n << " " << end << endl;
            total += pre[n] - pre[start- 1];
            total += pre[end];
        }
        else{
            // cout << "range " << start << " " << end << endl;
            total += pre[end] - pre[start- 1];
        }
        // cout << total << " total " << maxTotal << endl;
        if(total > maxTotal){
            maxTotal = total;
            finalStart = i;
        }
    }
    int ans = s - finalStart + 1;
    if(ans < 1){
        cout << ans + n << endl;
    }
    else{
        cout << ans << endl;
    }
	return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n,s,f;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    cin>>s>>f;
    int t=f-s,mx=0,po=1;
    for(int i=1;i<=t;i++){
        mx+=a[i];
    }
    int sum=mx;
    for(int i=2;i<=n-t+1;i++){
        sum=sum-a[i-1]+a[i+t-1];
        if(sum>mx){
            mx=sum;
            po=i;
        }
    }
    if(po>s){
        cout<<s+n-po+1;
    }else{
        cout<<s-po+1;
    }
    return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n,s,f;
    cin>>n;
    int a[n+n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
        a[n+i]=a[i];
    }
    cin>>s>>f;
    int t=f-s,mx=0,po=1;
    for(int i=1;i<=t;i++){
        mx+=a[i];
    }
    int sum=mx;
    for(int i=2;i<=n-t+1+n-1;i++){
        sum=sum-a[i-1]+a[i+t-1];
        if(sum>mx){
            mx=sum;
            po=i;
        }
    }
    if(po>s){
        cout<<s+n-po+1;
    }else{
        cout<<s-po+1;
    }
    return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n,s,f;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    cin>>s>>f;
    int t=f-s,mx=0,po=1;
    for(int i=1;i<=t;i++){
        mx+=a[i];
    }
    for(int i=2;i<=n-t+1;i++){
        int sum=mx-a[i-1]+a[i+t-1];
        if(sum>mx){
            mx=sum;
            po=i+t-1;
        }
    }
    cout<<po;
    return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n,s,f;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    cin>>s>>f;
    int t=f-s,mx=0,po=1;
    for(int i=1;i<=t;i++){
        mx+=a[i];
    }
    for(int i=2;i<=n-t+1;i++){
        int sum=mx-a[i-1]+a[i+t-1];
        if(sum>mx){
            mx=sum;
            po=i;
        }
    }
    cout<<po+s;
    return 0;
}


#include<iostream>
#include<climits>
using namespace std;

int main(){
    int n,s,f,ans,mn;
    cin>>n;
    int a[n+n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
        a[n+i]=a[i];
    }
    cin>>s>>f;
    int t=f-s,mx=0,po=1;
    for(int i=1;i<=t;i++){
        mx+=a[i];
        mn=s;
    }
    int sum=mx;
    for(int i=2;i<=n;i++){
        sum=sum-a[i-1]+a[i+t-1];
        if(sum>=mx){
            if(i>s){
                ans=s+n-i+1;
            }else{
                ans=s-i+1;
            }
        }
        if(sum>mx||(sum==mx&&ans<mn)){
            mx=sum;
            po=i;
            mn=ans;
        }
        //cout<<i<<' '<<ans<<endl;
    }
    cout<<mn;
    return 0;
}


#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int arr[n+5];
    for(int a=0;a<n;a++){
        scanf("%d",&arr[a]);
    }
    int s,f,sel;
    scanf("%d %d",&s,&f);
    sel=f-s;
    int id=n-1;
    int maks=0;
    for(int a=n-1;a>n-1-sel;a--){
        maks+=arr[a];
    }
    int sum=maks;
    for(int a=n-2;a>=0;a--){
        sel=min(sel,a+1);
        sum-=arr[a+1];
        sum+=arr[a-sel+1];
        if(sum>=maks){
            maks=sum;
            id=a;
        }
    }
    //printf("%d\n",maks);
    //sum=0;
    id++;
    printf("%d\n",id);
}


#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int arr[n+5];
    for(int a=0;a<n;a++){
        scanf("%d",&arr[a]);
    }
    int s,f,sel;
    scanf("%d %d",&s,&f);
    sel=f-s;
    int id=1;
    int maks=0;
    for(int a=0;a<sel;a++){
        maks+=arr[a];
    }
    int sum=maks;
    for(int a=1;a<n;a++){
        if((n-a)<sel){
           sum-=arr[a-1];
           sum+=arr[(a+sel-1)%n];
        }
        else{
            sum-=arr[a-1];
            sum+=arr[a+sel-1];
        }
        if(sum==maks){
            int new_id=s-a;
            if(new_id<=0) new_id=n+new_id;
            if(new_id<id) id=new_id;
        }
        if(sum>maks){
            id=s-a;
            if(id<=0) id=n+id;
            maks=sum;
        }
        //printf("%d %d %d\n",id,maks,sum);
    }
    //printf("%d\n",maks);
    //sum=0;
    printf("%d\n",id);
}


#include <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int arr[n+5];
    for(int a=0;a<n;a++){
        scanf("%d",&arr[a]);
    }
    int s,f,sel;
    scanf("%d %d",&s,&f);
    sel=f-s;
    int id=n-1;
    int maks=0;
    for(int a=n-1;a>n-1-sel;a--){
        maks+=arr[a];
    }
    int sum=maks;
    for(int a=n-2;a>=0;a--){
        sum-=arr[a+1];
        sum+=arr[a-sel+1];
        if(sum>=maks){
            maks=sum;
            id=a;
        }
        //printf("%d %d %d\n",maks,sum,a);
    }
    id++;
    printf("%d\n",id);
}


#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int arr[n+5];
    for(int a=0;a<n;a++){
        scanf("%d",&arr[a]);
    }
    int s,f,sel;
    scanf("%d %d",&s,&f);
    sel=f-s;
    int id=n-1;
    int maks=0;
    for(int a=n-1;a>n-1-sel;a--){
        maks+=arr[a];
    }
    int sum=maks;
    for(int a=n-2;a>=sel-1;a--){
        sum-=arr[a+1];
        sum+=arr[a-sel+1];
        if(sum>=maks){
            maks=sum;
            id=a;
        }
    }
    //printf("%d\n",maks);
    //sum=0;
    id++;
    id=(id+s-1)%n;
    if(!id) id=n;
    printf("%d\n",id);
}


#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int arr[n+5];
    for(int a=0;a<n;a++){
        scanf("%d",&arr[a]);
    }
    int s,f,sel;
    scanf("%d %d",&s,&f);
    sel=f-s;
    int id=n;
    int maks=0;
    for(int a=n-1;a>n-1-sel;a--){
        maks+=arr[a];
    }
    int sum=maks;
    for(int a=n-2;a>=sel-1;a--){
        sum-=arr[a+1];
        sum+=arr[a-sel+1];
        if(sum==maks){
            int new_id=(a+s)%n;
            if(!new_id) new_id=n;
            if(new_id<id) id=new_id;
        }
        if(sum>maks){
            id=(a+s)%n;
            if(!id)id=n;
            maks=sum;
        }
        //printf("%d %d %d\n",id,maks,sum);
    }
    //printf("%d\n",maks);
    //sum=0;
    printf("%d\n",id);
}


#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int arr[n+5];
    for(int a=0;a<n;a++){
        scanf("%d",&arr[a]);
    }
    int s,f,sel;
    scanf("%d %d",&s,&f);
    sel=f-s;
    int id=(n+s-1)%n;
    if(!id) id=n;
    int maks=0;
    for(int a=n-1;a>n-1-sel;a--){
        maks+=arr[a];
    }
    int sum=maks;
    for(int a=n-2;a>=0;a--){
        if(a<sel-1){
           sum-=arr[a+1];
           sum+=arr[(n-(sel-a-1))];
        }
        else{
            sum-=arr[a+1];
            sum+=arr[a-sel+1];
        }
        if(sum==maks){
            int new_id=((a+s)%n);
            if(!new_id) new_id=n;
            if(new_id<id) id=new_id;
        }
        if(sum>maks){
            id=(a+s)%n;
            if(!id)id=n;
            maks=sum;
        }
        //printf("%d %d %d\n",id,maks,sum);
    }
    //printf("%d\n",maks);
    //sum=0;
    printf("%d\n",id);
}


#include <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int arr[n+5];
    for(int a=0;a<n;a++){
        scanf("%d",&arr[a]);
    }
    int s,f,sel;
    scanf("%d %d",&s,&f);
    sel=f-s;
    int id=n-1;
    int maks=0;
    for(int a=n-1;a>n-1-sel;a--){
        maks+=arr[a];
    }
    int sum=maks;
    for(int a=n-2;a>=0;a--){
        sum-=arr[a+1];
        sum+=arr[a-sel+1];
        if(sum>=maks){
            maks=sum;
            id=a;
        }
        printf("%d %d %d\n",maks,sum,a);
    }
    id++;
    printf("%d\n",id);
}


#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int arr[n+5];
    for(int a=0;a<n;a++){
        scanf("%d",&arr[a]);
    }
    int s,f,sel;
    scanf("%d %d",&s,&f);
    sel=f-s;
    int id=n-1;
    int maks=0;
    for(int a=n-1;a>n-1-sel;a--){
        maks+=arr[a];
    }
    int sum=maks;
    for(int a=n-2;a>=0;a--){
        sel=min(sel,a+1);
        sum-=arr[a+1];
        sum+=arr[a-sel+1];
        if(sum>=maks){
            maks=sum;
            id=a;
        }
    }
    //sum=0;
    id++;
    printf("%d\n",id);
}


#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int arr[n+5];
    for(int a=0;a<n;a++){
        scanf("%d",&arr[a]);
    }
    int s,f,sel;
    scanf("%d %d",&s,&f);
    sel=f-s;
    int id=(n+s-1)%n;
    if(!id) id=n;
    int maks=0;
    for(int a=n-1;a>n-1-sel;a--){
        maks+=arr[a];
    }
    int sum=maks;
    for(int a=n-2;a>=sel-1;a--){
        sum-=arr[a+1];
        sum+=arr[a-sel+1];
        if(sum==maks){
            int new_id=(a+s)%n;
            if(!new_id) new_id=n;
            if(new_id<id) id=new_id;
        }
        if(sum>maks){
            id=(a+s)%n;
            if(!id)id=n;
            maks=sum;
        }
        //printf("%d %d %d\n",id,maks,sum);
    }
    //printf("%d\n",maks);
    //sum=0;
    printf("%d\n",id);
}


#include <bits/stdc++.h>

using namespace std;
int static const N = 200010;

int n, a[N], b[N], suma[N];

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int s, f;
	cin>>s>>f;
	if(f == s)
	{
		printf("1\n");
		return 0;
	}
	for(int i=0;i<n;i++)
	{
		int t = s + i;
		while(t > n)
			t -= n;
		b[t] += a[i];
	}
	for(int i=1;i<=n;i++)
		suma[i] = suma[i-1] + b[i];

	int maxx = -1, vreme = -1, period = f-s;
	for(int i=1;i<=n;i++)
	{
		int trbroj = 0;
		if(i-period > 0)
			trbroj = suma[i] - suma[i-period];
		else
		{
			trbroj = suma[i];
			trbroj += suma[n]-suma[n-(period-i)];
		}
		if(trbroj > maxx)
		{
			maxx = trbroj;
			vreme = i;
		}
	}

	cout<<vreme<<endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int static const N = 200010;

int n, a[N], b[N];
long long suma[N];

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int s, f;
	cin>>s>>f;
	if(f == s)
	{
		printf("1\n");
		return 0;
	}
	for(int i=0;i<n;i++)
	{
		int t = s + i;
		while(t > n)
			t -= n;
		b[t] += a[i];
	}
	for(int i=1;i<=n;i++)
		suma[i] = suma[i-1] + b[i];

	long long maxx = -1, vreme = 1, period = f-s;
	for(int i=1;i<=n;i++)
	{
		long long trbroj = 0;
		if(i-period >= 0)
			trbroj = suma[i] - suma[i-period];
		else
		{
			trbroj = suma[i];
			trbroj += suma[n]-suma[n-(period-i)];
		}
		if(trbroj > maxx)
		{
			maxx = trbroj;
			vreme = i;
		}
	}

	cout<<vreme<<endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int static const N = 200010;

int n, a[N], b[N], suma[N];

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int s, f;
	cin>>s>>f;
	if(f == s)
	{
		printf("1\n");
		return 0;
	}
	for(int i=0;i<n;i++)
	{
		int t = s + i;
		while(t > n)
			t -= n;
		b[t] += a[i];
	}
	for(int i=1;i<=n;i++)
		suma[i] = suma[i-1] + b[i];

	int maxx = -1, vreme = -1, period = f-s-1;
	for(int i=1;i<=n;i++)
	{
		int trbroj = 0;
		if(i-period > 0)
			trbroj = suma[i] - suma[i-period-1];
		else
		{
			trbroj = suma[i];
			trbroj += suma[n]-suma[n-(i-period)];
		}
		if(trbroj > maxx)
		{
			maxx = trbroj;
			vreme = i;
		}
	}

	cout<<vreme<<endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int static const N = 200010;

long long suma[N], b[N], n, a[N];

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	long long s, f;
	cin>>s>>f;
	if(f == s)
	{
		printf("1\n");
		return 0;
	}
	for(int i=0;i<n;i++)
	{
		long long t = s - i;
		while(t <= 0)
			t += n;
		b[t] += a[i];
	}
	for(int i=1;i<=n;i++)
		suma[i] = suma[i-1] + b[i];

	long long maxx = -1, vreme = 1, period = f-s;
	for(int i=1;i<=n;i++)
	{
		long long trbroj = 0;
		if(i-period >= 0)
			trbroj = suma[i] - suma[i-period];
		else
		{
			trbroj = suma[i];
			trbroj += suma[n]-suma[n-(period-i)];
		}
		if(trbroj > maxx)
		{
			maxx = trbroj;
			vreme = i;
		}
	}

	cout<<vreme<<endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int static const N = 200010;

class par
{
	public: int l, kraj, zona;
	void namesti(int a, int b, int c)
	{
		l = a;
		kraj = b;
		zona = c;
	}
};

bool compare(par a, par b)
{
	return a.l < b.l;
}

int n, a[N], m, otvoren[N];
par b[N];

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int s, f;
	cin>>s>>f;
	for(int i=0;i<n;i++)
	{
		int t = s+i;
		while(t > n)
			t -= n;
		b[m++].namesti(t,0,i);
		t = f + i;
		while(t > n)
			t -= n;
		b[m++].namesti(t,1,i);
	}

	sort(b,b+m,compare);
	int tr = 0, duz, maxx = -1, vreme = 1;
	for(int i=0;i<m;i++)
	{
		duz = b[i].l;
		while(b[i].l == duz)
		{
			if(b[i].kraj == 0)
			{
				duz += a[b[i].zona];
				otvoren[b[i].zona] = 1;
			}
			else
			{
				if(otvoren[b[i].zona] == 1)
				{
					otvoren[b[i].zona] = 0;
					duz -= a[b[i].zona];
				}
			}
			i++;
		}
		if(duz > maxx)
		{
			maxx = duz;
			vreme = b[i-1].l;
		}
		else
		{
			if(duz == maxx && vreme > b[i-1].l)
				vreme = b[i-1].l;

		}
		i--;
	}
	for(int i=0;i<m;i++)
	{
		duz = b[i].l;
		while(b[i].l == duz)
		{
			if(b[i].kraj == 0)
			{
				duz += a[b[i].zona];
				otvoren[b[i].zona] = 1;
			}
			else
			{
				if(otvoren[b[i].zona] == 1)
				{
					otvoren[b[i].zona] = 0;
					duz -= a[b[i].zona];
				}
			}
			i++;
		}
		if(duz > maxx)
		{
			maxx = duz;
			vreme = b[i-1].l;
		}
		else
		{
			if(duz == maxx && vreme > b[i-1].l)
				vreme = b[i-1].l;

		}
		i--;
	}

	cout<<vreme<<endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int static const N = 200010;

class par
{
	public: int l, kraj, zona;
	void namesti(int a, int b, int c)
	{
		l = a;
		kraj = b;
		zona = c;
	}
};

bool compare(par a, par b)
{
	return a.l < b.l;
}

int n, a[N], m, otvoren[N];
par b[N];

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int s, f;
	cin>>s>>f;
	for(int i=0;i<n;i++)
	{
		int t = s-i;
		while(t < 1)
			t += n;
		b[m++].namesti(t,0,i);
		t = f + i;
		while(t > n)
			t -= n;
		b[m++].namesti(t,1,i);
	}

	sort(b,b+m,compare);
	int tr = 0, duz, maxx = -1, vreme = 1;
	for(int i=0;i<m;i++)
	{
		duz = b[i].l;
		while(b[i].l == duz)
		{
			if(b[i].kraj == 0)
			{
				tr += a[b[i].zona];
				otvoren[b[i].zona] = 1;
			}
			else
			{
				if(otvoren[b[i].zona] == 1)
				{
					otvoren[b[i].zona] = 0;
					tr -= a[b[i].zona];
				}
			}
			i++;
		}
		if(tr > maxx)
		{
			maxx = tr;
			vreme = b[i-1].l;
		}
		else
		{
			if(tr == maxx && vreme > b[i-1].l)
				vreme = b[i-1].l;

		}
		i--;
	}

	for(int i=0;i<m;i++)
	{
		duz = b[i].l;
		while(b[i].l == duz)
		{
			if(b[i].kraj == 0)
			{
				tr += a[b[i].zona];
				otvoren[b[i].zona] = 1;
			}
			else
			{
				if(otvoren[b[i].zona] == 1)
				{
					otvoren[b[i].zona] = 0;
					tr -= a[b[i].zona];
				}
			}
			i++;
		}
		if(tr > maxx)
		{
			maxx = tr;
			vreme = b[i-1].l;
		}
		else
		{
			if(tr == maxx && vreme > b[i-1].l)
				vreme = b[i-1].l;

		}
		i--;
	}

	cout<<vreme<<endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int static const N = 200010;

int n, a[N], b[N], suma[N];

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int s, f;
	cin>>s>>f;
	if(f == s)
	{
		printf("1\n");
		return 0;
	}
	for(int i=0;i<n;i++)
	{
		int t = s + i;
		while(t > n)
			t -= n;
		b[t] += a[i];
	}
	for(int i=1;i<=n;i++)
		suma[i] = suma[i-1] + b[i];

	int maxx = -1, vreme = -1, period = f-s-1;
	for(int i=1;i<=n;i++)
	{
		int trbroj = 0;
		if(i-period > 0)
			trbroj = suma[i] - suma[i-period-1];
		else
		{
			trbroj = suma[i];
			trbroj += suma[n]-suma[n-(period-i)];
		}
		if(trbroj > maxx)
		{
			maxx = trbroj;
			vreme = i;
		}
	}

	cout<<vreme<<endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int static const N = 200010;

class par
{
	public: int l, kraj, zona;
	void namesti(int a, int b, int c)
	{
		l = a;
		kraj = b;
		zona = c;
	}
};

bool compare(par a, par b)
{
	return a.l < b.l;
}

int n, a[N], m, otvoren[N];
par b[N];

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int s, f;
	cin>>s>>f;
	for(int i=0;i<n;i++)
	{
		int t = s+i;
		while(t > n)
			t -= n;
		b[m++].namesti(t,0,i);
		t = f + i;
		while(t > n)
			t -= n;
		b[m++].namesti(t,1,i);
	}

	sort(b,b+m,compare);
	int tr = 0, duz, maxx = -1, vreme = 1;
	for(int i=0;i<m;i++)
	{
		duz = b[i].l;
		while(b[i].l == duz)
		{
			if(b[i].kraj == 0)
			{
				tr += a[b[i].zona];
				otvoren[b[i].zona] = 1;
			}
			else
			{
				if(otvoren[b[i].zona] == 1)
				{
					otvoren[b[i].zona] = 0;
					tr -= a[b[i].zona];
				}
			}
			i++;
		}
		if(tr > maxx)
		{
			maxx = tr;
			vreme = b[i-1].l;
		}
		else
		{
			if(tr == maxx && vreme > b[i-1].l)
				vreme = b[i-1].l;

		}
		i--;
	}

	for(int i=0;i<m;i++)
	{
		duz = b[i].l;
		while(b[i].l == duz)
		{
			if(b[i].kraj == 0)
			{
				tr += a[b[i].zona];
				otvoren[b[i].zona] = 1;
			}
			else
			{
				if(otvoren[b[i].zona] == 1)
				{
					otvoren[b[i].zona] = 0;
					tr -= a[b[i].zona];
				}
			}
			i++;
		}
		if(tr > maxx)
		{
			maxx = tr;
			vreme = b[i-1].l;
		}
		else
		{
			if(tr == maxx && vreme > b[i-1].l)
				vreme = b[i-1].l;

		}
		i--;
	}

	cout<<vreme<<endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int static const N = 200010;

long long suma[N], b[N], n, a[N];

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	long long s, f;
	cin>>s>>f;
	if(f == s)
	{
		printf("1\n");
		return 0;
	}
	for(int i=0;i<n;i++)
	{
		long long t = s + i;
		while(t > n)
			t -= n;
		b[t] += a[i];
	}
	for(int i=1;i<=n;i++)
		suma[i] = suma[i-1] + b[i];

	long long maxx = -1, vreme = 1, period = f-s;
	for(int i=1;i<=n;i++)
	{
		long long trbroj = 0;
		if(i-period >= 0)
			trbroj = suma[i] - suma[i-period];
		else
		{
			trbroj = suma[i];
			trbroj += suma[n]-suma[n-(period-i)];
		}
		if(trbroj > maxx)
		{
			maxx = trbroj;
			vreme = i;
		}
	}

	cout<<vreme<<endl;

	return 0;
}


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

#define ll unsigned long long

int main (){
	int n, s, f;
	scanf("%d", &n);
	int a[n];
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	scanf("%d%d", &s, &f);
	int bq = 0, bh = 0, cnt = 0, k = 0;
	int minval = min(f, n+s);
	for (int i = s; i < minval; i++){
		cnt += a[i-s];
		k++;
	}
	bq = cnt;
	int f_s = k;
	bh = f_s;
	for (int i = f_s; i < n; i++){
		cnt -= a[i-f_s];
		cnt += a[i];
		if (cnt > bq){
			bq = cnt;
			bh = 1+f_s+(i-f_s);
		}
	}
	printf ("%d\n", bh);
}


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

#define ll unsigned long long

int main (){
	int n, s, f;
	scanf("%d", &n);
	int a[n];
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	scanf("%d%d", &s, &f);
	int bq = 0, bh = 0, cnt = 0;
	for (int i = s; i < f; i++){
		cnt += a[i-1];
	}
	bq = cnt;
	bh = 1;
	int ch = n;
	int l = 0;
	for (int i = f-1; i < n+s; i++){
		cnt -= a[(l+s-1)%n];
		cnt += a[(l+f-1)%n];
		if (cnt > bq || (cnt == bq && ch < bh)){
			bq = cnt;
			bh = ch;
		}
		ch--;
		l++;
	}
	printf ("%d\n", bh);
}


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

#define ll unsigned long long

int main (){
	int n, s, f;
	scanf("%d", &n);
	int a[n];
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	scanf("%d%d", &s, &f);
	int bq = 0, bh = 0, cnt = 0;
	for (int i = s; i < f; i++){
		cnt += a[i-1];
	}
	bq = cnt;
	bh = 1;
	int ch = n;
	int l = 0;
	for (int i = f-1; l+s-1 != n+s-1; i++){
		cnt -= a[(l+s-1)%n];
		cnt += a[(l+f-1)%n];
		if (cnt > bq || (cnt == bq && ch < bh)){
			bq = cnt;
			bh = ch;
		}
		ch--;
		l++;
	}
	printf ("%d\n", bh);
}


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

#define ll unsigned long long

int main (){
	int n, s, f;
	scanf("%d", &n);
	int a[n];
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	scanf("%d%d", &s, &f);
	int bq = 0, bh = 0, cnt = 0;
	for (int i = s; i < f; i++){
		cnt += a[i-s];
	}
	bq = cnt;
	int f_s = f-1;
	bh = f_s;
	for (int i = f_s; i < n; i++){
		cnt -= a[i-f_s];
		cnt += a[i];
		if (cnt > bq){
			bq = cnt;
			bh = 1+f_s+(i-f_s);
		}
	}
	printf ("%d\n", bh);
}


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

#define ll unsigned long long

int main (){
	int n, s, f;
	scanf("%d", &n);
	int a[n];
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	scanf("%d%d", &s, &f);
	int bq = 0, bh = 0, cnt = 0;
	for (int i = s; i < f; i++){
		cnt += a[i-1];
	}
	bq = cnt;
	int f_s = f-s;
	bh = 1;
	//printf ("%d - %d = %d|%d\n", 0, f-1, bq, s);
	int ch = n;
	int l = 0;
	for (int i = f-1; i < n+s; i++){
		cnt -= a[(l+s-1)%n];
		cnt += a[(l+f_s)%n];
		//printf ("%d - %d = %d|%d\n", (l+s-1)%n, (l+f_s)%n, cnt, ch);
		if (cnt > bq || (cnt == bq && ch < bh)){
			bq = cnt;
			bh = ch;
		}
		ch--;
		l++;
	}
	printf ("%d\n", bh);
}


#include<bits/stdc++.h>
using namespace std;
const int N=100050;
int main(){
//	ifstream cin("file.in");
	long long n, s, f ,a[N];
	a[0]=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		a[i]+=a[i-1];
	}
	cin>>s>>f;
	int c=f-s, pos=0, mx=0;
	long long r;
	for(int i=1;i<=n;i++){
		if(i<=c)r=a[i]-a[n-c+i]; else r=a[i]-a[i-c];
		if(r>mx)mx=r, pos=i;
	}
	pos-=c-1;
	int h=s-pos;
	cout<<mx<<(h<0? n+h+1 : h+1);
}


#include<bits/stdc++.h>
using namespace std;
const int N=100050;
int main(){
//	ifstream cin("file.in");
	long long n, s, f ,a[N];
	a[0]=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		a[i]+=a[i-1];
	}
	cin>>s>>f;
	int c=f-s, pos=0, mx=0;
	long long r;
	for(int i=1;i<=n;i++){
		if(i<=c)r=a[i]-a[n-c+i]+a[n]; else r=a[i]-a[i-c];
		if(r>mx)mx=r, pos=i;
	}
	pos-=c-1;
	int h=s-pos;
	cout<<(h<0? n+h+1 : h+1);
}


#include<bits/stdc++.h>
using namespace std;
const int N=20020;
int main(){
//	ifstream cin("file.in");
	long long n, s, f ,a[N], d[N];
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	cin>>s>>f;
	int c=f-s;
	d[1]=a[1];
	for(int j=n-c+2;j<=n;j++)d[1]+=a[j];
	int mx=d[1], pos=1;
	for(int i=2;i<=n;i++){
		d[i]=d[i-1]-a[(i<=c? n-c+i :i-c)]+a[i];
		if(d[i]>mx)mx=d[i], pos=i;
	}
	pos-=c-1;
	int h=s-pos;
	cout<<(h<0? n+h+1 : h+1);
}


#include <cstdio>
#include <algorithm>

#include <queue>

typedef long long ll;
const int MAXN = 1e6 + 19;

int fa[MAXN], size[MAXN];
int getf(int node){
	return fa[node] == node ? node : fa[node] = getf(fa[node]);
}

int n, m, k;
int ans;

struct cmp{
	bool operator()(const int &a, const int &b)const{
		return size[a] > size[b];
	}
};
std::priority_queue<int, std::vector<int>, cmp> q;

int main(){
	std::scanf("%d%d%d", &n, &m, &k);
	for(int i = 1; i <= n; ++i)
		fa[i] = i, size[i] = 1;
	for(int i = 1; i <= m; ++i){
		int u, v;
		std::scanf("%d%d", &u, &v);
		if(getf(u) != getf(v)){
			size[getf(v)] += size[getf(u)];
			size[getf(u)] = 0;
			fa[getf(u)] = getf(v);
		}
	}

	int deg = 0;
	ll cap = 0;
	for(int i = 1; i <= n; ++i)
		if(getf(i) == i)
			q.push(i), ++deg, cap += std::min(k, size[i]);

	while(cap < 2 * (deg - 1)){
		--deg, ++ans;
		int a = q.top(); q.pop();
		int b = q.top(); q.pop();
		cap -= std::min(k, size[a]);
		cap -= std::min(k, size[b]);
		size[a] += size[b];
		cap += std::min(k, size[a]);
		q.push(a);
	}

	std::printf("%d\n", ans);
	return 0;
}


#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>

using namespace std;

#define sq(x) (x) * (x)
#define PI 3.1415926535897932384626433832795
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define sz(x) ((ll) (x).size())
#define mp make_pair
#define re return
#define fill(A,value) memset(A,value,sizeof(A))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define forn(i, n) for (ll i = 0; i < n; i++)
#define fore(i, e, n) for (ll i  = e; i < n; i++)
//#define mt make_tuple
#define pii pair<ll, ll>
#define pll pair<ll, ll>
#define ll long long

const int MAXN = 1000001;
int q = 0;
bool was[MAXN] = {false};
vector<int> v[MAXN];
void dfs (int x){
    was[x] = 1;
    q++;
    for (int i : v[x])
        if (!was[i])
            dfs (i);
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, m, k;
    cin >> n >> m >> k;

    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        v[a].pb(b);
        v[b].pb(a);
    }

    int e = 0, s = 0;
    for (int i = 1; i <= n; i++){
        if (!was[i])
            dfs (i), e++, s += q, q = 0;
    }

    if (k == 1)
        cout << max(0, e - 2);
    else{
        cout << max(0, e - s/2 - 1);
    }

    return 0;

}


#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>

using namespace std;

#define sq(x) (x) * (x)
#define PI 3.1415926535897932384626433832795
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define sz(x) ((ll) (x).size())
#define mp make_pair
#define re return
#define fill(A,value) memset(A,value,sizeof(A))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define forn(i, n) for (ll i = 0; i < n; i++)
#define fore(i, e, n) for (ll i  = e; i < n; i++)
//#define mt make_tuple
#define pii pair<ll, ll>
#define pll pair<ll, ll>
#define ll long long

const int MAXN = 1000001;
int q = 0;
bool was[MAXN] = {false};
vector<int> v[MAXN];
void dfs (int x){
    was[x] = 1;
    q++;
    for (int i : v[x])
        if (!was[i])
            dfs (i);
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, m, k;
    cin >> n >> m >> k;

    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        v[a].pb(b);
        v[b].pb(a);
    }

    int e = 0, s = 0;
    for (int i = 1; i <= n; i++){
        if (!was[i])
            dfs (i), e++, s += min(k, q), q = 0;
    }

    if (k == 1)
        cout << max(0, e - 2);
    else{
        cout << max(0, e - 1 - s/2);
    }

    return 0;

}


#if 1
#ifdef LOCAL
#define _GLIBCXX_DEBUG 1
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

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

#if 0
    #include <bits/extc++.h>
    using namespace __gnu_pbds;

    template<class T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;
#endif

#if 0
    /* #include <sys/time.h>
    int main() {
	    timeval tp;
	    gettimeofday(&tp, 0);
	    C = (int)tp.tv_usec; // (less than modulo)
    */

    typedef uint64_t ull;
    static int C;

    template<int M, class B>
    struct A {
        int x; B b; A(int x=0) : x(x), b(x) {}
        A(int x, B b) : x(x), b(b) {}
        A operator+(A o){int y = x+o.x; return{y - (y>=M)*M, b+o.b};}
        A operator-(A o){int y = x-o.x; return{y + (y< 0)*M, b-o.b};}
        A operator*(A o) { return {(int)(1LL*x*o.x % M), b*o.b}; }
        explicit operator ull() { return x ^ (ull) b << 21; }
    };
    typedef A<1000000007, A<1000000009, unsigned>> H;

    struct HashInterval {
        vector<H> ha, pw;
        HashInterval(string& str) : ha(sz(str)+1), pw(ha) {
            pw[0] = 1;
            rep(i,0,sz(str))
                ha[i+1] = ha[i] * C + str[i],
                pw[i+1] = pw[i] * C;
        }
        H hashInterval(int a, int b) { // hash [a, b)
            return ha[b] - ha[a] * pw[b - a];
        }
    };

    H hashString(string& s){H h{}; for(char c:s) h=h*C+c;return h;}
#endif

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)

typedef string str;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }

mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count());

#define ts to_string
str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) { str res = ""; F0R(i,SZ) res += char('0'+b[i]); return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { bool fst = 1; str res = "{"; for (const auto& x: v) {if (!fst) res += ", ";	fst = 0; res += ts(x);}	res += "}"; return res;}
template<class A, class B> str ts(pair<A,B> p) {return "("+ts(p.first)+", "+ts(p.second)+")"; }

template<class A> void pr(A x) { cout << ts(x); }
template<class H, class... T> void pr(const H& h, const T&... t) { pr(h); pr(t...); }
void ps() { pr("\n"); }
template<class H, class... T> void ps(const H& h, const T&... t) { pr(h); if (sizeof...(t)) pr(" "); ps(t...); }

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {cerr << ts(h); if (sizeof...(t)) cerr << ", ";	DBG(t...); }

int myrand(int l, int r) { return uniform_int_distribution(l, r)(rng); }

template<typename T, typename U> struct seg_tree_lazy {
    int S, H;

    T zero;
    std::vector<T> value;

    U noop;
    std::vector<bool> dirty;
    std::vector<U> prop;

    seg_tree_lazy<T, U>(int _S, T _zero = T(), U _noop = U());
    void set_leaves(std::vector<T> &leaves);
    void apply(int i, U &update);
    void rebuild(int i);
    void propagate(int i);
    void upd(int i, int j, U update);
    T query(int i, int j);
};

template<typename T, typename U>
seg_tree_lazy<T, U>::seg_tree_lazy(int _S, T _zero, U _noop) {
        zero = _zero, noop = _noop;
        for (S = 1, H = 1; S < _S; ) S *= 2, H++;

        value.resize(2*S, zero);
        dirty.resize(2*S, false);
        prop.resize(2*S, noop);
    }

template<typename T, typename U>
void seg_tree_lazy<T, U>::set_leaves(vector<T> &leaves) {
    copy(leaves.begin(), leaves.end(), value.begin() + S);

    for (int i = S - 1; i > 0; i--)
        value[i] = value[2 * i] + value[2 * i + 1];
}

template<typename T, typename U>
void seg_tree_lazy<T, U>::apply(int i, U &update) {
    value[i] = update(value[i]);
    if(i < S) {
        prop[i] = prop[i] + update;
        dirty[i] = true;
    }
}

template<typename T, typename U>
void seg_tree_lazy<T, U>::rebuild(int i) {
    for (int l = i/2; l; l /= 2) {
        T combined = value[2*l] + value[2*l+1];
        value[l] = prop[l](combined);
    }
}

template<typename T, typename U>
void seg_tree_lazy<T, U>::propagate(int i) {
    for (int h = H; h > 0; h--) {
        int l = i >> h;

        if (dirty[l]) {
            apply(2*l, prop[l]);
            apply(2*l+1, prop[l]);

            prop[l] = noop;
            dirty[l] = false;
        }
    }
}

template<typename T, typename U>
void seg_tree_lazy<T, U>::upd(int i, int j, U update) {
    i += S, j += S;
    propagate(i), propagate(j);

    for (int l = i, r = j; l <= r; l /= 2, r /= 2) {
        if((l&1) == 1) apply(l++, update);
        if((r&1) == 0) apply(r--, update);
    }

    rebuild(i), rebuild(j);
}

template<typename T, typename U>
T seg_tree_lazy<T, U>::query(int i, int j){
    i += S, j += S;
    propagate(i), propagate(j);

    T res_left = zero, res_right = zero;
    for(; i <= j; i /= 2, j /= 2){
        if((i&1) == 1) res_left = res_left + value[i++];
        if((j&1) == 0) res_right = value[j--] + res_right;
    }
    return res_left + res_right;
}

/*struct node {
    ll val = 0;

    node operator+(node ot) {
        ot.val = max(val, ot.val);
        return ot;
    }
};

struct update {
    ll val = 0;

    node operator()(node ot) {
        ot.val += val;
        return ot;
    }

    update operator+(update ot) {
        ot.val += val;
        return ot;
    }
};*/

#endif

vector<int> g[1100000];
vi seen;

int dfs(int v) {
    if (seen[v]) return 0;
    seen[v] = 1;

    int r = 1;
    for (int x: g[v]) {
        r += dfs(x);
    }

    return r;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n,m,k;
    cin >> n >> m >> k;
    seen = vi(n);

    for (int i = 0; i < m; i++) {
        int u,v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int comps = 0;
    int conns = 0;
    int isolated = 0;
    for (int i = 0; i < n; i++) if (!seen[i]) {
        if (g[i].empty()) {
            isolated++;
        }
        else {
            conns += min(k, dfs(i));
            comps++;
        }
    }

    conns -= max(0, 2*comps - 2);
    dbg(isolated,conns);
    cout << max(0, (isolated - conns) / 2 - (comps==0) ) << endl;
    return 0;
}


#if 1
#ifdef LOCAL
#define _GLIBCXX_DEBUG 1
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

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

#if 0
    #include <bits/extc++.h>
    using namespace __gnu_pbds;

    template<class T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;
#endif

#if 0
    /* #include <sys/time.h>
    int main() {
	    timeval tp;
	    gettimeofday(&tp, 0);
	    C = (int)tp.tv_usec; // (less than modulo)
    */

    typedef uint64_t ull;
    static int C;

    template<int M, class B>
    struct A {
        int x; B b; A(int x=0) : x(x), b(x) {}
        A(int x, B b) : x(x), b(b) {}
        A operator+(A o){int y = x+o.x; return{y - (y>=M)*M, b+o.b};}
        A operator-(A o){int y = x-o.x; return{y + (y< 0)*M, b-o.b};}
        A operator*(A o) { return {(int)(1LL*x*o.x % M), b*o.b}; }
        explicit operator ull() { return x ^ (ull) b << 21; }
    };
    typedef A<1000000007, A<1000000009, unsigned>> H;

    struct HashInterval {
        vector<H> ha, pw;
        HashInterval(string& str) : ha(sz(str)+1), pw(ha) {
            pw[0] = 1;
            rep(i,0,sz(str))
                ha[i+1] = ha[i] * C + str[i],
                pw[i+1] = pw[i] * C;
        }
        H hashInterval(int a, int b) { // hash [a, b)
            return ha[b] - ha[a] * pw[b - a];
        }
    };

    H hashString(string& s){H h{}; for(char c:s) h=h*C+c;return h;}
#endif

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)

typedef string str;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }

mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count());

#define ts to_string
str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) { str res = ""; F0R(i,SZ) res += char('0'+b[i]); return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { bool fst = 1; str res = "{"; for (const auto& x: v) {if (!fst) res += ", ";	fst = 0; res += ts(x);}	res += "}"; return res;}
template<class A, class B> str ts(pair<A,B> p) {return "("+ts(p.first)+", "+ts(p.second)+")"; }

template<class A> void pr(A x) { cout << ts(x); }
template<class H, class... T> void pr(const H& h, const T&... t) { pr(h); pr(t...); }
void ps() { pr("\n"); }
template<class H, class... T> void ps(const H& h, const T&... t) { pr(h); if (sizeof...(t)) pr(" "); ps(t...); }

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {cerr << ts(h); if (sizeof...(t)) cerr << ", ";	DBG(t...); }

int myrand(int l, int r) { return uniform_int_distribution(l, r)(rng); }

template<typename T, typename U> struct seg_tree_lazy {
    int S, H;

    T zero;
    std::vector<T> value;

    U noop;
    std::vector<bool> dirty;
    std::vector<U> prop;

    seg_tree_lazy<T, U>(int _S, T _zero = T(), U _noop = U());
    void set_leaves(std::vector<T> &leaves);
    void apply(int i, U &update);
    void rebuild(int i);
    void propagate(int i);
    void upd(int i, int j, U update);
    T query(int i, int j);
};

template<typename T, typename U>
seg_tree_lazy<T, U>::seg_tree_lazy(int _S, T _zero, U _noop) {
        zero = _zero, noop = _noop;
        for (S = 1, H = 1; S < _S; ) S *= 2, H++;

        value.resize(2*S, zero);
        dirty.resize(2*S, false);
        prop.resize(2*S, noop);
    }

template<typename T, typename U>
void seg_tree_lazy<T, U>::set_leaves(vector<T> &leaves) {
    copy(leaves.begin(), leaves.end(), value.begin() + S);

    for (int i = S - 1; i > 0; i--)
        value[i] = value[2 * i] + value[2 * i + 1];
}

template<typename T, typename U>
void seg_tree_lazy<T, U>::apply(int i, U &update) {
    value[i] = update(value[i]);
    if(i < S) {
        prop[i] = prop[i] + update;
        dirty[i] = true;
    }
}

template<typename T, typename U>
void seg_tree_lazy<T, U>::rebuild(int i) {
    for (int l = i/2; l; l /= 2) {
        T combined = value[2*l] + value[2*l+1];
        value[l] = prop[l](combined);
    }
}

template<typename T, typename U>
void seg_tree_lazy<T, U>::propagate(int i) {
    for (int h = H; h > 0; h--) {
        int l = i >> h;

        if (dirty[l]) {
            apply(2*l, prop[l]);
            apply(2*l+1, prop[l]);

            prop[l] = noop;
            dirty[l] = false;
        }
    }
}

template<typename T, typename U>
void seg_tree_lazy<T, U>::upd(int i, int j, U update) {
    i += S, j += S;
    propagate(i), propagate(j);

    for (int l = i, r = j; l <= r; l /= 2, r /= 2) {
        if((l&1) == 1) apply(l++, update);
        if((r&1) == 0) apply(r--, update);
    }

    rebuild(i), rebuild(j);
}

template<typename T, typename U>
T seg_tree_lazy<T, U>::query(int i, int j){
    i += S, j += S;
    propagate(i), propagate(j);

    T res_left = zero, res_right = zero;
    for(; i <= j; i /= 2, j /= 2){
        if((i&1) == 1) res_left = res_left + value[i++];
        if((j&1) == 0) res_right = value[j--] + res_right;
    }
    return res_left + res_right;
}

/*struct node {
    ll val = 0;

    node operator+(node ot) {
        ot.val = max(val, ot.val);
        return ot;
    }
};

struct update {
    ll val = 0;

    node operator()(node ot) {
        ot.val += val;
        return ot;
    }

    update operator+(update ot) {
        ot.val += val;
        return ot;
    }
};*/

#endif

vector<int> g[1100000];
vi seen;

int dfs(int v) {
    if (seen[v]) return 0;
    seen[v] = 1;

    int r = 1;
    for (int x: g[v]) {
        r += dfs(x);
    }

    return r;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n,m,k;
    cin >> n >> m >> k;
    seen = vi(n);

    for (int i = 0; i < m; i++) {
        int u,v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int comps = 0;
    int conns = 0;
    int isolated = 0;
    for (int i = 0; i < n; i++) if (!seen[i]) {
        if (g[i].empty()) {
            isolated++;
        }
        else {
            conns += min(k, dfs(i));
            comps++;
        }
    }

    if (k == 1) {
        cout << max(0, comps + isolated - 2) << endl;
        return 0;
    }

    conns -= max(0, 2*comps - 2);
    dbg(isolated,conns);
    cout << max(0, (isolated - conns + 1) / 2 - (comps==0) ) << endl;
    return 0;
}