// Version.20.39.55.05.26.20.
#include <bits/stdc++.h>
#define N 200200
#define ls (pos << 1)
#define rs (pos << 1 | 1)
using namespace std;
typedef long long ll;
const ll INF = 1e16;

int ansl = 1, ansr = 1;
ll mi[N << 2], tg[N << 2];

void build(int l, int r, int pos) {
    tg[pos] = 0;
    if (l == r) return mi[pos] = l, void();
    int mid = (l + r) >> 1;
    build(l, mid, ls), build(mid + 1, r, rs);
    mi[pos] = min(mi[ls], mi[rs]);
}

void add(int pos, int w) {
    mi[pos] += w, tg[pos] += w;
}

void pushdown(int pos) {
    if (tg[pos]) {
        add(ls, tg[pos]);
        add(rs, tg[pos]);
        tg[pos] = 0;
    }
}

void modify(int L, int R, ll w, int l, int r, int pos) {
    if (L <= l && r <= R) return add(pos, w);
    int mid = (l + r) >> 1;
    pushdown(pos);
    if (L <= mid) modify(L, R, w, l, mid, ls);
    if (mid < R) modify(L, R, w, mid + 1, r, rs);
    mi[pos] = min(mi[ls], mi[rs]);
}

int query(int w, int l, int r, int pos) {
    if (l == r) return mi[pos] <= w ? l : -1;
    pushdown(pos);
    int mid = (l + r) >> 1;
    return mi[ls] <= w
        ? query(w, l, mid, ls)
        : query(w, mid + 1, r, rs);
}

void chk(int l, int r) {
    if (r - l > ansr - ansl || (r - l == ansr - ansl && l < ansl))
        ansl = l, ansr = r;
}

ll qmin(int x, int l, int r, int pos) {
    if (l == r) return mi[pos];
    int mid = (l + r) >> 1;
    return x <= mid ? qmin(x, l, mid, ls) : qmin(x, mid + 1, r, rs);
}

int smi[N], tmi, smx[N], tmx;
map<int, int> las;

void work(int *a, int n, int m, int dlt) {
    build(1, n, 1);
    tmi = tmx = 0, las.clear();
    int lasi = 1;
    for (int i = 1; i <= n; ++i) {
        while (tmi && a[smi[tmi]] > a[i])
            modify(smi[tmi - 1] + 1, smi[tmi], a[smi[tmi]], 1, n, 1), tmi--;
        modify(smi[tmi] + 1, i, -a[i], 1, n, 1), smi[++tmi] = i;
        while (tmx && a[smx[tmx]] < a[i])
            modify(smx[tmx - 1] + 1, smx[tmx], -a[smx[tmx]], 1, n, 1), tmx--;
        modify(smx[tmx] + 1, i, a[i], 1, n, 1), smx[++tmx] = i;
        if (int tmp = las[a[i]])
            if (lasi <= tmp) modify(lasi, tmp, INF, 1, n, 1), lasi = tmp;
        las[a[i]] = i;
        int l = query(m + i, 1, n, 1);
        assert(l);
        if (l > 0 && l <= i) chk(l + dlt, i + dlt);
    }
}

int main() {
#ifdef isLOCAL
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#endif

    static int n, m, d, a[N];
    cin >> n >> m >> d;
    for (int i = 1; i <= n; ++i)
        scanf("%d", a + i);

    if (!d) {
        for (int l = 1, r; l <= n; l = r + 1) {
            for (r = l; r < n && a[r + 1] == a[l]; ++r);
            chk(l, r);
        }
        cout << ansl << " " << ansr << endl;
        return 0;
    }

    for (int l = 1, r; l <= n; l = r + 1) {
        for (r = l; r < n && (a[r + 1] % d + d) % d == (a[l] % d + d) % d; ++r);
        int tmp = 0;
        for (int i = l; i <= r; ++i)
            tmp = min(tmp, a[i]);
        for (int i = l; i <= r; ++i)
            a[i] = (a[i] - tmp) / d;
        work(a + l - 1, r - l + 1, m, l - 1);
    }

    cout << ansl << ' ' << ansr << endl;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
int n,k,d;
int a[200010],pre[200010];//ÉÏÒ»¸öÏàµÈµÄÎ»ÖÃ
map<int,int>vis;
int stackmax[200010],stackmin[200010],topmax=0,topmin=0;
struct node{
	int l;
	int r;
	int minn;
	int add;
}tree[800010];
void build(int now,int l,int r){
	tree[now].l=l;
	tree[now].r=r;
	tree[now].minn=1e9;
	tree[now].add=0;
	if(l==r)return;
	int mid=(l+r)/2;
	build(now*2,l,mid);
	build(now*2+1,mid+1,r);
}
void add(int now,int x,int y,int ad){
	int l=tree[now].l;
	int r=tree[now].r;
	if(l==x&&r==y){
		tree[now].add+=ad;
		tree[now].minn+=ad;
		return;
	}
	int mid=(l+r)/2;
	if(tree[now].add){
		add(now*2,l,mid,tree[now].add);
		add(now*2+1,mid+1,r,tree[now].add);
		tree[now].add=0;
	}
	if(y<=mid){
		add(now*2,x,y,ad);
	}
	else if(x>mid){
		add(now*2+1,x,y,ad);
	}
	else{
		add(now*2,x,mid,ad);
		add(now*2+1,mid+1,y,ad);
	}
	tree[now].minn=min(tree[now*2].minn,tree[now*2+1].minn);
}
int check(int now,int x){
	int l=tree[now].l;
	int r=tree[now].r;
	if(l==r)return l;
	int lson=now*2;
	int rson=now*2+1;
	int mid=(l+r)/2;
	if(tree[now].add){
		add(lson,l,mid,tree[now].add);
		add(rson,mid+1,r,tree[now].add);
	}
	if(tree[lson].minn<=x)return check(lson,x);
	else return check(rson,x);
}
int main(){
	scanf("%d%d%d",&n,&k,&d);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	if(d==0){
		int maxn=0,now=0,l=0,r=0;
		for(int i=1;i<=n;i++){
			if(a[i]!=a[i-1])now=i;
			if(i-now+1>maxn){
				maxn=i-now+1;
				l=now;
				r=i;
			}
		}
		printf("%d %d\n",l,r);
		return 0;
	}
	for(int i=1;i<=n;i++){
		pre[i]=vis[a[i]];
		vis[a[i]]=i;
	}
	int pr=1;
	int maxn=0,l=0,r=0;
	build(1,1,n);
	for(int i=1;i<=n;i++){
		while(pr<=pre[i]||a[pr]%d!=a[i]%d){
			add(1,pr,pr,1e9);
			pr++;
		}
		add(1,i,i,-1e9+i);
		while(topmax>0&&a[stackmax[topmax]]<a[i]){
			add(1,stackmax[topmax-1]+1,stackmax[topmax],a[i]/d-a[stackmax[topmax]]/d);
			topmax--;
		}
		stackmax[++topmax]=i;
		while(topmin>0&&a[stackmin[topmin]]>a[i]){
			add(1,stackmin[topmin-1]+1,stackmin[topmin],a[stackmin[topmin]]/d-a[i]/d);
			topmin--;
		}
		stackmin[++topmin]=i;
		int nowl=check(1,i+k);
		if(i-nowl+1>maxn){
			maxn=i-nowl+1;
			l=nowl;
			r=i;
		}
	}
	printf("%d %d\n",l,r);
	return 0;
}


// Version.20.39.55.05.26.20.
#include <bits/stdc++.h>
#define N 200200
#define ls (pos << 1)
#define rs (pos << 1 | 1)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int ansl = 1, ansr = 1;
ll mi[N], tg[N];

void build(int l, int r, int pos) {
    tg[pos] = 0;
    if (l == r) return mi[pos] = l, void();
    int mid = (l + r) >> 1;
    build(l, mid, ls), build(mid + 1, r, rs);
    mi[pos] = min(mi[ls], mi[rs]);
}

void add(int pos, int w) {
    mi[pos] += w, tg[pos] += w;
}

void pushdown(int pos) {
    if (tg[pos]) {
        add(ls, tg[pos]);
        add(rs, tg[pos]);
        tg[pos] = 0;
    }
}

void modify(int L, int R, int w, int l, int r, int pos) {
    if (L <= l && r <= R) return add(pos, w);
    int mid = (l + r) >> 1;
    pushdown(pos);
    if (L <= mid) modify(L, R, w, l, mid, ls);
    if (mid < R) modify(L, R, w, mid + 1, r, rs);
    mi[pos] = min(mi[ls], mi[rs]);
}

int query(int w, int l, int r, int pos) {
    if (l == r) return mi[pos] <= w ? l : -1;
    pushdown(pos);
    int mid = (l + r) >> 1;
    return mi[ls] <= w
        ? query(w, l, mid, ls)
        : query(w, mid + 1, r, rs);
}

void chk(int l, int r) {
    if (r - l > ansr - ansl || (r - l == ansr - ansl && l < ansl))
        ansl = l, ansr = r;
}

int smi[N], tmi, smx[N], tmx;
map<int, int> las;

void work(int *a, int n, int m, int dlt) {
    build(1, n, 1);
    tmi = tmx = 0, las.clear();
    for (int i = 1; i <= n; ++i) {
        while (tmi && a[smi[tmi]] >= a[i])
            modify(smi[tmi - 1] + 1, smi[tmi], a[smi[tmi]], 1, n, 1), tmi--;
        modify(smi[tmi] + 1, i, -a[i], 1, n, 1), smi[++tmi] = i;
        while (tmx && a[smx[tmx]] <= a[i])
            modify(smx[tmx - 1] + 1, smx[tmx], -a[smx[tmx]], 1, n, 1), tmx--;
        modify(smx[tmx] + 1, i, a[i], 1, n, 1), smx[++tmx] = i;
        if (int tmp = las[a[i]])
            modify(1, tmp, INF, 1, n, 1);
        las[a[i]] = i;
        int l = query(m + i, 1, n, 1);
        assert(l);
        if (l > 0) chk(l + dlt, i + dlt);
    }
}

int main() {
#ifdef isLOCAL
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#endif

    static int n, m, d, a[N];
    cin >> n >> m >> d;
    for (int i = 1; i <= n; ++i)
        scanf("%d", a + i);

    if (!d) {
        for (int l = 1, r; l <= n; l = r + 1) {
            for (r = l; r < n && a[r + 1] == a[l]; ++r);
            chk(l, r);
        }
        cout << ansl << " " << ansr << endl;
        return 0;
    }

    for (int l = 1, r; l <= n; l = r + 1) {
        for (r = l; r < n && (a[r + 1] % d + d) % d == (a[l] % d + d) % d; ++r);
        for (int i = l; i <= r; ++i)
            a[i] = (a[i] + INF) / d;
        work(a + l - 1, r - l + 1, m, l - 1);
    }

    cout << ansl << ' ' << ansr << endl;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k,d;
int a[200010],val[200010],pre[200010],vis[200010];
int read[200010],s[200010],cnt=0;
int stackmax[200010],stackmin[200010];//µ¥µ÷Õ»
struct node{
	int l;
	int r;
	int flag;//Çø¼äÄÚaÊÇ·ñÈ«ÏàÍ¬
	int real_val;//aÏàÍ¬µÄÖµ
	int maxn;//dµÄ±¶Êý×î´óÖµ
	int minn;//dµÄ±¶Êý×îÐ¡Öµ
	int maxpre;//ÉÏÒ»¸övalÏàµÈµÄÊý
	int real_min;//l+max-min×îÐ¡Öµ
	int can_min;//Í¬Ê±Âú×ãÏÞÖÆ
	int change_flag;
	int add;
	void clear(){
		l=0;
		r=0;
		flag=0;
		real_val=0;
		maxn=-1e9;
		minn=1e9;
		maxpre=-1e9;
		real_min=1e9;
		can_min=1e9;
		change_flag=0;
		add=0;
	}
}tree[800010];
node update_(node a,node b){
	node c;
	c.clear();
	if(a.flag&&b.flag&&a.real_val==b.real_val){
		c.flag=1;
		c.real_val=a.real_val;
	}
	c.maxn=max(a.maxn,b.maxn);
	c.minn=min(a.minn,b.minn);
	c.maxpre=max(a.maxpre,b.maxpre);
	c.real_min=min(a.real_min,b.real_min);
	return c;
}
void update(int now){
	if(tree[now*2].flag&&tree[now*2+1].flag&&tree[now*2].real_val==tree[now*2+1].real_val){
		tree[now].flag=1;
		tree[now].real_val=tree[now*2].real_val;
	}
	tree[now].maxn=max(tree[now*2].maxn,tree[now*2+1].maxn);
	tree[now].minn=min(tree[now*2].minn,tree[now*2+1].minn);
	tree[now].maxpre=max(tree[now*2].maxpre,tree[now*2+1].maxpre);
	tree[now].real_min=min(tree[now*2].real_min,tree[now*2+1].real_min);
}
void build(int now,int l,int r){
	tree[now].l=l;
	tree[now].r=r;
	tree[now].real_min=1e9;
	tree[now].flag=1;
	tree[now].maxn=-1e9;
	tree[now].minn=1e9;
	tree[now].maxpre=-1e9;
	if(l==r)return;
	int mid=(l+r)/2;
	build(now*2,l,mid);
	build(now*2+1,mid+1,r);
	update(now);
}
void add(int now,int x,int y,int ad){
	int l=tree[now].l;
	int r=tree[now].r;
	if(l==x&&r==y){
		tree[now].add+=ad;
		tree[now].real_min+=ad;
		return;
	}
	int mid=(l+r)/2;
	if(tree[now].add){
		add(now*2,l,mid,tree[now].add);
		add(now*2+1,mid+1,r,tree[now].add);
		tree[now].add=0;
	}
	if(y<=mid){
		add(now*2,x,y,ad);
	}
	else if(x>mid){
		add(now*2+1,x,y,ad);
	}
	else{
		add(now*2,x,mid,ad);
		add(now*2+1,mid+1,y,ad);
	}
	update(now);
}
void insert(int now,int x){
	int l=tree[now].l;
	int r=tree[now].r;
	if(l==r&&l==x){
		tree[now].flag=1;
		tree[now].maxn=val[x];
		tree[now].minn=val[x];
		tree[now].maxpre=pre[x];
		tree[now].real_min=x;
		tree[now].real_val=a[x];
		return;
	}
	int mid=(l+r)/2;
	if(tree[now].add){
		add(now*2,l,mid,tree[now].add);
		add(now*2+1,mid+1,r,tree[now].add);
		tree[now].add=0;
	}
	if(x<=mid){
		insert(now*2,x);
	}
	else{
		insert(now*2+1,x);
	}
	update(now);
}
void check1(int now,node kk,int x){
	int l=tree[now].l;
	int r=tree[now].r;
	tree[now].can_min=1e9;
	tree[now].change_flag=0;
//	cout<<"@"<<l<<" "<<r<<endl;
	if(l==r){
	//	cout<<"!!!"<<l<<endl;
		tree[now].can_min=tree[now].real_min;
		return;
	}
	int mid=(l+r)/2;
	int lson=now*2;
	int rson=now*2+1;
	if(tree[now].add){
		add(lson,l,mid,tree[now].add);
		add(rson,mid+1,r,tree[now].add);
		tree[now].add=0;
	}
	if(x<=mid){
		tree[rson].can_min=1e9;
		tree[rson].change_flag=2;
		check1(lson,kk,x);
	}
	else{
		node to;
		to.clear();
		to=update_(tree[rson],kk);
	//	cout<<"@@"<<to.maxpre<<" "<<to.flag<<endl;
		if(to.maxpre>=mid||to.flag==0||a[mid]!=to.real_val){
			tree[lson].can_min=1e9;
			tree[lson].change_flag=2;
			check1(rson,kk,x);
		}
		else{
			tree[rson].can_min=tree[rson].real_min;
			tree[rson].change_flag=1;
			check1(lson,to,x);
		}
	}
	update(now);
	tree[now].can_min=min(tree[lson].can_min,tree[rson].can_min);
}
int check2(int now,int x){
	int l=tree[now].l;
	int r=tree[now].r;
//	cout<<"#"<<l<<" "<<r<<" "<<tree[now].can_min<<endl;
	if(l==r)return l;
	int mid=(l+r)/2;
	int lson=now*2;
	int rson=now*2+1;
	if(tree[now].add){
		add(lson,l,mid,tree[now].add);
		add(rson,mid+1,r,tree[now].add);
		tree[now].add=0;
	}
	if(tree[now].change_flag){
		if(tree[now].change_flag==1){
			tree[lson].can_min=tree[lson].real_min;
			tree[rson].can_min=tree[rson].real_min;
			tree[lson].change_flag=tree[rson].change_flag=1;
		}
		else{
			tree[lson].can_min=1e9;
			tree[rson].can_min=1e9;
			tree[lson].change_flag=tree[rson].change_flag=2;
		}
		tree[now].change_flag=0;
	}
	if(x<=mid){
		return check2(lson,x);
	}
//	cout<<"##"<<tree[lson].can_min<<endl;
	if(tree[lson].can_min<=x+k)return check2(lson,x);
	return check2(rson,x);
}
int main(){
	scanf("%d%d%d",&n,&k,&d);
	if(d==0){
	    cout<<"!"<<endl;
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
		}
		int maxn=0,pre=0,now=0,l=0,r=0;
		for(int i=1;i<=n;i++){
			if(a[i]==a[i-1])now++;
			else{
				now=1;
				pre=i;
			}
			if(now>maxn){
				maxn=now;
				l=pre;
				r=i;
			}
		}
		printf("%d %d\n",l,r);
		return 0;
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		val[i]=a[i]/d;
		a[i]=(a[i]%d+d)%d;
		read[i]=val[i];
	}
	sort(read+1,read+n+1);
	for(int i=1;i<=n;i++){
		if(i==1||read[i]!=read[i-1]){
			s[++cnt]=read[i];
		}
	}
	for(int i=1;i<=n;i++){
		read[i]=lower_bound(s+1,s+cnt+1,val[i])-s;
		pre[i]=vis[read[i]];
		vis[read[i]]=i;
	}
	build(1,1,n);
	int topmax=0,topmin=0;
	int l=0,r=0,maxn=0;
	for(int i=1;i<=n;i++){
	//	cout<<"!"<<i<<endl;
		insert(1,i);
		while(topmax>0&&val[stackmax[topmax]]<val[i]){
			add(1,stackmax[topmax-1]+1,stackmax[topmax],val[i]-val[stackmax[topmax]]);
			topmax--;
		}
		stackmax[++topmax]=i;
		while(topmin>0&&val[stackmin[topmin]]>val[i]){
			add(1,stackmin[topmin-1]+1,stackmin[topmin],val[stackmin[topmin]]-val[i]);
			topmin--;
		}
		stackmin[++topmin]=i;
		node kk;
		kk.clear();
		kk.maxpre=pre[i];
		kk.real_val=a[i];
		kk.flag=1;
		check1(1,kk,i);
		int nowl=check2(1,i);
		if(i-nowl+1>maxn||(i-nowl+1==maxn&&nowl<l)){
			l=nowl;
			r=i;
			maxn=r-l+1;
		}
	//	cout<<l<<" "<<r<<endl;
	}
	printf("%d %d\n",l,r);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

const int N = 2333333;
struct Node { int l, r; } node[N];
int n, k, d, cnt = 0, tmp = 0, num = 0, ansl, ansr;
int a[N], b[N], rit[N], maxx[N], minn[N], vis[N];

struct SegmentTree
{
	void push_up(int x)
	{
		maxx[x] = max(maxx[x << 1], maxx[x << 1 | 1]);
		minn[x] = min(minn[x << 1], minn[x << 1 | 1]);
	}
	void build(int x, int l, int r)
	{
		if(l == r)
		{
			maxx[x] = minn[x] = b[l];
			return ;
		}
		int mid = (l + r) >> 1;
		build(x << 1, l, mid);
		build(x << 1 | 1, mid + 1, r);
		push_up(x);
	}
	int qMin(int x, int l, int r, int stdl, int stdr)
	{
		if(r < stdl || l > stdr) return 0x3f3f3f3f;
		if(stdl <= l && stdr >= r) return minn[x];
		int mid = (l + r) >> 1;
		return min(qMin(x << 1, l, mid, stdl, stdr),
		qMin(x << 1 | 1, mid + 1, r, stdl, stdr));
	}
	int qMax(int x, int l, int r, int stdl, int stdr)
	{
		if(r < stdl || l > stdr) return 0;
		if(stdl <= l && stdr >= r) return maxx[x];
		int mid = (l + r) >> 1;
		return max(qMax(x << 1, l, mid, stdl, stdr),
		qMax(x << 1 | 1, mid + 1, r, stdl, stdr));
	}
} Tree;

bool check(int l, int r)
{
	int Min = Tree.qMin(1, 1, n, l, r), Max = Tree.qMax(1, 1, n, l, r);
	if((Max - Min + 1) - (r - l + 1) <= k) return true;
	return false;
}

int main()
{
	scanf("%d%d%d", &n, &k, &d);
	memset(vis, 0, sizeof(vis));
	memset(maxx, 0, sizeof(maxx));
	memset(minn, 0x3f, sizeof(minn));
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(int i = 1; i <= n; i++) b[i] = a[i] / d;
	node[0].l = node[0].r = 0;
	for(int i = 1; i <= n; i++)
		if((a[i] % d) != (a[i - 1] % d))
		{
			node[++cnt].l = node[cnt - 1].r + 1;
			node[cnt].r = i - 1;
		}
	if(node[cnt].r != n)
		node[++cnt].l = node[cnt - 1].r + 1, node[cnt].r = n;
	Tree.build(1, 1, n);
	for(int i = 1; i <= cnt; i++)
	{
		int l = node[i].l, r = node[i].r;
		for(int j = node[i].r; j >= node[i].l; j--)
		{
			vis[b[j]]++;
			while(vis[b[j]] >= 2) vis[b[r]]--, r--;
			rit[j] = r;
		}
		for(int j = node[i].l; j <= node[i].r; j++)
		{
			int L = j, R = rit[j], res;
			for(int k = node[i].r - 1; k >= node[i].l; k--)
			{
				if(k - j + 1 <= num) break;
				if(check(j, k))
				{
					num = k - j + 1;
					ansl = j, ansr = k;
				}
			}
		}
		for(int j = node[i].l; j <= node[i].r; j++) vis[b[j]] = 0;
	}
	printf("%d %d", ansl, ansr);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
const int N=2e5+10;
const int INF=1e18;
int a[N],b[N],s1[N],s2[N];
int cnt,n,m,k,d,top1,top2,c[N],ansr,ansl,sum[N],pos[N],t[N],mn[N];
map<int,int>mp;
inline int findm(int l,int r){
	int ans=0;
	for(int i=l;i<=r;i++) ans=max(ans,a[i]);
	return ans;
}
inline int findmi(int l,int r){
	int ans=INF;
	for(int i=1;i<=n;i++) ans=min(ans,a[i]);
	return ans;
}
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=pos[i]*m;j>=(pos[i]-1)*m+1;j--)
				if(t[i]+sum[pos[i]]<=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;
		}
	}
//	return l;
}

