#include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <set>
#include <cstring>

using namespace std;

#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;

long long mod_div(long long a, long long b) {
	long long tmp = MOD - 2, c = b, ret = 1;
	while (tmp > 0) {
		if (tmp & 1) {
			ret *= c; ret %= MOD;
		}
		c *= c; c %= MOD; tmp >>= 1;
	}
	return a*ret%MOD;
}

#define MAX_K 1111111
vector<long long> kaijo(MAX_K);
long long fact(int a) {
	if (kaijo[0] != 1) {
		kaijo[0] = 1;
		for (long long i = 1; i < MAX_K; i++)kaijo[i] = (kaijo[i - 1] * i) % MOD;
	}
	return kaijo[a];
}

long long combination(long long n, long long r) {
	if (n < r || n < 0 || r < 0)
		return 0;
	long long ret = fact(n);
	long long tmp = (fact(r) * fact(n - r)) % MOD;
	return mod_div(ret, tmp);
}

int main() {

	int n; cin >> n;
	vector<ll> v(n);
	int flag = 0;
	REP(i, n) {
		cin >> v[i];
		if (v[i] > 1)flag++;
	}

	sort(ALL(v));
	ll ans = 0;
	if (flag == 1)ans = mod_div(n - 1, n);
	if (flag > 1)ans = 1;
	vector<ll> cou;

	REP(i, n) {
		ll now = i;
		while (i < n - 1 && v[i] == v[i + 1])i++;
		if (i - now > 0)cou.PB(i - now + 1);
		if (v[now] == 1 || i == n - 1)continue;
		ll tmp = (i - now + 1) * mod_div(n-1, n) % MOD * mod_div(1, n - now) % MOD;
		ans = (ans * tmp % MOD) * v[now] % MOD;
	}

	ans = (ans * fact(n)) % MOD;
	REP(i, cou.size())ans = mod_div(ans, fact(cou[i]));
	cout << ans << endl;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <set>
#include <cstring>

using namespace std;

#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;

long long mod_div(long long a, long long b) {
	long long tmp = MOD - 2, c = b, ret = 1;
	while (tmp > 0) {
		if (tmp & 1) {
			ret *= c; ret %= MOD;
		}
		c *= c; c %= MOD; tmp >>= 1;
	}
	return a*ret%MOD;
}

#define MAX_K 1111111
vector<long long> kaijo(MAX_K);
long long fact(int a) {
	if (kaijo[0] != 1) {
		kaijo[0] = 1;
		for (long long i = 1; i < MAX_K; i++)kaijo[i] = (kaijo[i - 1] * i) % MOD;
	}
	return kaijo[a];
}

long long combination(long long n, long long r) {
	if (n < r || n < 0 || r < 0)
		return 0;
	long long ret = fact(n);
	long long tmp = (fact(r) * fact(n - r)) % MOD;
	return mod_div(ret, tmp);
}

int main() {

	int n; cin >> n;
	vector<ll> v(n);
	REP(i, n)cin >> v[i];
	sort(ALL(v));

	ll ans = 0;

	REP(i, n) {
		int now = i;
		while (i < n - 1 && v[i] == v[i + 1])i++;
		if (i == n - 1)continue;
		ll tmp = mod_div(i - now + 1, n - now);
		ans = (ans + (tmp * v[now] % MOD)) % MOD;
	}

	cout << ans * fact(n) % MOD << endl;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <set>
#include <cstring>

using namespace std;

#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;

long long mod_div(long long a, long long b) {
	long long tmp = MOD - 2, c = b, ret = 1;
	while (tmp > 0) {
		if (tmp & 1) {
			ret *= c; ret %= MOD;
		}
		c *= c; c %= MOD; tmp >>= 1;
	}
	return a*ret%MOD;
}

#define MAX_K 1111111
vector<long long> kaijo(MAX_K);
long long fact(int a) {
	if (kaijo[0] != 1) {
		kaijo[0] = 1;
		for (long long i = 1; i < MAX_K; i++)kaijo[i] = (kaijo[i - 1] * i) % MOD;
	}
	return kaijo[a];
}

long long combination(long long n, long long r) {
	if (n < r || n < 0 || r < 0)
		return 0;
	long long ret = fact(n);
	long long tmp = (fact(r) * fact(n - r)) % MOD;
	return mod_div(ret, tmp);
}

int main() {

	int n; cin >> n;
	vector<ll> v(n);
	int flag = 0;
	REP(i, n) {
		cin >> v[i];
		if (v[i] > 1)flag++;
	}

	sort(ALL(v));
	ll ans = 0;
	if (flag == 1)ans = mod_div(n - 1, n);
	if (flag > 1)ans = 1;
	vector<ll> cou;

	REP(i, n) {
		ll now = i;
		while (i < n - 1 && v[i] == v[i + 1])i++;
		if (v[now] == 1 || i == n - 1)continue;
		ll tmp = (i - now + 1) * mod_div(n-1, n) % MOD * mod_div(1, n - now) % MOD;
		ans = (ans * tmp % MOD) * v[now] % MOD;
	}

	ans = (ans * fact(n)) % MOD;
	cout << ans << endl;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <set>
#include <cstring>

using namespace std;

#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;

long long mod_div(long long a, long long b) {
	long long tmp = MOD - 2, c = b, ret = 1;
	while (tmp > 0) {
		if (tmp & 1) {
			ret *= c; ret %= MOD;
		}
		c *= c; c %= MOD; tmp >>= 1;
	}
	return a*ret%MOD;
}

#define MAX_K 1111111
vector<long long> kaijo(MAX_K);
long long fact(int a) {
	if (kaijo[0] != 1) {
		kaijo[0] = 1;
		for (long long i = 1; i < MAX_K; i++)kaijo[i] = (kaijo[i - 1] * i) % MOD;
	}
	return kaijo[a];
}

long long combination(long long n, long long r) {
	if (n < r || n < 0 || r < 0)
		return 0;
	long long ret = fact(n);
	long long tmp = (fact(r) * fact(n - r)) % MOD;
	return mod_div(ret, tmp);
}

int main() {

	fastcin();

	int n; cin >> n;
	vector<ll> v(n);
	REP(i, n)cin >> v[i];
	sort(ALL(v));

	ll ans = 0;

	REP(i, n) {
		int now = i;
		while (i < n - 1 && v[i] == v[i + 1])i++;
		if (i == n - 1)continue;
		ll tmp = mod_div(i - now + 1, n - now);
		ans = (ans + (tmp * v[now] % MOD)) % MOD;
	}

	cout << ans * fact(n) % MOD << endl;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <set>
#include <cstring>

using namespace std;

#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;

long long mod_div(long long a, long long b) {
	long long tmp = MOD - 2, c = b, ret = 1;
	while (tmp > 0) {
		if (tmp & 1) {
			ret *= c; ret %= MOD;
		}
		c *= c; c %= MOD; tmp >>= 1;
	}
	return a*ret%MOD;
}

#define MAX_K 1111111
vector<long long> kaijo(MAX_K);
long long fact(int a) {
	if (kaijo[0] != 1) {
		kaijo[0] = 1;
		for (long long i = 1; i < MAX_K; i++)kaijo[i] = (kaijo[i - 1] * i) % MOD;
	}
	return kaijo[a];
}

long long combination(long long n, long long r) {
	if (n < r || n < 0 || r < 0)
		return 0;
	long long ret = fact(n);
	long long tmp = (fact(r) * fact(n - r)) % MOD;
	return mod_div(ret, tmp);
}

int main() {

	int n; cin >> n;
	vector<ll> v(n);
	int flag = 0;
	REP(i, n) {
		cin >> v[i];
		if (v[i] > 1)flag++;
	}

	sort(ALL(v));
	ll ans = 0;
	if (flag == 1)ans = mod_div(n - 1, n);
	if (flag > 1)ans = 1;
	vector<ll> cou;

	REP(i, n) {
		ll now = i;
		while (i < n - 1 && v[i] == v[i + 1])i++;
		if (v[now] == 1 || i == n - 1)continue;
		ll A = 0, B = 0, C = 0;
		if (now > 0)A = mod_div(now, n) * (i - now + 1) % MOD * mod_div(1, n - now) % MOD;
		if (i - now > 0) B = mod_div(i - now + 1, n) * (i - now) % MOD * mod_div(1, n - now - 1) % MOD;
		if(n - i > 2)C = mod_div(n - i - 1, n) * (i - now + 1) * mod_div(1, n - now - 1) % MOD;
		ll tmp = (A + B + C) % MOD;
		ans = (ans + (tmp * v[now] % MOD)) % MOD;
		//cout << v[now] << " " << A << " " << B << " " << C << endl;
	}

	ans = (ans * fact(n)) % MOD;
	cout << ans << endl;

	return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long LL;
const int maxn=1e6+5;
const LL MOD=1e9+7;
int n;
LL a[maxn],fact[maxn],finv[maxn];
LL powmod(LL a,LL b){
  LL ans=1;
  for(a%=MOD;b;b>>=1,a=a*a%MOD)if(b&1)ans=ans*a%MOD;
  return ans;
}
void initfact(int n){
  fact[0]=1;
  for(int i=1;i<=n;i++)fact[i]=fact[i-1]*i%MOD;
  finv[n]=powmod(fact[n],MOD-2);
  for(int i=n;i>=1;i--)finv[i-1]=finv[i]*i%MOD;
}
/*
>=a[i] x
< a[i] y
contr(a[i]) = x!*y!*C(n,x+1)
*/
int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++)cin>>a[i];
  initfact(n);
  sort(a+1,a+1+n);
  LL ans=0;
  for(int i=1;i<n;i++){
    if(a[i]==a[n])break;
    int y=lower_bound(a+1,a+1+n,a[i])-a-1;
    int x=n-y-1;
    LL tmp=fact[x]*fact[y]%MOD*fact[n]%MOD*finv[x+1]%MOD*finv[n-x-1]%MOD;
    ans=(ans+tmp)%MOD;
  }
  cout<<ans<<"\n";
  return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long LL;
const int maxn=1e6+5;
const LL MOD=1e9+7;
int n;
LL a[maxn],fact[maxn],finv[maxn];
LL powmod(LL a,LL b){
  LL ans=1;
  for(a%=MOD;b;b>>=1,a=a*a%MOD)if(b&1)ans=ans*a%MOD;
  return ans;
}
void initfact(int n){
  fact[0]=1;
  for(int i=1;i<=n;i++)fact[i]=fact[i-1]*i%MOD;
  finv[n]=powmod(fact[n],MOD-2);
  for(int i=n;i>=1;i--)finv[i-1]=finv[i]*i%MOD;
}
/*
>=a[i] x
< a[i] y
contr(a[i]) = x!*y!*C(n,x+1)
*/
int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++)cin>>a[i];
  initfact(n);
  sort(a+1,a+1+n);
  LL ans=0;
  for(int i=1;i<n;i++){
    if(a[i]==a[n])break;
    int y=lower_bound(a+1,a+1+n,a[i])-a-1;
    int x=n-y-1;
    LL tmp=fact[x]*fact[y]%MOD*fact[n]%MOD*finv[x+1]%MOD*finv[n-x-1]%MOD;
    ans=(ans+a[i]*tmp%MOD)%MOD;
  }
  cout<<ans<<"\n";
  return 0;
}
/*
6
1 4 5 2 3 3
*/


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long LL;
const int maxn=1e6+5;
const LL MOD=1e9+7;
int n;
LL a[maxn],fact[maxn],finv[maxn];
LL powmod(LL a,LL b){
  LL ans=1;
  for(a%=MOD;b;b>>=1,a=a*a%MOD)if(b&1)ans=ans*a%MOD;
  return ans;
}
void initfact(int n){
  fact[0]=1;
  for(int i=1;i<=n;i++)fact[i]=fact[i-1]*i%MOD;
  finv[n]=powmod(fact[n],MOD-2);
  for(int i=n;i>=1;i--)finv[i-1]=finv[i]*i%MOD;
}
/*
>=a[i] x
< a[i] y
contr(a[i]) = x!*y!*C(n,x+1)
*/
int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++)cin>>a[i];
  initfact(n);
  sort(a+1,a+1+n);
  LL ans=0;
  for(int i=1;i<n;i++){
    int y=lower_bound(a+1,a+1+n,a[i])-a-1;
    int x=n-y-1;
    LL tmp=fact[x]*fact[y]%MOD*fact[n]%MOD*finv[x+1]%MOD*finv[n-x-1]%MOD;
    ans=(ans+tmp)%MOD;
  }
  cout<<ans<<"\n";
  return 0;
}


#include<bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll inf=(1ll<<62);
const int MX=1e6+9;
int n;
ll a[MX],ans,orig[MX],fac[MX],cnt[MX],pre[MX];
map<ll,ll>hashy;
ll POW(ll x,ll y){
    if(y==0)return 1;
    if(y==1)return x;
    ll ans=POW(x,y/2)%mod;
    ans*=ans;
    ans%=mod;
    if(y%2)ans*=x;
    return ans%mod;
}
ll modv(ll x){
    ll ret=fac[n];
    ll ret1=POW(x,mod-2)%mod;
    return (ret*ret1)%mod;
}
ll C(ll n,ll r){
    ll ret=fac[n];
    ll ret1=fac[r];
    ret1=(fac[n-r]*ret1)%mod;
    ret=POW(ret1,mod-2)%mod;
    return (ret*ret1)%mod;
}
int main(){
    fac[0]=1;
    cin>>n;
    for(ll i=1;i<=n;i++)
        fac[i]=(fac[i-1]*i)%mod;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        hashy[a[i]]=1;
    }
    int tt=0;
    for(auto pp:hashy){
        hashy[pp.first]=++tt;
        orig[tt]=pp.first;
    }
    for(int i=1;i<=n;i++){
        cnt[hashy[a[i]]]++;
    }
    for(int i=1;i<=n;i++){
        pre[i]=pre[i-1]+cnt[i];
    }
    for(int i=1;i<=n;i++){
        if(i==tt)break;
        ll gr=n-pre[i-1];
    //    cout<<gr<<" "<<cnt[i]<<endl;
        ll x=(cnt[i]*orig[i])%mod;
        x=(x*modv(gr))%mod;
        ans+=x;
        ans%=mod;
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll inf=(1ll<<62);
const int MX=1e6+9;
int n;
ll a[MX],ans,orig[MX],fac[MX],cnt[MX],pre[MX];
map<ll,ll>hashy;
ll POW(ll x,ll y){
    if(y==0)return 1;
    if(y==1)return x;
    ll ans=POW(x,y/2)%mod;
    ans*=ans;
    ans%=mod;
    if(y%2)ans*=x;
    return ans%mod;
}
ll modv(ll x){
    ll ret=fac[n];
    ll ret1=POW(x,mod-2)%mod;
    return (ret*ret1)%mod;
}
ll C(ll n,ll r){
    ll ret=fac[n];
    ll ret1=fac[r];
    ret1=(fac[n-r]*ret1)%mod;
    ret=POW(ret1,mod-2)%mod;
    return (ret*ret1)%mod;
}
int main(){
    fac[0]=1;
    cin>>n;
    for(ll i=1;i<=n;i++)
        fac[i]=(fac[i-1]*i)%mod;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        hashy[a[i]]=1;
    }
    int tt=0;
    for(auto pp:hashy){
        hashy[pp.first]=++tt;
        orig[tt]=pp.first;
    }
    for(int i=1;i<=n;i++){
        cnt[hashy[a[i]]]++;
    }
    for(int i=1;i<=n;i++){
        pre[i]=pre[i-1]+cnt[i];
    }
    for(int i=1;i<=n;i++){
        if(i==tt)break;
        ll gr=n-pre[i];
        ll x=(cnt[i]*a[i])%mod;
        x=(x*modv(gr+cnt[i]))%mod;
        ans+=x;
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll inf=(1ll<<62);
const int MX=1e6+9;
int n;
ll a[MX],ans,orig[MX],fac[MX],cnt[MX],pre[MX];
map<ll,ll>hashy;
ll POW(ll x,ll y){
    if(y==0)return 1;
    if(y==1)return x;
    ll ans=POW(x,y/2)%mod;
    ans*=ans;
    ans%=mod;
    if(y%2)ans*=x;
    return ans%mod;
}
ll modv(ll x){
    ll ret=fac[n];
    ll ret1=POW(x,mod-2)%mod;
    return (ret*ret1)%mod;
}
ll C(ll n,ll r){
    ll ret=fac[n];
    ll ret1=fac[r];
    ret1=(fac[n-r]*ret1)%mod;
    ret=POW(ret1,mod-2)%mod;
    return (ret*ret1)%mod;
}
int main(){
    fac[0]=1;
    cin>>n;
    for(ll i=1;i<=n;i++)
        fac[i]=(fac[i-1]*i)%mod;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        hashy[a[i]]=1;
    }
    int tt=0;
    for(auto pp:hashy){
        hashy[pp.first]=++tt;
        orig[tt]=pp.first;
    }
    for(int i=1;i<=n;i++){
        cnt[hashy[a[i]]]++;
    }
    for(int i=1;i<=n;i++){
        pre[i]=pre[i-1]+cnt[i];
    }
    for(int i=1;i<=n;i++){
        if(i==tt)break;
        ll gr=n-pre[i-1];
    //    cout<<gr<<" "<<cnt[i]<<endl;
        ll x=(cnt[i]*orig[i])%mod;
        x=(x*modv(gr))%mod;
        ans+=x;
    }
    cout<<ans<<endl;
}


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

int mod=(1e9)+7, n, a[1001000];
ll jc[1001000], ans;

int main(){
  cin>>n;
  for (int i=0;i<n;++i) scanf("%d",&a[i]);
  sort(a,a+n);
  jc[0]=1; for (int i=1;i<=n;++i) jc[i]=jc[i-1]*i%mod;
  for (int i=0;i<n;++i){
    int t=lower_bound(a,a+n,a[i])-a;
    ans+= t *jc[t]%mod *jc[n-1-t]%mod;
  }
  cout<<ans;
}


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

int mod=(1e9)+7, n, a[1001000], mx;
ll jc[1001000], ans;

int main(){
  cin>>n;
  for (int i=0;i<n;++i) scanf("%d",&a[i]), mx=max(a[i],mx);
  sort(a,a+n);
  jc[0]=1; for (int i=1;i<=n;++i) jc[i]=jc[i-1]*i%mod;
  for (int i=0;a[i]!=mx;++i){
    int t=lower_bound(a,a+n,a[i])-a;
    ans+= (t+1) *jc[t]%mod *jc[n-1-t]%mod;
  }
  cout<<ans;
}


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

int mod=(1e9)+7, n, a[1001000], mx; ll jc=1, ans;
ll K(ll x,int y=mod-2){ return y? K(x*x%mod,y/2)*(y&1?x:1)%mod: 1; }

int main(){
  cin>>n;
  for (int i=0;i<n;jc=jc*++i%mod)
    scanf("%d",&a[i]), mx=max(a[i],mx);
  sort(a,a+n);
  for (int i=0;a[i]!=mx;++i){
    int t=lower_bound(a,a+n,a[i])-a;
    ans+= a[i] *jc%mod *K(n-t)%mod; ans%=mod;
  }
  cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
                        For(j,m-1) cout<<a[i][j]<<' ';\
                        cout<<a[i][m]<<endl; \
                        }
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll F=1e9+7;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
ll pow2(ll a,int b,ll p=F)  //a^b mod p
{
    if (b==0) return 1%p;
    if (b==1) return a%p;
    ll c=pow2(a,b/2,p)%p;
    c=c*c%p;
    if (b&1) c=c*a%p;
    return c%p;
}
ll inv(ll a,ll p=F) { //gcd(a,p)=1
    return pow2(a,p-2,p);
}
#define MAXN (1234567)
ll jie[MAXN],inj[MAXN],a[MAXN],iv[MAXN];
ll C(ll a,ll b) {
    return jie[a]*inj[b]%F*inj[a-b]%F;
}
int main()
{
//  freopen("D.in","r",stdin);
//  freopen(".out","w",stdout);
    int n=1000000+100;
    For(i,n) a[i]=i;

    jie[0]=1;
    For(i,n) jie[i]=jie[i-1]*i%F;
    inj[n]=inv(jie[n] );
    ForD(i,n-1) inj[i]=inj[i+1]*(i+1)%F;
    inj[0]=1;
    iv[0]=1;
    For(i,n) iv[i]=inj[i]*jie[i-1]%F;

    n=read();
    For(i,n) a[i]=read();
    sort(a+1,a+1+n);
    ll c=0,p=0;
    ll ans=0;
	For(i,n) {
		int j=i;
		while(j<n &&a[j+1]==a[i]) ++j;

		int pr=i-1,nx=n-j;
		if (!nx) break;
		ll t = jie[nx+j-i] * (j-i+1)%F;
		ll t2=j-i+nx+1+1;
		if (t2<=n)
			t=t*jie[n]%F*inj[t2-1]%F;

		ans=(ans+t*a[i]%F)%F;

		i=j;
	}
    cout<<ans;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
                        For(j,m-1) cout<<a[i][j]<<' ';\
                        cout<<a[i][m]<<endl; \
                        }
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll F=1e9+7;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
ll pow2(ll a,int b,ll p=F)  //a^b mod p
{
    if (b==0) return 1%p;
    if (b==1) return a%p;
    ll c=pow2(a,b/2,p)%p;
    c=c*c%p;
    if (b&1) c=c*a%p;
    return c%p;
}
ll inv(ll a,ll p=F) { //gcd(a,p)=1
    return pow2(a,p-2,p);
}
#define MAXN (3234567)
ll jie[MAXN],inj[MAXN],a[MAXN],iv[MAXN];
ll C(ll a,ll b) {
    return jie[a]*inj[b]%F*inj[a-b]%F;
}
int main()
{
//  freopen("D.in","r",stdin);
//  freopen(".out","w",stdout);
    int n=1000000+100;
    For(i,n) a[i]=i;

    jie[0]=1;
    For(i,n) jie[i]=jie[i-1]*i%F;
    inj[n]=inv(jie[n] );
    ForD(i,n-1) inj[i]=inj[i+1]*(i+1)%F;
    inj[0]=1;
    iv[0]=1;
    For(i,n) iv[i]=inj[i]*jie[i-1]%F;

    n=read();
    For(i,n) a[i]=read();
    sort(a+1,a+1+n);
    ll c=0,p=0;
    ll ans=0;
	For(i,n) {
		int j=i;
		while(j<n &&a[j+1]==a[i]) ++j;

		int pr=i-1,nx=n-j;
		if (!nx) continue;
		ll t = jie[nx+j-i] * (j-i+1)%F;
		ll t2=j-i+nx+1+1;
		if (t2<=n)
			t=t*jie[n]%F*inj[t2-1]%F;

		ans=(ans+t*a[i]%F)%F;

		i=j;
	}
    cout<<ans;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
                        For(j,m-1) cout<<a[i][j]<<' ';\
                        cout<<a[i][m]<<endl; \
                        }
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll F=1e9+7;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
ll pow2(ll a,int b,ll p=F)  //a^b mod p
{
    if (b==0) return 1%p;
    if (b==1) return a%p;
    ll c=pow2(a,b/2,p)%p;
    c=c*c%p;
    if (b&1) c=c*a%p;
    return c%p;
}
ll inv(ll a,ll p=F) { //gcd(a,p)=1
    return pow2(a,p-2,p);
}
#define MAXN (6234567)
ll jie[MAXN],inj[MAXN],a[MAXN],iv[MAXN];
ll C(ll a,ll b) {
    return jie[a]*inj[b]%F*inj[a-b]%F;
}
int main()
{
//  freopen("D.in","r",stdin);
//  freopen(".out","w",stdout);
    int n=3e6;
    For(i,n) a[i]=i;

    jie[0]=1;
    For(i,n) jie[i]=jie[i-1]*i%F;
    inj[n]=inv(jie[n] );
    ForD(i,n-1) inj[i]=inj[i+1]*(i+1)%F;
    inj[0]=1;
    iv[0]=1;
    For(i,n) iv[i]=inj[i]*jie[i-1]%F;

    n=read();
    For(i,n) a[i]=read();
    sort(a+1,a+1+n);
    ll c=0,p=0;
    ll ans=0;
	For(i,n) {
		int j=i;
		while(j<n &&a[j+1]==a[i]) ++j;

		int pr=i-1,nx=n-j;
		if (!nx) continue;
		ll t = jie[nx+j-i] * (j-i+1)%F;
		ll t2=j-i+nx+1+1;
		if (t2<=n)
			t=t*jie[n]%F*inj[t2-1]%F;

		ans=(ans+t*a[i]%F)%F;

		i=j;
	}
    cout<<ans;

	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,ans,la,p=1e9+7,a[1000001],fac[1000001],ny[1000001];
ll ksm(ll x,ll y){
	ll now=1;
	while(y){
		if(y&1)now=now*x%p;
		x=x*x%p;
		y/=2;
	}
	return now;
}
ll C(ll x,ll y){
	return fac[x]*ny[x-y]%p*ny[y]%p;
}
int main(){
	ll i,sum,now;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]);
	fac[0]=ny[0]=1;
	for(i=1;i<=n;i++)fac[i]=fac[i-1]*i%p,ny[i]=ksm(fac[i],p-2);
	sort(a+1,a+n+1);
	for(i=1;i<=n;i++){
		if(i==n)break;
		if(a[i]!=a[i+1]){
			sum=n-la;
			now=i-la;
			ans=(ans+C(n,sum)*fac[sum-1]%p*fac[la]%p*now%p)%p;
			la=i;
		}
	}
	printf("%lld",ans);
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,a[1000001],p=1e9+7,ans;
ll ksm(ll x,ll y){
	ll xlh=1;
	while(y){
		if(y&1)xlh=xlh*x%p;
		x=x*x%p;
		y/=2;
	}
	return xlh;
}
int main(){
	ll i,j,now;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	now=1;
	for(i=1;i<=n;i++)now=now*i%p;
	for(i=1;i<=n;i=j){
		j=i;
		while(a[i]==a[j]&&j<=n)j++;
		if(j<=n)ans=(ans+now*ksm(n-i+1,p-2)%p*(j-i)%p*a[i]%p)%p;
	}
	printf("%lld",ans);
}


#include<bits/stdc++.h>
#define mod 1000000007
#define maxn 1000005
using namespace std;
typedef long long LL;
int read()
{
	char c;int sum=0,f=1;c=getchar();
	while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();}
	return sum*f;
}
int n;
int a[maxn];
LL ksm(LL a,LL b)
{
	LL ret=1;
	while(b)
	{
		if(b&1) ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
LL A=1,ans;
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	a[i]=read(),A=A*i%mod;
	sort(a+1,a+1+n);
	int pos;
	for(int i=1;i<=n;i=pos)
	{
		pos=i;
		while(a[i]==a[pos] && pos<=n) pos++;
        if(pos<=n)
		ans=(ans+A*ksm(n-i+1,mod-2)%mod*(pos-i)%mod*a[i]%mod)%mod;
	}
	cout<<ans<<endl;
	return 0;
//
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,ans,la,p=1e9+7,a[1000001],fac[1000001],ny[1000001];
ll ksm(ll x,ll y){
	ll now=1;
	while(y){
		if(y&1)now=now*x%p;
		x=x*x%p;
		y/=2;
	}
	return now;
}
ll C(ll x,ll y){
	return fac[x]*ny[x-y]%p*ny[y]%p;
}
int main(){
	ll i,sum,now;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]);
	fac[0]=ny[0]=1;
	for(i=1;i<=n;i++)fac[i]=fac[i-1]*i%p,ny[i]=ksm(fac[i],p-2);
	sort(a+1,a+n+1);
	for(i=1;i<=n;i++){
		if(i==n)break;
		if(a[i]!=a[i+1]){
			sum=n-la;
			now=i-la;
			ans=(ans+C(n,sum)*fac[sum-1]%p*fac[la]%p*now%p*a[i]%p)%p;
			la=i;
			//printf("%lld %lld\n",i,ans);
		}
	}
	printf("%lld",ans);
}


/* GCC */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <sstream>

#define X first
#define Y second
#define mp(a, b) make_pair((a), (b))

using namespace std;

long long n, i, j, k, x, y, l, a[1000010], b[1000010], ans;
long long mod = 1e9 + 7;

long long gcd (long long a, long long b, long long & x, long long & y)
{
	if (a == 0)
    {
		x = 0; y = 1;
		return b;
	}

	long long x1, y1;
	long long d = gcd (b%a, a, x1, y1);

	x = y1 - (b / a) * x1;
	y = x1;

	return d;
}

int main()
{
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);

    b[0] = 1;
    for(i = 1; i <= 1000000; i++)
        b[i] = (b[i - 1] * i) % mod;

    cin >> n;
    for(i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a + n);

    ans = 0;
    j = 1;
    for(i = 0; i < n - 1; i++)
        if(a[i] != a[i + 1])
        {
            k = n - i - 1 + j;
            l = gcd(b[k], mod, x, y);
            x = (x % mod + mod) % mod;

            ans = (((((((((j * b[k - 1]) % mod) * b[n]) % mod) * x) % mod) * a[i]) % mod) + ans) % mod;

            //ans = (((((((b[j] * b[i + 1 - j]) % mod) * b[n - i - 1 + j - 1]) % mod) * a[i]) % mod) + ans) % mod;

            j = 1;
        }
        else
        {
            j++;
        }

    cout << ans << endl;

    return 0;
}


/* GCC */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <sstream>

#define X first
#define Y second
#define mp(a, b) make_pair((a), (b))

using namespace std;

long long n, i, j, k, x, y, l, a[1000010], b[1000010], ans;
long long mod = 1e9 + 7;