inline void sol(int L,int R){
	if(L==R) return ;
//	printf("%d %d\n",L,R);
	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]]);
	//	printf("\n\n");
		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]]);
	//	printf("add :%d %d\n",s1[top1],s1[top1-1]-1);
	//	for(int i=1;i<=n;i++) printf("%d ",t[i]+sum[pos[i]]);printf("\n");
	//	for(int j=i;j<=r-1;j++) printf("%d ",t[i]+sum[pos[i]]);printf("\n");
		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]]);
	//	for(int i=1;i<=n;i++) printf("%d ",t[i]+sum[pos[i]]);printf("\n");
		int rr=query(i,r-1,k-i);
	//	printf("ans :%d %d\n",rr,k-i);
		if(rr-i>ansr-ansl || (rr-i==ansr-ansl && i<ansl) ) ansl=i,ansr=rr;

	/*
		for(int j=i;j<=r-1;j++) {
			int mn=findm(i,j);int mi=findmi(i,j);
			if(mn-mi-j<=k-i){
				if(j-i>ansr-ansl) ansr=j,ansl=i;
				if(j-i==ansr-ansl && i<ansl) ansl=i,ansr=j;
			}
		}
		*/
		mp[a[i]]=i;
	}

	return ;
}

int main(){
//	freopen("cf407e.in","r",stdin);
	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]%d;a[i]=(a[i]-b[i])/d+1;
		pos[i]=(i-1)/m+1;t[i]=-i;
	}
//	for(int i=1;i<=n;i++) printf("%d ",a[i]);printf("\n");
	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<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
const int N=2e5+10;
const int M=1000000000;
const int INF=1e18;
int a[N],b[N],s1[N],s2[N];
int cnt,n,m,k,d,top1,top2,c[N],ansr,ansl,sum[N],pos[N],t[N],mn[N];
map<int,int>mp;
inline int findm(int l,int r){
	int ans=0;
	for(int i=l;i<=r;i++) ans=max(ans,a[i]);
	return ans;
}
inline int findmi(int l,int r){
	int ans=INF;
	for(int i=1;i<=n;i++) ans=min(ans,a[i]);
	return ans;
}
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=pos[i]*m;j>=(pos[i]-1)*m+1;j--)
				if(t[i]+sum[pos[i]]<=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;
		}
	}
//	return l;
}

inline void sol(int L,int R){
	if(L==R) return ;
//	printf("%d %d\n",L,R);
	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]]);
	//	printf("\n\n");
		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]]);
	//	printf("add :%d %d\n",s1[top1],s1[top1-1]-1);
	//	for(int i=1;i<=n;i++) printf("%d ",t[i]+sum[pos[i]]);printf("\n");
	//	for(int j=i;j<=r-1;j++) printf("%d ",t[i]+sum[pos[i]]);printf("\n");
		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]]);
	//	for(int i=1;i<=n;i++) printf("%d ",t[i]+sum[pos[i]]);printf("\n");
		int rr=query(i,r-1,k-i);
	//	printf("ans :%d %d\n",rr,k-i);
		if(rr-i>ansr-ansl || (rr-i==ansr-ansl && i<ansl) ) ansl=i,ansr=rr;

	/*
		for(int j=i;j<=r-1;j++) {
			int mn=findm(i,j);int mi=findmi(i,j);
			if(mn-mi-j<=k-i){
				if(j-i>ansr-ansl) ansr=j,ansl=i;
				if(j-i==ansr-ansl && i<ansl) ansl=i,ansr=j;
			}
		}
		*/
		mp[a[i]]=i;
	}

	return ;
}