long long gcd (long long a, long long b, long long & x, long long & y)
{
	if (a == 0)
    {
		x = 0; y = 1;
		return b;
	}

	long long x1, y1;
	long long d = gcd (b%a, a, x1, y1);

	x = y1 - (b / a) * x1;
	y = x1;

	return d;
}

int main()
{
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);

    b[0] = 1;
    for(i = 1; i <= 1000000; i++)
        b[i] = (b[i - 1] * i) % mod;

    cin >> n;
    for(i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a + n);

    ans = 0;
    j = 1;
    for(i = 0; i < n - 1; i++)
        if(a[i] != a[i + 1])
        {
            k = n - i - 1 + j;
            l = gcd(b[k], mod, x, y);
            x = (x % mod + mod) % mod;

            ans = (((((((b[j] * b[k - 1]) % mod) * b[n]) % mod) * x) % mod) + ans) % mod;

            //ans = (((((((b[j] * b[i + 1 - j]) % mod) * b[n - i - 1 + j - 1]) % mod) * a[i]) % mod) + ans) % mod;

            j = 1;
        }
        else
        {
            j++;
        }

    cout << ans << endl;

    return 0;
}


/* GCC */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <sstream>

#define X first
#define Y second
#define mp(a, b) make_pair((a), (b))

using namespace std;

long long n, i, j, k, x, y, l, a[1000010], b[1000010], ans;
long long mod = 1e9 + 7;

long long gcd (long long a, long long b, long long & x, long long & y)
{
	if (a == 0)
    {
		x = 0; y = 1;
		return b;
	}

	long long x1, y1;
	long long d = gcd (b%a, a, x1, y1);

	x = y1 - (b / a) * x1;
	y = x1;

	return d;
}

int main()
{
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);

    b[0] = 1;
    for(i = 1; i <= 1000000; i++)
        b[i] = (b[i - 1] * i) % mod;

    cin >> n;
    for(i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a + n);

    ans = 0;
    j = 1;
    for(i = 0; i < n - 1; i++)
        if(a[i] != a[i + 1])
        {
            k = n - i - 1 + j;
            l = gcd(b[k], mod, x, y);
            x = (x % mod + mod) % mod;

            ans = (((((((((b[j] * b[k - 1]) % mod) * b[n]) % mod) * x) % mod) * a[i]) % mod) + ans) % mod;

            //ans = (((((((b[j] * b[i + 1 - j]) % mod) * b[n - i - 1 + j - 1]) % mod) * a[i]) % mod) + ans) % mod;

            j = 1;
        }
        else
        {
            j++;
        }

    cout << ans << endl;

    return 0;
}


/* GCC */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <sstream>

#define X first
#define Y second
#define mp(a, b) make_pair((a), (b))

using namespace std;

long long n, i, j, k, x, y, l, a[1000010], b[1000010], ans;
long long mod = 1e9 + 7;

long long gcd (long long a, long long b, long long & x, long long & y)
{
	if (a == 0)
    {
		x = 0; y = 1;
		return b;
	}

	long long x1, y1;
	long long d = gcd (b%a, a, x1, y1);

	x = y1 - (b / a) * x1;
	y = x1;

	return d;
}