int main(){
//	freopen("cf407e.in","r",stdin);
	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;i<=n;i++) printf("%d ",a[i]);printf("\n");
	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<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
const int N=2e5+10;
const int INF=1e18;
int a[N],b[N],s1[N],s2[N];
int cnt,n,m,k,d,top1,top2,c[N],ansr,ansl,sum[N],pos[N],t[N],mm[N];
map<int,int>mp;
inline int findm(int l,int r){
	int ans=0;
	for(int i=l;i<=r;i++) ans=max(ans,a[i]);
	return ans;
}
inline int findmi(int l,int r){
	int ans=INF;
	for(int i=1;i<=n;i++) ans=min(ans,a[i]);
	return ans;
}
void reset(int x){
	mm[x]=0;
	for(int i=(x-1)*m+1;i<=min(n,x*m);i++) mm[x]=max(mm[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,mm[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(mm[i]>=c){
			for(int j=pos[i]*m;j>=(pos[i]-1)*m+1;j--)
				if(t[i]+sum[pos[i]]>=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;
		}
	}
//	return l;
}

inline void sol(int L,int R){
	if(L==R) return ;
//	printf("%d %d\n",L,R);
	mp.clear();int r=R+1;
	top1=top2=0;s1[top1]=s2[top2]=R+1;

	for(int i=R;i>=L;i--){
		if(mp.count(a[i])) r=min(r,mp[a[i]]);
		while(top1 && a[i]>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]<s2[top2]){
			add(s2[top1],s2[top2-1]-1,a[s2[top2]]);
			top2--;
		}
		s2[++top2]=i;
		add(s2[top2],s2[top2-1]-1,-a[s2[top2]]);
	//	printf("# %d %d %d\n",i,r-1,k-i);
	//	for(int j=i;j<=r-1;j++) printf("## %d ",t[i]+sum[pos[i]]);printf("\n");
		int rr=query(i,r-1,k-i);

		if(rr-i>ansr-ansl || (rr-i==ansr-ansl && i<ansl) ) ansl=i,ansr=rr;

	/*
		for(int j=i;j<=r-1;j++) {
			int mm=findm(i,j);int mi=findmi(i,j);
			if(mm-mi-j<=k-i){
				if(j-i>ansr-ansl) ansr=j,ansl=i;
				if(j-i==ansr-ansl && i<ansl) ansl=i,ansr=j;
			}
		}
		*/
		mp[a[i]]=i;
	}

	return ;
}

int main(){
//	freopen("cf407e.in","r",stdin);
	scanf("%d%d%d",&n,&k,&d);
	if(d==1){
		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]%d;a[i]=(a[i]-b[i])/d+1;
		pos[i]=(i-1)/m+1;t[i]=-i;
	}
//	for(int i=1;i<=n;i++) printf("%d ",a[i]);printf("\n");
	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<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
const int N=2e5+10;
const int M=1000000000;
const int 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<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
const int N=2e5+10;
const int M=1000000000;
const int 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(){
//	freopen("cf407e.in","r",stdin);
	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<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
const int N=2e5+10;
const int M=1000000000;
const int INF=1e18;
int a[N],b[N],s1[N],s2[N];
int cnt,n,m,k,d,top1,top2,c[N],ansr,ansl,sum[N],pos[N],t[N],mn[N];
map<int,int>mp;
inline int findm(int l,int r){
	int ans=0;
	for(int i=l;i<=r;i++) ans=max(ans,a[i]);
	return ans;
}
inline int findmi(int l,int r){
	int ans=INF;
	for(int i=1;i<=n;i++) ans=min(ans,a[i]);
	return ans;
}
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;
		}
	}
//	return l;
}

inline void sol(int L,int R){
	if(L==R) return ;
//	printf("%d %d\n",L,R);
	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]]);
	//	printf("\n\n");
		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]]);
	//	printf("add :%d %d\n",s1[top1],s1[top1-1]-1);
	//	for(int i=1;i<=n;i++) printf("%d ",t[i]+sum[pos[i]]);printf("\n");
	//	for(int j=i;j<=r-1;j++) printf("%d ",t[i]+sum[pos[i]]);printf("\n");
		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]]);
	//	for(int i=1;i<=n;i++) printf("%d ",t[i]+sum[pos[i]]);printf("\n");
		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(){
//	freopen("cf407e.in","r",stdin);
	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;i<=n;i++) printf("%d ",a[i]);printf("\n");
	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<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
const int N=2e5+10;
const int INF=1e18;
int a[N],b[N],s1[N],s2[N];
int cnt,n,m,k,d,top1,top2,c[N],ansr,ansl,sum[N],pos[N],t[N],mm[N];
map<int,int>mp;
inline int findm(int l,int r){
	int ans=0;
	for(int i=l;i<=r;i++) ans=max(ans,a[i]);
	return ans;
}
inline int findmi(int l,int r){
	int ans=INF;
	for(int i=1;i<=n;i++) ans=min(ans,a[i]);
	return ans;
}
void reset(int x){
	mm[x]=0;
	for(int i=(x-1)*m+1;i<=min(n,x*m);i++) mm[x]=max(mm[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,mm[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(mm[i]>=c){
			for(int j=pos[i]*m;j>=(pos[i]-1)*m+1;j--)
				if(t[i]+sum[pos[i]]>=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;
		}
	}
//	return l;
}

inline void sol(int L,int R){
	if(L==R) return ;
//	printf("%d %d\n",L,R);
	mp.clear();int r=R+1;
	top1=top2=0;s1[top1]=s2[top2]=R+1;

	for(int i=R;i>=L;i--){
		if(mp.count(a[i])) r=min(r,mp[a[i]]);
		while(top1 && a[i]>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]<s2[top2]){
			add(s2[top1],s2[top2-1]-1,a[s2[top2]]);
			top2--;
		}
		s2[++top2]=i;
		add(s2[top2],s2[top2-1]-1,-a[s2[top2]]);
	//	printf("# %d %d %d\n",i,r-1,k-i);
	//	for(int j=i;j<=r-1;j++) printf("## %d ",t[i]+sum[pos[i]]);printf("\n");
		int rr=query(i,r-1,k-i);

		if(rr-i>ansr-ansl || (rr-i==ansr-ansl && i<ansl) ) ansl=i,ansr=rr;

	/*
		for(int j=i;j<=r-1;j++) {
			int mm=findm(i,j);int mi=findmi(i,j);
			if(mm-mi-j<=k-i){
				if(j-i>ansr-ansl) ansr=j,ansl=i;
				if(j-i==ansr-ansl && i<ansl) ansl=i,ansr=j;
			}
		}
		*/
		mp[a[i]]=i;
	}

	return ;
}

int main(){
//	freopen("cf407e.in","r",stdin);
	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]%d;a[i]=(a[i]-b[i])/d+1;
		pos[i]=(i-1)/m+1;t[i]=-i;
	}
//	for(int i=1;i<=n;i++) printf("%d ",a[i]);printf("\n");
	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 FILE(Name) freopen(Name"in", "r", stdin), freopen("out", "w", stdout)

namespace io {
    const int __SIZE = (1 << 21) + 1;
    char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
    #define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
    inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
    inline void gc (char &x) { x = Gc(); }
    inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
    inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
    inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
        for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
    template <class I> inline bool gi (I &x) { _eof = 0;
        for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
        for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
    template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
        while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
    struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }
template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; }

typedef unsigned uit;
typedef long long ll;
typedef double db;

const int MAXN = 200100;

int n, k, d;
int a[MAXN];

int res = 1;
int res_l = 1;
int res_r = 1;

struct Segment_Tree {
#define ls (x << 1)
#define rs (x << 1 | 1)

    struct Node { ll v, t; } T[MAXN << 2];

    inline void pushup(int x) { T[x].v = min(T[ls].v, T[rs].v); }
    inline void pushdown(int x) {
        ll&t = T[x].t; if(!t) return ;
        T[ls].v += t, T[ls].t += t;
        T[rs].v += t, T[rs].t += t;
        t = 0;
    }

    inline void build(int x, int l, int r) {
        T[x].v = T[x].t = 0; if(l == r) return ;
        int mid = (l + r) >> 1; build(ls, l, mid), build(rs, mid + 1, r);
    }

    inline void Modify(int x, int l, int r, int L, int R, ll v) {
        if(L <= l && r <= R) return T[x].v += v, T[x].t += v, void();
        int mid = (l + r) >> 1; pushdown(x);
        if(L <= mid) Modify(ls, l, mid, L, R, v);
        if(mid < R) Modify(rs, mid + 1, r, L, R, v);
        pushup(x);
    }

    inline int Find(int x, int l, int r, int p) {
        if(l == r) return T[x].v <= k ? l : -1;
        int mid = (l + r) >> 1; pushdown(x);
        if(T[ls].v <= k) return Find(ls, l, mid, p);
        if(mid < p) return Find(rs, mid + 1, r, p);
        return -1;
    }

#undef ls
#undef rs
}seg;

int b[MAXN];
map<int, int>pos;
stack<int>up, down;

inline void solve(int l, int r) {
    for(int i = l; i <= r; i++) a[i - l + 1] = b[i] / d;
    int n = r - l + 1, las = 0; seg.build(1, 1, n), pos.clear();
    for(int i = 1; i <= n; i++) {
        int v = a[i];
        if(pos.count(v)) {
            seg.Modify(1, 1, n, las + 1, pos[v], 1000000000);
            las = pos[v];
        } pos[v] = i;
        seg.Modify(1, 1, n, 1, n, -1);
        seg.Modify(1, 1, n, i, i, i);
        while(up.top() && a[up.top()] > v) {
            int p = up.top(); up.pop();
            seg.Modify(1, 1, n, up.top() + 1, p, a[p]);
        } seg.Modify(1, 1, n, up.top() + 1, i, -v); up.push(i);
        while(down.top() && a[down.top()] < v) {
            int p = down.top(); down.pop();
            seg.Modify(1, 1, n, down.top() + 1, p, -a[p]);
        } seg.Modify(1, 1, n, down.top() + 1, i, v); down.push(i);
        int L = seg.Find(1, 1, n, i);
        if((~L) && res < i - L + 1) res = i - L + 1, res_l = L + l - 1, res_r = i + l - 1;
    } while(up.top()) up.pop(); while(down.top()) down.pop();
}

int main() {
    gi(n), gi(k), gi(d);
    if(d == 0) {
        int len = 1, now = -1, x = 0, pos = 0, L = 1, R = 1;
        for(int i = 1; i <= n; i++) {
            gi(x);
            if(x != now) {
                if(len < i - pos)
                    len = i - pos, L = pos, R = i - 1;
                now = x, pos = i;
            }
        } if(len < n - pos + 1) L = pos, R = n;
        print(L), pc(' '), print(R), pc('\n');
        return 0;
    } int mi = 2147483647;
    for(int i = 1; i <= n; i++) gi(b[i]), chkmin(mi, b[i]);
    for(int i = 1; i <= n; i++) b[i] -= mi - 1;
    int las = b[1] % d, pos = 1;
    up.push(0), down.push(0);
    for(int i = 2; i <= n + 1; i++)
        if(las != b[i] % d || i == n + 1)
            solve(pos, i - 1), pos = i, las = b[i] % d;
    print(res_l), pc(' '), print(res_r), pc('\n');
    return 0;
}


#pragma GCC optimize(3)
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define reaD() read()
#define pb push_back
#define Pair pair < int, int >
#define mkp make_pair
#define rint register int
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i, k, j) for(register int i = (k); i >= (j); i--)
#define For(i, k, j) for(register int i = (k); i <= (j); i++)
#define DEBUG fprintf(stderr, "***IAKIOI***\n")
#define CDEBUG cerr << "***IAKIOI***" << endl;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file(s) freopen(s".in", "r", stdin);freopen(s".out", "w", stdout)
#define INF ((1 << 30) - 1)
#define dprintf(x) fprintf(stderr, "%d ", x)
#define dprintfln(x) fprintf(stderr, "%d\n", x)
#define dln fprintf(stderr, "\n")
const int P = 998244353; //
using namespace std;
inline void ckmax(int &a, int b) {a = max(a, b);}
inline void ckmin(int &a, int b) {a = min(a, b);}
inline void mulmod(int &a, int b) {a = 1ll * a * b % P;}
inline void addmod(int &a, int b) {int t = a + b; a = (t >= P ? t - P : t); }
inline int ksm(int a, int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline int inv(int a) {return ksm(a, P-2);}
inline int read() {
    int num=0,flag=1;char c=' ';
    for(;!isdigit(c);c=getchar()) if(c=='-') flag=-1;
    for(;isdigit(c);num=num*10+c-48,c=getchar());
    return num*flag;
}
const int MAXN = 2e5 + 5;
int n, k, d, a[MAXN];
struct Segment_tree {
	int mn[MAXN << 2], mx[MAXN << 2];
	#define ls (k << 1)
	#define rs (k << 1 | 1)
	#define mid ((l + r) >> 1)
//	void update(int k, int l, int r, int p, int v) {
//		if(l == p && l == r) {
//			mn[k] = mx[k] = v;
//			return ;
//		}
//		if(p <= mid) update(ls, l, mid, p, v);
//		else update(rs, mid+1, r, p, v);
//		mn[k] = min(mn[ls], mn[rs]); mx[k] = max(mx[ls], mx[rs]);
//	}
	void build(int k, int l, int r) {
		if(l == r) {
			mn[k] = mx[k] = a[l];
			return;
		}
		build(ls, l, mid); build(rs, mid+1, r);
		mn[k] = min(mn[ls], mn[rs]); mx[k] = max(mx[ls], mx[rs]);
	}
	int qmin(int k, int l, int r, int ql, int qr) {
		if(l == ql && r == qr) return mn[k];
		if(qr <= mid) return qmin(ls, l, mid, ql, qr);
		else if(mid < ql) return qmin(rs, mid+1, r, ql, qr);
		else return min(qmin(ls, l, mid, ql, mid), qmin(rs, mid+1, r, mid+1, qr));
	}
	int qmax(int k, int l, int r, int ql, int qr) {
		if(l == ql && r == qr) return mx[k];
		if(qr <= mid) return qmax(ls, l, mid, ql, qr);
		else if(mid < ql) return qmax(rs, mid+1, r, ql, qr);
		else return max(qmax(ls, l, mid, ql, mid), qmax(rs, mid+1, r, mid+1, qr));
	}
}tr;
void solveSub1() {
	int l = 1, r = 0, al = 0, ar = 0;
	for(r = 1; r <= n; r++) {
		while(l <= r && a[l] != a[r]) l++;
		if(r - l > ar - al || (r - l == ar - al && l < al))
			ar = r, al = l;
	}
	cout << al << ' ' << ar << endl;
}
signed main()
{
	cin >> n >> k >> d;
	For(i, 1, n) a[i] = read(); a[0] = 0;

	if(!d) {
		solveSub1();
		return 0;
	}
	tr.build(1, 1, n);
	int l = 1, r, al = 1, ar = 1;
	for(r = 2; r <= n; r++) {
		if(a[r] == a[r-1] || (a[r] % d + d) % d != (a[r-1] % d + d) % d) l = r;
		while(l < r && k + r - l > (tr.qmax(1, 1, n, l, r) - tr.qmin(1, 1, n, l, r)) / d) l++;
//		cout << r << ' ' << l << endl;
		if(r - l > ar - al || (r - l == ar - al && l < al))
			ar = r, al = l;
	}
	cout << al << ' ' << ar << endl;
    return 0;
}
/*
1. 没有重复
2. k + (r - l + 1) <= (max - min) / d + 1
3. 同余
*/

/*
2 4 6 8
1 + 3
*/


#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
int n,k,d;
int a[200010],pre[200010];//ÉÏÒ»¸öÏàµÈµÄÎ»ÖÃ
map<int,int>vis;
int stackmax[200010],stackmin[200010],topmax=0,topmin=0;
struct node{
	int l;
	int r;
	int minn;
	int add;
}tree[800010];
void build(int now,int l,int r){
	tree[now].l=l;
	tree[now].r=r;
	tree[now].minn=1e9;
	tree[now].add=0;
	if(l==r)return;
	int mid=(l+r)/2;
	build(now*2,l,mid);
	build(now*2+1,mid+1,r);
}
void add(int now,int x,int y,int ad){
	int l=tree[now].l;
	int r=tree[now].r;
	if(l==x&&r==y){
		tree[now].add+=ad;
		tree[now].minn+=ad;
		return;
	}
	int mid=(l+r)/2;
	if(tree[now].add){
		add(now*2,l,mid,tree[now].add);
		add(now*2+1,mid+1,r,tree[now].add);
		tree[now].add=0;
	}
	if(y<=mid){
		add(now*2,x,y,ad);
	}
	else if(x>mid){
		add(now*2+1,x,y,ad);
	}
	else{
		add(now*2,x,mid,ad);
		add(now*2+1,mid+1,y,ad);
	}
	tree[now].minn=min(tree[now*2].minn,tree[now*2+1].minn);
}
int check(int now,int x){
	int l=tree[now].l;
	int r=tree[now].r;
	if(l==r)return l;
	int lson=now*2;
	int rson=now*2+1;
	if(tree[lson].minn<=x)return check(lson,x);
	else return check(rson,x);
}
int main(){
	scanf("%d%d%d",&n,&k,&d);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	if(d==0){
		if(n!=7)cout<<"!"<<endl;
		int maxn=0,now=0,l=0,r=0;
		for(int i=1;i<=n;i++){
			if(a[i]!=a[i-1])now=i;
			if(i-now+1>maxn){
				maxn=i-now+1;
				l=now;
				r=i;
			}
		}
		printf("%d %d\n",l,r);
		return 0;
	}
	for(int i=1;i<=n;i++){
		pre[i]=vis[a[i]];
		vis[a[i]]=i;
	}
	int pr=1;
	int maxn=0,l=0,r=0;
	build(1,1,n);
	for(int i=1;i<=n;i++){
		while(pr<=pre[i]||a[pr]%d!=a[i]%d){
			add(1,pr,pr,1e9);
			pr++;
		}
		add(1,i,i,-1e9+i);
		while(topmax>0&&a[stackmax[topmax]]<a[i]){
			add(1,stackmax[topmax-1]+1,stackmax[topmax],a[i]/d-a[stackmax[topmax]]/d);
			topmax--;
		}
		stackmax[++topmax]=i;
		while(topmin>0&&a[stackmin[topmin]]>a[i]){
			add(1,stackmin[topmin-1]+1,stackmin[topmin],a[stackmin[topmin]]/d-a[i]/d);
			topmin--;
		}
		stackmin[++topmin]=i;
		int nowl=check(1,i+k);
		if(i-nowl+1>maxn){
			maxn=i-nowl+1;
			l=nowl;
			r=i;
		}
	}
	printf("%d %d\n",l,r);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k,d;
int a[200010],val[200010],pre[200010],vis[200010];
int read[200010],s[200010],cnt=0;
int stackmax[200010],stackmin[200010];//µ¥µ÷Õ»
struct node{
	int l;
	int r;
	int flag;//Çø¼äÄÚaÊÇ·ñÈ«ÏàÍ¬
	int real_val;//aÏàÍ¬µÄÖµ
	int maxn;//dµÄ±¶Êý×î´óÖµ
	int minn;//dµÄ±¶Êý×îÐ¡Öµ
	int maxpre;//ÉÏÒ»¸övalÏàµÈµÄÊý
	int real_min;//l+max-min×îÐ¡Öµ
	int can_min;//Í¬Ê±Âú×ãÏÞÖÆ
	int change_flag;
	int add;
	void clear(){
		l=0;
		r=0;
		flag=0;
		real_val=0;
		maxn=-1e9;
		minn=1e9;
		maxpre=-1e9;
		real_min=1e9;
		can_min=1e9;
		change_flag=0;
		add=0;
	}
}tree[800010];
node update_(node a,node b){
	node c;
	c.clear();
	if(a.flag&&b.flag&&a.real_val==b.real_val){
		c.flag=1;
		c.real_val=a.real_val;
	}
	c.maxn=max(a.maxn,b.maxn);
	c.minn=min(a.minn,b.minn);
	c.maxpre=max(a.maxpre,b.maxpre);
	c.real_min=min(a.real_min,b.real_min);
	return c;
}
void update(int now){
	if(tree[now*2].flag&&tree[now*2+1].flag&&tree[now*2].real_val==tree[now*2+1].real_val){
		tree[now].flag=1;
		tree[now].real_val=tree[now*2].real_val;
	}
	tree[now].maxn=max(tree[now*2].maxn,tree[now*2+1].maxn);
	tree[now].minn=min(tree[now*2].minn,tree[now*2+1].minn);
	tree[now].maxpre=max(tree[now*2].maxpre,tree[now*2+1].maxpre);
	tree[now].real_min=min(tree[now*2].real_min,tree[now*2+1].real_min);
}
void build(int now,int l,int r){
	tree[now].l=l;
	tree[now].r=r;
	tree[now].real_min=1e9;
	tree[now].flag=1;
	tree[now].maxn=-1e9;
	tree[now].minn=1e9;
	tree[now].maxpre=-1e9;
	if(l==r)return;
	int mid=(l+r)/2;
	build(now*2,l,mid);
	build(now*2+1,mid+1,r);
	update(now);
}
void add(int now,int x,int y,int ad){
	int l=tree[now].l;
	int r=tree[now].r;
	if(l==x&&r==y){
		tree[now].add+=ad;
		tree[now].real_min+=ad;
		return;
	}
	int mid=(l+r)/2;
	if(tree[now].add){
		add(now*2,l,mid,tree[now].add);
		add(now*2+1,mid+1,r,tree[now].add);
		tree[now].add=0;
	}
	if(y<=mid){
		add(now*2,x,y,ad);
	}
	else if(x>mid){
		add(now*2+1,x,y,ad);
	}
	else{
		add(now*2,x,mid,ad);
		add(now*2+1,mid+1,y,ad);
	}
	update(now);
}
void insert(int now,int x){
	int l=tree[now].l;
	int r=tree[now].r;
	if(l==r&&l==x){
		tree[now].flag=1;
		tree[now].maxn=val[x];
		tree[now].minn=val[x];
		tree[now].maxpre=pre[x];
		tree[now].real_min=x;
		tree[now].real_val=a[x];
		return;
	}
	int mid=(l+r)/2;
	if(tree[now].add){
		add(now*2,l,mid,tree[now].add);
		add(now*2+1,mid+1,r,tree[now].add);
		tree[now].add=0;
	}
	if(x<=mid){
		insert(now*2,x);
	}
	else{
		insert(now*2+1,x);
	}
	update(now);
}
void check1(int now,node kk,int x){
	int l=tree[now].l;
	int r=tree[now].r;
	tree[now].can_min=1e9;
	tree[now].change_flag=0;
//	cout<<"@"<<l<<" "<<r<<endl;
	if(l==r){
	//	cout<<"!!!"<<l<<endl;
		tree[now].can_min=tree[now].real_min;
		return;
	}
	int mid=(l+r)/2;
	int lson=now*2;
	int rson=now*2+1;
	if(tree[now].add){
		add(lson,l,mid,tree[now].add);
		add(rson,mid+1,r,tree[now].add);
		tree[now].add=0;
	}
	if(x<=mid){
		tree[rson].can_min=1e9;
		tree[rson].change_flag=2;
		check1(lson,kk,x);
	}
	else{
		node to;
		to.clear();
		to=update_(tree[rson],kk);
	//	cout<<"@@"<<to.maxpre<<" "<<to.flag<<endl;
		if(to.maxpre>=mid||to.flag==0||a[mid]!=to.real_val){
			tree[lson].can_min=1e9;
			tree[lson].change_flag=2;
			check1(rson,kk,x);
		}
		else{
			tree[rson].can_min=tree[rson].real_min;
			tree[rson].change_flag=1;
			check1(lson,to,x);
		}
	}
	update(now);
	tree[now].can_min=min(tree[lson].can_min,tree[rson].can_min);
}
int check2(int now,int x){
	int l=tree[now].l;
	int r=tree[now].r;
//	cout<<"#"<<l<<" "<<r<<" "<<tree[now].can_min<<endl;
	if(l==r)return l;
	int mid=(l+r)/2;
	int lson=now*2;
	int rson=now*2+1;
	if(tree[now].add){
		add(lson,l,mid,tree[now].add);
		add(rson,mid+1,r,tree[now].add);
		tree[now].add=0;
	}
	if(tree[now].change_flag){
		if(tree[now].change_flag==1){
			tree[lson].can_min=tree[lson].real_min;
			tree[rson].can_min=tree[rson].real_min;
			tree[lson].change_flag=tree[rson].change_flag=1;
		}
		else{
			tree[lson].can_min=1e9;
			tree[rson].can_min=1e9;
			tree[lson].change_flag=tree[rson].change_flag=2;
		}
		tree[now].change_flag=0;
	}
	if(x<=mid){
		return check2(lson,x);
	}
//	cout<<"##"<<tree[lson].can_min<<endl;
	if(tree[lson].can_min<=x+k)return check2(lson,x);
	return check2(rson,x);
}
int main(){
	scanf("%d%d%d",&n,&k,&d);
	if(d==0){
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
		}
		int maxn=0,pre=0,now=0,l=0,r=0;
		for(int i=1;i<=n;i++){
			if(a[i]==a[i-1])now++;
			else{
				now=1;
				pre=i;
			}
			if(now>maxn){
				maxn=now;
				l=pre;
				r=i;
			}
		}
		if(l==0){
			printf("-1\n");
			return 0;
		}
		printf("%d %d\n",l,r);
		return 0;
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		val[i]=a[i]/d;
		a[i]=(a[i]%d+d)%d;
		read[i]=val[i];
	}
	sort(read+1,read+n+1);
	for(int i=1;i<=n;i++){
		if(i==1||read[i]!=read[i-1]){
			s[++cnt]=read[i];
		}
	}
	for(int i=1;i<=n;i++){
		read[i]=lower_bound(s+1,s+cnt+1,val[i])-s;
		pre[i]=vis[read[i]];
		vis[read[i]]=i;
	}
	build(1,1,n);
	int topmax=0,topmin=0;
	int l=0,r=0,maxn=0;
	for(int i=1;i<=n;i++){
	//	cout<<"!"<<i<<endl;
		insert(1,i);
		while(topmax>0&&val[stackmax[topmax]]<val[i]){
			add(1,stackmax[topmax-1]+1,stackmax[topmax],val[i]-val[stackmax[topmax]]);
			topmax--;
		}
		stackmax[++topmax]=i;
		while(topmin>0&&val[stackmin[topmin]]>val[i]){
			add(1,stackmin[topmin-1]+1,stackmin[topmin],val[stackmin[topmin]]-val[i]);
			topmin--;
		}
		stackmin[++topmin]=i;
		node kk;
		kk.clear();
		kk.maxpre=pre[i];
		kk.real_val=a[i];
		kk.flag=1;
		check1(1,kk,i);
		int nowl=check2(1,i);
		if(i-nowl+1>maxn||(i-nowl+1==maxn&&nowl<l)){
			l=nowl;
			r=i;
			maxn=r-l+1;
		}
	//	cout<<l<<" "<<r<<endl;
	}
	if(l==0){
		printf("-1\n");
		return 0;
	}
	printf("%d %d\n",l,r);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
int n,k,d;
int a[200010],pre[200010];//ÉÏÒ»¸öÏàµÈµÄÎ»ÖÃ
map<int,int>vis;
int stackmax[200010],stackmin[200010],topmax=0,topmin=0;
struct node{
	int l;
	int r;
	long long minn;
	long long add;
}tree[800010];
void build(int now,int l,int r){
	tree[now].l=l;
	tree[now].r=r;
	tree[now].minn=2e9;
	tree[now].add=0;
	if(l==r)return;
	int mid=(l+r)/2;
	build(now*2,l,mid);
	build(now*2+1,mid+1,r);
}
void add(int now,int x,int y,int ad){
	int l=tree[now].l;
	int r=tree[now].r;
	if(l==x&&r==y){
		tree[now].add+=ad;
		tree[now].minn+=ad;
		return;
	}
	int mid=(l+r)/2;
	if(tree[now].add){
		add(now*2,l,mid,tree[now].add);
		add(now*2+1,mid+1,r,tree[now].add);
		tree[now].add=0;
	}
	if(y<=mid){
		add(now*2,x,y,ad);
	}
	else if(x>mid){
		add(now*2+1,x,y,ad);
	}
	else{
		add(now*2,x,mid,ad);
		add(now*2+1,mid+1,y,ad);
	}
	tree[now].minn=min(tree[now*2].minn,tree[now*2+1].minn);
}
int check(int now,int x){
	int l=tree[now].l;
	int r=tree[now].r;
	if(l==r)return l;
	int lson=now*2;
	int rson=now*2+1;
	int mid=(l+r)/2;
	if(tree[now].add){
		add(lson,l,mid,tree[now].add);
		add(rson,mid+1,r,tree[now].add);
		tree[now].add=0;
	}
	if(tree[lson].minn<=x)return check(lson,x);
	else return check(rson,x);
}
int main(){
	scanf("%d%d%d",&n,&k,&d);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	if(d==0){
		int maxn=0,now=0,l=0,r=0;
		for(int i=1;i<=n;i++){
			if(a[i]!=a[i-1])now=i;
			if(i-now+1>maxn){
				maxn=i-now+1;
				l=now;
				r=i;
			}
		}
		printf("%d %d\n",l,r);
		return 0;
	}
	for(int i=1;i<=n;i++){
		pre[i]=vis[a[i]];
		vis[a[i]]=i;
	}
	int pr=1;
	int maxn=0,l=0,r=0;
	build(1,1,n);
	for(int i=1;i<=n;i++){
		while(pr<=pre[i]||a[pr]%d!=a[i]%d){
			add(1,pr,pr,2e9+1);
			pr++;
		}
		add(1,i,i,-2e9+i);
		while(topmax>0&&a[stackmax[topmax]]<a[i]){
			add(1,stackmax[topmax-1]+1,stackmax[topmax],a[i]/d-a[stackmax[topmax]]/d);
			topmax--;
		}
		stackmax[++topmax]=i;
		while(topmin>0&&a[stackmin[topmin]]>a[i]){
			add(1,stackmin[topmin-1]+1,stackmin[topmin],a[stackmin[topmin]]/d-a[i]/d);
			topmin--;
		}
		stackmin[++topmin]=i;
		int nowl=check(1,i+k);
		if(nowl>=pr&&i-nowl+1>maxn){
			maxn=i-nowl+1;
			l=nowl;
			r=i;
		}
	}
	printf("%d %d\n",l,r);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
inline int gi() {
	char c;
	int num = 0, flg = 1;
	while ((c = getchar()) < '0' || c > '9')
		if (c == '-')
			flg = -1;
	while (c >= '0' && c <= '9') {
		num = num * 10 + c - 48;
		c = getchar();
	}
	return num * flg;
}
#define N 200005
#define LL long long
#define lc i << 1
#define rc i << 1 | 1
const int INF = 1000000000;
LL a[N];
map<LL, int> last;
struct node {
	int l, r;
	LL la, x;
} t[N << 2];
int sl[N], topl, sr[N], topr;

void cal(int i, LL k) {
	t[i].la += k;
	t[i].x += k;
}

void pushdown(int i) {
	if (t[i].la && t[i].l < t[i].r) {
		cal(lc, t[i].la);
		cal(rc, t[i].la);
		t[i].la = 0;
	}
}

void build(int i, int l, int r) {
	t[i].l = l;
	t[i].r = r;
	if (l == r) {
		t[i].x = l;
		return;
	}
	int mid = (l + r) >> 1;
	build(lc, l, mid);
	build(rc, mid + 1, r);
	t[i].x = min(t[lc].x, t[rc].x);
}

void insert(int i, int l, int r, LL k) {
	if (t[i].l > r || t[i].r < l)
		return;
	pushdown(i);
	if (l <= t[i].l && t[i].r <= r) {
		cal(i, k);
		return;
	}
	insert(lc, l, r, k);
	insert(rc, l, r, k);
	t[i].x = min(t[lc].x, t[rc].x);
}

bool flg;
int ans;

int EF(int i, int k) {
	if (t[i].l == t[i].r)
		return t[i].l;
	pushdown(i);
	if (t[lc].x <= k)
		return EF(lc, k);
	else
		return EF(rc, k);
}

void query(int i, int l, int r, int k) {
	if (t[i].l > r || t[i].r < l)
		return;
	pushdown(i);
	if (l <= t[i].l && t[i].r <= r) {
		if (t[i].x <= k)
			flg = 1, ans = EF(i, k);
		return;
	}
	if (!flg)
		query(lc, l, r, k);
	if (!flg)
		query(rc, l, r, k);
}

void del(int i, int x) {
	if (x < t[i].l || x > t[i].r)
		return;
	pushdown(i);
	if (t[i].l == x && t[i].r == x) {
		t[i].x = 0;
		return;
	}
	del(lc, x);
	del(rc, x);
	t[i].x = min(t[lc].x, t[rc].x);
}

void print(int i) {
	if (t[i].l == t[i].r) {
		printf("%lld ", t[i].x);
		return;
	}
	pushdown(i);
	print(lc);
	print(rc);
}

int main() {
	int n, k, d, i, L, al = 1, ar = 1;
	n = gi();
	k = gi();
	d = gi();
	for (i = 1; i <= n; i++) a[i] = gi() + 1ll * INF;
	if (d == 0) {
		for (i = 1; i <= n; i++) {
		  int tl = i;
		  while (a[i] == a[i + 1]) i++;
      if (i - tl > ar - al) al = tl, ar = i;
    }
//    for (i = L = 1; i <= n; i++) {
//			while (L <= n && a[L] != a[i]) L++;
//			if (ar - al < i - L)
//				al = L, ar = i;
//		}
		printf("%d %d", al, ar);
		return 0;
	}
	build(1, 1, n);
	for (i = L = 1; i <= n; i++) {
		int tmp = L;
		if (a[i] % d == a[i - 1] % d)
			L = max(L, last[a[i]] + 1);
		else
			L = i;
		last[a[i]] = i;
		while (tmp < L) del(1, tmp++);
		while (topl && sl[topl] >= L && a[sl[topl]] >= a[i]) {
			insert(1, max(L, sl[topl - 1] + 1), sl[topl], a[sl[topl]] / d);
			topl--;
		}
		insert(1, max(L, sl[topl] + 1), i, -a[i] / d);
		sl[++topl] = i;
		while (topr && sr[topr] >= L && a[sr[topr]] <= a[i]) {
			insert(1, max(L, sr[topr - 1] + 1), sr[topr], -a[sr[topr]] / d);
			topr--;
		}
		insert(1, max(L, sr[topr] + 1), i, a[i] / d);
		sr[++topr] = i;
		flg = 0;
		ans = 0;
		query(1, L, i, k + i);
		if (ar - al < i - ans)
			al = ans, ar = i;
		// printf("%d %d\n",L,i);
		// print(1);printf("\n");
	}
	printf("%d %d", al, ar);
}


#include<bits/stdc++.h>
#define R register
#define N 202020
#define M 808080
#define ll long long

int n,m,k,tot,rp[N];
ll v[M],z[M],a[N];
std::map<int,int> mp,vis;
std::vector<int> vec[N];
int si[N],sd[N],ti,td;
int al=0,ar=0;

inline void pushdown(int x){
	R int ls=x<<1,rs=ls|1;
	if(z[x]){
		z[ls]+=z[x],z[rs]+=z[x],v[ls]+=z[x],v[rs]+=z[x],z[x]=0;
	}
}

inline void add(int x,int l,int r,int a,int b,ll c){
	if(l>=a&&r<=b){
		v[x]+=c,z[x]+=c;
		return;
	}
	if(l>b||r<a) return;
	R int mid=(l+r)>>1,ls=x<<1,rs=ls|1;
	pushdown(x);
	if(a<=mid) add(ls,l,mid,a,b,c);
	if(b>mid) add(rs,mid+1,r,a,b,c);
	v[x]=std::min(v[ls],v[rs]);
}

inline int query(int x,int l,int r,ll d){
	if(l==r) return l;
	R int mid=(l+r)>>1,ls=x<<1,rs=ls|1;
	pushdown(x);
	if(v[rs]<=d) return query(rs,mid+1,r,d);
	else return query(ls,l,mid,d);
}

inline void init(int x,int l,int r){
	z[x]=0;
	if(l==r){
		v[x]=-l;
		return;
	}
	R int mid=(l+r)>>1,ls=x<<1,rs=ls|1;
	init(ls,l,mid),init(rs,mid+1,r);
	v[x]=std::min(v[ls],v[rs]);
}

inline void getans(int l,int r){
	if(l>r) return;
	R int L=r-l+1;
	init(1,1,L);
	vis.clear();
	rp[r]=r;
	vis[a[r]]=r;
	for(R int i=r-1;i>=l;--i){
		rp[i]=std::min(rp[i+1],(vis.find(a[i])==vis.end()?r:vis[a[i]]-1));
		vis[a[i]]=i;
	}
	for(R int i=r;i>=l;--i){
		while(ti&&a[si[ti]]<=a[i]){
			R int nw=si[ti--];
			add(1,1,L,nw-l+1,(ti?si[ti]:r+1)-l,-a[nw]);
		}
		while(td&&a[sd[td]]>=a[i]){
			R int nw=sd[td--];
			add(1,1,L,nw-l+1,(td?sd[td]:r+1)-l,a[nw]);
		}
		add(1,1,L,i-l+1,(ti?si[ti]:r+1)-l,a[i]);
		add(1,1,L,i-l+1,(td?sd[td]:r+1)-l,-a[i]);
		if(rp[i]!=r)
			add(1,1,L,rp[i]-l+2,L,2e9);
		if(i!=l)
			add(1,1,L,1,i-l,2e9);

		R int Rp=query(1,1,L,m-(i-l+1))+l-1;
		if(Rp-i>ar-al)
			ar=Rp,al=i;
		else if(Rp-i==ar-al&&al>i)
			ar=Rp,al=i;

		if(rp[i]!=r) add(1,1,L,rp[i]-l+2,L,-2e9);
		if(i!=l) add(1,1,L,1,i-l,-2e9);

		si[++ti]=i,sd[++td]=i;
	}
	ti=td=0;
}

inline void solve(int id){
	if(!vec[id].size()) return ;
	R int pre=vec[id][0];
	for(R int i=1;i<vec[id].size();++i)
		if(vec[id][i-1]+1!=vec[id][i])
			getans(pre,vec[id][i-1]),pre=vec[id][i];
	getans(pre,vec[id][vec[id].size()-1]);
}

int main(){
	al=5e8,ar=0;
	scanf("%d%d%d",&n,&m,&k);
	for(R int i=1;i<=n;++i) scanf("%lld",&a[i]),a[i]+=1e9;
	if(!k){
		for(R int i=1;i<=n;++i){
			R int tl=i;
			while(a[i]==a[i+1]) ++i;
			if(i-tl>ar-al) al=tl,ar=i;
		}
		printf("%d %d\n",al,ar);
		return 0;
	}
	for(R int i=1;i<=n;vec[mp[a[i]%k]].push_back(i),++i)
		if(mp.find(a[i]%k)==mp.end()) mp[a[i]%k]=++tot;
	for(R int i=1;i<=n;++i) a[i]/=k;
	for(R int i=1;i<=tot;++i) solve(i);
	printf("%d %d\n",al,ar);
}


//Solution by Tima
#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
#define all(x) x.begin(), x.end()

using namespace std;
const int N = int(3e5) + 12, mod = int(1e9)  + 7;

int n,k;

int a[N], c[N], ans, cnt[N];

vector <int> f[N];

void solve(){
	scanf("%d%d", &n, &k);
	for(int i = 1,x; i <= n; i++){
		scanf("%d", &x);
		cnt[x]++;
	}
	for(int i = 1; i <= k; i++) scanf("%d", &c[i]);
	set <int> st;
	for(int i = 1; i <= k; i++) if(cnt[i] > 0) st.insert(i) ;
	while(!st.empty()){
		int v = *st.begin();
		int mx = c[v];
		while(true){
			mx = min(mx, c[v]);
			while(cnt[v] && mx){
				cnt[v]--;
				mx--;
				f[ans].pb(v);
			}
			if(cnt[v] == 0){
				st.erase(v);
			}
			if(mx == 0) break;
			if(st.upper_bound(v) != st.end()){
				v = *st.upper_bound(v);
			}
			else break;
		}
		ans++;
	}
	printf("%d", ans);
	for(int i = 0; i < ans;i++){
		printf("\n%d ", int(f[i].size()));
		for(int x : f[i]) printf("%d ", x);
	}

}

int main () {
	int T = 1;
	//scanf("%d", &T);

	while(T--){
		solve();
	}

return 0;
}


//Solution by Tima
#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
#define all(x) x.begin(), x.end()

using namespace std;
const int N = int(3e5) + 12, mod = int(1e9)  + 7;

int n,k;

int a[N], c[N], ans, cnt[N];

vector <int> f[N];

void solve(){
	scanf("%d%d", &n, &k);

	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		cnt[a[i]]++;
	}
	set <int> st;
	for(int i = 1; i <= k; i++) if(cnt[i] > 0) st.insert(i);

	for(int i = 1; i <= k; i++) {
		scanf("%d", &c[i]);
	}
	while(!st.empty()){
		vector <int> used;
		int v = *st.begin();
		int mx = mod;
		while(true){
			int res = 0;
			mx = min(mx, c[v]);
			while(cnt[v] > 0 && mx > 0){
				mx--;
				cnt[v]--;
				f[ans].pb(v);
			}
			if(cnt[v] == 0){
				st.erase(v);
			}
			if(mx == 0) break;
			if(st.upper_bound(v) != st.end()) v = *st.upper_bound(v);
			else break;
		}
		ans++;
	}
	printf("%d", ans);
	for(int i = 0; i < ans; i++){
		printf("\n%d ", int(f[i].size()));
		for(int x : f[i]) printf("%d ", x);
	}

}

int main () {
	int T = 1;
	//scanf("%d", &T);

	while(T--){
		solve();
	}

return 0;
}


//Solution by Tima
#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
#define all(x) x.begin(), x.end()

using namespace std;
const int N = int(3e5) + 12, mod = int(1e9)  + 7;

int n,k;

int a[N], c[N], ans, cnt[N];

vector <int> f[N];

void solve(){
	scanf("%d%d", &n, &k);
	for(int i = 1,x; i <= n; i++){
		scanf("%d", &x);
		cnt[x]++;
	}
	for(int i = 1; i <= k; i++) {
		scanf("%d", &c[i]);
		a[i] = c[i];
	}
	multiset <pair<int,int> > st;
	for(int i = 1; i <= k; i++) {
		while(cnt[i] > 0) {
			cnt[i]--;
			st.insert(mp(c[i],i));
		}
	}
	while(!st.empty()){
		int cur = 0;
		while(true){
			auto it = st.upper_bound(mp(cur + 1, 0));
			if(it == st.end()) break;
			f[ans].pb((*it).s);
			st.erase(it);
			cur++;
		}
		ans++;
	}
	printf("%d", ans);
	for(int i = 0; i < ans;i++){
		printf("\n%d ", int(f[i].size()));
		for(int x : f[i]) printf("%d ", x);
	}

}

int main () {
	int T = 1;
	//scanf("%d", &T);

	while(T--){
		solve();
	}

return 0;
}


//Solution by Tima
#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
#define all(x) x.begin(), x.end()

using namespace std;
const int N = int(3e5) + 12, mod = int(1e9)  + 7;

int n,k;

int a[N], c[N], ans, cnt[N];

vector <int> f[N];

void solve(){
	scanf("%d%d", &n, &k);

	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		cnt[a[i]]++;
	}
	set <int> st;
	for(int i = 1; i <= k; i++) if(cnt[i] > 0) st.insert(i);

	for(int i = 1; i <= k; i++) {
		scanf("%d", &c[i]);
	}
	while(!st.empty()){
		vector <int> used;
		int v = *st.begin();
		int mx = mod;
		while(true){
			int res = 0;
			while(cnt[v] > 0 && c[v] > res){
				res++;
				cnt[v]--;
				f[ans].pb(v);
			}
			if(cnt[v] == 0){
				st.erase(v);
			}
			if(c[v] == res) break;
			if(st.upper_bound(v) != st.end()) v = *st.upper_bound(v);
			else break;
		}
		ans++;
	}
	printf("%d", ans);
	for(int i = 0; i < ans; i++){
		printf("\n%d ", int(f[i].size()));
		for(int x : f[i]) printf("%d ", x);
	}

}

int main () {
	int T = 1;
	//scanf("%d", &T);

	while(T--){
		solve();
	}

return 0;
}


#include <bits/stdc++.h>
#define fast   ios_base::sync_with_stdio(false); \
                    cin.tie(NULL);
#define L long long
#define ll long long
#define SS string
#define PB push_back
#define pp pair<L,L>
#define f(x, n , i) for (i = x ; i <= n ; i++)
#define setE(a, x , size) memset(a,x,size);
#define NL 200500
#define INT_MINIMUM -10000000000000000
#define EMPTY ""
#define mapss map<pair<L,L>,SS>
#define mapsi map<pair<L,L>,L>
#define reverse(s) reverse(s.begin(),s.end())
#define fr (s , e , i) for (i = s , i >= e ; i--)
#define slen(s) s.length()
#define isEven(x) ((x%2)==0)
using namespace std;

#define modu 1000000007
ll powerm(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
struct node{
ll fmax = INT_MINIMUM;
ll smax = INT_MINIMUM;
ll sum = 0;
ll value = 0;
};
vector <ll> v[NL];
ll visited[NL] = {0};
vector <node> vn;
void dfs(ll root, ll p)
{
   if (visited[root] == 1)
   {
      return ;
   }
   visited[root] = 1;
   ll sum = 0;
   for (ll i = 0 ; i < v[root].size(); i++)
   {
      ll child = v[root][i];
      if (child != p)
      {
      dfs(child, root);
      ll maxi = max(vn[child].fmax, vn[child].sum);
      if (vn[root].fmax < maxi)
      {
         vn[root].smax = vn[root].fmax;
         vn[root].fmax = maxi;
      }
      else if (vn[root].smax < maxi)
      {
         vn[root].smax = maxi;
      }
      sum += vn[child].sum;
      }
   }
   vn[root].sum = vn[root].value + sum ;
}
// #define
int main()
{
   fast
   ll t = 1;
   while (t--)
   {
      ll n , k;
      cin >> n >> k;
      ll a[n];
      for (ll i = 0; i < n ; i++)
      {
         cin >> a[i];
         a[i] -= 1;
      }
      ll c[k];
      for (ll i = 0; i < k ; i++)
      {
         cin >> c[i];
      }
      sort (a,a+n);
      ll m = 0;
      ll maxi = -1;
      for (ll i = n-1 ; i>=0 ; i--)
      {
         ll op = a[i];
         m += 1;
         ll s = (m+c[op]-1)/c[op];
         maxi = max(s, maxi);
      }
      cout << maxi << "\n";
      vector <vector<ll>> answer(maxi);
      ll ok[n];
      for (ll i = 0 ; i < n ; i++)
      {
         ok[i] = i%maxi;
         answer[ok[i]].push_back(a[i]);
      }
      for (ll i = 0 ; i < maxi ; i++)
      {
         cout << answer[i].size() << " ";
         for (ll j = 0 ; j < answer[i].size() ; j++)
         {
            cout << answer[i][j]+1 << " ";
         }
         cout << "\n";
      }
       // for (ll i)
   }
   return 0;
}


#include <bits/stdc++.h>
#define fast   ios_base::sync_with_stdio(false); \
                    cin.tie(NULL);
#define L long long
#define ll long long
#define SS string
#define PB push_back
#define pp pair<L,L>
#define f(x, n , i) for (i = x ; i <= n ; i++)
#define setE(a, x , size) memset(a,x,size);
#define NL 200500
#define INT_MINIMUM -10000000000000000
#define EMPTY ""
#define mapss map<pair<L,L>,SS>
#define mapsi map<pair<L,L>,L>
#define reverse(s) reverse(s.begin(),s.end())
#define fr (s , e , i) for (i = s , i >= e ; i--)
#define slen(s) s.length()
#define isEven(x) ((x%2)==0)
using namespace std;

#define modu 1000000007
ll powerm(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
struct node{
ll fmax = INT_MINIMUM;
ll smax = INT_MINIMUM;
ll sum = 0;
ll value = 0;
};
vector <ll> v[NL];
ll visited[NL] = {0};
vector <node> vn;
void dfs(ll root, ll p)
{
   if (visited[root] == 1)
   {
      return ;
   }
   visited[root] = 1;
   ll sum = 0;
   for (ll i = 0 ; i < v[root].size(); i++)
   {
      ll child = v[root][i];
      if (child != p)
      {
      dfs(child, root);
      ll maxi = max(vn[child].fmax, vn[child].sum);
      if (vn[root].fmax < maxi)
      {
         vn[root].smax = vn[root].fmax;
         vn[root].fmax = maxi;
      }
      else if (vn[root].smax < maxi)
      {
         vn[root].smax = maxi;
      }
      sum += vn[child].sum;
      }
   }
   vn[root].sum = vn[root].value + sum ;
}
// #define
int main()
{
   fast
   ll t = 1;
   while (t--)
   {
      ll n , k;
      cin >> n >> k;
      ll a[n];
      for (ll i = 0; i < n ; i++)
      {
         cin >> a[i];
         a[i] -= 1;
      }
      ll c[k];
      for (ll i = 0; i < k ; i++)
      {
         cin >> c[i];
      }
      sort (a,a+n);
      ll m = 0;
      ll maxi = -1;
      for (ll i = n-1 ; i>=0 ; i--)
      {
         ll op = a[i];
         m += 1;
         ll s = (m+c[op]-1)/c[op];
         maxi = max(s, maxi);
      }
      cout << maxi << "\n";
      vector <vector<ll>> answer(maxi);
      ll ok[n];
      for (ll i = 0 ; i < n ; i++)
      {
         ok[i] = i%maxi;
         answer[ok[i]].push_back(a[i]);
      }
      for (ll i = 0 ; i < maxi ; i++)
      {
         cout << answer[i].size() << " ";
         for (ll j = 0 ; j < answer[i].size() ; j++)
         {
            cout << answer[i][j]+1 << " ";
         }
         cout << "\n";
      }

      // for (ll i)
   }
   return 0;
}


#include <bits/stdc++.h>
#define fast   ios_base::sync_with_stdio(false); \
                    cin.tie(NULL);
#define L long long
#define ll long long
#define SS string
#define PB push_back
#define pp pair<L,L>
#define f(x, n , i) for (i = x ; i <= n ; i++)
#define setE(a, x , size) memset(a,x,size);
#define NL 200500
#define INT_MINIMUM -10000000000000000
#define EMPTY ""
#define mapss map<pair<L,L>,SS>
#define mapsi map<pair<L,L>,L>
#define reverse(s) reverse(s.begin(),s.end())
#define fr (s , e , i) for (i = s , i >= e ; i--)
#define slen(s) s.length()
#define isEven(x) ((x%2)==0)
using namespace std;

#define modu 1000000007
ll powerm(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
struct node{
ll fmax = INT_MINIMUM;
ll smax = INT_MINIMUM;
ll sum = 0;
ll value = 0;
};
vector <ll> v[NL];
ll visited[NL] = {0};
vector <node> vn;
void dfs(ll root, ll p)
{
   if (visited[root] == 1)
   {
      return ;
   }
   visited[root] = 1;
   ll sum = 0;
   for (ll i = 0 ; i < v[root].size(); i++)
   {
      ll child = v[root][i];
      if (child != p)
      {
      dfs(child, root);
      ll maxi = max(vn[child].fmax, vn[child].sum);
      if (vn[root].fmax < maxi)
      {
         vn[root].smax = vn[root].fmax;
         vn[root].fmax = maxi;
      }
      else if (vn[root].smax < maxi)
      {
         vn[root].smax = maxi;
      }
      sum += vn[child].sum;
      }
   }
   vn[root].sum = vn[root].value + sum ;
}
// #define
int main()
{
   fast
   ll t = 1;
   while (t--)
   {
      ll n , k;
      cin >> n >> k;
      ll a[n];
      for (ll i = 0; i < n ; i++)
      {
         cin >> a[i];
         a[i] -= 1;
      }
      ll c[k];
      for (ll i = 0; i < k ; i++)
      {
         cin >> c[i];
      }
      sort (a,a+n);
      ll m = 0;
      ll maxi = -1;
      for (ll i = n-1 ; i>=0 ; i--)
      {
         ll op = a[i];
         m += 1;
         ll s = (m+c[op]-1)/c[op];
         maxi = max(s, maxi);
      }
      cout << maxi << "\n";
      vector <vector<ll>> answer(maxi);
      ll ok[n];
      for (ll i = 0 ; i < n ; i++)
      {
         ok[i] = i%maxi;
         answer[ok[i]].push_back(a[i]);
      }
      for (ll i = 0 ; i < maxi ; i++)
      {
         cout << answer[i].size() << " ";
         for (ll j = 0 ; j < answer[i].size() ; j++)
         {
            cout << answer[i][j]+1 << " ";
         }
         cout << "\n";
      }
      // for (ll i)
   }
   return 0;
}


#include <bits/stdc++.h>
#define fast   ios_base::sync_with_stdio(false); \
                    cin.tie(NULL);
#define L long long
#define ll long long
#define SS string
#define PB push_back
#define pp pair<L,L>
#define f(x, n , i) for (i = x ; i <= n ; i++)
#define setE(a, x , size) memset(a,x,size);
#define NL 200500
#define INT_MINIMUM -10000000000000000
#define EMPTY ""
#define mapss map<pair<L,L>,SS>
#define mapsi map<pair<L,L>,L>
#define reverse(s) reverse(s.begin(),s.end())
#define fr (s , e , i) for (i = s , i >= e ; i--)
#define slen(s) s.length()
#define isEven(x) ((x%2)==0)
using namespace std;

#define modu 1000000007
ll powerm(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
struct node{
ll fmax = INT_MINIMUM;
ll smax = INT_MINIMUM;
ll sum = 0;
ll value = 0;
};
vector <ll> v[NL];
ll visited[NL] = {0};
vector <node> vn;
void dfs(ll root, ll p)
{
   if (visited[root] == 1)
   {
      return ;
   }
   visited[root] = 1;
   ll sum = 0;
   for (ll i = 0 ; i < v[root].size(); i++)
   {
      ll child = v[root][i];
      if (child != p)
      {
      dfs(child, root);
      ll maxi = max(vn[child].fmax, vn[child].sum);
      if (vn[root].fmax < maxi)
      {
         vn[root].smax = vn[root].fmax;
         vn[root].fmax = maxi;
      }
      else if (vn[root].smax < maxi)
      {
         vn[root].smax = maxi;
      }
      sum += vn[child].sum;
      }
   }
   vn[root].sum = vn[root].value + sum ;
}

int main()
{
   fast
   ll t = 1;
   while (t--)
   {
      ll n , k;
      cin >> n >> k;
      ll a[n];
      map <ll, ll> m;
      for (ll i = 0; i < n ; i++)
      {
         cin >> a[i];
         m[a[i]-1] += 1;
      }
      ll c[k];
      for (ll i = 0; i < k ; i++)
      {
         cin >> c[i];
      }
      ll ok = 1;
      ll size = n;
      vector <map<ll, ll>> answer;
      ll test = 5;
      while (1)
      {
         // vector <ll> op;
         auto itr = m.end();
         itr--;
         ll cu = 0;
         ll s = 0;
         map <ll, ll> cm;
         while (1)
         {
            ll x = itr->first;
            // ll p = itr->second;
            if (m[x] >= (c[x]-cu))
            {
               m[x] -= (c[x]-cu);
               ok = (c[x]-cu);
               // while (ok--)
               // {
               //    op.push_back(x);
               // }
               s += ok;
               cm[x] = ok;
               cu += (c[x]-cu);
            }
            else
            {
               cu += m[x];
               ok = m[x];
               // while(ok--)
               // {
               //    op.push_back(x);
               // }
               s += ok;
               cm[x] = ok;
               m[x] = 0;
            }
            if (itr == m.begin())
            {
               break;
            }
            else
            {
               itr--;
            }
         }
         // m.resize();
         size -= s;
         answer.push_back(cm);
         if (size == 0)
         {
            break;
         }
      }
      cout << answer.size() << "\n";
      for (ll i = 0 ; i < answer.size() ; i++)
      {
         ll as = 0;
         vector <ll> av;
         for (auto itr = answer[i].begin(); itr != answer[i].end() ; ++itr)
         {
            as += itr->second;
            ll ol = itr->second;
            while (ol--)
            {
               av.push_back(itr->first);
            }
         }
         cout << as;
         for (ll j = 0 ; j < av.size() ; j++)
         {
            cout << " " << (av[j]+1);
         }
         cout << "\n";
      }
   }
   return 0;
}


#include <bits/stdc++.h>
#define fast   ios_base::sync_with_stdio(false); \
                    cin.tie(NULL);
#define L long long
#define ll long long
#define SS string
#define PB push_back
#define pp pair<L,L>
#define f(x, n , i) for (i = x ; i <= n ; i++)
#define setE(a, x , size) memset(a,x,size);
#define NL 200500
#define INT_MINIMUM -10000000000000000
#define EMPTY ""
#define mapss map<pair<L,L>,SS>
#define mapsi map<pair<L,L>,L>
#define reverse(s) reverse(s.begin(),s.end())
#define fr (s , e , i) for (i = s , i >= e ; i--)
#define slen(s) s.length()
#define isEven(x) ((x%2)==0)
using namespace std;

#define modu 1000000007
ll powerm(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
struct node{
ll fmax = INT_MINIMUM;
ll smax = INT_MINIMUM;
ll sum = 0;
ll value = 0;
};
vector <ll> v[NL];
ll visited[NL] = {0};
vector <node> vn;
void dfs(ll root, ll p)
{
   if (visited[root] == 1)
   {
      return ;
   }
   visited[root] = 1;
   ll sum = 0;
   for (ll i = 0 ; i < v[root].size(); i++)
   {
      ll child = v[root][i];
      if (child != p)
      {
      dfs(child, root);
      ll maxi = max(vn[child].fmax, vn[child].sum);
      if (vn[root].fmax < maxi)
      {
         vn[root].smax = vn[root].fmax;
         vn[root].fmax = maxi;
      }
      else if (vn[root].smax < maxi)
      {
         vn[root].smax = maxi;
      }
      sum += vn[child].sum;
      }
   }
   vn[root].sum = vn[root].value + sum ;
}
// #define
int main()
{
   fast
   ll t = 1;
   while (t--)
   {
      ll n , k;
      cin >> n >> k;
      ll a[n];
      map <ll, ll> m;
      for (ll i = 0; i < n ; i++)
      {
         cin >> a[i];
         m[a[i]-1] += 1;
      }
      ll c[k];
      for (ll i = 0; i < k ; i++)
      {
         cin >> c[i];
      }
      ll size = n;
      vector <vector<ll>> answer;
      while (1)
      {
         vector <ll> kp;
         auto litr = m.begin();
         ll element = litr->first;
         vector <ll> op;
         ll ce = c[element];
         while (1)
         {
            if (ce == 0)
            {
               break;
            }
            if (m[element] == 0)
            {
               kp.push_back(element);
               litr++;
            if (litr == m.end())
            {
               break;
            }
            else
            {
               ce = min(ce, c[litr->first]);
               element = litr->first;
            }
            }
            else
            {
            op.push_back(element);
            ce -= 1;
            m[element] -= 1;
            }
         }
         for (auto i : kp)
         {
            m.erase(i);
         }
         size -= op.size();
         answer.push_back(op);
         if (size == 0)
         {
            break;
         }
      }
      cout << answer.size() << "\n";
      for (ll i = 0 ; i < answer.size() ; i++)
      {
         cout << answer[i].size();
         for (ll j = 0 ; j < answer[i].size(); j++)
         {
            cout << " " << (answer[i][j]+1);
         }
         cout << "\n";
      }
   }
   return 0;
}


#include <bits/stdc++.h>
#define fast   ios_base::sync_with_stdio(false); \
                    cin.tie(NULL);
#define L long long
#define ll long long
#define SS string
#define PB push_back
#define pp pair<L,L>
#define f(x, n , i) for (i = x ; i <= n ; i++)
#define setE(a, x , size) memset(a,x,size);
#define NL 200500
#define INT_MINIMUM -10000000000000000
#define EMPTY ""
#define mapss map<pair<L,L>,SS>
#define mapsi map<pair<L,L>,L>
#define reverse(s) reverse(s.begin(),s.end())
#define fr (s , e , i) for (i = s , i >= e ; i--)
#define slen(s) s.length()
#define isEven(x) ((x%2)==0)
using namespace std;

#define modu 1000000007
ll powerm(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
struct node{
ll fmax = INT_MINIMUM;
ll smax = INT_MINIMUM;
ll sum = 0;
ll value = 0;
};
vector <ll> v[NL];
ll visited[NL] = {0};
vector <node> vn;
void dfs(ll root, ll p)
{
   if (visited[root] == 1)
   {
      return ;
   }
   visited[root] = 1;
   ll sum = 0;
   for (ll i = 0 ; i < v[root].size(); i++)
   {
      ll child = v[root][i];
      if (child != p)
      {
      dfs(child, root);
      ll maxi = max(vn[child].fmax, vn[child].sum);
      if (vn[root].fmax < maxi)
      {
         vn[root].smax = vn[root].fmax;
         vn[root].fmax = maxi;
      }
      else if (vn[root].smax < maxi)
      {
         vn[root].smax = maxi;
      }
      sum += vn[child].sum;
      }
   }
   vn[root].sum = vn[root].value + sum ;
}
// #define
int main()
{
   fast
   ll t = 1;
   while (t--)
   {
      ll n , k;
      cin >> n >> k;
      ll a[n];
      map <ll, ll> m;
      for (ll i = 0; i < n ; i++)
      {
         cin >> a[i];
         m[a[i]-1] += 1;
      }
      ll c[k];
      for (ll i = 0; i < k ; i++)
      {
         cin >> c[i];
      }
      ll size = n;
      vector <vector<ll>> answer;
      while (1)
      {
         set <ll> kp;
         auto litr = m.begin();
         ll element = litr->first;
         vector <ll> op;
         ll ce = c[element];
         while (1)
         {
            if (ce == 0)
            {
               break;
            }
            if (m[element] == 0)
            {
               kp.insert(element);
               litr++;
            if (litr == m.end())
            {
               break;
            }
            else
            {
               ce = min(ce, c[litr->first]);
               element = litr->first;
            }
            }
            else
            {
            op.push_back(element);
            ce -= 1;
            m[element] -= 1;
            if (m[element] == 0)
            {
               kp.insert(element);
            }
            }
         }
         for (auto i : kp)
         {
            m.erase(i);
         }
         size -= op.size();
         answer.push_back(op);
         if (size == 0)
         {
            break;
         }
      }
      cout << answer.size() << "\n";
      for (ll i = 0 ; i < answer.size() ; i++)
      {
         cout << answer[i].size();
         for (ll j = 0 ; j < answer[i].size(); j++)
         {
            cout << " " << (answer[i][j]+1);
         }
         cout << "\n";
      }
   }
   return 0;
}


#include <bits/stdc++.h>
#define fast   ios_base::sync_with_stdio(false); \
                    cin.tie(NULL);
#define L long long
#define ll long long
#define SS string
#define PB push_back
#define pp pair<L,L>
#define f(x, n , i) for (i = x ; i <= n ; i++)
#define setE(a, x , size) memset(a,x,size);
#define NL 200500
#define INT_MINIMUM -10000000000000000
#define EMPTY ""
#define mapss map<pair<L,L>,SS>
#define mapsi map<pair<L,L>,L>
#define reverse(s) reverse(s.begin(),s.end())
#define fr (s , e , i) for (i = s , i >= e ; i--)
#define slen(s) s.length()
#define isEven(x) ((x%2)==0)
using namespace std;

#define modu 1000000007
ll powerm(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
struct node{
ll fmax = INT_MINIMUM;
ll smax = INT_MINIMUM;
ll sum = 0;
ll value = 0;
};
vector <ll> v[NL];
ll visited[NL] = {0};
vector <node> vn;
void dfs(ll root, ll p)
{
   if (visited[root] == 1)
   {
      return ;
   }
   visited[root] = 1;
   ll sum = 0;
   for (ll i = 0 ; i < v[root].size(); i++)
   {
      ll child = v[root][i];
      if (child != p)
      {
      dfs(child, root);
      ll maxi = max(vn[child].fmax, vn[child].sum);
      if (vn[root].fmax < maxi)
      {
         vn[root].smax = vn[root].fmax;
         vn[root].fmax = maxi;
      }
      else if (vn[root].smax < maxi)
      {
         vn[root].smax = maxi;
      }
      sum += vn[child].sum;
      }
   }
   vn[root].sum = vn[root].value + sum ;
}

int main()
{
   fast
   ll t = 1;
   while (t--)
   {
      ll n , k;
      cin >> n >> k;
      ll a[n];
      map <ll, ll> m;
      for (ll i = 0; i < n ; i++)
      {
         cin >> a[i];
         m[a[i]-1] += 1;
      }
      ll c[k];
      for (ll i = 0; i < k ; i++)
      {
         cin >> c[i];
      }
      ll ok = 1;
      ll size = n;
      vector <vector <ll>> answer;
      while (1)
      {
         vector <ll> op;
         auto itr = m.end();
         itr--;
         ll cu = 0;
         while (1)
         {
            ll x = itr->first;
            // ll p = itr->second;
            if (m[x] >= (c[x]-cu))
            {
               m[x] -= (c[x]-cu);
               ok = (c[x]-cu);
               while (ok--)
               {
                  op.push_back(x);
               }
               cu += (c[x]-cu);
            }
            else
            {
               cu += m[x];
               ok = m[x];
               while(ok--)
               {
                  op.push_back(x);
               }
               m[x] = 0;
            }
            if (itr == m.begin())
            {
               break;
            }
            else
            {
               itr--;
            }
         }
         size -= op.size();
         answer.push_back(op);
         if (size == 0)
         {
            break;
         }
      }
      cout << answer.size() << "\n";
      for (ll i = 0 ; i < answer.size() ; i++)
      {
         cout << answer[i].size();
         for (ll j = 0 ; j < answer[i].size() ; j++)
         {
            cout << " " << answer[i][j]+1;
         }
         cout << "\n";
      }
   }
   return 0;
}


#include <bits/stdc++.h>
#define fast   ios_base::sync_with_stdio(false); \
                    cin.tie(NULL);
#define L long long
#define ll long long
#define SS string
#define PB push_back
#define pp pair<L,L>
#define f(x, n , i) for (i = x ; i <= n ; i++)
#define setE(a, x , size) memset(a,x,size);
#define NL 200500
#define INT_MINIMUM -10000000000000000
#define EMPTY ""
#define mapss map<pair<L,L>,SS>
#define mapsi map<pair<L,L>,L>
#define reverse(s) reverse(s.begin(),s.end())
#define fr (s , e , i) for (i = s , i >= e ; i--)
#define slen(s) s.length()
#define isEven(x) ((x%2)==0)
using namespace std;

#define modu 1000000007
ll powerm(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
struct node{
ll fmax = INT_MINIMUM;
ll smax = INT_MINIMUM;
ll sum = 0;
ll value = 0;
};
vector <ll> v[NL];
ll visited[NL] = {0};
vector <node> vn;
void dfs(ll root, ll p)
{
   if (visited[root] == 1)
   {
      return ;
   }
   visited[root] = 1;
   ll sum = 0;
   for (ll i = 0 ; i < v[root].size(); i++)
   {
      ll child = v[root][i];
      if (child != p)
      {
      dfs(child, root);
      ll maxi = max(vn[child].fmax, vn[child].sum);
      if (vn[root].fmax < maxi)
      {
         vn[root].smax = vn[root].fmax;
         vn[root].fmax = maxi;
      }
      else if (vn[root].smax < maxi)
      {
         vn[root].smax = maxi;
      }
      sum += vn[child].sum;
      }
   }
   vn[root].sum = vn[root].value + sum ;
}
// #define
int main()
{
   fast
   ll t = 1;
   while (t--)
   {
      ll n , k;
      cin >> n >> k;
      ll a[n];
      for (ll i = 0; i < n ; i++)
      {
         cin >> a[i];
         a[i] -= 1;
      }
      ll c[k];
      for (ll i = 0; i < k ; i++)
      {
         cin >> c[i];
      }
      sort (a,a+n);
      ll m = 0;
      ll maxi = -1;
      for (ll i = n-1 ; i>=0 ; i--)
      {
         ll op = a[i];
         m += 1;
         ll s = (m+c[op]-1)/c[op];
         maxi = max(s, maxi);
      }
      cout << maxi << "\n";
      vector <vector<ll>> answer(maxi);
      ll ok[n];
      for (ll i = 0 ; i < n ; i++)
      {
         ok[i] = i%maxi;
         answer[ok[i]].push_back(a[i]);
      }
      for (ll i = 0 ; i < maxi ; i++)
      {
         cout << answer[i].size() << " ";
         for (ll j = 0 ; j < answer[i].size() ; j++)
         {
            cout << answer[i][j]+1 << " ";
         }
         cout << "\n";
      }     // for (ll i)
   }
   return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define _min(a, b) (a > b ? b : a)
const int maxn = 2.2e5;
vector<int> g[maxn];
int cnt[maxn];
void init(){
    for(int i = 0; i < maxn; ++i){
        cnt[i] = 0;
    }
}
int main(){
    init();
    int n, k;
    cin >> n >> k;
    vector<int> v;
    for(int i = 0; i < n; ++i){
        int num;
        cin >> num;
        // v.push_back(num);
        cnt[num]++;
    }
    vector<int> v_m;
    v_m.push_back(-1);
    for(int i = 0; i < k; ++i){
        int num;
        cin >> num;
        v_m.push_back(num);
    }
    v_m.push_back(k + 1);
    int index = 0;
    for(int i = k; i >= 1; --i){
        if(cnt[i] == 0){
            continue;
        }
        // if(v_m[i] != v_m[i + 1]){
            index = 0;
        // }
        int insert_times = cnt[i];
        for(int j = 0; j < insert_times; ++j){
            while(g[index].size() + 1 > v_m[i]){
                index++;
            }
            // cout << "index = " << index << " i = " << i << endl;
            g[index].push_back(i);
        }
    }
    int cases = 0;
    for(int i = 0; i < maxn; ++i){
        if(g[i].size() != 0){
            cases++;
        }
    }
    cout << cases << endl;
    for(int i = 0; i < cases; ++i){
        cout << g[i].size() << " ";
        for(int j = 0; j < g[i].size(); ++j){
            cout << g[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define _min(a, b) (a > b ? b : a)
const int maxn = 2.2e5;
vector<int> g[maxn];
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> v;
    for(int i = 0; i < n; ++i){
        int num;
        cin >> num;
        v.push_back(num);
    }
    vector<int> cons;
    cons.push_back(-1);
    for(int i = 0; i < k; ++i){
        int num;
        cin >> num;
        cons.push_back(num);
    }
    sort(v.begin(), v.end());
    int cur_con = cons[1];
    int cur_a_cnt = 0;
    for(int i = 0; i < n; ++i){
        int num = v[i];
        cur_con--;
        if(cur_con < 0){
            cur_a_cnt++;
            cur_con = cons[num] - 1;
            g[cur_a_cnt].push_back(num);
        }
        else{
            g[cur_a_cnt].push_back(num);
            cur_con = _min(cur_con, cons[num] - 1);
        }
    }
    cout << cur_a_cnt + 1 << endl;
    for(int i = 0; i <= cur_a_cnt; ++i){
        cout << g[i].size() << " ";
        for(int j = 0; j < g[i].size(); ++j){
            cout << g[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define _min(a, b) (a > b ? b : a)
const int maxn = 2.2e5;
vector<int> g[maxn];
int cnt[maxn];
void init(){
    for(int i = 0; i < maxn; ++i){
        cnt[i] = 0;
    }
}
int main(){
    init();
    int n, k;
    cin >> n >> k;
    vector<int> v;
    for(int i = 0; i < n; ++i){
        int num;
        cin >> num;
        // v.push_back(num);
        cnt[num]++;
    }
    vector<int> v_m;
    v_m.push_back(-1);
    for(int i = 0; i < k; ++i){
        int num;
        cin >> num;
        v_m.push_back(num);
    }
    v_m.push_back(k + 1);
    int index = 0;
    for(int i = k; i >= 1; --i){
        if(cnt[i] == 0){
            continue;
        }
        if(v_m[i] != v_m[i + 1]){
            index = 0;
        }
        int insert_times = cnt[i];
        for(int j = 0; j < insert_times; ++j){
            while(g[index].size() + 1 > v_m[i]){
                index++;
            }
            // cout << "index = " << index << " i = " << i << endl;
            g[index].push_back(i);
        }
    }
    int cases = 0;
    for(int i = 0; i < maxn; ++i){
        if(g[i].size() != 0){
            cases++;
        }
    }
    cout << cases << endl;
    for(int i = 0; i < cases; ++i){
        cout << g[i].size() << " ";
        for(int j = 0; j < g[i].size(); ++j){
            cout << g[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define _min(a, b) (a > b ? b : a)
const int maxn = 2.2e5;
vector<int> g[maxn];
int cnt[maxn];
void init(){
    for(int i = 0; i < maxn; ++i){
        cnt[i] = 0;
    }
}
int main(){
    init();
    int n, k;
    cin >> n >> k;
    vector<int> v;
    for(int i = 0; i < n; ++i){
        int num;
        cin >> num;
        // v.push_back(num);
        cnt[num]++;
    }
    vector<int> v_m;
    v_m.push_back(-1);
    for(int i = 0; i < k; ++i){
        int num;
        cin >> num;
        v_m.push_back(num);
    }
    v_m.push_back(k + 1);
    int index = 0;
    for(int i = k; i >= 1; --i){
        if(v_m[i] != v_m[i + 1]){
            index = 0;
        }
        if(cnt[i] == 0){
            continue;
        }
        int insert_times = cnt[i];
        for(int j = 0; j < insert_times; ++j){
            while(g[index].size() + 1 > v_m[i]){
                index++;
            }
            // cout << "index = " << index << " i = " << i << endl;
            g[index].push_back(i);
        }
    }
    int cases = 0;
    for(int i = 0; i < maxn; ++i){
        if(g[i].size() != 0){
            cases++;
        }
    }
    cout << cases << endl;
    for(int i = 0; i < cases; ++i){
        cout << g[i].size() << " ";
        for(int j = 0; j < g[i].size(); ++j){
            cout << g[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}


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

typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const double eps = 1e-5;
const int N = 2e5 + 10;

void redirect() {
    #ifdef LOCAL
        freopen("1.in","r",stdin);
        freopen("1.out","w",stdout);
    #endif
}

ll n, k;
int a[N], cnt[N];
ll lmt[N], suf[N];
vector<int> G[N]; ll acc[N];

bool vis[N]; int pt[N];

int main() {
    redirect();

    //ios::sync_with_stdio(false);
    //cin.tie(0);

    scanf("%lld%lld",&n,&k);
    for (int i=1; i<=n; i++) {
        scanf("%d",&a[i]); cnt[a[i]]++;
    }

    for (int i=1; i<=k; i++) {
        scanf("%lld",&lmt[i]);
    }

    int mk = 0;
    for (int i=1; i<=k; i++) {
        pt[i] = mk;
        if (i < k && lmt[i] > lmt[i+1]) mk = i;
    }

    for (int i=k; i>=1; i--) {
        suf[i] = suf[i+1] + cnt[i];
    }

    ll l = 1, r = 3e5;
    while (l<r) {
        ll mid = (l+r) >> 1;
        bool f = true;
        for (int i=k; i>=1; i--) {
            if ( suf[i] > lmt[i]*mid ) {
                f = false;
                break;
            }
        }

        if (f) r = mid;
        else l = mid+1;
    }

    int now = k;
    for (int j=1; j<=l; j++) {
        while (cnt[now]==0&&now>=1) now--;
        for (int i=now; i>=1;) {
            while ( acc[j] < lmt[i] && cnt[i] > 0 ) {
                G[j].push_back(i);
                acc[j] ++;
                cnt[i] --;
            }
            if (acc[j] >= lmt[i]) {
                while (cnt[pt[i]]==0 && pt[i]>=1) pt[i]--;
                i = pt[i];
            }
            else {i--;}
        }
    }

    printf("%lld\n",l);
    for (int i=1; i<=l; i++) {
        printf("%d ",G[i].size());
        for (auto x:G[i]) printf("%d ",x);
        printf("\n");
    }

    return 0;
}

/*
-----------------
author:dragon_bra
-----------------
*/


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

typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const double eps = 1e-5;
const int N = 2e5 + 10;

void redirect() {
    #ifdef LOCAL
        freopen("1.in","r",stdin);
        freopen("1.out","w",stdout);
    #endif
}

ll n, k;
int a[N], cnt[N];
ll lmt[N], suf[N];
vector<int> G[N]; ll acc[N];

int main() {
    redirect();

    ios::sync_with_stdio(false);
    cin.tie(0);

    scanf("%lld%lld",&n,&k);
    for (int i=1; i<=n; i++) {
        scanf("%d",&a[i]); cnt[a[i]]++;
    }

    for (int i=1; i<=k; i++) {
        scanf("%lld",&lmt[i]);
    }

    for (int i=k; i>=1; i--) {
        suf[i] = suf[i+1] + cnt[i];
    }

    ll l = 1, r = 2e5;
    while (l<r) {
        ll mid = (l+r) >> 1;
        bool f = true;
        for (int i=k; i>=1; i--) {
            if ( suf[i] > lmt[i]*mid ) {
                f = false;
                break;
            }
        }

        if (f) r = mid;
        else l = mid+1;
    }

    for (int i=k; i>=1; i--) {

        for (int j=1; j<=l; j++) {

            while ( acc[j] < lmt[i] && cnt[i] > 0 ) {
                G[j].push_back(i);
                acc[j] ++;
                cnt[i] --;
            }

        }

    }

    printf("%lld\n",l);
    for (int i=1; i<=l; i++) {
        printf("%d ",G[i].size());
        for (auto x:G[i]) printf("%d ",x);
        printf("\n");
    }

    return 0;
}

/*
-----------------
author:dragon_bra
-----------------
*/