int main()
{
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);

    b[0] = 1;
    for(i = 1; i <= 1000000; i++)
        b[i] = (b[i - 1] * i) % mod;

    cin >> n;
    for(i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a + n);

    ans = 0;
    j = 1;
    for(i = 0; i < n - 1; i++)
        if(a[i] != a[i + 1])
        {
            k = n - i - 1 + j;
            l = gcd(k, mod, x, y);
            x = (x % mod + mod) % mod;

            ans = (((((((b[j] * b[n]) % mod) * x) % mod) * a[i]) % mod) + ans) % mod;

            //ans = (((((((b[j] * b[i + 1 - j]) % mod) * b[n - i - 1 + j - 1]) % mod) * a[i]) % mod) + ans) % mod;

            j = 1;
        }
        else
        {
            j++;
        }

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
ll po(ll base)
{
    ll power = 1e9+5;
    ll mod = 1e9+7;
    ll ans = 1;
    while(power>0)
    {
        if(power%2==1)
            ans = (ans*base)%mod;
        base = (base*base)%mod;
        power/=2;
    }
    return ans;
}
ll fact[1000005]={0},mod = 1e9+7,a[1000005]={0},freq[1000005]={0};
int main()
{
    ios::sync_with_stdio(false);
    fact[0]=1;
    for(ll i =1;i<=1000000;i++)
        fact[i] = (fact[i-1]*i)%mod;
    int n;
    cin>>n;
    int m=n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int cnt=1;
    vector< pair<ll,ll> > v;
    for(int i=1;i<n;i++)
    {
        if(a[i]==a[i-1])
            cnt++;
        else
        {
            v.push_back({a[i-1],cnt});
            cnt=1;
        }
    }
    //cout<<cnt<<"\n";
    v.push_back({a[n-1],cnt});
    freq[0] = v[0].ss;
    n = v.size();
    for(int i=1;i<n;i++)
        freq[i] = freq[i-1]+v[i].ss;
    int curr = v[n-1].ss;
    ll ans=0;
    for(int i = n-2;i>=0;i--)
    {
        //cout<<v[i].ss<<curr<<"\n";
        ll d = curr + v[i].ss;
        ll temp = (fact[m]*po(fact[d]))%mod;
        //cout<<temp<<" "<<d<<"\n";
        temp = (temp * fact[d-1])%mod;
        temp = (temp*freq[i])%mod;
        ans = (ans + (temp*v[i].ff)%mod)%mod;
        curr+=v[i].ss;
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
ll po(ll base)
{
    ll power = 1e9+5;
    ll mod = 1e9+7;
    ll ans = 1;
    while(power>0)
    {
        if(power%2==1)
            ans = (ans*base)%mod;
        base = (base*base)%mod;
        power/=2;
    }
    return ans;
}
ll fact[1000005]={0},mod = 1e9+7,a[1000005]={0},freq[1000005]={0};
int main()
{
    ios::sync_with_stdio(false);
    fact[0]=1;
    for(ll i =1;i<=1000000;i++)
        fact[i] = (fact[i-1]*i)%mod;
    int n;
    cin>>n;
    int m=n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int cnt=1;
    vector< pair<ll,ll> > v;
    for(int i=1;i<n;i++)
    {
        if(a[i]==a[i-1])
            cnt++;
        else
        {
            v.push_back({a[i-1],cnt});
            cnt=1;
        }
    }
    //cout<<cnt<<"\n";
    v.push_back({a[n-1],cnt});
    freq[0] = v[0].ss;
    n = v.size();
    for(int i=1;i<n;i++)
        freq[i] = freq[i-1]+v[i].ss;
    int curr = v[n-1].ss;
    ll ans=0;
    for(int i = n-2;i>=0;i--)
    {
        //cout<<v[i].ss<<curr<<"\n";
        ll d = curr + v[i].ss;
        ll temp = (fact[m]*po(fact[d]))%mod;
        //cout<<i<<" "<<temp<<" "<<d<<"\n";
        temp = (temp * fact[d-1])%mod;
        temp = (temp*v[i].ss)%mod;
        ans = (ans + (temp*v[i].ff)%mod)%mod;
        curr+=v[i].ss;
//        if(i==1)
//            cout<<ans<<"\n";
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define llong long long
int n,K,D;
int nu[200200];
struct SEG{
	llong mi[2000200];
	llong laz[2000200];
	void build(int rt,int l,int r)
	{
		if(l==r)
		{
			mi[rt]=1ll*l*D;
			return;
		}
		int mid=(l+r)/2;
		build(rt*2,l,mid);
		build(rt*2+1,mid+1,r);
		mi[rt]=min(mi[rt*2],mi[rt*2+1]);
	}
	void Tag(int rt,llong v)
	{
		mi[rt]+=v;
		laz[rt]+=v;
	}
	void pd(int rt)
	{
		if(!laz[rt])return;
		Tag(rt*2,laz[rt]);
		Tag(rt*2+1,laz[rt]);
		laz[rt]=0;
	}
	void change(int rt,int l,int r,int st,int ed,llong v)
	{
		pd(rt);
		if(l>=st&&r<=ed)
		{
			Tag(rt,v);
			return;
		}
		int mid=(l+r)/2;
		if(mid>=st)change(rt*2,l,mid,st,ed,v);
		if(mid<ed)change(rt*2+1,mid+1,r,st,ed,v);
		mi[rt]=min(mi[rt*2],mi[rt*2+1]);
	}
	int ask(int rt,int l,int r,int st,int ed,llong v)
	{
		pd(rt);
		if(mi[rt]>v||l>ed||r<st)return n+1;
		if(l==r)return l;
		int mid=(l+r)/2;
		int lp=ask(rt*2,l,mid,st,ed,v);
		if(lp<=n)return lp;
		return ask(rt*2+1,mid+1,r,st,ed,v);
	}
	void print(int rt,int l,int r)
	{
		pd(rt);
		if(l==r)
		{
			cout<<mi[rt]<<" ";
			return;
		}
		int mid=(l+r)/2;
		print(rt*2,l,mid);
		print(rt*2+1,mid+1,r);
	}
}seg;
int s1[200200],t1;
int s2[200200],t2;
map<int,int>la;
int ml[200200];
int main()
{
	scanf("%d%d%d",&n,&K,&D);
	for(int i=1;i<=n;++i)scanf("%d",&nu[i]);
	if(D==0)
	{
		int ans,len=0;
		for(int i=1,j;i<=n;++i)
		{
			for(j=i;j<n&&nu[j+1]==nu[i];++j);
			if(j-i+1>len)len=j-i+1,ans=i;
		}
		printf("%d %d\n",ans,ans+len-1);
		return 0;
	}
	ml[0]=1;
	int L=0;
	seg.build(1,1,n);
	int p;
	int ans,len=0;
	for(int i=1;i<=n;++i)
	{
		if((nu[i]%D+D)%D==(nu[i-1]%D+D)%D)ml[i]=ml[i-1];
		else ml[i]=i;
		L=max(L,la[nu[i]]);la[nu[i]]=i;
		seg.change(1,1,n,1,n,-D);
		while(t1&&nu[i]>=nu[s1[t1]])
			seg.change(1,1,n,s1[t1-1]+1,s1[t1],-nu[s1[t1]]),t1--;
		s1[++t1]=i;
		seg.change(1,1,n,s1[t1-1]+1,s1[t1],nu[s1[t1]]);
		while(t2&&nu[i]<=nu[s2[t2]])
			seg.change(1,1,n,s2[t2-1]+1,s2[t2],nu[s2[t2]]),t2--;
		s2[++t2]=i;
		seg.change(1,1,n,s2[t2-1]+1,s2[t2],-nu[s2[t2]]);
		p=seg.ask(1,1,n,max(ml[i],L+1),i,1ll*K*D);
		if(i-p+1>len)len=i-p+1,ans=p;
		/*
		if(i==13)
		{
			seg.print(1,1,n);puts("");
		}
		*/
	}
	printf("%d %d\n",ans,ans+len-1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define llong long long
int n,K,D;
int nu[200200];
struct SEG{
	llong mi[2000200];
	llong laz[2000200];
	void build(int rt,int l,int r)
	{
		if(l==r)
		{
			mi[rt]=1ll*l*D;
			return;
		}
		int mid=(l+r)/2;
		build(rt*2,l,mid);
		build(rt*2+1,mid+1,r);
		mi[rt]=min(mi[rt*2],mi[rt*2+1]);
	}
	void Tag(int rt,llong v)
	{
		mi[rt]+=v;
		laz[rt]+=v;
	}
	void pd(int rt)
	{
		if(!laz[rt])return;
		Tag(rt*2,laz[rt]);
		Tag(rt*2+1,laz[rt]);
		laz[rt]=0;
	}
	void change(int rt,int l,int r,int st,int ed,llong v)
	{
		pd(rt);
		if(l>=st&&r<=ed)
		{
			Tag(rt,v);
			return;
		}
		int mid=(l+r)/2;
		if(mid>=st)change(rt*2,l,mid,st,ed,v);
		if(mid<ed)change(rt*2+1,mid+1,r,st,ed,v);
		mi[rt]=min(mi[rt*2],mi[rt*2+1]);
	}
	int ask(int rt,int l,int r,int st,int ed,llong v)
	{
		pd(rt);
		if(mi[rt]>v||l>ed||r<st)return n+1;
		if(l==r)return l;
		int mid=(l+r)/2;
		int lp=ask(rt*2,l,mid,st,ed,v);
		if(lp<=n)return lp;
		return ask(rt*2+1,mid+1,r,st,ed,v);
	}
}seg;
int s1[200200],t1;
int s2[200200],t2;
map<int,int>la;
int ml[200200];
int main()
{
	scanf("%d%d%d",&n,&K,&D);
	for(int i=1;i<=n;++i)scanf("%d",&nu[i]);
	if(D==0)
	{
		int ans,len=0;
		for(int i=1,j;i<=n;++i)
		{
			for(j=i;j<n&&nu[j+1]==nu[i];++j);
			if(j-i+1>len)len=j-i+1,ans=i;
		}
		printf("%d %d\n",ans,ans+len-1);
		return 0;
	}
	ml[0]=1;
	int L=0;
	seg.build(1,1,n);
	int p;
	int ans,len=0;
	for(int i=1;i<=n;++i)
	{
		if((nu[i]%D+D)%D==(nu[i-1]%D+D)%D)ml[i]=ml[i-1];
		else ml[i]=i;
		L=max(L,la[nu[i]]);la[nu[i]]=i;
		seg.change(1,1,n,1,n,-D);
		while(t1&&nu[i]>=nu[s1[t1]])
			seg.change(1,1,n,s1[t1-1]+1,s1[t1],-nu[s1[t1]]),t1--;
		s1[++t1]=i;
		seg.change(1,1,n,s1[t1-1]+1,s1[t1],nu[s1[t1]]);
		while(t2&&nu[i]<=nu[s2[t2]])
			seg.change(1,1,n,s2[t2-1]+1,s2[t2],nu[s2[t2]]),t2--;
		s2[++t2]=i;
		seg.change(1,1,n,s2[t2-1]+1,s2[t2],-nu[s2[t2]]);
		p=seg.ask(1,1,n,max(ml[i],L+1),i,1ll*K*D);
		if(i-p+1>len)len=i-p+1,ans=p;
	}
	printf("%d %d\n",ans,ans+len-1);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define llong long long
int n,K,D;
int nu[200200];
struct SEG{
	llong mi[2000200];
	llong laz[2000200];
	void build(int rt,int l,int r)
	{
		if(l==r)
		{
			mi[rt]=1ll*l*D;
			return;
		}
		int mid=(l+r)/2;
		build(rt*2,l,mid);
		build(rt*2+1,mid+1,r);
		mi[rt]=min(mi[rt*2],mi[rt*2+1]);
	}
	void Tag(int rt,llong v)
	{
		mi[rt]+=v;
		laz[rt]+=v;
	}
	void pd(int rt)
	{
		if(!laz[rt])return;
		Tag(rt*2,laz[rt]);
		Tag(rt*2+1,laz[rt]);
		laz[rt]=0;
	}
	void change(int rt,int l,int r,int st,int ed,llong v)
	{
		pd(rt);
		if(l>=st&&r<=ed)
		{
			Tag(rt,v);
			return;
		}
		int mid=(l+r)/2;
		if(mid>=st)change(rt*2,l,mid,st,ed,v);
		if(mid<ed)change(rt*2+1,mid+1,r,st,ed,v);
		mi[rt]=min(mi[rt*2],mi[rt*2+1]);
	}
	int ask(int rt,int l,int r,int st,int ed,llong v)
	{
		pd(rt);
		if(mi[rt]>v||l>ed||r<st)return n+1;
		if(l==r)return l;
		int mid=(l+r)/2;
		int lp=ask(rt*2,l,mid,st,ed,v);
		if(lp<=n)return lp;
		return ask(rt*2+1,mid+1,r,st,ed,v);
	}
}seg;
int s1[200200],t1;
int s2[200200],t2;
map<int,int>la;
int ml[200200];
int main()
{
	scanf("%d%d%d",&n,&K,&D);
	for(int i=1;i<=n;++i)scanf("%d",&nu[i]);
	if(D==0)
	{
		int ans,len=0;
		for(int i=1,j;i<=n;++i)
		{
			for(j=i;j<n&&nu[j+1]==nu[i];++j);
			if(j-i+1>len)len=j-i+1,ans=i;
		}
		printf("%d %d\n",ans,ans+len-1);
		return 0;
	}
	ml[0]=1;
	int L=0;
	seg.build(1,1,n);
	int p;
	int ans,len=0;
	for(int i=1;i<=n;++i)
	{
		if((nu[i]%D+D)%D==(nu[i-1]%D+D)%D)ml[i]=ml[i-1];
		else ml[i]=i;
		L=max(L,la[nu[i]]);la[nu[i]]=i;
		seg.change(1,1,n,1,n,-D);
		while(t1&&nu[i]>=nu[s1[t1]])
			seg.change(1,1,n,s1[t1-1]+1,s1[t1],-nu[s1[t1]]),t1--;
		s1[++t1]=i;
		seg.change(1,1,n,s1[t1-1]+1,s1[t1],nu[s1[t1]]);
		while(t2&&nu[i]>=nu[s2[t2]])
			seg.change(1,1,n,s2[t2-1]+1,s2[t2],nu[s2[t2]]),t2--;
		s2[++t2]=i;
		seg.change(1,1,n,s2[t2-1]+1,s2[t2],-nu[s2[t2]]);
		p=seg.ask(1,1,n,max(ml[i],L+1),i,1ll*K*D);
		if(i-p+1>len)len=i-p+1,ans=p;
	}
	printf("%d %d\n",ans,ans+len-1);
	return 0;
}


/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ?
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
	static short st[30];short tp=0;
	if(x<0) putchar('-'),x=-x;
	do st[++tp]=x%10,x/=10; while(x);
	while(tp) putchar('0'|st[tp--]);
	putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

const int N = 300500;
int t1, t2, L, R, n, k, d;
int s1[N], s2[N], a[N];
int add[N<<2], mn[N<<2];

#define ls p << 1
#define rs ls | 1
inline void spread(int p) {
	mn[ls] += add[p];
	mn[rs] += add[p];
	add[ls] += add[p], add[rs] += add[p];
	add[p] = 0;
}

void change(int p, int l, int r, int L, int R, int k) {
	if (L <= l && r <= R) return add[p] += k, mn[p] += k, void();
	int mid = (l + r) >> 1; spread(p);
	if (L <= mid) change(ls, l, mid, L, R, k);
	if (R > mid) change(rs, mid + 1, r, L, R, k);
	mn[p] = min(mn[ls], mn[rs]);
}

void update(int l, int r) {
	if (r - l < R - L) return;
	if (r - l > R - L) return R = r, L = l, void();
	if (l < L) R = r, L = l;
}

int visit, now;
void query(int p, int l, int r) {
	if (l == r) return update(l, now);
	int mid = (l + r) >> 1;
	if (mn[ls] <= k) query(ls, l, mid);
	else query(rs, mid + 1, r);
}

void query(int p, int l, int r, int L, int R) {
	if (visit || mn[p] > k) return;
	if (L <= l && r <= R) return visit = 1, query(p, l, r);
	int mid = (l + r) >> 1; spread(p);
	if (L <= mid) query(ls, l, mid, L, R);
	if (mid < R) query(rs, mid + 1, r, L, R);
}

#include <map>
map<int, int> mp;
void solve(int l, int r) {
	t1 = t2 = 0; mp.clear();
	s1[0] = s2[0] = l - 1; int mx = l;
	for (int i = l;i <= r; i++) {
		while (t1 && a[s1[t1]] < a[i]) change(1, 1, n, s1[t1-1] + 1, s1[t1], -a[s1[t1]]), t1--;
		while (t2 && a[s2[t2]] > a[i]) change(1, 1, n, s2[t2-1] + 1, s2[t2], a[s2[t2]]), t2--;
		s1[++t1] = i, s2[++t2] = i;
		change(1, 1, n, s1[t1-1] + 1, i, a[i]);
		change(1, 1, n, s2[t2-1] + 1, i, -a[i]);
		if (i != 1) change(1, 1, n, 1, i - 1, -1);
		now = i; Mx(mx, mp[a[i]] + 1);
		visit = 0, query(1, 1, n, mx, i), mp[a[i]] = i;
	}
}

int main() {
	read(n), read(k), read(d); R = -1;
	for (int i = 1;i <= n; i++) read(a[i]);
	if (d == 0) {
		for (int l = 1, r = 1;l <= n; l = r) {
			while (r <= n && a[r] == a[l]) r++;
			update(l, r - 1);
		}
		write(L, ' ' ), write(R);
		return 0;
	}
	for (int l = 1, r = 1;l <= n; l = r) {
		int t = (a[l] % d + d) % d;
		while (r <= n && (a[r] % d + d) % d == t)
			a[r] = (a[r] - t) / d, r++;
		solve(l, r - 1);
	}
	write(L, ' '), write(R);
	return 0;
}


/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ?
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
	static short st[30];short tp=0;
	if(x<0) putchar('-'),x=-x;
	do st[++tp]=x%10,x/=10; while(x);
	while(tp) putchar('0'|st[tp--]);
	putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

const int N = 300500;
int t1, t2, L, R, n, k, d;
int s1[N], s2[N], a[N];
int add[N<<2], mn[N<<2];

#define ls p << 1
#define rs ls | 1
inline void spread(int p) {
	mn[ls] += add[p];
	mn[rs] += add[p];
	add[ls] += add[p], add[rs] += add[p];
	add[p] = 0;
}

void change(int p, int l, int r, int L, int R, int k) {
	if (L <= l && r <= R) return add[p] += k, mn[p] += k, void();
	int mid = (l + r) >> 1; spread(p);
	if (L <= mid) change(ls, l, mid, L, R, k);
	if (R > mid) change(rs, mid + 1, r, L, R, k);
	mn[p] = min(mn[ls], mn[rs]);
}

void update(int l, int r) {
	if (r - l < R - L) return;
	if (r - l > R - L) return R = r, L = l, void();
	if (l < L) R = r, L = l;
}

int visit, now;
void query(int p, int l, int r) {
	if (l == r) return update(l, now);
	int mid = (l + r) >> 1; spread(p);
	if (mn[ls] <= k) query(ls, l, mid);
	else query(rs, mid + 1, r);
}

void query(int p, int l, int r, int L, int R) {
	if (visit || mn[p] > k) return;
	if (L <= l && r <= R) return visit = 1, query(p, l, r);
	int mid = (l + r) >> 1; spread(p);
	if (L <= mid) query(ls, l, mid, L, R);
	if (mid < R) query(rs, mid + 1, r, L, R);
}

#include <map>
map<int, int> mp;
void solve(int l, int r) {
	t1 = t2 = 0; mp.clear();
	s1[0] = s2[0] = l - 1; int mx = l;
	for (int i = l;i <= r; i++) {
		while (t1 && a[s1[t1]] < a[i]) change(1, 1, n, s1[t1-1] + 1, s1[t1], -a[s1[t1]]), t1--;
		while (t2 && a[s2[t2]] > a[i]) change(1, 1, n, s2[t2-1] + 1, s2[t2], a[s2[t2]]), t2--;
		s1[++t1] = i, s2[++t2] = i;
		change(1, 1, n, s1[t1-1] + 1, i, a[i]);
		change(1, 1, n, s2[t2-1] + 1, i, -a[i]);
		if (i != 1) change(1, 1, n, 1, i - 1, -1);
		now = i; Mx(mx, mp[a[i]] + 1);
		visit = 0, query(1, 1, n, mx, i), mp[a[i]] = i;
	}
}

int main() {
	read(n), read(k), read(d); R = -1;
	for (int i = 1;i <= n; i++) read(a[i]);
	if (d == 0) {
		for (int l = 1, r = 1;l <= n; l = r) {
			while (r <= n && a[r] == a[l]) r++;
			update(l, r - 1);
		}
		write(L, ' ' ), write(R);
		return 0;
	}
	for (int l = 1, r = 1;l <= n; l = r) {
		int t = (a[l] % d + d) % d;
		while (r <= n && (a[r] % d + d) % d == t)
			a[r] = (a[r] - t) / d, r++;
		solve(l, r - 1);
	}
	write(L, ' '), write(R);
	return 0;
}

/*

20 1 1
1 7 8 9 6 3 2 5 6 9 8 7 1 5 5 3 2 6 9 8

*/


#include <cstdio>
#include <algorithm>

#define ll long long
#define db double
#define ull unsigned long long
#define uint unsigned int
#define FIO "sequence"
#define dbug(...) fprintf(stderr, __VA_ARGS__)

template <typename Y> inline bool updmin(Y &a, Y b){if (a > b) {a = b; return 1;} return 0;}
template <typename Y> inline bool updmax(Y &a, Y b){if (a < b) {a = b; return 1;} return 0;}
template <typename Y> inline Y abs(Y a){if (a < 0) a = -a; return a;}
template <typename Y> inline Y sqr(Y a){return a * a;}

typedef std::pair<int, int> par;
#define fx first
#define fy second
#define mpar std::make_pair
#define pb push_back

int read() {
	int w = 1, q = 0, ch = ' ';
	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') w = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) q = q * 10 + ch - 48;
	return q * w;
}

inline void FileIO(){freopen(FIO".in", "r", stdin); freopen(FIO".out", "w", stdout);}

const int maxn = 200090;

int n, k, d, a[200090], b[maxn];
#include <set>
std::set <int> s;

par ans = mpar(1, 1);

inline void updans(par pr) {
	if (pr.fy - pr.fx > ans.fy - ans.fx) {
		ans = pr;
	} else if (pr.fy - pr.fx == ans.fy - ans.fx && pr.fx < ans.fx) {
		ans = pr;
	}
}

namespace Seg{
	struct Segment{
		int l, r, mini, lazy;
	}tr[maxn << 2];

#define mid ((tr[p].l + tr[p].r) >> 1)
#define ls (p << 1)
#define rs (p << 1 | 1)

	inline void update(int p){
		tr[p].mini = std::min(tr[ls].mini, tr[rs].mini);
	}

	inline void pushdown(int p){
		if (!tr[p].lazy) return;
		tr[ls].lazy += tr[p].lazy;
		tr[rs].lazy += tr[p].lazy;
		tr[ls].mini += tr[p].lazy;
		tr[rs].mini += tr[p].lazy;
		tr[p].lazy = 0;
	}

	void Build(int p, int l, int r){
		tr[p] = (Segment){l, r, 0, 0};
		if (l == r) {
			tr[p].mini = 0;
			return;
		}
		Build(ls, l, mid);
		Build(rs, mid + 1, r);
		update(p);
	}

	int QueryMin(int p, int l, int r, int val){
		if (r < l) return -1;
		if (tr[p].mini > val) return -1;
		if (tr[p].l == tr[p].r) {
			return tr[p].l;
		}
		pushdown(p);
		if (r <= mid) {
			return QueryMin(ls, l, r, val);
		} else if (l > mid) {
			return QueryMin(rs, l, r, val);
		} else {
			int tmp = QueryMin(ls, l, mid, val);
			if (tmp == -1) {
				return QueryMin(rs, mid + 1, r, val);
			} else {
				return tmp;
			}
		}
	}

	void Modify(int p, int l, int r, int val){
		if (r < l) return;
		if (tr[p].l == l && tr[p].r == r){
			tr[p].lazy += val;
			tr[p].mini += val;
			return;
		}
		pushdown(p);
		if (r <= mid) Modify(ls, l, r, val);
		if (l > mid) Modify(rs, l, r, val);
		if (l <= mid && r > mid) Modify(ls, l, mid, val), Modify(rs, mid + 1, r, val);
		update(p);
	}
}

#include <vector>
std::vector <par> MIN, MAX;
#include <map>
std::map <int, int> MP;

inline void calc(int L, int R) {
	for (int i = L; i <= R; i++) {
		if (a[i] > 0) {
			a[i] /= d;
		} else {
			a[i] = -(-a[i] - 1) / d - 1;
		}
	}
	MIN.clear();
	MAX.clear();
	MP.clear();
	int queryleft = L;
	for (int i = L; i <= R; i++) {
		if (MP[a[i]]) {
			updmax(queryleft, MP[a[i]] + 1);
		}
		MP[a[i]] = i;
		while (MIN.size()) {
			par lst = MIN[MIN.size() - 1];
			if (lst.fx > a[i]) {
				MIN.pop_back();
				int LL;
				if (MIN.size()) {
					LL = MIN[MIN.size() - 1].fy + 1;
				} else {
					LL = L;
				}
				Seg::Modify(1, LL, lst.fy, lst.fx - a[i]);
			} else {
				break;
			}
		}
		MIN.pb(mpar(a[i], i));
		while (MAX.size()) {
			par lst = MAX[MAX.size() - 1];
			if (lst.fx < a[i]) {
				MAX.pop_back();
				int LL;
				if (MAX.size()) {
					LL = MAX[MAX.size() - 1].fy + 1;
				} else {
					LL = L;
				}
				Seg::Modify(1, LL, lst.fy, a[i] - lst.fx);
			} else {
				break;
			}
		}
		MAX.pb(mpar(a[i], i));
		Seg::Modify(1, i, i, i);
		int rev = Seg::QueryMin(1, queryleft, i, k + i);
		if (rev != -1) {
			updans(mpar(rev, i));
		}
	}
}

int main() {
	n = read(), k = read(), d = read();
	for (int i = 1; i <= n; i++) {
		a[i] = read();
	}
	if (d == 0) {
		int L = 0, R = 0;
		while (L < n) {
			L++;
			R = L;
			while (R < n && a[R + 1] == a[L]) {
				R++;
			}
			updans(mpar(L, R));
			L = R;
		}
		printf("%d %d\n", ans.fx, ans.fy);
		return 0;
	}
	Seg::Build(1, 1, n);
	int L = 0, R = 0;
	while (L < n) {
		L++;
		R = L;
		while (R < n && (a[R + 1] - a[L]) % d == 0) {
			R++;
		}
		calc(L, R);
		L = R;
	}
	printf("%d %d\n", ans.fx, ans.fy);
	return 0;
}


#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

template <typename T>
struct hash_map_t {
    vector <T> v, val, nxt;
    vector <int> head;
    int mod, tot, lastv;
    T lastans;
    bool have_ans;

    hash_map_t (int md = 0) {
        head.clear(); v.clear(); val.clear(); nxt.clear(); tot = 0; mod = md;
        nxt.resize(1); v.resize(1); val.resize(1); head.resize(mod);
        have_ans = 0;
    }

    bool count(int x) {
        int u = x % mod;
        for(register int i = head[u]; i; i = nxt[i]) {
            if(v[i] == x) {
                have_ans = 1;
                lastv = x;
                lastans = val[i];
                return 1;
            }
        }
        return 0;
    }

    void ins(int x, int y) {
        int u = x % mod;
        nxt.push_back(head[u]); head[u] = ++tot;
        v.push_back(x); val.push_back(y);
    }

    int qry(int x) {
        if(have_ans && lastv == x) return lastans;
        count(x);
        return lastans;
    }
};

const int N = 2e5 + 5, INF = 0x7fffffff;

struct node_t {
    int l, r, minn, tag;
} p[N << 2];

void update(int u) { p[u].minn = min(p[u << 1].minn, p[u << 1 | 1].minn); }

inline void add_tag(int u, int x) { p[u].minn += x; p[u].tag += x; }

void pushdown(int u) {
    if(p[u].tag) {
        add_tag(u << 1, p[u].tag);
        add_tag(u << 1 | 1, p[u].tag);
        p[u].tag = 0;
    }
}

void build(int u, int l, int r) {
    p[u].l = l; p[u].r = r; p[u].minn = 0;
    if(l == r) return;
    int mid = (l + r) >> 1;
    build(u << 1, l, mid); build(u << 1 | 1, mid + 1, r);
}

void change(int u, int l, int r, int x) {
    if(l <= p[u].l && p[u].r <= r) {
        add_tag(u, x);
        return;
    }
    pushdown(u);
    int mid = (p[u].l + p[u].r) >> 1;
    if(mid >= l) change(u << 1, l, r, x);
    if(mid + 1 <= r) change(u << 1 | 1, l, r, x);
    update(u);
}

int query(int u, int l, int r, int x) {
    if(p[u].minn > x) return 0;
    if(p[u].l == p[u].r) return p[u].l;
    int mid = (p[u].l + p[u].r) >> 1;
    if(mid >= l && mid + 1 <= r) {
        int ans = query(u << 1 | 1, l, r, x);
        if(ans) return ans;
        return query(u << 1, l, r, x);
    } else if(mid >= l) return query(u << 1, l, r, x);
    return query(u << 1 | 1, l, r, x);
}

map <int, int> pre;
int a[N], v[N], st1[N], st2[N], top1, top2;
int n, k, d, maxn, ansl, ansr, minn = INF;

int main() {
    read(n); read(k); read(d);
    for(register int i = 1; i <= n; i++) read(a[i]);
    if(d == 0) {
        int now = 1, last = 1;
        maxn = ansl = ansr = 1;
        for(register int i = 2; i <= n; i++) {
            if(a[i] == a[i - 1]) {
                ++now;
                if(now > maxn) {
                    maxn = now;
                    ansl = last;
                    ansr = i;
                }
            } else now = 1, last = i;
        }
        print(ansl, ' '); print(ansr, '\n');
        return 0;
    }
    build(1, 1, n);
    for(register int i = 1; i <= n; i++) minn = min(minn, a[i]);
    for(register int i = 1; i <= n; i++) v[i] = (v[i] - minn) / d;
    for(register int r = n, l; r >= 1; r = l - 1) {
        l = r;
        while(l - 1 && (a[l - 1] % d + d) % d == (a[r] % d + d) % d) --l;
        pre.clear(); top1 = top2 = 0; st1[0] = st2[0] = r + 1;
        for(register int i = r; i >= l; i--) {
            while(top1 && v[i] >= v[st1[top1]]) {
                change(1, st1[top1], st1[top1 - 1] - 1, v[i] - v[st1[top1]]);
                --top1;
            }
            while(top2 && v[i] <= v[st2[top2]]) {
                change(1, st2[top2], st2[top2 - 1] - 1, v[st2[top2]] - v[i]);
                --top2;
            }
            st1[++top1] = st2[++top2] = i;
            change(1, i, i, -i);
            int ans;
            if(pre.count(a[i])) ans = query(1, i, pre[a[i]] - 1, k - i);
            else ans = query(1, i, r, k - i);
            if(ans - i + 1 >= maxn) {
                maxn = ans - i + 1;
                ansl = i;
                ansr = ans;
            }
            pre[a[i]] = i;
        }
    }
    print(ansl, ' '); print(ansr, '\n');
    return 0;
}


#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

template <typename T>
struct hash_map_t {
    vector <T> v, val, nxt;
    vector <int> head;
    int mod, tot, lastv;
    T lastans;
    bool have_ans;

    hash_map_t (int md = 0) {
        head.clear(); v.clear(); val.clear(); nxt.clear(); tot = 0; mod = md;
        nxt.resize(1); v.resize(1); val.resize(1); head.resize(mod);
        have_ans = 0;
    }

    bool count(int x) {
        int u = x % mod;
        for(register int i = head[u]; i; i = nxt[i]) {
            if(v[i] == x) {
                have_ans = 1;
                lastv = x;
                lastans = val[i];
                return 1;
            }
        }
        return 0;
    }

    void ins(int x, int y) {
        int u = x % mod;
        nxt.push_back(head[u]); head[u] = ++tot;
        v.push_back(x); val.push_back(y);
    }

    int qry(int x) {
        if(have_ans && lastv == x) return lastans;
        count(x);
        return lastans;
    }
};

const int N = 2e5 + 5, INF = 0x7fffffff;

struct node_t {
    int l, r, minn, tag;
} p[N << 2];

void update(int u) { p[u].minn = min(p[u << 1].minn, p[u << 1 | 1].minn); }

inline void add_tag(int u, int x) { p[u].minn += x; p[u].tag += x; }

void pushdown(int u) {
    if(p[u].tag) {
        add_tag(u << 1, p[u].tag);
        add_tag(u << 1 | 1, p[u].tag);
        p[u].tag = 0;
    }
}

void build(int u, int l, int r) {
    p[u].l = l; p[u].r = r; p[u].minn = 0;
    if(l == r) return;
    int mid = (l + r) >> 1;
    build(u << 1, l, mid); build(u << 1 | 1, mid + 1, r);
}

void change(int u, int l, int r, int x) {
    if(l <= p[u].l && p[u].r <= r) {
        add_tag(u, x);
        return;
    }
    pushdown(u);
    int mid = (p[u].l + p[u].r) >> 1;
    if(mid >= l) change(u << 1, l, r, x);
    if(mid + 1 <= r) change(u << 1 | 1, l, r, x);
    update(u);
}

int query(int u, int l, int r, int x) {
    if(p[u].minn > x) return 0;
    if(p[u].l == p[u].r) return p[u].l;
    int mid = (p[u].l + p[u].r) >> 1;
    if(mid >= l && mid + 1 <= r) {
        int ans = query(u << 1 | 1, l, r, x);
        if(ans) return ans;
        return query(u << 1, l, r, x);
    } else if(mid >= l) return query(u << 1, l, r, x);
    return query(u << 1 | 1, l, r, x);
}

map <int, int> pre;
int a[N], v[N], st1[N], st2[N], top1, top2;
int n, k, d, maxn, ansl, ansr, minn = INF, maxr;

int main() {
    read(n); read(k); read(d);
    for(register int i = 1; i <= n; i++) read(a[i]);
    if(d == 0) {
        int now = 1, last = 1;
        maxn = ansl = ansr = 1;
        for(register int i = 2; i <= n; i++) {
            if(a[i] == a[i - 1]) {
                ++now;
                if(now > maxn) {
                    maxn = now;
                    ansl = last;
                    ansr = i;
                }
            } else now = 1, last = i;
        }
        print(ansl, ' '); print(ansr, '\n');
        return 0;
    }
    build(1, 1, n);
    for(register int i = 1; i <= n; i++) minn = min(minn, a[i]);
    for(register int i = 1; i <= n; i++) v[i] = (a[i] - minn) / d;
    for(register int r = n, l; r >= 1; r = l - 1) {
        l = r;
        while(l - 1 && (a[l - 1] % d + d) % d == (a[r] % d + d) % d) --l;
        pre.clear(); top1 = top2 = 0; st1[0] = st2[0] = r + 1; maxr = r;
        for(register int i = r; i >= l; i--) {
            while(top1 && v[i] >= v[st1[top1]]) {
                change(1, st1[top1], st1[top1 - 1] - 1, v[i] - v[st1[top1]]);
                --top1;
            }
            while(top2 && v[i] <= v[st2[top2]]) {
                change(1, st2[top2], st2[top2 - 1] - 1, v[st2[top2]] - v[i]);
                --top2;
            }
            st1[++top1] = st2[++top2] = i;
            change(1, i, i, -i);
            if(pre.count(a[i])) maxr = min(maxr, pre[a[i]] - 1);
            int ans = query(1, i, maxr, k - i);
            if(ans - i + 1 >= maxn) {
                maxn = ans - i + 1;
                ansl = i;
                ansr = ans;
            }
            pre[a[i]] = i;
        }
    }
    print(ansl, ' '); print(ansr, '\n');
    return 0;
}


#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

template <typename T>
struct hash_map_t {
    vector <T> v, val, nxt;
    vector <int> head;
    int mod, tot, lastv;
    T lastans;
    bool have_ans;

    hash_map_t (int md = 0) {
        head.clear(); v.clear(); val.clear(); nxt.clear(); tot = 0; mod = md;
        nxt.resize(1); v.resize(1); val.resize(1); head.resize(mod);
        have_ans = 0;
    }

    bool count(int x) {
        int u = x % mod;
        for(register int i = head[u]; i; i = nxt[i]) {
            if(v[i] == x) {
                have_ans = 1;
                lastv = x;
                lastans = val[i];
                return 1;
            }
        }
        return 0;
    }

    void ins(int x, int y) {
        int u = x % mod;
        nxt.push_back(head[u]); head[u] = ++tot;
        v.push_back(x); val.push_back(y);
    }

    int qry(int x) {
        if(have_ans && lastv == x) return lastans;
        count(x);
        return lastans;
    }
};

const int N = 2e5 + 5, INF = 0x7fffffff;

struct node_t {
    int l, r, minn, tag;
} p[N << 2];

void update(int u) { p[u].minn = min(p[u << 1].minn, p[u << 1 | 1].minn); }

inline void add_tag(int u, int x) { p[u].minn += x; p[u].tag += x; }

void pushdown(int u) {
    if(p[u].tag) {
        add_tag(u << 1, p[u].tag);
        add_tag(u << 1 | 1, p[u].tag);
        p[u].tag = 0;
    }
}

void build(int u, int l, int r) {
    p[u].l = l; p[u].r = r; p[u].minn = 0;
    if(l == r) return;
    int mid = (l + r) >> 1;
    build(u << 1, l, mid); build(u << 1 | 1, mid + 1, r);
}

void change(int u, int l, int r, int x) {
    if(l <= p[u].l && p[u].r <= r) {
        add_tag(u, x);
        return;
    }
    pushdown(u);
    int mid = (p[u].l + p[u].r) >> 1;
    if(mid >= l) change(u << 1, l, r, x);
    if(mid + 1 <= r) change(u << 1 | 1, l, r, x);
    update(u);
}

int query(int u, int l, int r, int x) {
    if(p[u].minn > x) return 0;
    if(p[u].l == p[u].r) return p[u].l;
    pushdown(u);
    int mid = (p[u].l + p[u].r) >> 1;
    if(mid >= l && mid + 1 <= r) {
        int ans = query(u << 1 | 1, l, r, x);
        if(ans) return ans;
        return query(u << 1, l, r, x);
    } else if(mid >= l) return query(u << 1, l, r, x);
    return query(u << 1 | 1, l, r, x);
}

map <int, int> pre;
int a[N], v[N], st1[N], st2[N], top1, top2;
int n, k, d, maxn, ansl, ansr, minn = INF, maxr;

int main() {
    read(n); read(k); read(d);
    for(register int i = 1; i <= n; i++) read(a[i]);
    if(d == 0) {
        int now = 1, last = 1;
        maxn = ansl = ansr = 1;
        for(register int i = 2; i <= n; i++) {
            if(a[i] == a[i - 1]) {
                ++now;
                if(now > maxn) {
                    maxn = now;
                    ansl = last;
                    ansr = i;
                }
            } else now = 1, last = i;
        }
        print(ansl, ' '); print(ansr, '\n');
        return 0;
    }
    build(1, 1, n);
    for(register int i = 1; i <= n; i++) minn = min(minn, a[i]);
    for(register int i = 1; i <= n; i++) v[i] = (a[i] - minn) / d;
    for(register int r = n, l; r >= 1; r = l - 1) {
        l = r;
        while(l - 1 && (a[l - 1] % d + d) % d == (a[r] % d + d) % d) --l;
        pre.clear(); top1 = top2 = 0; st1[0] = st2[0] = r + 1; maxr = r;
        for(register int i = r; i >= l; i--) {
            while(top1 && v[i] >= v[st1[top1]]) {
                change(1, st1[top1], st1[top1 - 1] - 1, v[i] - v[st1[top1]]);
                --top1;
            }
            while(top2 && v[i] <= v[st2[top2]]) {
                change(1, st2[top2], st2[top2 - 1] - 1, v[st2[top2]] - v[i]);
                --top2;
            }
            st1[++top1] = st2[++top2] = i;
            change(1, i, i, -i);
            if(pre.count(a[i])) maxr = min(maxr, pre[a[i]] - 1);
            int ans = query(1, i, maxr, k - i);
            if(ans - i + 1 >= maxn) {
                maxn = ans - i + 1;
                ansl = i;
                ansr = ans;
            }
            pre[a[i]] = i;
        }
    }
    print(ansl, ' '); print(ansr, '\n');
    return 0;
}


#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

template <typename T>
struct hash_map_t {
    vector <T> v, val, nxt;
    vector <int> head;
    int mod, tot, lastv;
    T lastans;
    bool have_ans;

    hash_map_t (int md = 0) {
        head.clear(); v.clear(); val.clear(); nxt.clear(); tot = 0; mod = md;
        nxt.resize(1); v.resize(1); val.resize(1); head.resize(mod);
        have_ans = 0;
    }

    bool count(int x) {
        int u = x % mod;
        for(register int i = head[u]; i; i = nxt[i]) {
            if(v[i] == x) {
                have_ans = 1;
                lastv = x;
                lastans = val[i];
                return 1;
            }
        }
        return 0;
    }

    void ins(int x, int y) {
        int u = x % mod;
        nxt.push_back(head[u]); head[u] = ++tot;
        v.push_back(x); val.push_back(y);
    }

    int qry(int x) {
        if(have_ans && lastv == x) return lastans;
        count(x);
        return lastans;
    }
};

const int N = 2e5 + 5, INF = 0x7fffffff;

struct node_t {
    int l, r, minn, tag;
} p[N << 2];

void update(int u) { p[u].minn = min(p[u << 1].minn, p[u << 1 | 1].minn); }

inline void add_tag(int u, int x) { p[u].minn += x; p[u].tag += x; }

void pushdown(int u) {
    if(p[u].tag) {
        add_tag(u << 1, p[u].tag);
        add_tag(u << 1 | 1, p[u].tag);
        p[u].tag = 0;
    }
}

void build(int u, int l, int r) {
    p[u].l = l; p[u].r = r; p[u].minn = 0;
    if(l == r) return;
    int mid = (l + r) >> 1;
    build(u << 1, l, mid); build(u << 1 | 1, mid + 1, r);
}

void change(int u, int l, int r, int x) {
    if(l <= p[u].l && p[u].r <= r) {
        add_tag(u, x);
        return;
    }
    pushdown(u);
    int mid = (p[u].l + p[u].r) >> 1;
    if(mid >= l) change(u << 1, l, r, x);
    if(mid + 1 <= r) change(u << 1 | 1, l, r, x);
    update(u);
}

int query(int u, int l, int r, int x) {
    if(p[u].minn > x) return 0;
    if(p[u].l == p[u].r) return p[u].l;
    int mid = (p[u].l + p[u].r) >> 1;
    if(mid >= l && mid + 1 <= r) {
        int ans = query(u << 1 | 1, l, r, x);
        if(ans) return ans;
        return query(u << 1, l, r, x);
    } else if(mid >= l) return query(u << 1, l, r, x);
    return query(u << 1 | 1, l, r, x);
}

map <int, int> pre;
int a[N], v[N], st1[N], st2[N], top1, top2;
int n, k, d, maxn, ansl, ansr, minn = INF, maxr;

int main() {
    read(n); read(k); read(d);
    for(register int i = 1; i <= n; i++) read(a[i]);
    if(d == 0) {
        int now = 1, last = 1;
        maxn = ansl = ansr = 1;
        for(register int i = 2; i <= n; i++) {
            if(a[i] == a[i - 1]) {
                ++now;
                if(now > maxn) {
                    maxn = now;
                    ansl = last;
                    ansr = i;
                }
            } else now = 1, last = i;
        }
        print(ansl, ' '); print(ansr, '\n');
        return 0;
    }
    build(1, 1, n);
    for(register int i = 1; i <= n; i++) minn = min(minn, a[i]);
    for(register int i = 1; i <= n; i++) v[i] = (a[i] - minn) / d + 1;
    for(register int r = n, l; r >= 1; r = l - 1) {
        l = r;
        while(l - 1 && (a[l - 1] % d + d) % d == (a[r] % d + d) % d) --l;
        pre.clear(); top1 = top2 = 0; st1[0] = st2[0] = r + 1; maxr = r;
        for(register int i = r; i >= l; i--) {
            while(top1 && v[i] >= v[st1[top1]]) {
                change(1, st1[top1], st1[top1 - 1] - 1, v[i] - v[st1[top1]]);
                --top1;
            }
            while(top2 && v[i] <= v[st2[top2]]) {
                change(1, st2[top2], st2[top2 - 1] - 1, v[st2[top2]] - v[i]);
                --top2;
            }
            st1[++top1] = st2[++top2] = i;
            change(1, i, i, -i);
            if(pre.count(a[i])) maxr = min(maxr, pre[a[i]] - 1);
            int ans = query(1, i, maxr, k - i);
            if(ans - i + 1 >= maxn) {
                maxn = ans - i + 1;
                ansl = i;
                ansr = ans;
            }
            pre[a[i]] = i;
        }
    }
    print(ansl, ' '); print(ansr, '\n');
    return 0;
}


#include<map>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e5+5;
map<int,int>M;
int n,a[N],k,d,pll=2147483647,prr=2147483647,tot;//mmp读题是硬伤
int mod[N],lim,t1,t2;
void solve_common(){
	int ans=0,l=-1,ansl,ansr;
	for(int i=1;i<=n;i++){
		if(a[i-1]!=a[i])l=i;
		if(i-l+1>ans)ans=i-l+1,ansl=l,ansr=i;
	}
	printf("%d %d\n",ansl,ansr);
}
struct S{int l,r,d;}s1[N],s2[N],t;
// d1=max+l d2=-min+l d=max-min+l lz1=l&r the min lz2=l&r the max of the left
struct N{int l,r,lc,rc,d1,d2,d,lz1,lz2;}node[N<<1];//l=lline r=rline lc=lson rc=rson
void pushdown(int now){//get the min and put it down
	int lc=node[now].lc,rc=node[now].rc;
	if(node[now].lz1!=-1 && node[now].lz2!=-1){
        node[now].d=node[now].lz1-node[now].lz2+node[now].l;//
        node[now].d1=node[now].lz1+node[now].l;//
        node[now].d2=-node[now].lz2+node[now].l;//
        node[lc].lz1=node[now].lz1;node[lc].lz2=node[now].lz2;
        node[rc].lz1=node[now].lz1;node[rc].lz2=node[now].lz2;
    }
    else if(node[now].lz1!=-1){
        node[now].d=node[now].d2+node[now].lz1;//
        node[now].d1=node[now].lz1+node[now].l;//
        node[lc].lz1=node[now].lz1;node[rc].lz1=node[now].lz1;
    }
    else if(node[now].lz2!=-1){
        node[now].d=node[now].d1-node[now].lz2;//
        node[now].d2=-node[now].lz2+node[now].l;//
        node[lc].lz2=node[now].lz2;node[rc].lz2=node[now].lz2;
    }
    node[now].lz1=node[now].lz2=-1;
}
void update(int now){
	int lc=node[now].lc,rc=node[now].rc;pushdown(lc),pushdown(rc);
	node[now].d=min(node[lc].d,node[rc].d);
	node[now].d1=min(node[lc].d1,node[rc].d1);
	node[now].d2=min(node[lc].d2,node[rc].d2);
}
void build(int l,int r){//build tree
	int now=++tot;
	node[now].l=l,node[now].r=r,node[now].lz1=node[now].lz2=-1;
	if(l<r){
		int mid=(l+r)>>1;
		node[now].lc=tot+1,build(l,mid);
		node[now].rc=tot+1,build(mid+1,r);
		update(now);
	}
	else node[now].d1=node[now].d2=node[now].d=l;
}
void modify(int now,int l,int r,int d,int o){
	int lc=node[now].lc,rc=node[now].rc,mid=(node[now].l+node[now].r)>>1;pushdown(now);
	if(node[now].l==l&&node[now].r==r){if(o==1)node[now].lz1=d;else node[now].lz2=d;return ;}
	if(mid>=r)modify(lc,l,r,d,o);
	else if(l>mid)modify(rc,l,r,d,o);
	else modify(lc,l,mid,d,o),modify(rc,mid+1,r,d,o);
	update(now);
}
int find(int now,int l,int r){
	int lc=node[now].lc,rc=node[now].rc,mid=(node[now].l+node[now].r)>>1;pushdown(now);
    if(node[now].d>lim)return -1;
    if(node[now].l==node[now].r) return node[now].l;//single point
    if(mid>=r) return find(lc,l,r);
    else if(l>mid) return find(rc,l,r);
    else{
        int t=find(lc,l,mid);//from left to right
        if(t==-1) t=find(rc,mid+1,r);
        return t;//minimum
    }
}
void solve(int st,int ed){
	t1=t2=0;int pre=st;
    for(int i=st;i<=ed;i++){
        t=(S){i,i,a[i]/d};
        while(t1 && s1[t1].d<t.d) {t.l=s1[t1].l;t1--;}
        s1[++t1]=t;
        modify(1,s1[t1].l,s1[t1].r,s1[t1].d,1);
        t=(S){i,i,a[i]/d};
        while(t2 && s2[t2].d>t.d) {t.l=s2[t2].l;t2--;}
        s2[++t2]=t;
        modify(1,s2[t2].l,s2[t2].r,s2[t2].d,2);
        if(M.count(a[i])) pre=max(pre,M[a[i]]+1);
        lim=i+k;
        int l=find(1,pre,i);
        if(i-l>prr-pll||(i-l==prr-pll&&pll>l))pll=l,prr=i;
        M[a[i]]=i;
    }
}
int main(){
	scanf("%d%d%d",&n,&k,&d);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);int mini=a[1];
	for(int i=2;i<=n;i++)mini=min(mini,a[i]);
	for(int i=1;i<=n;i++)a[i]+=abs(mini);
	if(!d){solve_common();}
	else {
		build(1,n);
		for(int i=1;i<=n;i++)mod[i]=a[i]%d;
		int st=1;
		while(st<n){
	        int ed=st;
	        while(ed<=n&&mod[ed]==mod[st])ed++;ed--;
	        solve(st,ed);st=ed+1;
	    }
		//for(int i=1;i<=n;i++)cout<<mod[i]<<" ";putchar('\n');
		//for(int i=1;i<=n;i++)cout<<fir[i]<<" ";putchar('\n');
		printf("%d %d\n",pll,prr);
	}
}


#include<map>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e5+5;
map<int,int>M;
int n,a[N],k,d,pll,prr,tot;//mmp读题是硬伤
int mod[N],lim,t1,t2;
void solve_common(){
	int ans=0,l=-1,ansl,ansr;
	for(int i=1;i<=n;i++){
		if(a[i-1]!=a[i])l=i;
		if(i-l+1>ans)ans=i-l+1,ansl=l,ansr=i;
	}
	printf("%d %d\n",ansl,ansr);
}
struct S{int l,r,d;}s1[N],s2[N],t;
// d1=max+l d2=-min+l d=max-min+l lz1=l&r the min lz2=l&r the max of the left
struct N{int l,r,lc,rc,d1,d2,d,lz1,lz2;}node[N<<1];//l=lline r=rline lc=lson rc=rson
void pushdown(int now){//get the min and put it down
	int lc=node[now].lc,rc=node[now].rc;
	if(node[now].lz1!=-1 && node[now].lz2!=-1){
        node[now].d=node[now].lz1-node[now].lz2+node[now].l;//
        node[now].d1=node[now].lz1+node[now].l;//
        node[now].d2=-node[now].lz2+node[now].l;//
        node[lc].lz1=node[now].lz1;node[lc].lz2=node[now].lz2;
        node[rc].lz1=node[now].lz1;node[rc].lz2=node[now].lz2;
    }
    else if(node[now].lz1!=-1){
        node[now].d=node[now].d2+node[now].lz1;//
        node[now].d1=node[now].lz1+node[now].l;//
        node[lc].lz1=node[now].lz1;node[rc].lz1=node[now].lz1;
    }
    else if(node[now].lz2!=-1){
        node[now].d=node[now].d1-node[now].lz2;//
        node[now].d2=-node[now].lz2+node[now].l;//
        node[lc].lz2=node[now].lz2;node[rc].lz2=node[now].lz2;
    }
    node[now].lz1=node[now].lz2=-1;
}
void update(int now){
	int lc=node[now].lc,rc=node[now].rc;pushdown(lc),pushdown(rc);
	node[now].d=min(node[lc].d,node[rc].d);
	node[now].d1=min(node[lc].d1,node[rc].d1);
	node[now].d2=min(node[lc].d2,node[rc].d2);
}
void build(int l,int r){//build tree
	int now=++tot;
	node[now].l=l,node[now].r=r,node[now].lz1=node[now].lz2=-1;
	if(l<r){
		int mid=(l+r)>>1;
		node[now].lc=tot+1,build(l,mid);
		node[now].rc=tot+1,build(mid+1,r);
		update(now);
	}
	else node[now].d1=node[now].d2=node[now].d=l;
}
void modify(int now,int l,int r,int d,int o){
	int lc=node[now].lc,rc=node[now].rc,mid=(node[now].l+node[now].r)>>1;pushdown(now);
	if(node[now].l==l&&node[now].r==r){if(o==1)node[now].lz1=d;else node[now].lz2=d;return ;}
	if(mid>=r)modify(lc,l,r,d,o);
	else if(l>mid)modify(rc,l,r,d,o);
	else modify(lc,l,mid,d,o),modify(rc,mid+1,r,d,o);
	update(now);
}
int find(int now,int l,int r){
	int lc=node[now].lc,rc=node[now].rc,mid=(node[now].l+node[now].r)>>1;pushdown(now);
    if(node[now].d>lim)return -1;
    if(node[now].l==node[now].r) return node[now].l;//single point
    if(mid>=r) return find(lc,l,r);
    else if(l>mid) return find(rc,l,r);
    else{
        int t=find(lc,l,mid);//from left to right
        if(t==-1) t=find(rc,mid+1,r);
        return t;//minimum
    }
}
void solve(int st,int ed){
	t1=t2=0;int pre=st;
    for(int i=st;i<=ed;i++){
        t=(S){i,i,a[i]/d};
        while(t1 && s1[t1].d<t.d) {t.l=s1[t1].l;t1--;}
        s1[++t1]=t;
        modify(1,s1[t1].l,s1[t1].r,s1[t1].d,1);
        t=(S){i,i,a[i]/d};
        while(t2 && s2[t2].d>t.d) {t.l=s2[t2].l;t2--;}
        s2[++t2]=t;
        modify(1,s2[t2].l,s2[t2].r,s2[t2].d,2);
        if(M.count(a[i])) pre=max(pre,M[a[i]]+1);
        lim=i+k;
        int l=find(1,pre,i);
        if(i-l>prr-pll)pll=l,prr=i;
        M[a[i]]=i;
    }
}
int main(){
	scanf("%d%d%d",&n,&k,&d);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);int mini=a[1];
	for(int i=2;i<=n;i++)mini=min(mini,a[i]);
	for(int i=1;i<=n;i++)a[i]+=abs(mini);
	if(!d){solve_common();}
	else {
		build(1,n);
		for(int i=1;i<=n;i++)mod[i]=a[i]%d;
		int st=1;
		while(st<n){
	        int ed=st;
	        while(ed<=n&&mod[ed]==mod[st])ed++;ed--;
	        solve(st,ed);st=ed+1;
	    }
		//for(int i=1;i<=n;i++)cout<<mod[i]<<" ";putchar('\n');
		//for(int i=1;i<=n;i++)cout<<fir[i]<<" ";putchar('\n');
		printf("%d %d\n",pll,prr);
	}
}


#include<bits/stdc++.h>
#define re register
#define LL long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read() {
	char c=getchar();int x=0,r=1;
	while(c<'0'||c>'9') {if(c=='-')r=-1;c=getchar();}
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-48,c=getchar();return r*x;
}
const int maxn=2e5+5;
int n,K,D,ansl,ansr,tot,sz[2],tmp;
int a[maxn],v[maxn],res[maxn],va[maxn];
int B[maxn],A[maxn],lm[maxn],tax[maxn];
namespace subtask1 {
	int b[maxn];
	inline int solve() {
		b[1]=1;
		for(re int i=2;i<=n;i++)
			b[i]=(a[i]==a[i-1]?b[i-1]:i);
		for(re int i=1;i<=n;++i)
			if(i-b[i]+1>ansr-ansl+1) ansl=b[i],ansr=i;
		return printf("%d %d\n",ansl,ansr),0;
	}
}
struct Stack{int x,y,v;}st[2][maxn];
int l[maxn*3],r[maxn*3],tag[maxn*3],d[maxn*3];
inline void pushr(int i,int dt) {tag[i]+=dt,d[i]+=dt;}
inline void pushup(int i) {d[i]=min(d[i<<1],d[i<<1|1]);}
inline void pushdown(int i) {
	if(!tag[i])return;pushr(i<<1,tag[i]);
	pushr(i<<1|1,tag[i]);tag[i]=0;
}
void bud(int x,int y,int i) {
	l[i]=x,r[i]=y;d[i]=x;tag[i]=0;if(x==y)return;
	int mid=x+y>>1;bud(x,mid,i<<1),bud(mid+1,y,i<<1|1);
}
void chg(int x,int y,int i,int dt) {
	if(x<=l[i]&&y>=r[i]) {pushr(i,dt);return;}
	int mid=l[i]+r[i]>>1;pushdown(i);
	if(x<=mid) chg(x,y,i<<1,dt);
	if(y>mid) chg(x,y,i<<1|1,dt);pushup(i);
}
int ask(int i,int dt) {
	if(l[i]==r[i]) return l[i];
	if(d[i<<1]<=dt) return ask(i<<1,dt);
	return ask(i<<1|1,dt);
}
int qry(int x,int y,int i,int dt) {
	if(x<=l[i]&&y>=r[i]) {
		if(d[i]<=dt) return ask(i,dt);
		return n+1;
	}
	int mid=l[i]+r[i]>>1;pushdown(i);
	if(y<=mid) return qry(x,y,i<<1,dt);
	if(x>mid) return qry(x,y,i<<1|1,dt);
	int h=qry(x,y,i<<1,dt);
	return h==n+1?qry(x,y,i<<1|1,dt):h;
}
inline void calc(int pos) {
	bud(1,tot,1);sz[0]=sz[1]=0;
	for(re int i=1;i<=tot;++i)B[i]=A[i];
	std::sort(B+1,B+tot+1);tmp=std::unique(B+1,B+tot+1)-B-1;
	for(re int i=1;i<=tot;++i)
		A[i]=std::lower_bound(B+1,B+tmp+1,A[i])-B;
	for(re int i=1;i<=tmp;++i) tax[i]=0;int L=1;
	for(re int i=1;i<=tot;++i) {
		while(tax[A[i]]) --tax[A[L]],++L;
		lm[i]=L;tax[A[i]]=1;
	}
	for(re int i=1;i<=tot;++i) {
		int L=i;
		while(sz[0]&&st[0][sz[0]].v<=va[i]) {
			L=st[0][sz[0]].x;
			chg(st[0][sz[0]].x,st[0][sz[0]].y,1,-st[0][sz[0]].v);
			--sz[0];
		}
		st[0][++sz[0]]=(Stack){L,i,va[i]};
		chg(st[0][sz[0]].x,st[0][sz[0]].y,1,st[0][sz[0]].v);
		L=i;
		while(sz[1]&&st[1][sz[1]].v>=va[i]) {
			L=st[1][sz[1]].x;
			chg(st[1][sz[1]].x,st[1][sz[1]].y,1,st[1][sz[1]].v);
			--sz[1];
		}
		st[1][++sz[1]]=(Stack){L,i,va[i]};
		chg(st[1][sz[1]].x,st[1][sz[1]].y,1,-st[1][sz[1]].v);
		int t=qry(lm[i],i,1,K+i);
		if(i-t+1>ansr-ansl+1) ansr=pos+i,ansl=pos+t;
	}
	tot=tmp=0;
}
int main() {
	n=read(),K=read(),D=read();int M=0;
	for(re int i=1;i<=n;i++) {
		a[i]=read();
		if(a[i]<0) M=min(M,a[i]);
	}
	for(re int i=1;i<=n;i++) a[i]-=M;
	if(D==0) return subtask1::solve();
	for(re int i=1;i<=n;i++)
		res[i]=a[i]%D,v[i]=a[i]/D;
	int L=1;res[n+1]=D;
	for(re int i=2;i<=n+1;++i)
		if(res[i]!=res[i-1]) {
			for(re int j=L;j<i;++j)
				va[++tot]=v[j],A[tot]=a[j];
			calc(L-1);L=i;
		}
	printf("%d %d\n",ansl,ansr);
	return 0;
}
/*
6 1 2
4 3 2 2 6 2
*/


#include<bits/stdc++.h>
#define re register
#define LL long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read() {
	char c=getchar();int x=0,r=1;
	while(c<'0'||c>'9') {if(c=='-')r=-1;c=getchar();}
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-48,c=getchar();return r*x;
}
const int maxn=2e5+5;
int n,K,D,ansl=1,ansr=1,tot,sz[2],tmp;
int a[maxn],v[maxn],res[maxn],va[maxn];
int B[maxn],A[maxn],lm[maxn],tax[maxn];
namespace subtask1 {
	int b[maxn];
	inline int solve() {
		b[1]=1;
		for(re int i=2;i<=n;i++)
			b[i]=(a[i]==a[i-1]?b[i-1]:i);
		for(re int i=1;i<=n;++i)
			if(i-b[i]+1>ansr-ansl+1) ansl=b[i],ansr=i;
		return printf("%d %d\n",ansl,ansr),0;
	}
}
struct Stack{int x,y,v;}st[2][maxn];
int l[maxn*3],r[maxn*3],tag[maxn*3],d[maxn*3];
inline void pushr(int i,int dt) {tag[i]+=dt,d[i]+=dt;}
inline void pushup(int i) {d[i]=min(d[i<<1],d[i<<1|1]);}
inline void pushdown(int i) {
	if(!tag[i])return;pushr(i<<1,tag[i]);
	pushr(i<<1|1,tag[i]);tag[i]=0;
}
void bud(int x,int y,int i) {
	l[i]=x,r[i]=y;d[i]=x;tag[i]=0;if(x==y)return;
	int mid=x+y>>1;bud(x,mid,i<<1),bud(mid+1,y,i<<1|1);
}
void chg(int x,int y,int i,int dt) {
	if(x<=l[i]&&y>=r[i]) {pushr(i,dt);return;}
	int mid=l[i]+r[i]>>1;pushdown(i);
	if(x<=mid) chg(x,y,i<<1,dt);
	if(y>mid) chg(x,y,i<<1|1,dt);pushup(i);
}
int ask(int i,int dt) {
	if(l[i]==r[i]) return l[i];pushdown(i);
	if(d[i<<1]<=dt) return ask(i<<1,dt);
	return ask(i<<1|1,dt);
}
int qry(int x,int y,int i,int dt) {
	if(x<=l[i]&&y>=r[i]) {
		if(d[i]<=dt) return ask(i,dt);
		return n+1;
	}
	int mid=l[i]+r[i]>>1;pushdown(i);
	if(y<=mid) return qry(x,y,i<<1,dt);
	if(x>mid) return qry(x,y,i<<1|1,dt);
	int h=qry(x,y,i<<1,dt);
	return h==n+1?qry(x,y,i<<1|1,dt):h;
}
inline void calc(int pos) {
	bud(1,tot,1);sz[0]=sz[1]=0;
	for(re int i=1;i<=tot;++i)B[i]=A[i];
	std::sort(B+1,B+tot+1);tmp=std::unique(B+1,B+tot+1)-B-1;
	for(re int i=1;i<=tot;++i)
		A[i]=std::lower_bound(B+1,B+tmp+1,A[i])-B;
	for(re int i=1;i<=tmp;++i) tax[i]=0;int L=1;
	for(re int i=1;i<=tot;++i) {
		while(tax[A[i]]) --tax[A[L]],++L;
		lm[i]=L;tax[A[i]]=1;
	}
	for(re int i=1;i<=tot;++i) {
		int L=i;
		while(sz[0]&&st[0][sz[0]].v<=va[i]) {
			L=st[0][sz[0]].x;
			chg(st[0][sz[0]].x,st[0][sz[0]].y,1,-st[0][sz[0]].v);
			--sz[0];
		}
		st[0][++sz[0]]=(Stack){L,i,va[i]};
		chg(st[0][sz[0]].x,st[0][sz[0]].y,1,st[0][sz[0]].v);
		L=i;
		while(sz[1]&&st[1][sz[1]].v>=va[i]) {
			L=st[1][sz[1]].x;
			chg(st[1][sz[1]].x,st[1][sz[1]].y,1,st[1][sz[1]].v);
			--sz[1];
		}
		st[1][++sz[1]]=(Stack){L,i,va[i]};
		chg(st[1][sz[1]].x,st[1][sz[1]].y,1,-st[1][sz[1]].v);
		int t=qry(lm[i],i,1,K+i);
		if(i-t+1>ansr-ansl+1) ansr=pos+i,ansl=pos+t;
	}
	tot=tmp=0;
}
int main() {
	n=read(),K=read(),D=read();int M=0;
	for(re int i=1;i<=n;i++) {
		a[i]=read();
		if(a[i]<0) M=min(M,a[i]);
	}
	for(re int i=1;i<=n;i++) a[i]-=M;
	if(D==0) return subtask1::solve();
	for(re int i=1;i<=n;i++)
		res[i]=a[i]%D,v[i]=a[i]/D;
	int L=1;res[n+1]=D;
	for(re int i=2;i<=n+1;++i)
		if(res[i]!=res[i-1]) {
			for(re int j=L;j<i;++j)
				va[++tot]=v[j],A[tot]=a[j];
			calc(L-1);L=i;
		}
	printf("%d %d\n",ansl,ansr);
	return 0;
}
/*
7 0 1
7654 55700 32362 32363 32361 32365 32364
*/


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10,M=1e9,INF=1e18;
int a[N],b[N],s1[N],s2[N];
int n,m,k,d,top1,top2,ansr,ansl,sum[N],pos[N],t[N],mn[N];
map<int,int>mp;
void reset(int x){
	mn[x]=INF;
	for(int i=(x-1)*m+1;i<=min(n,x*m);i++) mn[x]=min(mn[x],t[i]+sum[x]);
}
inline void add(int l,int r,int c){
	for(int i=l;i<=min(r,pos[l]*m);i++) t[i]+=c;
	reset(pos[l]);
	if(pos[l]!=pos[r]){
		for(int i=(pos[r]-1)*m+1;i<=min(n,r);i++) t[i]+=c;
		reset(pos[r]);
	}
	for(int i=pos[l]+1;i<=pos[r]-1;i++) sum[i]+=c,mn[i]+=c;
}
inline int query(int l,int r,int c){
	for(int i=r;i>=max((pos[r]-1)*m+1,l);i--)
		if(t[i]+sum[pos[i]]<=c){ return i;}

	for(int i=pos[r]-1;i>=pos[l]+1;i--)
		if(mn[i]<=c)
			for(int j=i*m;j>=(i-1)*m+1;j--)
				if(t[j]+sum[pos[j]]<=c) {return j;}
	if(pos[l]!=pos[r]){
		for(int i=pos[l]*m;i>=l;i--) {
			if(t[i]+sum[pos[i]]<=c)return i;
		}
	}
}
inline void sol(int L,int R){
	if(L==R) return ;
	mp.clear();int r=R+1;
	top1=top2=0;s1[top1]=s2[top2]=R+1;
	for(int i=0;i<=pos[n];i++) sum[i]=0;
	for(int i=R;i>=L;i--){
		if(mp.count(a[i])) r=min(r,mp[a[i]]);
		while(top1 && a[i]>a[s1[top1]]){
			add(s1[top1],s1[top1-1]-1,-a[s1[top1]]);
			top1--;
		}
		s1[++top1]=i;
		add(s1[top1],s1[top1-1]-1,a[s1[top1]]);
		while(top2 && a[i]<a[s2[top2]]){
			add(s2[top2],s2[top2-1]-1,a[s2[top2]]);
			top2--;
		}
		s2[++top2]=i;
		add(s2[top2],s2[top2-1]-1,-a[s2[top2]]);
		int rr=query(i,r-1,k-i);
		if(rr-i>ansr-ansl || (rr-i==ansr-ansl && i<ansl) ) ansl=i,ansr=rr;
		mp[a[i]]=i;
	}
	return ;
}
int main(){
	scanf("%d%d%d",&n,&k,&d);
	if(d==0){
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		int ansl=1;int ansr=1;int lst=1;
		for(int i=2;i<=n;i++){
			if(a[i]!=a[lst]){
				if(i-1-lst>ansr-ansl){ansl=lst;ansr=i-1;}
				lst=i;
			}
		}
		printf("%d %d\n",ansl,ansr);
		return 0;
	}
	ansl=n+1;ansr=0;m=sqrt(n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		b[i]=(a[i]+=M)%d;a[i]=(a[i])/d+1;
		pos[i]=(i-1)/m+1;t[i]=-i;
	}
	for(int i=1,j;i<=n;i=j){
		for(j=i+1;j<=n;j++){
			if(b[i]!=b[j]) break;
		}
		sol(i,j-1);
	}
	printf("%d %d\n",ansl,ansr);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=200010;
const int inf=2147483647;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
unordered_map<int,int>pos;
int n,k,d,a[Maxn],b[Maxn],pre[Maxn],f[Maxn][18],Log[Maxn];
int query_mx(int l,int r)
{
	int t=Log[r-l+1];
	return max(f[l][t],f[r-(1<<t)+1][t]);
}
struct Seg{int l,r,lc,rc,c[3],cmx,cmx1,cmn,cmn1,tmx,tmn;}tr[Maxn<<1];
int tot=0;
void wmx(int x,int v)
{
//	printf("l=%d r=%d\n",tr[x].l,tr[x].r);
//	printf("%d %d\n",tr[x].cmn,tr[x].cmx);
	tr[x].cmx1=tr[x].cmx=v;tr[x].c[2]=tr[x].l+v;tr[x].c[0]=tr[x].c[1]+v;tr[x].tmx=v;
//	printf("%d %d\n",tr[x].cmn,tr[x].cmx);
}
void wmn(int x,int v)
{
	tr[x].cmn1=tr[x].cmn=v;tr[x].c[1]=tr[x].l-v;tr[x].c[0]=tr[x].c[2]-v;tr[x].tmn=v;
}
void up(int x)
{
	int lc=tr[x].lc,rc=tr[x].rc;
	tr[x].cmx=max(tr[lc].cmx,tr[rc].cmx);
	tr[x].cmn=min(tr[lc].cmn,tr[rc].cmn);
	tr[x].cmx1=min(tr[lc].cmx1,tr[rc].cmx1);
	tr[x].cmn1=max(tr[lc].cmn1,tr[rc].cmn1);
	for(int i=0;i<3;i++)tr[x].c[i]=min(tr[lc].c[i],tr[rc].c[i]);
}
void down(int x)
{
	int t=tr[x].tmx;
	if(t!=inf)wmx(tr[x].lc,t),wmx(tr[x].rc,t),tr[x].tmx=inf;
	t=tr[x].tmn;
	if(t!=inf)wmn(tr[x].lc,t),wmn(tr[x].rc,t),tr[x].tmn=inf;
}
void build(int l,int r)
{
	int x=++tot;
	tr[x].l=l;tr[x].r=r;tr[x].tmx=tr[x].tmn=inf;
	if(l==r)return;
	int mid=l+r>>1;
	tr[x].lc=tot+1,build(l,mid);
	tr[x].rc=tot+1,build(mid+1,r);
}
void w(int x,int p)
{
	if(tr[x].l==tr[x].r)
	{
		tr[x].cmx=tr[x].cmn=tr[x].cmx1=tr[x].cmn1=b[p];
		tr[x].c[0]=p;tr[x].c[1]=p-b[p];tr[x].c[2]=p+b[p];
		return;
	}
	int mid=tr[x].l+tr[x].r>>1,lc=tr[x].lc,rc=tr[x].rc;
	down(x);
	if(p<=mid)w(lc,p);
	else w(rc,p);
	up(x);
}
int tmp[30],lt;
void _w(int x,int l,int r,int v,int o)
{
	if(tr[x].l==l&&tr[x].r==r)
	{
		if(o==1)
		{
//			printf("l=%d r=%d\n",tr[x].l,tr[x].r);
//			printf("%d %d\n",tr[x].cmn,tr[x].cmx);
			wmx(x,v);
//			printf("%d %d\n",tr[x].cmn,tr[x].cmx);
		}
		if(o==2)wmn(x,v);
		if(o==3)tmp[++lt]=x;
		return;
	}
	int mid=tr[x].l+tr[x].r>>1,lc=tr[x].lc,rc=tr[x].rc;
	down(x);
	if(r<=mid)_w(lc,l,r,v,o);
	else if(l>mid)_w(rc,l,r,v,o);
	else _w(lc,l,mid,v,o),_w(rc,mid+1,r,v,o);
	up(x);
}
int V;
int go(int x,int op)
{
	if(tr[x].l==tr[x].r)return x;
	int mid=tr[x].l+tr[x].r>>1,lc=tr[x].lc,rc=tr[x].rc;
	down(x);
	if(op==1)
	{
		if(tr[lc].c[0]<=V)return go(lc,op);
		return go(rc,op);
	}
	else if(op==2)
	{
		if(tr[lc].cmn1>=V)return go(lc,op);
		return go(rc,op);
	}
	else
	{
//		printf("&       %d %d %d\n",tr[lc].l,tr[lc].r,tr[lc].cmx);
		if(tr[lc].cmx1<=V)return go(lc,op);
		return go(rc,op);
	}
}
int fuck[Maxn];
int main()
{
//	freopen("3.in","r",stdin);
//	freopen("my.txt","w",stdout);
	n=read(),k=read(),d=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		pre[i]=pos[a[i]];pos[a[i]]=i;
	}
//	for(int i=144805;i<=181498;i++)fuck[i-144804]=a[i];
//	sort(fuck+1,fuck+36695);
//	printf("%d %d\n",fuck[36694],fuck[1]);
//	return 0;
//	for(int i=1;i<=n;i++)printf("%d ",pre[i]);puts("");
	int ans=1,L=1,R=1,v=1;
	if(d==0)
	{
		for(int i=2;i<=n;i++)
		{
			if(a[i]==a[i-1])v++;
			else v=1;
			if(v>ans)ans=v,R=i,L=i-v+1;
		}
		return printf("%d %d",L,R),0;
	}
	Log[1]=0;for(int i=2;i<=n;i++)Log[i]=Log[i>>1]+1;
	for(int i=1;i<=n;i++)f[i][0]=pre[i];
	for(int j=1;(1<<j)<=n;j++)
	for(int i=1;i+(1<<j)-1<=n;i++)
	f[i][j]=max(f[i][j-1],f[i+(1<<(j-1))][j-1]);
	for(int i=1;i<=n;i++)b[i]=(int)floor((double)a[i]/(double)d);
	build(1,n);w(1,1);
	for(int i=2;i<=n;i++)
	{

		if(abs(a[i])%d==abs(a[i-1])%d)v++;
		else v=1;
//		printf("%d %d\n",i,v);
		if(v>1)
		{
			lt=0;_w(1,i-v+1,i-1,0,3);
			int op=(b[i]>b[i-1]);
			bool flag=false;
//			printf("i=%d\n",i);
			for(int j=lt;j;j--)
			{
				int x=tmp[j];
				if(op==1)
				{
					if(tr[x].cmx<=b[i])wmx(x,b[i])/*,printf("!   %d %d\n",tr[x].l,tr[x].r)*/;
					else{V=b[i];int o=go(x,3);_w(1,tr[o].l,tr[x].r,b[i],1);/*printf("!   %d %d\n",tr[o].l,tr[x].r);*/break;}
				}
				else
				{/**/
					if(tr[x].cmn>=b[i])wmn(x,b[i]);
					else{V=b[i];int o=go(x,2);_w(1,tr[o].l,tr[x].r,b[i],2);break;}
				}/**/
			}
		}
		w(1,i);
		if(v<=R-L+1)continue;
		int l=i-v+1,r=i;bool flag=false;
		while(l<=r)
		{
			int mid=l+r>>1;
			if(query_mx(mid,i)<mid)r=mid-1,flag=true;
			else l=mid+1;
		}
		if(!flag)continue;
		r++;lt=0;
//		printf("r=%d\n",r);
		_w(1,r,i,0,3);V=i+k;
		for(int j=1;j<=lt;j++)
		{
			int x=tmp[j];
			if(tr[x].c[0]<=V)
			{
//				printf("%d %d %d\n",tr[x].l,tr[x].r,tr[x].c[0]);
				int o=go(x,1);
//				printf("%d %d %d %d %d %d\n",i,tr[o].l,tr[o].cmn,tr[o].cmx,tr[o].c[0],V);
				if(i-tr[o].l+1>R-L+1)R=i,L=tr[o].l;
				break;
			}
		}
	}
	printf("%d %d",L,R);
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=200010;
const int inf=2147483647;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
unordered_map<int,int>pos;
int n,k,d,a[Maxn],b[Maxn],pre[Maxn],f[Maxn][18],Log[Maxn];
int query_mx(int l,int r)
{
	int t=Log[r-l+1];
	return max(f[l][t],f[r-(1<<t)+1][t]);
}
struct Seg{int l,r,lc,rc,c[3],cmx,cmx1,cmn,cmn1,tmx,tmn;}tr[Maxn<<1];
int tot=0;
void wmx(int x,int v)
{
	if(v<tr[x].cmx)return;
//	printf("l=%d r=%d\n",tr[x].l,tr[x].r);
//	printf("%d %d\n",tr[x].cmn,tr[x].cmx);
	tr[x].cmx1=tr[x].cmx=v;tr[x].c[2]=tr[x].l+v;tr[x].c[0]=tr[x].c[1]+v;tr[x].tmx=v;
//	printf("%d %d\n",tr[x].cmn,tr[x].cmx);
}
void wmn(int x,int v)
{
	if(v>tr[x].cmn)return;
	tr[x].cmn1=tr[x].cmn=v;tr[x].c[1]=tr[x].l-v;tr[x].c[0]=tr[x].c[2]-v;tr[x].tmn=v;
}
void up(int x)
{
	int lc=tr[x].lc,rc=tr[x].rc;
	tr[x].cmx=max(tr[lc].cmx,tr[rc].cmx);
	tr[x].cmn=min(tr[lc].cmn,tr[rc].cmn);
	tr[x].cmx1=min(tr[lc].cmx1,tr[rc].cmx1);
	tr[x].cmn1=max(tr[lc].cmn1,tr[rc].cmn1);
	for(int i=0;i<3;i++)tr[x].c[i]=min(tr[lc].c[i],tr[rc].c[i]);
}
void down(int x)
{
	int t=tr[x].tmx;
	if(t!=inf)wmx(tr[x].lc,t),wmx(tr[x].rc,t),tr[x].tmx=inf;
	t=tr[x].tmn;
	if(t!=inf)wmn(tr[x].lc,t),wmn(tr[x].rc,t),tr[x].tmn=inf;
}
void build(int l,int r)
{
	int x=++tot;
	tr[x].l=l;tr[x].r=r;tr[x].tmx=tr[x].tmn=inf;
	if(l==r)return;
	int mid=l+r>>1;
	tr[x].lc=tot+1,build(l,mid);
	tr[x].rc=tot+1,build(mid+1,r);
}
void w(int x,int p)
{
	if(tr[x].l==tr[x].r)
	{
		tr[x].cmx=tr[x].cmn=tr[x].cmx1=tr[x].cmn1=b[p];
		tr[x].c[0]=p;tr[x].c[1]=p-b[p];tr[x].c[2]=p+b[p];
		return;
	}
	int mid=tr[x].l+tr[x].r>>1,lc=tr[x].lc,rc=tr[x].rc;
	down(x);
	if(p<=mid)w(lc,p);
	else w(rc,p);
	up(x);
}
int tmp[30],lt;
void _w(int x,int l,int r,int v,int o)
{
	if(tr[x].l==l&&tr[x].r==r)
	{
		if(o==1)
		{
//			printf("l=%d r=%d\n",tr[x].l,tr[x].r);
//			printf("%d %d\n",tr[x].cmn,tr[x].cmx);
			wmx(x,v);
//			printf("%d %d\n",tr[x].cmn,tr[x].cmx);
		}
		if(o==2)wmn(x,v);
		if(o==3)tmp[++lt]=x;
		return;
	}
	int mid=tr[x].l+tr[x].r>>1,lc=tr[x].lc,rc=tr[x].rc;
	down(x);
	if(r<=mid)_w(lc,l,r,v,o);
	else if(l>mid)_w(rc,l,r,v,o);
	else _w(lc,l,mid,v,o),_w(rc,mid+1,r,v,o);
	up(x);
}
int V;
int go(int x,int op)
{
	if(tr[x].l==tr[x].r)return x;
	int mid=tr[x].l+tr[x].r>>1,lc=tr[x].lc,rc=tr[x].rc;
	down(x);
	if(op==1)
	{
		if(tr[lc].c[0]<=V)return go(lc,op);
		return go(rc,op);
	}
	else if(op==2)
	{
		if(tr[lc].cmn1>=V)return go(lc,op);
		return go(rc,op);
	}
	else
	{
//		printf("&       %d %d %d\n",tr[lc].l,tr[lc].r,tr[lc].cmx);
		if(tr[lc].cmx1<=V)return go(lc,op);
		return go(rc,op);
	}
}
int fuck[Maxn];
int main()
{
//	freopen("3.in","r",stdin);
//	freopen("my.txt","w",stdout);
	n=read(),k=read(),d=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		pre[i]=pos[a[i]];pos[a[i]]=i;
	}
//	for(int i=144805;i<=181498;i++)fuck[i-144804]=a[i];
//	sort(fuck+1,fuck+36695);
//	printf("%d %d\n",fuck[36694],fuck[1]);
//	return 0;
//	for(int i=1;i<=n;i++)printf("%d ",pre[i]);puts("");
	int ans=1,L=1,R=1,v=1;
	if(d==0)
	{
		for(int i=2;i<=n;i++)
		{
			if(a[i]==a[i-1])v++;
			else v=1;
			if(v>ans)ans=v,R=i,L=i-v+1;
		}
		return printf("%d %d",L,R),0;
	}
	Log[1]=0;for(int i=2;i<=n;i++)Log[i]=Log[i>>1]+1;
	for(int i=1;i<=n;i++)f[i][0]=pre[i];
	for(int j=1;(1<<j)<=n;j++)
	for(int i=1;i+(1<<j)-1<=n;i++)
	f[i][j]=max(f[i][j-1],f[i+(1<<(j-1))][j-1]);
	for(int i=1;i<=n;i++)b[i]=(int)floor((double)a[i]/(double)d);
	build(1,n);w(1,1);
	for(int i=2;i<=n;i++)
	{

		if(abs(a[i])%d==abs(a[i-1])%d)v++;
		else v=1;
//		printf("%d %d\n",i,v);
		if(v>1)
		{
			lt=0;_w(1,i-v+1,i-1,0,3);
			int op=(b[i]>b[i-1]);
			bool flag=false;
//			printf("i=%d\n",i);
			for(int j=lt;j;j--)
			{
				int x=tmp[j];
				if(op==1)
				{
					if(tr[x].cmx<=b[i])wmx(x,b[i])/*,printf("!3   %d %d\n",tr[x].l,tr[x].r)*/;
					else{V=b[i];int o=go(x,3);_w(1,tr[o].l,tr[x].r,b[i],1);/*printf("!4   %d %d\n",tr[o].l,tr[x].r);*/break;}
				}
				else
				{/**/
					if(tr[x].cmn>=b[i])wmn(x,b[i])/*,printf("!1   %d %d\n",tr[x].l,tr[x].r)*/;
					else{V=b[i];int o=go(x,2);_w(1,tr[o].l,tr[x].r,b[i],2);/*printf("!2   %d %d\n",tr[o].l,tr[x].r);*/break;}
				}/**/
			}
		}
		w(1,i);
		if(v<=R-L+1)continue;
		int l=i-v+1,r=i;bool flag=false;
		while(l<=r)
		{
			int mid=l+r>>1;
			if(query_mx(mid,i)<mid)r=mid-1,flag=true;
			else l=mid+1;
		}
		if(!flag)continue;
		r++;lt=0;
//		printf("r=%d\n",r);
		_w(1,r,i,0,3);V=i+k;
		for(int j=1;j<=lt;j++)
		{
			int x=tmp[j];
			if(tr[x].c[0]<=V)
			{
//				printf("%d %d %d\n",tr[x].l,tr[x].r,tr[x].c[0]);
				int o=go(x,1);
//				printf("%d %d %d %d %d %d\n",i,tr[o].l,tr[o].cmn,tr[o].cmx,tr[o].c[0],V);
				if(i-tr[o].l+1>R-L+1)R=i,L=tr[o].l;
				break;
			}
		}
	}
	printf("%d %d",L,R);
}