#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define N 100005
using namespace std;
int ans=0,flag=0;
char st[25]; int r[N];
int n,m,T,col[N],l[N];
void read(int t)
{
    int h,m,s;
    scanf("%s",st+1);
    h=(st[1]-'0')*10+st[2]-'0';
    m=(st[4]-'0')*10+st[5]-'0';
    s=(st[7]-'0')*10+st[8]-'0';
    l[t]=h*3600+m*60+s;
    r[t]=l[t]+T-1;
}
int main()
{
    int i,x;
    scanf("%d %d %d\n",&n,&m,&T);
    for(i=1;i<=n;i++) read(i);
    if(m==1) flag=1;
    for(i=1;i<=n;i++){
        if(r[i-1]<l[i]){ col[i]=++ans; continue;}
        x=lower_bound(r+1,r+n+1,l[i])-r;
        if(col[i-1]-col[x]+1==m) col[i]=col[i-1];
        else col[i]=++ans;
        if(col[i]-col[x]+1==m) flag=1;
      }
    if(!flag){
        printf("No solution");
        return 0;
    }
    printf("%d\n",ans);
    for(i=1;i<=n;i++)
        printf("%d\n",col[i]);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<set>
#define N 100005
#define PAIR pair<int,int>
#define LL long long
#define oo (1<<30)
using namespace std;
set<PAIR> S;
set<PAIR> :: iterator it;
bool flag=0; int R[N];
char st[N]; int ans=0,c[N];
int n,m,len=0,T,cnt,col[N];
struct ran{ int num,l,s;}A[N];
bool cmp(ran p,ran q){ return p.l<q.l||(p.l==q.l&&p.s<q.s);}
void read(int t)
{
    int h,m,s,ti;
    scanf("%s",st+1);
    h=(st[1]-'0')*10+st[2]-'0';
    m=(st[4]-'0')*10+st[5]-'0';
    s=(st[7]-'0')*10+st[8]-'0';
    ti=h*3600+m*60+s;
    A[++len]=(ran){t,ti,1};
    A[++len]=(ran){t,ti+T+1,-1};
    R[t]=ti+T;
}
int main()
{
    int i;
    scanf("%d %d %d\n",&n,&m,&T);
    for(i=1;i<=n;i++) read(i);
    sort(A+1,A+len+1,cmp);
    for(i=1;i<=len;i++)
        if(A[i].s<0){
            c[col[A[i].num]]--;
            if(!c[col[A[i].num]]) cnt--;
          }
        else{
            if((++cnt)>=m) flag=1;
            if(cnt<=m) col[A[i].num]=++ans;
            else{
                cnt--;
                it=S.lower_bound(PAIR(A[i].l,-oo));
                col[A[i].num]=col[(*it).second];
              }
            c[col[A[i].num]]++;
            S.insert(PAIR(R[A[i].num],A[i].num));
          }
    if(!flag) printf("No solution");
    else{
        printf("%d\n",ans);
        for(i=1;i<=n;i++)
            printf("%d\n",col[i]);
      }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<pair<int,int> >v1;
vector<pair<pair<int,int>,int> >v2;
int id[20001];
int end1[20001];
bool closed[20001];

int main()
{
	int n,m,t;
	scanf("%d%d%d",&n,&m,&t);

	for(int i=0;i<n;i++)
	{
		id[i]=-1;
	}

	for(int i=0;i<n;i++)
	{
		char s[10];
		scanf("%s",s);
		int temp1=0;
		int temp2=0;
		int temp3=0;
		temp1=((s[0]-'0')*10+(s[1]-'0'))*60*60;
		temp2=((s[3]-'0')*10+(s[4]-'0'))*60;
		temp3=((s[6]-'0')*10+(s[7]-'0'));
		temp1=temp1+temp2+temp3;

		v1.push_back(make_pair(temp1,temp1+t-1));
		v2.push_back(make_pair(make_pair(temp1,0),i));
		v2.push_back(make_pair(make_pair(temp1+t-1,1),i));
	}

	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());

	int max1=0;
	int answer=0;
	int id1=0;

	for(vector<pair<pair<int,int>,int> >::iterator it=v2.begin();it!=v2.end();it++)
	{
		pair<pair<int,int>,int>t1=(*it);

		if(t1.first.second==0)
		{
			max1++;
			answer=max(answer,max1);
		}
		else
		{
			max1--;
			answer=max(answer,max1);
		}
	}

	if(answer<m)
	{
		printf("No solution\n");
		return 0;
	}
	else
	{
		max1=0;
		for(vector<pair<pair<int,int>,int> >::iterator it=v2.begin();it!=v2.end();it++)
		{
			pair<pair<int,int>,int>t1=(*it);

			if(t1.first.second==0)
			{
				max1=max1+1;
				if(max1<=m)
				{
					id1++;
					id[t1.second]=id1;
					end1[id[t1.second]]=max(end1[id[t1.second]],t1.first.first+t-1);
				}
				else
				{
					max1--;
					id[t1.second]=id1;
					end1[id[t1.second]]=max(end1[id[t1.second]],t1.first.first+t-1);
				}
				//printf("enter->(%d,%d,%d) ",t1.first.first,max1,t1.second);

			}
			else
			{
				//printf("exit->(%d,%d,%d) ",t1.first.second,max1-1,t1.second);
				if(end1[id[t1.second]]==t1.first.first)
				{
					max1--;
					closed[id[t1.second]]=true;
				}

			}
		}
	}

	//printf("%d\n",id1);

	if(id1==0)
	{
		printf("No solution\n");
		return 0;
	}

	printf("%d\n",id1);

	for(int i=0;i<n;i++)
	{
		printf("%d\n",id[i]);
	}
return 0;}


#include <bits/stdc++.h>

using namespace std;

vector<pair<int,int> >v1;
vector<pair<pair<int,int>,int> >v2;
int id[20001];
int end1[20001];
bool closed[20001];
int time1[20001];
int count1[20001];

int main()
{
	int n,m,t;
	scanf("%d%d%d",&n,&m,&t);

	for(int i=0;i<n;i++)
	{
		id[i]=-1;
		end1[i]=-1;
	}

	for(int i=1;i<=n;i++)
	{
		char s[10];
		scanf("%s",s);
		int temp1=0;
		int temp2=0;
		int temp3=0;
		temp1=((s[0]-'0')*10+(s[1]-'0'))*60*60;
		temp2=((s[3]-'0')*10+(s[4]-'0'))*60;
		temp3=((s[6]-'0')*10+(s[7]-'0'));
		temp1=temp1+temp2+temp3;
		time1[i]=temp1;

		v1.push_back(make_pair(temp1,temp1+t-1));
		v2.push_back(make_pair(make_pair(temp1,1),i));
		v2.push_back(make_pair(make_pair(temp1+t,0),i));
	}

	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());

	int max1=0;
	int answer=0;
	int id1=1;

	for(vector<pair<pair<int,int>,int> >::iterator it=v2.begin();it!=v2.end();it++)
	{
		pair<pair<int,int>,int>t1=(*it);

		if(t1.first.second==1)
		{
			max1++;
			answer=max(answer,max1);
		}
		else
		{
			max1--;
			answer=max(answer,max1);
		}
	}

	if(answer<m)
	{
		printf("No solution\n");
		return 0;
	}
	else
	{
		max1=0;
		//int id1=1;
		int curr=0;
		int prev=-1;
		int pos=0;

		for(int i=1;i<=n;i++)
		{
			while(time1[i]-time1[pos]>=t)
			{
				count1[id[pos]]--;
				if(count1[id[pos]]==0)
				{
					curr--;
				}
				pos++;
			}

			if(curr<m)
			{
				count1[id1]++;
				curr++;
				prev=id1;
				id[i]=id1;
				id1++;
			}

			else
			{
				id[i]=prev;
				count1[prev]++;
			}
		}
	}

	//printf("%d\n",id1);

	printf("%d\n",id1-1);

	for(int i=1;i<=n;i++)
	{
		printf("%d\n",id[i]);
	}
return 0;}


#include <bits/stdc++.h>

using namespace std;

vector<pair<int,int> >v1;
vector<pair<pair<int,int>,int> >v2;
int id[20001];

int main()
{
	int n,m,t;
	scanf("%d%d%d",&n,&m,&t);

	for(int i=0;i<n;i++)
	{
		id[i]=-1;
	}

	for(int i=0;i<n;i++)
	{
		char s[10];
		scanf("%s",s);
		int temp1=0;
		int temp2=0;
		int temp3=0;
		temp1=((s[0]-'0')*10+(s[1]-'0'))*60*60;
		temp2=((s[3]-'0')*10+(s[4]-'0'))*60;
		temp3=((s[6]-'0')*10+(s[7]-'0'));
		temp1=temp1+temp2+temp3;

		v1.push_back(make_pair(temp1,temp1+t-1));
		v2.push_back(make_pair(make_pair(temp1,0),i));
		v2.push_back(make_pair(make_pair(temp1+t-1,1),i));
	}

	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());

	int max1=0;
	int answer=0;
	int id1=0;

	for(vector<pair<pair<int,int>,int> >::iterator it=v2.begin();it!=v2.end();it++)
	{
		pair<pair<int,int>,int>t1=(*it);

		if(t1.first.second==0)
		{
			max1++;
			answer=max(answer,max1);
		}
		else
		{
			max1--;
			answer=max(answer,max1);
		}
	}

	if(answer<m)
	{
		printf("No solution\n");
		return 0;
	}
	else
	{
		max1=0;
		for(vector<pair<pair<int,int>,int> >::iterator it=v2.begin();it!=v2.end();it++)
		{
			pair<pair<int,int>,int>t1=(*it);

			if(t1.first.second==0)
			{
				max1=max1+1;
				if(max1<=m)
				{
					id1++;
					id[t1.second]=id1;
				}
				else
				{
					max1--;
					id[t1.second]=id1;
				}
				//printf("enter->(%d,%d) ",t1.first.first,max1);

			}
			else
			{
				//printf("exit->%d ",t1.first.second);
				max1=max1-1;
			}
		}
	}

	//printf("%d\n",id1);

	if(id1==0)
	{
		printf("No solution\n");
		return 0;
	}

	printf("%d\n",id1);

	for(int i=0;i<n;i++)
	{
		printf("%d\n",id[i]);
	}
return 0;}


#include <bits/stdc++.h>

using namespace std;

vector<pair<int,int> >v1;
vector<pair<pair<int,int>,int> >v2;
int id[20001];
int end1[20001];
bool closed[20001];

int main()
{
	int n,m,t;
	scanf("%d%d%d",&n,&m,&t);

	for(int i=0;i<n;i++)
	{
		id[i]=-1;
		end1[i]=-1;
	}

	for(int i=0;i<n;i++)
	{
		char s[10];
		scanf("%s",s);
		int temp1=0;
		int temp2=0;
		int temp3=0;
		temp1=((s[0]-'0')*10+(s[1]-'0'))*60*60;
		temp2=((s[3]-'0')*10+(s[4]-'0'))*60;
		temp3=((s[6]-'0')*10+(s[7]-'0'));
		temp1=temp1+temp2+temp3;

		v1.push_back(make_pair(temp1,temp1+t-1));
		v2.push_back(make_pair(make_pair(temp1,0),i));
		v2.push_back(make_pair(make_pair(temp1+t-1,1),i));
	}

	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());

	int max1=0;
	int answer=0;
	int id1=0;

	for(vector<pair<pair<int,int>,int> >::iterator it=v2.begin();it!=v2.end();it++)
	{
		pair<pair<int,int>,int>t1=(*it);

		if(t1.first.second==0)
		{
			max1++;
			answer=max(answer,max1);
		}
		else
		{
			max1--;
			answer=max(answer,max1);
		}
	}

	if(answer<m)
	{
		printf("No solution\n");
		return 0;
	}
	else
	{
		max1=0;
		for(vector<pair<pair<int,int>,int> >::iterator it=v2.begin();it!=v2.end();it++)
		{
			pair<pair<int,int>,int>t1=(*it);

			if(t1.first.second==0)
			{
				max1=max1+1;
				if(max1<=m)
				{
					id1++;
					id[t1.second]=id1;
					end1[id[t1.second]]=max(end1[id[t1.second]],t1.first.first+t-1);
				}
				else
				{
					max1--;
					id[t1.second]=id1;
					end1[id[t1.second]]=max(end1[id[t1.second]],t1.first.first+t-1);
				}
				//printf("enter->(%d,%d,%d) ",t1.first.first,max1,t1.second);

			}
			else
			{
				//printf("exit->(%d,%d,%d) ",t1.first.second,max1-1,t1.second);
				if(end1[id[t1.second]]==t1.first.first)
				{
					max1--;
				}

			}
		}
	}

	//printf("%d\n",id1);

	if(id1==0)
	{
		printf("No solution\n");
		return 0;
	}

	printf("%d\n",id1);

	for(int i=0;i<n;i++)
	{
		printf("%d\n",id[i]);
	}
return 0;}


#include <bits/stdc++.h>

using namespace std;

vector<pair<int,int> >v1;
vector<pair<pair<int,int>,int> >v2;
int id[20001];
bool closed[20001];

int main()
{
	int n,m,t;
	scanf("%d%d%d",&n,&m,&t);

	for(int i=0;i<n;i++)
	{
		id[i]=-1;
	}

	for(int i=0;i<n;i++)
	{
		char s[10];
		scanf("%s",s);
		int temp1=0;
		int temp2=0;
		int temp3=0;
		temp1=((s[0]-'0')*10+(s[1]-'0'))*60*60;
		temp2=((s[3]-'0')*10+(s[4]-'0'))*60;
		temp3=((s[6]-'0')*10+(s[7]-'0'));
		temp1=temp1+temp2+temp3;

		v1.push_back(make_pair(temp1,temp1+t-1));
		v2.push_back(make_pair(make_pair(temp1,0),i));
		v2.push_back(make_pair(make_pair(temp1+t-1,1),i));
	}

	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());

	int max1=0;
	int answer=0;
	int id1=0;

	for(vector<pair<pair<int,int>,int> >::iterator it=v2.begin();it!=v2.end();it++)
	{
		pair<pair<int,int>,int>t1=(*it);

		if(t1.first.second==0)
		{
			max1++;
			answer=max(answer,max1);
		}
		else
		{
			max1--;
			answer=max(answer,max1);
		}
	}

	if(answer<m)
	{
		printf("No solution\n");
		return 0;
	}
	else
	{
		max1=0;
		for(vector<pair<pair<int,int>,int> >::iterator it=v2.begin();it!=v2.end();it++)
		{
			pair<pair<int,int>,int>t1=(*it);

			if(t1.first.second==0)
			{
				max1=max1+1;
				if(max1<=m)
				{
					id1++;
					id[t1.second]=id1;
				}
				else
				{
					max1--;
					id[t1.second]=id1;
				}
				//printf("enter->(%d,%d,%d) ",t1.first.first,max1,id1);

			}
			else
			{
				//printf("exit->(%d,%d) ",t1.first.second,max1);
				if(!closed[id[t1.second]])
				{
					max1--;
					closed[id[t1.second]]=true;
				}

			}
		}
	}

	//printf("%d\n",id1);

	if(id1==0)
	{
		printf("No solution\n");
		return 0;
	}

	printf("%d\n",id1);

	for(int i=0;i<n;i++)
	{
		printf("%d\n",id[i]);
	}
return 0;}


#include <bits/stdc++.h>

using namespace std;

vector<pair<int,int> >v1;
vector<pair<pair<int,int>,int> >v2;
int id[20001];
int end1[20001];
bool closed[20001];

int main()
{
	int n,m,t;
	scanf("%d%d%d",&n,&m,&t);

	for(int i=0;i<n;i++)
	{
		id[i]=-1;
		end1[i]=-1;
	}

	for(int i=0;i<n;i++)
	{
		char s[10];
		scanf("%s",s);
		int temp1=0;
		int temp2=0;
		int temp3=0;
		temp1=((s[0]-'0')*10+(s[1]-'0'))*60*60;
		temp2=((s[3]-'0')*10+(s[4]-'0'))*60;
		temp3=((s[6]-'0')*10+(s[7]-'0'));
		temp1=temp1+temp2+temp3;

		v1.push_back(make_pair(temp1,temp1+t-1));
		v2.push_back(make_pair(make_pair(temp1,1),i));
		v2.push_back(make_pair(make_pair(temp1+t,0),i));
	}

	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());

	int max1=0;
	int answer=0;
	int id1=0;

	for(vector<pair<pair<int,int>,int> >::iterator it=v2.begin();it!=v2.end();it++)
	{
		pair<pair<int,int>,int>t1=(*it);

		if(t1.first.second==1)
		{
			max1++;
			answer=max(answer,max1);
		}
		else
		{
			max1--;
			answer=max(answer,max1);
		}
	}

	if(answer<m)
	{
		printf("No solution\n");
		return 0;
	}
	else
	{
		max1=0;
		for(vector<pair<pair<int,int>,int> >::iterator it=v2.begin();it!=v2.end();it++)
		{
			pair<pair<int,int>,int>t1=(*it);

			if(t1.first.second==1)
			{
				max1=max1+1;
				if(max1<=m)
				{
					id1++;
					id[t1.second]=id1;
					end1[id[t1.second]]=max(end1[id[t1.second]],t1.first.first+t);
				}
				else
				{
					max1--;
					id[t1.second]=id1;
					end1[id[t1.second]]=max(end1[id[t1.second]],t1.first.first+t);
				}
				//printf("enter->(%d,%d,%d) ",t1.first.first,max1,t1.second);

			}
			else
			{
				//printf("exit->(%d,%d,%d) ",t1.first.second,max1-1,t1.second);
				if(end1[id[t1.second]]==t1.first.first)
				{
					max1--;
				}

			}
		}
	}

	//printf("%d\n",id1);

	if(id1==0)
	{
		printf("No solution\n");
		return 0;
	}

	printf("%d\n",id1);

	for(int i=0;i<n;i++)
	{
		printf("%d\n",id[i]);
	}
return 0;}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;
struct P{
	int t,id,r;
}p[20000];
bool cmp(P a,P b){
	return a.t<b.t;
}
bool cmp1(P a,P b){
	return a.id<b.id;
}
int in(){
	int h,m,s;
	scanf("%d%*c%d%*c%d",&h,&m,&s);
	return h*3600+m*60+s;
}
int main(){
	int n,m,t;
	while(scanf("%d%d%d",&n,&m,&t)!=EOF){
		for(int i=0;i<n;i++){
			p[i].t=in();
			p[i].id=i;
		}
		sort(p,p+n,cmp);
		deque<pair<int,int> >que;
		bool get=false;
		int cnt=0;
		for(int i=0;i<n;i++){
			while(!que.empty()&&que.front().first<=p[i].t-t)que.pop_front();
			if(que.size()==m){
				p[i].r=que.back().second;
				que.pop_back();
			}
			else{
				p[i].r=++cnt;
			}
			que.push_back(make_pair(p[i].t,p[i].r));
			if(que.size()==m)get=true;
		}
		if(!get)printf("No solution\n");
		else{
			printf("%d\n",cnt);
			sort(p,p+n,cmp1);
			for(int i=0;i<n;i++)
				printf("%d\n",p[i].r);
		}
	}
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;
struct P{
	int t,id,r;
}p[20000];
bool cmp(P a,P b){
	return a.t<b.t;
}
bool cmp1(P a,P b){
	return a.id<b.id;
}
int in(){
	int h,m,s;
	scanf("%d%*c%d%*c%d",&h,&m,&s);
	return h*3600+m*60+s;
}
int main(){
	int n,m,t;
	while(scanf("%d%d%d",&n,&m,&t)!=EOF){
		for(int i=0;i<n;i++){
			p[i].t=in();
			p[i].id=i;
		}
		sort(p,p+n,cmp);
		queue<pair<int,int> >que;
		bool get=false;
		int cnt=0;
		for(int i=0;i<n;i++){
			while(!que.empty()&&que.front().first<=p[i].t-t)que.pop();
			if(que.size()==m){
				p[i].r=que.front().second;
				que.pop();
			}
			else{
				p[i].r=++cnt;
			}
			que.push(make_pair(p[i].t,p[i].r));
			if(que.size()==m)get=true;
		}
		if(!get)printf("No solution\n");
		else{
			printf("%d\n",cnt);
			sort(p,p+n,cmp1);
			for(int i=0;i<n;i++)
				printf("%d\n",p[i].r);
		}
	}
}


#include <cstdio>
const int maxn = 20001;
int n, m, t, a[maxn], l, r, que[maxn], ans, out[maxn];
bool flag;
int main()
{
	scanf("%d%d%d", &n, &m, &t);
	for(int i = 0; i < n; ++i)
	{
		int hh, mm, ss;
		scanf("%d:%d:%d", &hh, &mm, &ss);
		a[i] = hh * 3600 + mm * 60 + ss;
		que[r++] = i;
		while(l < r && a[que[r - 1]] - a[que[l]] >= t)
			++l;
		if(r - l == m)
			flag = 1;
		if(r - l <= m)
			out[i] = ++ans;
		else
		{
			out[i] = out[que[r - 2]];
			que[r - 2] = que[r - 1];
			--r;
		}
	}
	if(flag)
	{
		printf("%d\n", ans);
		for(int i = 0; i < n; ++i)
			printf("%d\n", out[i]);
	}
	else
		printf("No solution\n");
	return 0;
}


#include <cstdio>
const int maxn = 20001;
int n, m, t, a[maxn], l, r, que[maxn], ans, out[maxn];
bool flag;
int main()
{
	scanf("%d%d%d", &n, &m, &t);
	for(int i = 0; i < n; ++i)
	{
		int hh, mm, ss;
		scanf("%d:%d:%d", &hh, &mm, &ss);
		a[i] = hh * 3600 + mm * 60 + ss;
		que[r++] = i;
		while(l < r && a[que[r - 1]] - a[que[l]] >= t)
			++l;
		if(r - l == m)
			flag = 1;
		if(r - l <= m)
			out[i] = ++ans;
		else
		{
			out[i] = out[que[r - 2]];
			--r;
		}
	}
	if(flag)
	{
		printf("%d\n", ans);
		for(int i = 0; i < n; ++i)
			printf("%d\n", out[i]);
	}
	else
		printf("No solution\n");
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <iostream>
#include <cassert>

using namespace std;

#define fru(j,n) for(int j=0; j<(n); ++j)
#define tr(it,v) for(typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define x first
#define y second
#define pb push_back
#define ALL(G) (G).begin(),(G).end()

#define DEBUG
#ifdef DEBUG
	#define DEB printf
#else
	#define DEB(...)
#endif

typedef long long LL;
typedef double D;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int inft = 1000000009;
const int MAXN = 1000006;//10^6
vector<int> A[MAXN];
int ans[MAXN],last[MAXN];
void NIE(){
	puts("No solution");
	exit(0);
}
int main(){
	int n,M,T;
	scanf("%d%d%d",&n,&M,&T);
	fru(i,n){
		int h,m,s;
		scanf("%d:%d:%d",&h,&m,&s);
		int t=3600*h+60*m+s;
		A[t].pb(i);
	}
	bool czy=0;
	deque<int> UP; //aktywni goscie
	int juz=0;
	fru(i,86401){
		tr(it,A[i])	if(UP.size()==M){
			//podmien starego
			int w=UP.back();
			UP.pop_back();
			ans[*it]=w;
			UP.pb(w);
			last[w]=i;
		}
		else
		{
			UP.pb(++juz);
			ans[*it]=juz;
			last[juz]=i;
		}
		czy|=UP.size()==M;
		while(UP.size() && last[UP.front()]+T-1==i) UP.pop_front();
	}
	if(czy==0) NIE();
	printf("%d\n",juz);
	fru(i,n) printf("%d\n",ans[i]);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <iostream>
#include <cassert>

using namespace std;

#define fru(j,n) for(int j=0; j<(n); ++j)
#define tr(it,v) for(typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define x first
#define y second
#define pb push_back
#define ALL(G) (G).begin(),(G).end()

#define DEBUG
#ifdef DEBUG
	#define DEB printf
#else
	#define DEB(...)
#endif

typedef long long LL;
typedef double D;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int inft = 1000000009;
const int MAXN = 1000006;//10^6
vector<int> A[MAXN];
int ans[MAXN],last[MAXN];
void NIE(){
	puts("No solution");
	exit(0);
}
int main(){
	int n,M,T;
	scanf("%d%d%d",&n,&M,&T);
	fru(i,n){
		int h,m,s;
		scanf("%d:%d:%d",&h,&m,&s);
		int t=3600*h+60*m+s;
		A[t].pb(i);
	}
	fru(i,MAXN) if(A[i].size()>M) NIE();
	bool czy=0;
	deque<int> UP; //aktywni goscie
	int juz=0;
	fru(i,86401){
		vi TU;
		tr(it,A[i])	if(UP.size()+TU.size()==M){
			//podmien starego
			assert(UP.size());
			int w=UP.back();
			UP.pop_back();
			ans[*it]=w;
			TU.pb(w);
		}
		else
		{
			TU.pb(++juz);
			ans[*it]=juz;
		}
		czy|=UP.size()+TU.size()==M;
		tr(it,TU) UP.pb(*it);
		tr(it,TU) last[*it]=i;
		while(UP.size() && last[UP.front()]+T-1==i) UP.pop_front();
	}
	if(czy==0) NIE();
	printf("%d\n",juz);
	fru(i,n) printf("%d\n",ans[i]);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <iostream>
#include <cassert>

using namespace std;

#define fru(j,n) for(int j=0; j<(n); ++j)
#define tr(it,v) for(typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define x first
#define y second
#define pb push_back
#define ALL(G) (G).begin(),(G).end()

#define DEBUG
#ifdef DEBUG
	#define DEB printf
#else
	#define DEB(...)
#endif

typedef long long LL;
typedef double D;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int inft = 1000000009;
const int MAXN = 1000006;//10^6
vector<int> A[MAXN];
int ans[MAXN],last[MAXN];
void NIE(){
	puts("No solution");
	exit(0);
}
int main(){
	int n,M,T;
	scanf("%d%d%d",&n,&M,&T);
	fru(i,n){
		int h,m,s;
		scanf("%d:%d:%d",&h,&m,&s);
		int t=3600*h+60*m+s;
		A[t].pb(i);
	}
	fru(i,MAXN) if(A[i].size()>M) NIE();
	bool czy=0;
	deque<int> UP; //aktywni goscie
	int juz=0;
	fru(i,86401){
		tr(it,A[i])	if(UP.size()==M){
			//podmien starego
			assert(UP.size());
			int w=UP.back();
			UP.pop_back();
			ans[*it]=w;
			UP.pb(w);
			last[w]=i;
		}
		else
		{
			UP.pb(++juz);
			ans[*it]=juz;
			last[juz]=i;
		}
		czy|=UP.size()==M;
		while(UP.size() && last[UP.front()]+T-1==i) UP.pop_front();
	}
	if(czy==0) NIE();
	printf("%d\n",juz);
	fru(i,n) printf("%d\n",ans[i]);
	return 0;
}


#include <stdio.h>
#include <set>
#include <string>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
using namespace std;

#define N 3000
#define E 20000
#define INF 200000000
#define tl(x) (x << 1)
#define tr(x) (x << 1 | 1)
#define MAXN 100100

int n, m, T;

int bx[20010], cx[20010];

int ans;

int f_ans[20011];

int main()
{

    scanf("%d%d%d", &n, &m, &T);

    for(int i = 1, a, b, c; i <= n; i++) {
        scanf("%d:%d:%d", &a, &b, &c);
        bx[i] = a * 3600 + b * 60 + c;
    }

    int sum = 0;
    bool find = 0;

    int pos = 1;
    for(int i = 1; i <= n; i++) {
        while(pos < i && bx[pos] + T <= bx[i]) {
            cx[f_ans[pos]]--;
            if(cx[f_ans[pos]] == 0) sum--;
            pos++;
        }
        if(sum < m) {
            sum++;
            f_ans[i] = ++ans;
            cx[ans]++;
        } else {
            f_ans[i] = f_ans[i - 1];
            cx[f_ans[i]]++;
        }
        if(sum == m) find = 1;
    }

    if(find) {
        printf("%d\n", ans);
        for(int i = 1; i <= n; i++) {
            printf("%d\n", f_ans[i]);
        }
    }
    else printf("No solution\n");

    return 0;
}


#include <stdio.h>
#include <set>
#include <string>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
using namespace std;

#define N 3000
#define E 20000
#define INF 200000000
#define tl(x) (x << 1)
#define tr(x) (x << 1 | 1)
#define MAXN 100100

int n, m, T;

int bx[20010], cx[20010];

int ans;

int f_ans[20011];
int ax[42000], o;

int main()
{

    scanf("%d%d%d", &n, &m, &T);

    for(int i = 1, a, b, c; i <= n; i++) {
        scanf("%d:%d:%d", &a, &b, &c);
        bx[i] = a * 3600 + b * 60 + c;
        cx[i] = bx[i] + T;
        ax[++o] = bx[i]; ax[++o] = cx[i];
    }

    sort(ax + 1, ax + 1 + o);

    o = unique(ax + 1, ax + 1 + o) - ax - 1;

    bool find = 0;

    int sum = 0;
    int now1 = 1, now2 = 1;
    int pre;
    for(int i = 1; i <= o; i++) {
        while(now2 <= n && cx[now2] == ax[i]) {
            if(now2 == n) sum--;
            else if(f_ans[now2] != f_ans[now2 + 1]) sum--;
            now2++;
        }
        while(now1 <= n && ax[now1] == ax[i]) {
            if(sum < m) ans++, f_ans[now1] = ans, pre = ans, sum++;
            else f_ans[now1] = pre;
            now1++;
            if(sum == m) find = 1;
        }
    }

    if(find) {
        printf("%d\n", ans);
        for(int i = 1; i <= n; i++) {
            printf("%d\n", f_ans[i]);
        }
    }
    else printf("No solution\n");

    return 0;
}


#include <stdio.h>
#include <set>
#include <string>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
using namespace std;

#define N 3000
#define E 20000
#define INF 200000000
#define tl(x) (x << 1)
#define tr(x) (x << 1 | 1)
#define MAXN 100100

int n, m, T;

int bx[20010], cx[20010];

int ans;

int f_ans[20011];
int ax[42000], o;

int main()
{
    //freopen("pro.in","r",stdin);

    scanf("%d%d%d", &n, &m, &T);

    for(int i = 1, a, b, c; i <= n; i++) {
        scanf("%d:%d:%d", &a, &b, &c);
        bx[i] = a * 3600 + b * 60 + c;
        cx[i] = bx[i] + T;
        ax[++o] = bx[i]; ax[++o] = cx[i];
    }

    sort(ax + 1, ax + 1 + o);

    o = unique(ax + 1, ax + 1 + o) - ax - 1;

    bool find = 0;

    int sum = 0;
    int now1 = 1, now2 = 1;
    int pre;
    for(int i = 1; i <= o; i++) {
        while(now2 <= n && cx[now2] == ax[i]) sum--, now2++;
        while(now1 <= n && ax[now1] == ax[i]) {
            if(sum < m) ans++, f_ans[now1] = ans, pre = ans, sum++;
            else f_ans[now1] = pre;
            now1++;
            if(sum == m) find = 1;
        }
    }

    if(find) {
        printf("%d\n", ans);
        for(int i = 1; i <= n; i++) {
            printf("%d\n", f_ans[i]);
        }
    }
    else printf("No solution\n");

    return 0;
}


#include <stdio.h>
#include <set>
#include <string>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
using namespace std;

#define N 3000
#define E 20000
#define INF 200000000
#define tl(x) (x << 1)
#define tr(x) (x << 1 | 1)
#define MAXN 100100

int n, m, T;

int bx[20010], cx[20010];

int ans;

int f_ans[20011];
int ax[42000], o;

int main()
{

    scanf("%d%d%d", &n, &m, &T);

    for(int i = 1, a, b, c; i <= n; i++) {
        scanf("%d:%d:%d", &a, &b, &c);
        bx[i] = a * 3600 + b * 60 + c;
        cx[i] = bx[i] + T;
        ax[++o] = bx[i]; ax[++o] = cx[i];
    }

    sort(ax + 1, ax + 1 + o);

    o = unique(ax + 1, ax + 1 + o) - ax - 1;

    bool find = 0;

    int sum = 0;
    int now1 = 1, now2 = 1;
    int pre;
    for(int i = 1; i <= o; i++) {
        while(now2 <= n && cx[now2] == ax[i]) {
            if(now2 + 1 < now1 && f_ans[now2] != f_ans[now2 + 1]) sum--;
            now2++;
        }
        while(now1 <= n && ax[now1] == ax[i]) {
            if(sum < m) ans++, f_ans[now1] = ans, pre = ans, sum++;
            else f_ans[now1] = pre;
            now1++;
            if(sum == m) find = 1;
        }
    }

    if(find) {
        printf("%d\n", ans);
        for(int i = 1; i <= n; i++) {
            printf("%d\n", f_ans[i]);
        }
    }
    else printf("No solution\n");

    return 0;
}


#include <stdio.h>
#include <set>
#include <string>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
using namespace std;

#define N 3000
#define E 20000
#define INF 200000000
#define tl(x) (x << 1)
#define tr(x) (x << 1 | 1)
#define MAXN 100100

int n, m, T;

int bx[20010];

set <int> key;
set <int>::iterator itt;

multiset <int> q;
multiset <int>::iterator it;

queue <pair<int, int> > qq;

int ans;

int ax[40011], o;

int f_ans[40011];

int main()
{

    scanf("%d%d%d", &n, &m, &T);

    for(int i = 1, a, b, c; i <= n; i++) {
        scanf("%d:%d:%d", &a, &b, &c);
        bx[i] = a * 3600 + b * 60 + c;
        ax[++o] = bx[i]; ax[++o] = bx[i] + T;
    }

    sort(ax + 1, ax + 1 + o);

    o = unique(ax + 1, ax + 1 + o) - ax - 1;

    bool find = 0;

    int pre;
    int now = 1;
    for(int i = 1; i <= o; i++) {
        if(!qq.empty()) {
            pair<int, int> tmp = qq.front();
            while(tmp.first <= ax[i]) {
                int b = tmp.second;
                it = q.find(b);
                q.erase(it);
                if(q.find(b) == q.end()) {
                    itt = key.find(b);
                    key.erase(itt);
                }
                qq.pop();
                if(qq.empty()) break;
                tmp = qq.front();
            }
        }
        if(now <= n && bx[now] == ax[i]) {
            if(key.size() < m) {
                ans++;
                pre = ans;
                q.insert(ans);
                key.insert(ans);
                f_ans[now] = ans;
                if(key.size() == m) find = 1;
                qq.push(make_pair(bx[now] + T, ans));
            } else {
                q.insert(pre);
                key.insert(pre);
                f_ans[now] = pre;
                qq.push(make_pair(bx[now] + T, pre));
            }
            now++;
        }
    }

    if(find) {
        printf("%d\n", ans);
        for(int i = 1; i <= n; i++) {
            printf("%d\n", f_ans[i]);
        }
    }
    else printf("No solution\n");

    return 0;
}


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

//ifstream f("wow.in");

#define LE 100666

int pos[LE],ST[LE],color[LE];
#define f cin

int main()
{
    int n,M,t,i;
    int nr_col=0;
    string str;

    f>>n>>M>>t;
    f.get();

    bool okz=false;

    if (M==1) okz=true;

    for(i=1; i<=n; ++i)
    {
        f>>str;
        int v0=(str[0]-'0')*10+(str[1]-'0');
        int v1=(str[3]-'0')*10+(str[4]-'0');
        int v2=(str[6]-'0')*10+(str[7]-'0');

        pos[i]=v0*3600;
        pos[i]+=v1*60;
        pos[i]+=v2;
    }

   // for(i=1;i<=n;++i)
    //  cout<<pos[i]<<" ";

   // cout<<'\n';

    int st=1,dr=0;

    for(i=1; i<=n; ++i)
    {
        while (st<=dr&&pos[i]-pos[ST[st]]>=t) ++st;

        if (st>dr)
            ++nr_col;
        else if (nr_col+2-color[ST[st]]<=M)
            ++nr_col;

        color[i]=nr_col;
         if (color[i]-color[ST[st]]+1==M&&st<=dr) okz=true;
        ST[++dr]=i;
    }

    if (okz==false)
    {
        cout<<"No solution"<<'\n';
        return 0;
    }

    cout<<color[n]<<'\n';
    for(i=1; i<=n; ++i) cout<<color[i]<<" ";

    return 0;
}


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

//ifstream f("wow.in");

#define LE 100666

int pos[LE],ST[LE],color[LE];
#define f cin

int main()
{
    int n,M,t,i;
    int nr_col=0;
    string str;

    f>>n>>M>>t;
    f.get();

    bool okz=false;

    if (M==1) okz=true;

    for(i=1; i<=n; ++i)
    {
        f>>str;
        int v0=(str[0]-'0')*10+(str[1]-'0');
        int v1=(str[3]-'0')*10+(str[4]-'0');
        int v2=(str[6]-'0')*10+(str[7]-'0');

        pos[i]=v0*3600;
        pos[i]+=v1*60;
        pos[i]+=v2;
    }

   // for(i=1;i<=n;++i)
    //  cout<<pos[i]<<" ";

   // cout<<'\n';

    int st=1,dr=0;

    for(i=1; i<=n; ++i)
    {
        while (st<=dr&&pos[i]-pos[ST[st]]>t) ++st;

        if (st>dr)
            ++nr_col;
        else if (nr_col+2-color[ST[st]]<=M)
            ++nr_col;

        color[i]=nr_col;
         if (color[i]-color[ST[st]]+1==M&&st<=dr) okz=true;
        ST[++dr]=i;
    }

    if (okz==false)
    {
        cout<<"No solution"<<'\n';
        return 0;
    }

    cout<<color[n]<<'\n';
    for(i=1; i<=n; ++i) cout<<color[i]<<" ";

    return 0;
}


#include <fstream>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include<stack>
#include<map>
#include<queue>
#include <math.h>
#include<set>
#include<stdint.h>
#include <utility>
#include <cmath>
#include <iostream>
#include <iomanip>
#define MAXN 100005
#define MaxVal 86410
#define MAXLG 17
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;
typedef long long int ll;
typedef pair<int, int> mp;
template<class T> void chmin(T &t, const T &f) { if (t > f) t = f; }
template<class T> void chmax(T &t, const T &f) { if (t < f) t = f; }

int tree[86410];

int read(int idx){
    int sum = 0;
    while (idx > 0){
        sum += tree[idx];
        idx -= (idx & -idx);
    }
    return sum;
}

void update(int idx ,int val){
    while (idx <= MaxVal){
        tree[idx] += val;
        idx += (idx & -idx);
    }
}

int getTime(char a[100])
{
    int hour = 0, mini=0, sec=0, time;

    if(a[0] != '0')
        hour = (a[0] - '0')*(10);
    if(a[1] != '0')
        hour += (a[1] - '0');

    if(a[3] != '0')
        mini = (a[3] - '0')*10;
    if(a[4] != '0')
        mini += (a[4] - '0');

    if(a[6] != '0')
        sec = (a[6] - '0')*10;
    if(a[7] != '0')
        sec += (a[7] - '0');

    time += (hour*(60*60)) + (mini*(60)) + sec;
    return time+1;
}

int main()
{
    int n, m, t, prevId, prevTime=0, id=0, pos = 0;
    vector<int> ans;
    scanf("%d %d %d", &n, &m, &t);

    for(int i=0; i<n; ++i)
    {
        char a[100];
        scanf("%s", a);

        int time = getTime(a);
        int num = read(time);

        if(num < m)
        {
            ans.push_back(++id);
            update(time, 1);
            update(min(MaxVal, time+t), -1);

            prevTime = time;
            prevId = id;
        }
        else
        {
            ans.push_back(id);
            pos = 1;

            update(prevTime, 1);
            update(min(MaxVal, time+t), -1);

            prevTime = time;
            prevId = id;
        }
    }

    if(pos)
    {
        printf("%ld\n", ans.size());
        for(int i=0; i<ans.size(); ++i)
            printf("%d\n", ans[i]);
        return 0;
    }

    printf("No solution");
    return 0;
}


#include <fstream>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include<stack>
#include<map>
#include<queue>
#include <math.h>
#include<set>
#include<stdint.h>
#include <utility>
#include <cmath>
#include <iostream>
#include <iomanip>
#define MAXN 100005
#define MaxVal 86410
#define MAXLG 17
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;
typedef long long int ll;
typedef pair<int, int> mp;
template<class T> void chmin(T &t, const T &f) { if (t > f) t = f; }
template<class T> void chmax(T &t, const T &f) { if (t < f) t = f; }

int tree[86410];

int read(int idx){
    int sum = 0;
    while (idx > 0){
        sum += tree[idx];
        idx -= (idx & -idx);
    }
    return sum;
}

void update(int idx ,int val){
    while (idx <= MaxVal){
        tree[idx] += val;
        idx += (idx & -idx);
    }
}

int getTime(char a[100])
{
    int hour = 0, mini=0, sec=0, time;

    if(a[0] != '0')
        hour = (a[0] - '0')*(10);
    if(a[1] != '0')
        hour += (a[1] - '0');

    if(a[3] != '0')
        mini = (a[3] - '0')*10;
    if(a[4] != '0')
        mini += (a[4] - '0');

    if(a[6] != '0')
        sec = (a[6] - '0')*10;
    if(a[7] != '0')
        sec += (a[7] - '0');

    time += (hour*(60*60)) + (mini*(60)) + sec;
    return time+1;
}

int main()
{
    int n, m, t, prevId, prevTime=0, id=0, pos = 0;
    vector<int> ans;
    scanf("%d %d %d", &n, &m, &t);

    for(int i=0; i<n; ++i)
    {
        char a[100];
        scanf("%s", a);

        int time = getTime(a);
        int num = read(time);

        if(num < m)
        {
            ans.push_back(++id);
            update(time, 1);
            update(min(MaxVal, time+t), -1);

            prevTime = time;
            prevId = id;
        }
        else
        {
            ans.push_back(id);
            pos = 1;

            update(prevTime, 1);
            update(min(MaxVal, time+t), -1);

            prevTime = time;
            prevId = id;
        }
    }

    if(pos)
    {
        printf("%d\n", id);
        for(int i=0; i<ans.size(); ++i)
            printf("%d\n", ans[i]);
        return 0;
    }

    printf("No solution");
    return 0;
}


#include <fstream>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include<stack>
#include<map>
#include<queue>
#include <math.h>
#include<set>
#include<stdint.h>
#include <utility>
#include <cmath>
#include <iostream>
#include <iomanip>
#define MAXN 100005
#define MaxVal 86410
#define MAXLG 17
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;
typedef long long int ll;
typedef pair<int, int> mp;
template<class T> void chmin(T &t, const T &f) { if (t > f) t = f; }
template<class T> void chmax(T &t, const T &f) { if (t < f) t = f; }

int tree[86410];

int read(int idx){
    int sum = 0;
    while (idx > 0){
        sum += tree[idx];
        idx -= (idx & -idx);
    }
    return sum;
}

void update(int idx ,int val){
    while (idx <= MaxVal){
        tree[idx] += val;
        idx += (idx & -idx);
    }
}

int getTime(char a[100])
{
    int hour = 0, mini=0, sec=0, time;

    if(a[0] != '0')
        hour = (a[0] - '0')*(10);
    if(a[1] != '0')
        hour += (a[1] - '0');

    if(a[3] != '0')
        mini = (a[3] - '0')*10;
    if(a[4] != '0')
        mini += (a[4] - '0');

    if(a[6] != '0')
        sec = (a[6] - '0')*10;
    if(a[7] != '0')
        sec += (a[7] - '0');

    time += (hour*(60*60)) + (mini*(60)) + sec;
    return time+1;
}

int main()
{
    int n, m, t, prevId, prevTime=0, id=0, pos = 0;
    vector<int> ans;
    scanf("%d %d %d", &n, &m, &t);

    for(int i=0; i<n; ++i)
    {
        char a[100];
        scanf("%s", a);

        int time = getTime(a);
        int num = read(time);

        if(num < m)
        {
            ans.push_back(++id);
            update(time, 1);
            update(min(MaxVal, time+t), -1);

            prevTime = min(MaxVal, time+t);
            prevId = id;
        }
        else
        {
            ans.push_back(id);
            pos = 1;

            update(prevTime, 1);
            update(min(MaxVal, time+t), -1);

            prevTime = min(MaxVal, time+t);
            prevId = id;
        }
    }

    if(!pos)
    {
        for(int i=1; i<MaxVal; ++i)
        {
            int num = read(i);
            if(num >= m)
                pos = 1;
        }
    }

    if(pos)
    {
        printf("%d\n", id);
        for(int i=0; i<ans.size(); ++i)
            printf("%d\n", ans[i]);
        return 0;
    }

    printf("No solution");
    return 0;
}


#include <fstream>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include<stack>
#include<map>
#include<queue>
#include <math.h>
#include<set>
#include<stdint.h>
#include <utility>
#include <cmath>
#include <iostream>
#include <iomanip>
#define MAXN 100005
#define MaxVal 86410
#define MAXLG 17
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;
typedef long long int ll;
typedef pair<int, int> mp;
template<class T> void chmin(T &t, const T &f) { if (t > f) t = f; }
template<class T> void chmax(T &t, const T &f) { if (t < f) t = f; }

int tree[86410];

int read(int idx){
    int sum = 0;
    while (idx > 0){
        sum += tree[idx];
        idx -= (idx & -idx);
    }
    return sum;
}

void update(int idx ,int val){
    while (idx <= MaxVal){
        tree[idx] += val;
        idx += (idx & -idx);
    }
}

int getTime(char a[100])
{
    int hour = 0, mini=0, sec=0, time;

    if(a[0] != '0')
        hour = (a[0] - '0')*(10);
    if(a[1] != '0')
        hour += (a[1] - '0');

    if(a[3] != '0')
        mini = (a[3] - '0')*10;
    if(a[4] != '0')
        mini += (a[4] - '0');

    if(a[6] != '0')
        sec = (a[6] - '0')*10;
    if(a[7] != '0')
        sec += (a[7] - '0');

    time += (hour*(60*60)) + (mini*(60)) + sec;
    return time+1;
}

int main()
{
    int n, m, t, prevId, prevTime=0, id=0, pos = 0;
    vector<int> ans;
    scanf("%d %d %d", &n, &m, &t);

    for(int i=0; i<n; ++i)
    {
        char a[100];
        scanf("%s", a);

        int time = getTime(a);
        int num = read(time);

        if(num < m)
        {
            ans.push_back(++id);
            update(time, 1);
            update(min(MaxVal, time+t), -1);

            prevTime = min(MaxVal, time+t);
            prevId = id;
        }
        else
        {
            ans.push_back(id);
            pos = 1;

            update(prevTime, 1);
            update(min(MaxVal, time+t), -1);

            prevTime = min(MaxVal, time+t);
            prevId = id;
        }
    }

    if(pos)
    {
        printf("%d\n", id);
        for(int i=0; i<ans.size(); ++i)
            printf("%d\n", ans[i]);
        return 0;
    }

    printf("No solution");
    return 0;
}


/*
    Look at me!
    Look at me!
    Look at how large the monster inside me has become!
*/

#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#define FIT(a,b) for(vector<int >::iterator a=b.begin();a!=b.end();a++)
#define FITP(a,b) for(vector<pair<int,int> >::iterator a=b.begin();a!=b.end();a++)
#define RIT(a,b) for(vector<int>::reverse_iterator a=b.end();a!=b.begin();++a)
#include<stack>
#define ROF(a,b,c) for(int a=b;a>=c;--a)
#include<vector>
#include<algorithm>
#define FOR(a,b,c) for(int a=b;a<=c;++a)
#define REP(a,b) for(register int a=0;a<b;++a)
#include<cstring>
#include<bitset>
#include<cmath>
#include<iomanip>
#define f cin
#define g cout
#include<queue>
#define INF 0x3f3f3f3f
#define debug cerr<<"OK";
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define eps 1.e-9
#define BUFMAX 10100100
#define N 1000100
#define mod 1000000007
using namespace std;
/*int dx[]={0,0,0,1,-1};
int dy[]={0,1,-1,0,0};*/

vector<int> sol;
int n,m,T,h,mi,cnt,fndm,v[N],sec;
char ch;
int main ()
{
    #ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    #endif

    f>>n>>m>>T;
    FOR(i,1,n)
    {
        f>>h;
        f>>ch;
        h*=3600;
        f>>mi;
        f>>ch;
        mi*=60;
        f>>sec;
        v[i]=h+mi+sec;
    }
    int la=0;
    int lt=0;
    int user=0;
    multiset<int> hm;
    FOR(i,1,n)
    {
            while(!hm.empty()&&*hm.begin()<v[i])
                hm.erase(hm.begin());

        if(hm.size()==m)
        {
            sol.pb(user);
            if(hm.count(v[i-1]+T-1))
                hm.erase(hm.find(v[i-1]+T-1));
        }
        else
            sol.pb(++user);
        hm.insert(v[i]+T-1);
        if(hm.size()==m)
            fndm=1;
    }
    if(!fndm)
    {
        g<<"No solution";
        return 0;
    }
    g<<user<<"\n";
    FIT(it,sol)
    g<<*it<<"\n";

    return 0;
}


/*
    Look at me!
    Look at me!
    Look at how large the monster inside me has become!
*/

#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#define FIT(a,b) for(vector<int >::iterator a=b.begin();a!=b.end();a++)
#define FITP(a,b) for(vector<pair<int,int> >::iterator a=b.begin();a!=b.end();a++)
#define RIT(a,b) for(vector<int>::reverse_iterator a=b.end();a!=b.begin();++a)
#include<stack>
#define ROF(a,b,c) for(int a=b;a>=c;--a)
#include<vector>
#include<algorithm>
#define FOR(a,b,c) for(int a=b;a<=c;++a)
#define REP(a,b) for(register int a=0;a<b;++a)
#include<cstring>
#include<bitset>
#include<cmath>
#include<iomanip>
#define f cin
#define g cout
#include<queue>
#define INF 0x3f3f3f3f
#define debug cerr<<"OK";
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define eps 1.e-9
#define BUFMAX 10100100
#define N 1000100
#define mod 1000000007
using namespace std;
/*int dx[]={0,0,0,1,-1};
int dy[]={0,1,-1,0,0};*/

vector<int> sol;
int n,m,T,h,mi,cnt,fndm,v[N],sec;
char ch;
int main ()
{
    #ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    #endif

    f>>n>>m>>T;
    FOR(i,1,n)
    {
        f>>h;
        f>>ch;
        h*=3600;
        f>>mi;
        f>>ch;
        mi*=60;
        f>>sec;
        v[h+mi+sec]++;
        v[h+mi+sec+T]--;
    }
    int la=0;
    int user=0;
    FOR(i,0,86500)
    {
        if(i)
            v[i]+=v[i-1];
        if(v[i]<=la)
        {
            la=v[i];
            continue;
        }
        if(v[i]>=m)
        {
            cnt+=m-la;
            FOR(j,1,m-la)
                sol.pb(++user);
            FOR(j,1,v[i]-m)
                sol.pb(user);
            v[i]=m;
            la=m;
            fndm=1;
        }
        else
        {
            cnt+=v[i]-la;
            FOR(j,1,v[i]-la)
                sol.pb(++user);
            la=v[i];
        }
    }
    if(!fndm)
    {
        g<<"No solution";
        return 0;
    }
    g<<cnt<<"\n";
    FIT(it,sol)
    g<<*it<<"\n";

    return 0;
}


/*
    Look at me!
    Look at me!
    Look at how large the monster inside me has become!
*/

#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#define FIT(a,b) for(vector<int >::iterator a=b.begin();a!=b.end();a++)
#define FITP(a,b) for(vector<pair<int,int> >::iterator a=b.begin();a!=b.end();a++)
#define RIT(a,b) for(vector<int>::reverse_iterator a=b.end();a!=b.begin();++a)
#include<stack>
#define ROF(a,b,c) for(int a=b;a>=c;--a)
#include<vector>
#include<algorithm>
#define FOR(a,b,c) for(int a=b;a<=c;++a)
#define REP(a,b) for(register int a=0;a<b;++a)
#include<cstring>
#include<bitset>
#include<cmath>
#include<iomanip>
#define f cin
#define g cout
#include<queue>
#define INF 0x3f3f3f3f
#define debug cerr<<"OK";
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define eps 1.e-9
#define BUFMAX 10100100
#define N 1000100
#define mod 1000000007
using namespace std;
/*int dx[]={0,0,0,1,-1};
int dy[]={0,1,-1,0,0};*/

vector<int> sol;
int n,m,T,h,mi,cnt,fndm,v[N],sec;
char ch;
int main ()
{
    #ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    #endif

    f>>n>>m>>T;
    FOR(i,1,n)
    {
        f>>h;
        f>>ch;
        h*=3600;
        f>>mi;
        f>>ch;
        mi*=60;
        f>>sec;
        v[h+mi+sec]++;
        v[h+mi+sec+T]--;
    }
    int la=0;
    int lt=0;
    int user=0;
    FOR(i,0,86500)
    {
        if(i)
            v[i]+=v[i-1];
        if(v[i]<=la)
        {
            la=v[i];
            continue;
        }
        if(v[i]>=m)
        {
            cnt+=m-la;
            FOR(j,1,m-la)
            {
                sol.pb(++user);
                lt=i+T;
            }
            FOR(j,1,v[i]-m)
                sol.pb(user);
            FOR(j,1,v[i]-m)
                v[i+T]++;
            if(v[i]!=m)
            {
            v[lt]++;
            v[i+T]--;
            }
            v[i]=m;
            la=m;
            fndm=1;
        }
        else
        {
            cnt+=v[i]-la;
            FOR(j,1,v[i]-la)
            {
                sol.pb(++user);
                lt=i+T;
            }
            la=v[i];
        }
    }
    if(!fndm)
    {
        g<<"No solution";
        return 0;
    }
    g<<cnt<<"\n";
    FIT(it,sol)
    g<<*it<<"\n";

    return 0;
}


/*
    Look at me!
    Look at me!
    Look at how large the monster inside me has become!
*/

#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#define FIT(a,b) for(vector<int >::iterator a=b.begin();a!=b.end();a++)
#define FITP(a,b) for(vector<pair<int,int> >::iterator a=b.begin();a!=b.end();a++)
#define RIT(a,b) for(vector<int>::reverse_iterator a=b.end();a!=b.begin();++a)
#include<stack>
#define ROF(a,b,c) for(int a=b;a>=c;--a)
#include<vector>
#include<algorithm>
#define FOR(a,b,c) for(int a=b;a<=c;++a)
#define REP(a,b) for(register int a=0;a<b;++a)
#include<cstring>
#include<bitset>
#include<cmath>
#include<iomanip>
#define f cin
#define g cout
#include<queue>
#define INF 0x3f3f3f3f
#define debug cerr<<"OK";
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define eps 1.e-9
#define BUFMAX 10100100
#define N 1000100
#define mod 1000000007
using namespace std;
/*int dx[]={0,0,0,1,-1};
int dy[]={0,1,-1,0,0};*/

vector<int> sol;
int n,m,T,h,mi,cnt,fndm,v[N],sec;
char ch;
int main ()
{
    #ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    #endif

    f>>n>>m>>T;
    FOR(i,1,n)
    {
        f>>h;
        f>>ch;
        h*=3600;
        f>>mi;
        f>>ch;
        mi*=60;
        f>>sec;
        v[h+mi+sec]++;
        v[h+mi+sec+T]--;
    }
    int la=0;
    int user=0;
    FOR(i,0,86500)
    {
        if(i)
            v[i]+=v[i-1];
        if(v[i]<=la)
        {
            la=v[i];
            continue;
        }
        if(v[i]>=m)
        {
            cnt+=m-la;
            FOR(j,1,m-la)
                sol.pb(++user);
            FOR(j,1,v[i]-m)
                sol.pb(user);
            FOR(j,1,v[i]-m)
                v[i+T]++;
            v[i]=m;
            la=m;
            fndm=1;
        }
        else
        {
            cnt+=v[i]-la;
            FOR(j,1,v[i]-la)
                sol.pb(++user);
            la=v[i];
        }
    }
    if(!fndm)
    {
        g<<"No solution";
        return 0;
    }
    g<<cnt<<"\n";
    FIT(it,sol)
    g<<*it<<"\n";

    return 0;
}


/*
    Look at me!
    Look at me!
    Look at how large the monster inside me has become!
*/

#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#define FIT(a,b) for(vector<int >::iterator a=b.begin();a!=b.end();a++)
#define FITP(a,b) for(vector<pair<int,int> >::iterator a=b.begin();a!=b.end();a++)
#define RIT(a,b) for(vector<int>::reverse_iterator a=b.end();a!=b.begin();++a)
#include<stack>
#define ROF(a,b,c) for(int a=b;a>=c;--a)
#include<vector>
#include<algorithm>
#define FOR(a,b,c) for(int a=b;a<=c;++a)
#define REP(a,b) for(register int a=0;a<b;++a)
#include<cstring>
#include<bitset>
#include<cmath>
#include<iomanip>
#define f cin
#define g cout
#include<queue>
#define INF 0x3f3f3f3f
#define debug cerr<<"OK";
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define eps 1.e-9
#define BUFMAX 10100100
#define N 1000100
#define mod 1000000007
using namespace std;
/*int dx[]={0,0,0,1,-1};
int dy[]={0,1,-1,0,0};*/

vector<int> sol;
int n,m,T,h,mi,cnt,fndm,v[N],sec;
char ch;
int main ()
{
    #ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    #endif

    f>>n>>m>>T;
    FOR(i,1,n)
    {
        f>>h;
        f>>ch;
        h*=3600;
        f>>mi;
        f>>ch;
        mi*=60;
        f>>sec;
        v[i]=h+mi+sec;
    }
    int la=0;
    int lt=0;
    int user=0;
    multiset<int> hm;
    FOR(i,1,n)
    {
        if(!hm.empty())
        {
            while(*hm.begin()<v[i])
                hm.erase(hm.begin());
        }
        if(hm.size()==m)
        {
            sol.pb(user);
            if(hm.count(v[i-1]+T-1))
                hm.erase(hm.find(v[i-1]+T-1));
        }
        else
            sol.pb(++user);
        hm.insert(v[i]+T-1);
        if(hm.size()==m)
            fndm=1;
    }
    if(!fndm)
    {
        g<<"No solution";
        return 0;
    }
    g<<user<<"\n";
    FIT(it,sol)
    g<<*it<<"\n";

    return 0;
}


/*
    Look at me!
    Look at me!
    Look at how large the monster inside me has become!
*/

#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#define FIT(a,b) for(vector<int >::iterator a=b.begin();a!=b.end();a++)
#define FITP(a,b) for(vector<pair<int,int> >::iterator a=b.begin();a!=b.end();a++)
#define RIT(a,b) for(vector<int>::reverse_iterator a=b.end();a!=b.begin();++a)
#include<stack>
#define ROF(a,b,c) for(int a=b;a>=c;--a)
#include<vector>
#include<algorithm>
#define FOR(a,b,c) for(int a=b;a<=c;++a)
#define REP(a,b) for(register int a=0;a<b;++a)
#include<cstring>
#include<bitset>
#include<cmath>
#include<iomanip>
#define f cin
#define g cout
#include<queue>
#define INF 0x3f3f3f3f
#define debug cerr<<"OK";
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define eps 1.e-9
#define BUFMAX 10100100
#define N 1000100
#define mod 1000000007
using namespace std;
/*int dx[]={0,0,0,1,-1};
int dy[]={0,1,-1,0,0};*/

vector<int> sol;
int n,m,T,h,mi,cnt,fndm,v[N],sec;
char ch;
int main ()
{
    #ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    #endif

    f>>n>>m>>T;
    FOR(i,1,n)
    {
        f>>h;
        f>>ch;
        h*=3600;
        f>>mi;
        f>>ch;
        mi*=60;
        f>>sec;
        v[h+mi+sec]++;
        v[h+mi+sec+T]--;
    }
    int la=0;
    int lt=0;
    int user=0;
    FOR(i,0,200000)
    {
        if(i)
            v[i]+=v[i-1];
        if(v[i]<=la)
        {
            la=v[i];
            continue;
        }
        if(v[i]>m)
        {
            cnt+=m-la;
            FOR(j,1,m-la)
            {
                sol.pb(++user);
                lt=i+T;
            }
            FOR(j,1,v[i]-m)
                sol.pb(user);
            FOR(j,1,v[i]-m)
                v[i+T]++;

            v[lt]++;
            v[i+T]--;
            lt=i+T;

            v[i]=m;
            la=m;
            fndm=1;
        }
        else
        {
            cnt+=v[i]-la;
            FOR(j,1,v[i]-la)
            {
                sol.pb(++user);
                lt=i+T;
            }
            la=v[i];
        }
    }
    if(!fndm)
    {
        g<<"No solution";
        return 0;
    }
    g<<user<<"\n";
    FIT(it,sol)
    g<<*it<<"\n";

    return 0;
}


/*
    Look at me!
    Look at me!
    Look at how large the monster inside me has become!
*/

#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#define FIT(a,b) for(vector<int >::iterator a=b.begin();a!=b.end();a++)
#define FITP(a,b) for(vector<pair<int,int> >::iterator a=b.begin();a!=b.end();a++)
#define RIT(a,b) for(vector<int>::reverse_iterator a=b.end();a!=b.begin();++a)
#include<stack>
#define ROF(a,b,c) for(int a=b;a>=c;--a)
#include<vector>
#include<algorithm>
#define FOR(a,b,c) for(int a=b;a<=c;++a)
#define REP(a,b) for(register int a=0;a<b;++a)
#include<cstring>
#include<bitset>
#include<cmath>
#include<iomanip>
#define f cin
#define g cout
#include<queue>
#define INF 0x3f3f3f3f
#define debug cerr<<"OK";
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define eps 1.e-9
#define BUFMAX 10100100
#define N 1000100
#define mod 1000000007
using namespace std;
/*int dx[]={0,0,0,1,-1};
int dy[]={0,1,-1,0,0};*/

vector<int> sol;
int n,m,T,h,mi,cnt,fndm,v[N],sec;
char ch;
int main ()
{
    #ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    #endif

    f>>n>>m>>T;
    FOR(i,1,n)
    {
        f>>h;
        f>>ch;
        h*=3600;
        f>>mi;
        f>>ch;
        mi*=60;
        f>>sec;
        v[h+mi+sec]++;
        v[h+mi+sec+T]--;
    }
    int la=0;
    int lt=0;
    int user=0;
    FOR(i,0,86500)
    {
        if(i)
            v[i]+=v[i-1];
        if(v[i]<=la)
        {
            la=v[i];
            continue;
        }
        if(v[i]>=m)
        {
            cnt+=m-la;
            FOR(j,1,m-la)
            {
                sol.pb(++user);
                lt=i+T;
            }
            FOR(j,1,v[i]-m)
                sol.pb(user);
            FOR(j,1,v[i]-m)
                v[i+T]++;
            if(v[i]!=m)
            {
            v[lt]++;
            v[i+T]--;
            lt=i+T;
            }
            v[i]=m;
            la=m;
            fndm=1;
        }
        else
        {
            cnt+=v[i]-la;
            FOR(j,1,v[i]-la)
            {
                sol.pb(++user);
                lt=i+T;
            }
            la=v[i];
        }
    }
    if(!fndm)
    {
        g<<"No solution";
        return 0;
    }
    g<<cnt<<"\n";
    FIT(it,sol)
    g<<*it<<"\n";

    return 0;
}


/*
    Look at me!
    Look at me!
    Look at how large the monster inside me has become!
*/

#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#define FIT(a,b) for(vector<int >::iterator a=b.begin();a!=b.end();a++)
#define FITP(a,b) for(vector<pair<int,int> >::iterator a=b.begin();a!=b.end();a++)
#define RIT(a,b) for(vector<int>::reverse_iterator a=b.end();a!=b.begin();++a)
#include<stack>
#define ROF(a,b,c) for(int a=b;a>=c;--a)
#include<vector>
#include<algorithm>
#define FOR(a,b,c) for(int a=b;a<=c;++a)
#define REP(a,b) for(register int a=0;a<b;++a)
#include<cstring>
#include<bitset>
#include<cmath>
#include<iomanip>
#define f cin
#define g cout
#include<queue>
#define INF 0x3f3f3f3f
#define debug cerr<<"OK";
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define eps 1.e-9
#define BUFMAX 10100100
#define N 1000100
#define mod 1000000007
using namespace std;
/*int dx[]={0,0,0,1,-1};
int dy[]={0,1,-1,0,0};*/

vector<int> sol;
int n,m,T,h,mi,cnt,fndm,v[N],sec;
char ch;
int main ()
{
    #ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    #endif

    f>>n>>m>>T;
    FOR(i,1,n)
    {
        f>>h;
        f>>ch;
        h*=3600;
        f>>mi;
        f>>ch;
        mi*=60;
        f>>sec;
        v[h+mi+sec]++;
        v[h+mi+sec+T]--;
    }
    int la=0;
    int lt=0;
    int user=0;
    FOR(i,0,86500)
    {
        if(i)
            v[i]+=v[i-1];
        if(v[i]<=la)
        {
            la=v[i];
            continue;
        }
        if(v[i]>=m)
        {
            cnt+=m-la;
            FOR(j,1,m-la)
            {
                sol.pb(++user);
                lt=i+T;
            }
            FOR(j,1,v[i]-m)
                sol.pb(user);
            FOR(j,1,v[i]-m)
                v[i+T]++;
            v[lt]++;
            v[i+T]--;
            v[i]=m;
            la=m;
            fndm=1;
        }
        else
        {
            cnt+=v[i]-la;
            FOR(j,1,v[i]-la)
            {
                sol.pb(++user);
                lt=i+T;
            }
            la=v[i];
        }
    }
    if(!fndm)
    {
        g<<"No solution";
        return 0;
    }
    g<<cnt<<"\n";
    FIT(it,sol)
    g<<*it<<"\n";

    return 0;
}


/*
    Look at me!
    Look at me!
    Look at how large the monster inside me has become!
*/

#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#define FIT(a,b) for(vector<int >::iterator a=b.begin();a!=b.end();a++)
#define FITP(a,b) for(vector<pair<int,int> >::iterator a=b.begin();a!=b.end();a++)
#define RIT(a,b) for(vector<int>::reverse_iterator a=b.end();a!=b.begin();++a)
#include<stack>
#define ROF(a,b,c) for(int a=b;a>=c;--a)
#include<vector>
#include<algorithm>
#define FOR(a,b,c) for(int a=b;a<=c;++a)
#define REP(a,b) for(register int a=0;a<b;++a)
#include<cstring>
#include<bitset>
#include<cmath>
#include<iomanip>
#define f cin
#define g cout
#include<queue>
#define INF 0x3f3f3f3f
#define debug cerr<<"OK";
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define eps 1.e-9
#define BUFMAX 10100100
#define N 1000100
#define mod 1000000007
using namespace std;
/*int dx[]={0,0,0,1,-1};
int dy[]={0,1,-1,0,0};*/

vector<int> sol;
int n,m,T,h,mi,cnt,fndm,v[N],sec;
char ch;
int main ()
{
    #ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    #endif

    f>>n>>m>>T;
    FOR(i,1,n)
    {
        f>>h;
        f>>ch;
        h*=3600;
        f>>mi;
        f>>ch;
        mi*=60;
        f>>sec;
        v[h+mi+sec]++;
        v[h+mi+sec+T]--;
    }
    int la=0;
    int lt=0;
    int user=0;
    FOR(i,0,200000)
    {
        if(i)
            v[i]+=v[i-1];
        if(v[i]<=la)
        {
            la=v[i];
            continue;
        }
        if(v[i]>m)
        {
            cnt+=m-la;
            FOR(j,1,m-la)
            {
                sol.pb(++user);
                lt=i+T;
            }
            FOR(j,1,v[i]-m)
                sol.pb(user);
            FOR(j,1,v[i]-m)
                v[i+T]++;

            v[lt]++;
            v[i+T]--;
            lt=i+T;

            v[i]=m;
            la=m;
            fndm=1;
        }
        else
        {
            cnt+=v[i]-la;
            FOR(j,1,v[i]-la)
            {
                sol.pb(++user);
                lt=i+T;
            }
            la=v[i];
        }
    }
    if(!fndm)
    {
        g<<"No solution";
        return 0;
    }
    g<<cnt<<"\n";
    FIT(it,sol)
    g<<*it<<"\n";

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <utility>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int const MAX_N = 100100 * 2;
int const MAX_Q = 100100;
int const MAX_CH = 100100;
long long const LL_INF = 1000000000000000009LL;

char st[MAX_CH];

int tm[MAX_N];
int zp_user[MAX_N];

set<int> us;
multiset<int> us_multi;

struct pp {
	int x, tp, ind;
	pp() {}
	pp(int x, int tp, int ind):x(x),tp(tp),ind(ind) {}
} ms[MAX_N];
int ms_len = 0;

bool operator < (const pp &A, const pp &B) {
	return A.x < B.x || (A.x == B.x && A.tp > B.tp);
}

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

	gets(st);
	int n,M,T;
	sscanf(st,"%d%d%d",&n,&M,&T);
	for (int i=0; i<n; i++) {
		gets(st);
		int hh,mm,ss;
		sscanf(st,"%d:%d:%d",&hh,&mm,&ss);
		tm[i] =  hh*3600+mm*60+ss;
	}

	int cnt = 0;
	int mx_onl = 0;

	ms_len = 0;
	for (int i=0; i<n; i++) {
		ms[ms_len++] = pp(tm[i], +1, i);
		ms[ms_len++] = pp(tm[i]+T-1 ,-1,i);
	}

	sort(ms,ms+ms_len);

	int j = 0;
	do {
		int bg = j;
		while (j +1 < ms_len && ms[j].x == ms[j+1].x) j++;
		int en = j;
		j++;

		for (int i=bg; i<=en; i++) {
			if (ms[i].tp == +1) {
				cnt++;
				us.insert(cnt);
				us_multi.insert(cnt);
				zp_user[ms[i].ind] = cnt;

				if (us.size() > M) {
					us.erase(us.find(cnt));
					us_multi.erase(us_multi.find(cnt));
					cnt--;

					zp_user[ms[i].ind] = *(us.begin());
					us_multi.insert(*(us.begin()));
				}

				mx_onl = max(mx_onl,(int) us.size());
			}
			else {
				us_multi.erase(us_multi.find(zp_user[ms[i].ind]));
				if (us_multi.find(zp_user[ms[i].ind]) == us_multi.end())
					us.erase(us.find(zp_user[ms[i].ind]));

				mx_onl = max(mx_onl,(int) us.size());
			}
		}
	} while (j < ms_len);

	if (mx_onl < M) {
		cout<<"No solution";
		return 0;
	}

	cout<<cnt<<"\n";
	for (int i=0; i<n; i++)
		printf("%d\n",zp_user[i]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <utility>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int const MAX_N = 100100 * 2;
int const MAX_Q = 100100;
int const MAX_CH = 100100;
long long const LL_INF = 1000000000000000009LL;

char st[MAX_CH];

int tm[MAX_N];
int zp_user[MAX_N];

set<int> us;
multiset<int> us_multi;

struct pp {
	int x, tp, ind;
	pp() {}
	pp(int x, int tp, int ind):x(x),tp(tp),ind(ind) {}
} ms[MAX_N];
int ms_len = 0;

bool operator < (const pp &A, const pp &B) {
	return A.x < B.x || (A.x == B.x && A.tp > B.tp);
}

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

	gets(st);
	int n,M,T;
	sscanf(st,"%d%d%d",&n,&M,&T);
	for (int i=0; i<n; i++) {
		gets(st);
		int hh,mm,ss;
		sscanf(st,"%d:%d:%d",&hh,&mm,&ss);
		tm[i] =  hh*3600+mm*60+ss;
	}

	int cnt = 0;
	int mx_onl = 0;

	ms_len = 0;
	for (int i=0; i<n; i++) {
		ms[ms_len++] = pp(tm[i], +1, i);
		ms[ms_len++] = pp(tm[i]+T-1 ,-1,i);
	}

	sort(ms,ms+ms_len);
	int Mx_X = -1000000;
	int Person = -1;

	int j = 0;
	do {
		int bg = j;
		while (j +1 < ms_len && ms[j].x == ms[j+1].x) j++;
		int en = j;
		j++;

		for (int i=bg; i<=en; i++) {
			if (ms[i].tp == +1) {
				cnt++;
				us.insert(cnt);
				us_multi.insert(cnt);
				zp_user[ms[i].ind] = cnt;

				int save_Mx_X = Mx_X;
				int save_Person = Person;

				if (ms[i].x + T - 1 > Mx_X) {
					Mx_X = ms[i].x + T - 1;
					Person = cnt;
				}

				if (us.size() > M) {
					us.erase(us.find(cnt));
					us_multi.erase(us_multi.find(cnt));
					cnt--;

					Mx_X = save_Mx_X;
					Person = save_Person;

					zp_user[ms[i].ind] = Person;
					us_multi.insert(Person);
					Mx_X = max(Mx_X, ms[i].x + T - 1);
				}

				mx_onl = max(mx_onl,(int) us.size());
			}
			else {
				us_multi.erase(us_multi.find(zp_user[ms[i].ind]));
				if (us_multi.find(zp_user[ms[i].ind]) == us_multi.end())
					us.erase(us.find(zp_user[ms[i].ind]));

				mx_onl = max(mx_onl,(int) us.size());
			}
		}
	} while (j < ms_len);

	if (mx_onl < M) {
		cout<<"No solution";
		return 0;
	}

	cout<<cnt<<"\n";
	for (int i=0; i<n; i++)
		printf("%d\n",zp_user[i]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <utility>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int const MAX_N = 100100 * 2;
int const MAX_Q = 100100;
int const MAX_CH = 100100;
long long const LL_INF = 1000000000000000009LL;

char st[MAX_CH];

int tm[MAX_N];
int zp_user[MAX_N];

set<int> us;
multiset<int> us_multi;

struct pp {
	int x, tp, ind;
	pp() {}
	pp(int x, int tp, int ind):x(x),tp(tp),ind(ind) {}
} ms[MAX_N];
int ms_len = 0;

bool operator < (const pp &A, const pp &B) {
	return A.x < B.x || (A.x == B.x && A.tp > B.tp);
}

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

	gets(st);
	int n,M,T;
	sscanf(st,"%d%d%d",&n,&M,&T);
	for (int i=0; i<n; i++) {
		gets(st);
		int hh,mm,ss;
		sscanf(st,"%d:%d:%d",&hh,&mm,&ss);
		tm[i] =  hh*3600+mm*60+ss;
	}

	int cnt = 0;
	int mx_onl = 0;

	for (int i=0; i<n; i++) {
		ms[ms_len++] = pp(tm[i], +1, i);
		ms[ms_len++] = pp(tm[i]+T,-1,i);
	}

	sort(ms,ms+ms_len);

	int j = 0;
	do {
		int bg = j;
		while (j +1 < ms_len && ms[j].x == ms[j+1].x) j++;
		int en = j;
		j++;

		for (int i=bg; i<=en; i++) {
			if (ms[i].tp == +1) {
				cnt++;
				us.insert(cnt);
				us_multi.insert(cnt);
				zp_user[ms[i].ind] = cnt;

				if (us.size() > M) {
					us.erase(us.find(cnt));
					us_multi.erase(us_multi.find(cnt));
					cnt--;

					zp_user[ms[i].ind] = *(us.begin());
					us_multi.insert(*(us.begin()));
				}

				mx_onl = max(mx_onl,(int) us.size());
			}
			else {
				us_multi.erase(us_multi.find(zp_user[ms[i].ind]));
				if (us_multi.find(zp_user[ms[i].ind]) == us_multi.end())
					us.erase(us.find(zp_user[ms[i].ind]));

				mx_onl = max(mx_onl,(int) us.size());
			}
		}
	} while (j < ms_len);

	if (mx_onl < M) {
		cout<<"No solution";
		return 0;
	}

	cout<<cnt<<"\n";
	for (int i=0; i<n; i++)
		printf("%d\n",zp_user[i]);
	return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <set>
#include <map>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

int n, m, t;
pair<int, int> in[20001];
int s[20001];

vector<int> freq;
void init(int size) {
  freq.clear();
  size = 1 << (int) ceil(log2(size));
  freq.resize(size);
}
void add(int ind, int val) {
  ind++;
  while (ind <= freq.size()) {
    freq[ind - 1] += val;
    ind += ind & (-ind);
  }
}
int get(int ind) {
  int ret = 0;
  ind++;
  while (ind) {
    ret += freq[ind - 1];
    ind -= ind & (-ind);
  }
  return ret;
}

int main()
{
    //freopen("D.txt", "r", stdin);
    cin >> n>>m>>t;
    init(100000);
    for (int i=1;i<=n;i++) {
        int a, b, c;
        char d;
        cin >> a>>d>>b>>d>>c;
        in[i].first=a*60*60+b*60+c;
        in[i].second=in[i].first+t-1;
    }
    bool lehet=false;
    int ki=0;
    for (int i=1;i<=n;i++) {
        if (get(in[i].first)<m) {
            s[i]=++ki;
            add(in[i].first, 1);
            add(in[i].second+1, -1);
        }
        else {
            s[i]=ki;
            add(in[i-1].second+1, 1);
            add(in[i].second+1, -1);
        }
        if (get(in[i].first)==m) lehet=true;
    }

    if (lehet) {
        cout << ki<<endl;
        for (int i=1;i<=n;i++) cout << s[i]<<endl;
    }
    else {
        cout << "No solution"<<endl;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <set>
#include <map>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

int n, m, t;
pair<int, int> in[20001];
int s[20001];

vector<int> freq;
void init(int size) {
  freq.clear();
  size = 1 << (int) ceil(log2(size));
  freq.resize(size);
}
void add(int ind, int val) {
  ind++;
  while (ind <= freq.size()) {
    freq[ind - 1] += val;
    ind += ind & (-ind);
  }
}
int get(int ind) {
  int ret = 0;
  ind++;
  while (ind) {
    ret += freq[ind - 1];
    ind -= ind & (-ind);
  }
  return ret;
}

int main()
{
    //freopen("D.txt", "r", stdin);
    cin >> n>>m>>t;
    init(100000);
    for (int i=1;i<=n;i++) {
        int a, b, c;
        char d;
        cin >> a>>d>>b>>d>>c;
        in[i].first=a*60*60+b*60+c;
        in[i].second=in[i].first+t-1;
    }
    bool lehet=false;
    int ki=0;
    for (int i=1;i<=n;i++) {
        if (get(in[i].first)<m) {
            s[i]=++ki;
            add(in[i].second, 1);
        }
        else {
            s[i]=ki;
            add(in[i-1].second, -1);
            add(in[i].second, 1);
        }
        if (get(in[i].first)==m) lehet=true;
    }

    if (lehet) {
        cout << ki<<endl;
        for (int i=1;i<=n;i++) cout << s[i]<<endl;
    }
    else {
        cout << "No solution"<<endl;
    }

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iostream>
#include <set>
#include <fstream>
#include <string>
#include <vector>

using namespace std;
#define FOR(i,s,e) for (int i=(s); i<(e); i++)
#define FOE(i,s,e) for (int i=(s); i<=(e); i++)
#define FOD(i,s,e) for (int i=(s); i>=(e); i--)
#define LL long long
#define eps 1e-9
#define pi acos(-1.0)
#define fail {printf("Impossible\n"); return 0;}
LL max(LL a,LL b){if (a>b){return a;} else {return b;}}
LL min(LL a,LL b){if (a<b){return a;} else {return b;}}

struct P{
    double x, y;
    P(){}
    P(int x, int y):x(double(x)), y(double(y)){}
    P(double x, double y):x(x) , y(y){}
    P operator+ (const P &a) const {return P(x+a.x, y+a.y);}
    P operator- (const P &a) const {return P(x-a.x, y-a.y);}
    double operator^ (const P &a) const {return x*a.x+y*a.y;}
    void in(){scanf("%lf%lf", &x, &y);}
    void out(){printf("REQUIRED %.7f %.7f\n", x, y);}
    double dist(P a, P b) {return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
    double sqdist(P a, P b) {return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}

};

#define M 600000
#define N 200001

struct dd{
    int v;
    int id, ty, c;
    dd(){}
    dd(int v, int id, int ty, int c):v(v), id(id), ty(ty), c(c){}
}a[N];

bool operator< (dd u, dd w){
    if (u.v == w.v)
        return u.ty > w.ty;
    return u.v > w.v;
}

priority_queue<dd> Q;

int cnt;

int n, m, tt, a2, b, c;
int arr = 0;
int ans[N];

multiset<int> S;
set<int> S2;

int main(){
    scanf("%d%d%d", &n, &m, &tt);
    FOE(i, 1, n){
        scanf("%d:%d:%d", &a2, &b, &c);
        a[i].v = c + b * 60 + a2 * 60 * 60;
        a[i].ty = 0;
        a[i].id = i;
    }
    FOE(i, 1, n){
        Q.push(a[i]);
    }

    int s = 0;

    while (Q.size()){
        dd t = Q.top(); Q.pop();
      //  printf("%d %d %d %d %d\n", t.v, t.id, t.c, t.ty, S2.size());
        if (t.ty) {
            S.erase(S.find(t.c));
            if (S.find(t.c) == S.end()) S2.erase(S2.find(t.c));
        }
        else {
            if (S2.size() == m){
                ans[t.id] = *S.begin();
                Q.push(dd(t.v + tt, t.id, 1, ans[t.id]));
            } else {
                cnt++;
                ans[t.id] = cnt;
                Q.push(dd(t.v + tt, t.id, 1, cnt));
            }
            S.insert(ans[t.id]);
            S2.insert(ans[t.id]);
            if (S2.size() == m) arr = 1;
        }
    }
    int res = cnt;
    if (arr == 0) res = -1;
    printf("%d\n", res);
    if (res > 0) FOE(i, 1, n) printf("%d\n", ans[i]);
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iostream>
#include <set>
#include <fstream>
#include <string>
#include <vector>

using namespace std;
#define FOR(i,s,e) for (int i=(s); i<(e); i++)
#define FOE(i,s,e) for (int i=(s); i<=(e); i++)
#define FOD(i,s,e) for (int i=(s); i>=(e); i--)
#define LL long long
#define eps 1e-9
#define pi acos(-1.0)
#define fail {printf("Impossible\n"); return 0;}
LL max(LL a,LL b){if (a>b){return a;} else {return b;}}
LL min(LL a,LL b){if (a<b){return a;} else {return b;}}

struct P{
    double x, y;
    P(){}
    P(int x, int y):x(double(x)), y(double(y)){}
    P(double x, double y):x(x) , y(y){}
    P operator+ (const P &a) const {return P(x+a.x, y+a.y);}
    P operator- (const P &a) const {return P(x-a.x, y-a.y);}
    double operator^ (const P &a) const {return x*a.x+y*a.y;}
    void in(){scanf("%lf%lf", &x, &y);}
    void out(){printf("REQUIRED %.7f %.7f\n", x, y);}
    double dist(P a, P b) {return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
    double sqdist(P a, P b) {return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}

};

#define M 600000
#define N 200001

struct dd{
    int v;
    int id, ty, c;
    dd(){}
    dd(int v, int id, int ty, int c):v(v), id(id), ty(ty), c(c){}
}a[N];

bool operator< (dd u, dd w){
    if (u.v == w.v)
        return u.ty > w.ty;
    return u.v > w.v;
}

priority_queue<dd> Q;

int cnt;

int n, m, tt, a2, b, c;
int arr = 0;
int ans[N];

multiset<int> S;
set<int> S2;

int main(){
    scanf("%d%d%d", &n, &m, &tt);
    FOE(i, 1, n){
        scanf("%d:%d:%d", &a2, &b, &c);
        a[i].v = c + b * 60 + a2 * 60 * 60;
        a[i].ty = 0;
        a[i].id = i;
    }
    FOE(i, 1, n){
        Q.push(a[i]);
    }

    int s = 0;

    while (Q.size()){
        dd t = Q.top(); Q.pop();
      //  printf("%d %d %d %d %d\n", t.v, t.id, t.c, t.ty, S2.size());
        if (t.ty) {
            S.erase(S.find(t.c));
            if (S.find(t.c) == S.end()) S2.erase(S2.find(t.c));
        }
        else {
            if (S2.size() == m){
                ans[t.id] = *S.begin();
                Q.push(dd(t.v + tt - 1, t.id, 1, ans[t.id]));
            } else {
                cnt++;
                ans[t.id] = cnt;
                Q.push(dd(t.v + tt - 1, t.id, 1, cnt));
            }
            S.insert(ans[t.id]);
            S2.insert(ans[t.id]);
            if (S2.size() == m) arr = 1;
        }
    }
    int res = cnt;
    if (arr == 0) res = -1;
    if (res == -1){
        printf("No solution\n");
        return 0;
    }
    printf("%d\n", res);
    if (res > 0) FOE(i, 1, n) printf("%d\n", ans[i]);
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iostream>
#include <set>
#include <fstream>
#include <string>
#include <vector>

using namespace std;
#define FOR(i,s,e) for (int i=(s); i<(e); i++)
#define FOE(i,s,e) for (int i=(s); i<=(e); i++)
#define FOD(i,s,e) for (int i=(s); i>=(e); i--)
#define LL long long
#define eps 1e-9
#define pi acos(-1.0)
#define fail {printf("Impossible\n"); return 0;}
LL max(LL a,LL b){if (a>b){return a;} else {return b;}}
LL min(LL a,LL b){if (a<b){return a;} else {return b;}}

struct P{
    double x, y;
    P(){}
    P(int x, int y):x(double(x)), y(double(y)){}
    P(double x, double y):x(x) , y(y){}
    P operator+ (const P &a) const {return P(x+a.x, y+a.y);}
    P operator- (const P &a) const {return P(x-a.x, y-a.y);}
    double operator^ (const P &a) const {return x*a.x+y*a.y;}
    void in(){scanf("%lf%lf", &x, &y);}
    void out(){printf("REQUIRED %.7f %.7f\n", x, y);}
    double dist(P a, P b) {return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
    double sqdist(P a, P b) {return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}

};

#define M 600000
#define N 200001

struct dd{
    int v;
    int id, ty, c;
    dd(){}
    dd(int v, int id, int ty, int c):v(v), id(id), ty(ty), c(c){}
}a[N];

bool operator< (dd u, dd w){
    if (u.v == w.v)
        return u.ty > w.ty;
    return u.v > w.v;
}

priority_queue<dd> Q;

int cnt;

int n, m, tt, a2, b, c;
int arr = 0;
int ans[N];

multiset<int> S;
set<int> S2;

int main(){
    scanf("%d%d%d", &n, &m, &tt);
    FOE(i, 1, n){
        scanf("%d:%d:%d", &a2, &b, &c);
        a[i].v = c + b * 60 + a2 * 60 * 60;
        a[i].ty = 0;
        a[i].id = i;
    }
    FOE(i, 1, n){
        Q.push(a[i]);
    }

    int s = 0;

    while (Q.size()){
        dd t = Q.top(); Q.pop();
      //  printf("%d %d %d %d %d\n", t.v, t.id, t.c, t.ty, S2.size());
        if (t.ty) {
            S.erase(S.find(t.c));
            if (S.find(t.c) == S.end()) S2.erase(S2.find(t.c));
        }
        else {
            if (S2.size() == m){
                ans[t.id] = cnt;
                Q.push(dd(t.v + tt - 1, t.id, 1, ans[t.id]));
            } else {
                cnt++;
                ans[t.id] = cnt;
                Q.push(dd(t.v + tt - 1, t.id, 1, cnt));
            }
            S.insert(ans[t.id]);
            S2.insert(ans[t.id]);
            if (S2.size() == m) arr = 1;
        }
    }
    int res = cnt;
    if (arr == 0) res = -1;
    if (res == -1){
        printf("No solution\n");
        return 0;
    }
    printf("%d\n", res);
    if (res > 0) FOE(i, 1, n) printf("%d\n", ans[i]);
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iostream>
#include <set>
#include <fstream>
#include <string>
#include <vector>

using namespace std;
#define FOR(i,s,e) for (int i=(s); i<(e); i++)
#define FOE(i,s,e) for (int i=(s); i<=(e); i++)
#define FOD(i,s,e) for (int i=(s); i>=(e); i--)
#define LL long long
#define eps 1e-9
#define pi acos(-1.0)
#define fail {printf("Impossible\n"); return 0;}
LL max(LL a,LL b){if (a>b){return a;} else {return b;}}
LL min(LL a,LL b){if (a<b){return a;} else {return b;}}

struct P{
    double x, y;
    P(){}
    P(int x, int y):x(double(x)), y(double(y)){}
    P(double x, double y):x(x) , y(y){}
    P operator+ (const P &a) const {return P(x+a.x, y+a.y);}
    P operator- (const P &a) const {return P(x-a.x, y-a.y);}
    double operator^ (const P &a) const {return x*a.x+y*a.y;}
    void in(){scanf("%lf%lf", &x, &y);}
    void out(){printf("REQUIRED %.7f %.7f\n", x, y);}
    double dist(P a, P b) {return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
    double sqdist(P a, P b) {return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}

};

#define M 600000
#define N 200001

struct dd{
    int v;
    int id, ty, c;
    dd(){}
    dd(int v, int id, int ty, int c):v(v), id(id), ty(ty), c(c){}
}a[N];

bool operator< (dd u, dd w){
    if (u.v == w.v)
        return u.ty > w.ty;
    return u.v > w.v;
}

priority_queue<dd> Q;

int cnt;

int n, m, tt, a2, b, c;
int arr = 0;
int ans[N];

multiset<int> S;
set<int> S2;

int main(){
    scanf("%d%d%d", &n, &m, &tt);
    FOE(i, 1, n){
        scanf("%d:%d:%d", &a2, &b, &c);
        a[i].v = c + b * 60 + a2 * 60 * 60;
        a[i].ty = 0;
        a[i].id = i;
    }
    FOE(i, 1, n){
        Q.push(a[i]);
    }

    int s = 0;

    while (Q.size()){
        dd t = Q.top(); Q.pop();
      //  printf("%d %d %d %d %d\n", t.v, t.id, t.c, t.ty, S2.size());
        if (t.ty) {
            S.erase(S.find(t.c));
            if (S.find(t.c) == S.end()) S2.erase(S2.find(t.c));
        }
        else {
            if (S2.size() == m){
                ans[t.id] = *S.begin();
                Q.push(dd(t.v + tt, t.id, 1, ans[t.id]));
            } else {
                cnt++;
                ans[t.id] = cnt;
                Q.push(dd(t.v + tt, t.id, 1, cnt));
            }
            S.insert(ans[t.id]);
            S2.insert(ans[t.id]);
            if (S2.size() == m) arr = 1;
        }
    }
    int res = cnt;
    if (arr == 0) res = -1;
    if (res == -1){
        printf("No solution\n");
        return 0;
    }
    printf("%d\n", res);
    if (res > 0) FOE(i, 1, n) printf("%d\n", ans[i]);
    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int n, m, t;
vector< pair<int, int> > event[100005];
int id[20005];
char format[10];

int main(){
    //freopen("in", "r", stdin);
    scanf("%d%d%d", &n, &m, &t);
    for (int i = 0; i < n; ++ i){
        scanf("%s", format);
        int hour = (format[0] - '0') * 10 + (format[1] - '0');
        int minute = (format[3] - '0') * 10 + (format[4] - '0');
        int second = (format[6] - '0') * 10 + (format[7] - '0');
        int left = hour * 60 * 60 + minute * 60 + second;
        int right = left + t - 1;
        event[left].push_back(make_pair(i, 1));
        event[right].push_back(make_pair(i, -1));
    }
    int online = 0, user = 0, max_online = 0;
    for (int i = 0; i <= 86400; ++ i){
        for (int j = 0; j < event[i].size(); ++ j){
            if (event[i][j].second == -1) continue;
            online ++;
            id[event[i][j].first] = ++user;
            if (online > m){
                id[event[i][j].first] = --user;
                online --;
            }
        }
        max_online = max(max_online, online);
        for (int j = 0; j < event[i].size(); ++ j){
            if (event[i][j].second == 1) continue;
            online --;
            if (event[i][j].first < n - 1 && id[event[i][j].first+1] == id[event[i][j].first]) online ++;
        }
        //if (i <= 20) printf("%d %d\n", i, online);
    }
    if (max_online < m){
        puts("No solution");
    } else{
        printf("%d\n", user);
        for (int i = 0; i < n; ++ i){
            printf("%d\n", id[i]);
        }
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int n, m, t;
vector< pair<int, int> > event[100005];
int id[20005];
char format[10];

int main(){
   // freopen("in", "r", stdin);
    scanf("%d%d%d", &n, &m, &t);
    for (int i = 0; i < n; ++ i){
        scanf("%s", format);
        int hour = (format[0] - '0') * 10 + (format[1] - '0');
        int minute = (format[3] - '0') * 10 + (format[4] - '0');
        int second = (format[6] - '0') * 10 + (format[7] - '0');
        int left = hour * 60 * 60 + minute * 60 + second;
        int right = left + t - 1;
        event[left].push_back(make_pair(i, 1));
        event[right].push_back(make_pair(i, -1));
    }
    int online = 0, user = 0, max_online = 0;
    for (int i = 0; i <= 86400; ++ i){
        for (int j = 0; j < event[i].size(); ++ j){
            if (event[i][j].second == -1) continue;
            online ++;
            id[event[i][j].first] = ++user;
            if (online > m){
                id[event[i][j].first] = --user;
                online --;
            }
        }
        max_online = max(max_online, online);
        for (int j = 0; j < event[i].size(); ++ j){
            if (event[i][j].second == 1) continue;
            online --;
            if (event[i][j].first > 0 && id[event[i][j].first-1] == id[event[i][j].first]) online ++;
        }
    }
    if (max_online < m){
        puts("No solution");
    } else{
        printf("%d\n", user);
        for (int i = 0; i < n; ++ i){
            printf("%d\n", id[i]);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define red(i, a, b) for(int i = a; i > b; i--)
#define RED true
#define BLACK false
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ii, int> iii;
typedef vector<int> vi;
const int N = 2e4 + 7;
const int M = 1e9;
const int inf = 1e9 + 7;
const ll base = 1e18;
const double pi = acos(-1);
const double ep = 1e-9;

int n, m, T;
deque<int> q;
int id[N];

int main(){
    //freopen("in.txt", "r", stdin);
    int cnt = 0;
    scanf("%d%d%d", &n, &m, &T);
    bool check = false;
    rep(i, 0, n){
        int A, B, C;
        scanf("%d:%d:%d", &A, &B, &C);

        int u = A * 3600 + B * 60 + C;
        //cout<<u<<endl;
        while (!q.empty() && (q.front() < u)) q.pop_front();
        if (q.size() < m){
            id[i] = ++cnt;
            q.push_back(u + T - 1);
        }else{
            q.back() = u + T - 1;
            id[i] = cnt;
            check = true;
        }
        //cout<<q.size()<<endl;
    }

    //return 0;
    if (check == false)
        puts("No solution");
    else {
        cout<<cnt<<endl;
        rep(i, 0, n)
            cout<<id[i]<<endl;
    }

}


#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define red(i, a, b) for(int i = a; i > b; i--)
#define RED true
#define BLACK false
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ii, int> iii;
typedef vector<int> vi;
const int N = 2e5 + 7;
const int M = 1e9;
const int inf = 1e9 + 7;
const ll base = 1e18;
const double pi = acos(-1);
const double ep = 1e-9;

int n, m, T;
deque<int> q;
int id[N];

int main(){
    //freopen("in.txt", "r", stdin);
    int cnt = 0;
    cin >> n >> m >> T;
    bool check = false;
    rep(i, 0, n){
        int A, B, C;
        scanf("%d:%d:%d", &A, &B, &C);

        int u = A * 3600 + B * 60 + C;
        //cout<<u<<endl;
        while (!q.empty() && q.front() < u)
            q.pop_front();
        if (q.size() < m){
            cnt++; id[i] = cnt;
            //heap.push(mk(-(u + T - 1), cnt));
            q.push_back(u + T - 1);
        }else{
            id[i] = cnt;
            check = true;
        }
    }
    if (check == false)
        puts("No solution");
    else {
        cout<<cnt<<endl;
        rep(i, 0, n)
            cout<<id[i]<<endl;
    }

}


#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define red(i, a, b) for(int i = a; i > b; i--)
#define RED true
#define BLACK false
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ii, int> iii;
typedef vector<int> vi;
const int N = 2e4 + 7;
const int M = 1e9;
const int inf = 1e9 + 7;
const ll base = 1e18;
const double pi = acos(-1);
const double ep = 1e-9;

int n, m, T;
deque<int> q;
int id[N];

int main(){
    //freopen("in.txt", "r", stdin);
    int cnt = 0;
    scanf("%d%d%d", &n, &m, &T);
    bool check = false;
    rep(i, 0, n){
        int A, B, C;
        scanf("%d:%d:%d", &A, &B, &C);

        int u = A * 3600 + B * 60 + C;
        //cout<<u<<endl;
        while (!q.empty() && (q.front() < u)) q.pop_front();
        if (q.size() < m){
            id[i] = ++cnt;
            q.push_back(u + T - 1);
        }else{
            q.front() = u + T - 1;
            id[i] = cnt;

        }
        if (q.size() == m) check = true;
    }

    //return 0;
    if (check == false)
        puts("No solution");
    else {
        cout<<cnt<<endl;
        rep(i, 0, n)
            cout<<id[i]<<endl;
    }

}


#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define red(i, a, b) for(int i = a; i > b; i--)
#define RED true
#define BLACK false
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ii, int> iii;
typedef vector<int> vi;
const int N = 2e5 + 7;
const int M = 1e9;
const int inf = 1e9 + 7;
const ll base = 1e18;
const double pi = acos(-1);
const double ep = 1e-9;

int n, m, T;
priority_queue<ii> heap;
int id[N];

int toString(string s){
    int tmp = ((s[0] - '0') * 10 + s[1] - '0') * 3600;
    tmp += ((s[3] - '0') * 10 + s[4] - '0') * 60;
    tmp += (s[6] - '0') * 10 + s[7] - '0';
    return tmp;
}

int main(){
    //freopen("in.txt", "r", stdin);
    int cnt = 0;
    cin >> n >> m >> T;
    bool check = false;
    rep(i, 0, n){
        string s;
        cin >> s;
        int u = toString(s);
        //cout<<u<<endl;
        while (!heap.empty() && -heap.top().fi < u)
            heap.pop();
        if (heap.size() < m){
            cnt++; id[i] = cnt;
            heap.push(mk(-(u + T - 1), cnt));
        }else{
            id[i] = cnt;
            check = true;
        }
    }
    if (check == false)
        puts("No solution");
    else {
        cout<<cnt<<endl;
        rep(i, 0, n)
            cout<<id[i]<<endl;
    }

}


#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define red(i, a, b) for(int i = a; i > b; i--)
#define RED true
#define BLACK false
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ii, int> iii;
typedef vector<int> vi;
const int N = 2e5 + 7;
const int M = 1e9;
const int inf = 1e9 + 7;
const ll base = 1e18;
const double pi = acos(-1);
const double ep = 1e-9;

int n, m, T;
priority_queue<ii> heap;
int id[N];

int toString(string s){
    int tmp = ((s[0] - '0') * 10 + s[1] - '0') * 3600;
    tmp += ((s[3] - '0') * 10 + s[4] - '0') * 60;
    tmp += (s[6] - '0') * 10 + s[7] - '0';
    return tmp;
}

int main(){
    //freopen("in.txt", "r", stdin);
    int cnt = 0;
    cin >> n >> m >> T;
    bool check = false;
    rep(i, 0, n){
        string s;
        cin >> s;
        int u = toString(s);
        while (!heap.empty() && -heap.top().fi + T - 1 < u)
            heap.pop();
        if (heap.size() < m){
            cnt++; id[i] = cnt;
            heap.push(mk(-u, cnt));
        }else{
            id[i] = heap.top().se;
            check = true;
        }
    }
    if (check == false)
        puts("No solution");
    else {
        cout<<cnt<<endl;
        rep(i, 0, n)
            cout<<id[i]<<endl;
    }

}


#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define red(i, a, b) for(int i = a; i > b; i--)
#define RED true
#define BLACK false
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ii, int> iii;
typedef vector<int> vi;
const int N = 2e4 + 7;
const int M = 1e9;
const int inf = 1e9 + 7;
const ll base = 1e18;
const double pi = acos(-1);
const double ep = 1e-9;

int n, m, T;
deque<int> q;
int id[N];

int main(){
    //freopen("in.txt", "r", stdin);
    int cnt = 0;
    cin >> n >> m >> T;
    bool check = false;
    rep(i, 0, n){
        int A, B, C;
        scanf("%d:%d:%d", &A, &B, &C);

        int u = A * 3600 + B * 60 + C;
        //cout<<u<<endl;
        while (!q.empty() && q.front() < u)
            q.pop_front();
        if (q.size() < m){
            id[i] = ++cnt;
            //heap.push(mk(-(u + T - 1), cnt));
            q.push_back(u + T - 1);
        }else{
            id[i] = cnt;
            check = true;
        }
    }
    if (check == false)
        puts("No solution");
    else {
        cout<<cnt<<endl;
        rep(i, 0, n)
            cout<<id[i]<<endl;
    }

}


#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define red(i, a, b) for(int i = a; i > b; i--)
#define RED true
#define BLACK false
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ii, int> iii;
typedef vector<int> vi;
const int N = 2e4 + 7;
const int M = 1e9;
const int inf = 1e9 + 7;
const ll base = 1e18;
const double pi = acos(-1);
const double ep = 1e-9;

int n, m, T;
deque<int> q;
int id[N];

int main(){
    //freopen("in.txt", "r", stdin);
    int cnt = 0;
    scanf("%d%d%d", &n, &m, &T);
    bool check = false;
    rep(i, 0, n){
        int A, B, C;
        scanf("%d:%d:%d", &A, &B, &C);

        int u = A * 3600 + B * 60 + C;
        //cout<<u<<endl;
        while (!q.empty() && (q.front() < u)) q.pop_front();
        if (q.size() < m){
            id[i] = ++cnt;
            q.push_back(u + T - 1);
        }else{
            q.back() = u + T - 1;
            id[i] = cnt;

        }
        if (q.size() == m) check = true;
    }

    //return 0;
    if (check == false)
        puts("No solution");
    else {
        cout<<cnt<<endl;
        rep(i, 0, n)
            cout<<id[i]<<endl;
    }

}


#include<cstdio>
using namespace std;
const int NN=20005;
int q[NN],a[NN],ans[NN],n,M,T,cnt;
int main()
{
	//freopen("1.in","r",stdin);freopen("1.out","w",stdout);
	scanf("%d%d%d",&n,&M,&T);
	int i,x,y,z;
	for (i=1;i<=n;i++)
	{
		scanf("%d:%d:%d",&x,&y,&z);
		a[i]=x*60*60+y*60+z;
	}
	int head=0,tail=0;
	bool flag=false;
	for (i=1;i<=n;i++)
	{
		while (head<tail&&q[head+1]<a[i]) head++;
		if (tail-head<M)
		{
			q[++tail]=a[i]+T-1;
			ans[i]=++cnt;
		}
		else
		{
			q[tail]=a[i]+T-1;
			ans[i]=cnt;
		}
		if (tail-head==M) flag=true;
	}
	if (!flag) {printf("No solution\n");return 0;}
	printf("%d\n",cnt);
	for (i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}


#include<cstdio>
using namespace std;
const int NN=20005;
int q[NN],a[NN],ans[NN],n,M,T,cnt;
int main()
{
	//freopen("1.in","r",stdin);freopen("1.out","w",stdout);
	scanf("%d%d%d",&n,&M,&T);
	if (n<M) {printf("No solution\n");return 0;}
	int i,x,y,z;
	for (i=1;i<=n;i++)
	{
		scanf("%d:%d:%d",&x,&y,&z);
		a[i]=x*60*60+y*60+z;
	}
	int head=0,tail=0;
	bool flag=false;
	for (i=1;i<=n;i++)
	{
		while (head<tail&&q[head+1]<a[i]) head++;
		if (tail-head<M)
		{
			q[++tail]=a[i]+T-1;
			ans[i]=++cnt;
		}
		else
		{
			q[tail]=a[i]+T-1;
			ans[i]=cnt;
		}
		if (tail-head==M) flag=true;
	}
	if (!flag) {printf("No solution\n");return 0;}
	printf("%d\n",cnt);
	for (i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}


#include<cstdio>
using namespace std;
const int NN=20005;
int q[NN],a[NN],ans[NN],n,M,T,cnt;
int main()
{
	scanf("%d%d%d",&n,&M,&T);
	if (n<M) {printf("No solution\n");return 0;}
	int i,x,y,z;
	for (i=1;i<=n;i++)
	{
		scanf("%d:%d:%d",&x,&y,&z);
		a[i]=x*60*60+y*60+z;
	}
	int head=0,tail=0;
	for (i=1;i<=n;i++)
	{
		while (head<tail&&q[head+1]<a[i]) head++;
		if (tail-head<M)
		{
			q[++tail]=a[i]+T-1;
			ans[i]=++cnt;
		}
		else
		{
			q[tail]=a[i]+T-1;
			ans[i]=cnt;
		}
	}
	printf("%d\n",cnt);
	for (i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int x1,x2,x3;
int tim[120000];
int n,m,t;
int a[120000],lef,rig,res,rep,ans[120000];
int main()
{
	scanf("%d %d %d",&n,&m,&t);
	for (int i=1;i<=n;i++)
	{
		scanf("%d:%d:%d",&x1,&x2,&x3);
		tim[i]=x1*3600+x2*60+x3;
	}
	for (int i=1;i<=n;i++)
	{
		rig++;
		a[rig]=i;
		while (lef<rig&&tim[i]-tim[a[lef+1]]>=t)lef++;
		if(rig-lef<=m)
		{
			rep++;
			ans[i]=rep;
		}
		else
		{
			ans[i]=ans[a[rig-1]];
			a[rig-1]=a[rig];
			rig--;
		}
		//printf("%d %d\n",lef,rig);
		//for (int j=lef+1;j<=rig;j++)printf("%d\n",a[j]);
		res=max(res,rig-lef);
	}
	if(res==m)
	{
		printf("%d\n",rep);
		for (int i=1;i<=n;i++)
		{
			printf("%d\n",ans[i]);
		}
	}
	else
	{
		printf("No solution\n");
	}
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define For( i , a ) for(int i=1;i<=a;i++)
#define ort (b+s)/2
#define y2 asrwjaelkf
#define y1 asseopirwjaelkf

using namespace std;

const int maxn = 20020;
const int maxx = 10000;
const int MOd = 1e9+7;
const int K = 750;
const int P = 143;

typedef long long Lint;
typedef double db;
typedef pair<Lint,Lint> ii;
typedef pair<ii,int> iii;

int a, b, T, n;
int s[maxn], ar[maxn];
//~ ii sagment[1<<16];

//~ ii merge( ii a, ii b ) {
	//~
//~ }
//~
//~ void up( int k, int x ) {
	//~ k += n-1;
	//~ segment[k].fi += x;
	//~ if( segment[k].fi == 1 ) segment[k].se = 1;
	//~ if( segment[k].fi == 0 ) segment[k].se = 0;
	//~ for(k>>=1;k;k>>=1)
		//~ segment[k] = merge( segment[k] );
//~ }

void bit() {
	printf("No solution\n");
	exit(0);
}

int main() {

	scanf("%d %d %d",&a,&b,&T);

	//~ n = 1;
	//~ while( n < a ) n <<= 1;

	for(int i=1,j,k,l;i<=a;i++) {
		char c, ch;
		scanf(" %d %c %d %c %d",&j,&c,&k,&ch,&l);
		ar[i] = j * 3600 + k * 60 + l;
	}
	sort( ar+1, ar+1+a );
	int sz = 0;
	int ans[maxn], next = 0;
	int h = 0;
	for(int i=1,j=1;i<=a;i++) {
		while( j < i && ar[j]+T < ar[i] ) {
			s[ans[j]]--;
			if( s[ans[j]] == 0 ) sz--;
			j++;
		}
		if( sz == b ) {
			h = 1;
			int c = 0;
			for(int l=1;l<=next;l++)
				if( s[l] ) {
					s[l]++;
					ans[i]= l;
					c = 1;
					break;
				}
			if( !c ) bit();
		} else {
			if( next < a ) next++;
			ans[i] = next;
			s[next]++;
			sz++;
		}
	}
	if( !h ) bit();

	printf("%d\n",next);

	for(int i=1;i<=a;i++)
		printf("%d\n",ans[i]);

	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define For( i , a ) for(int i=1;i<=a;i++)
#define ort (b+s)/2
#define y2 asrwjaelkf
#define y1 asseopirwjaelkf

using namespace std;

const int maxn = 20020;
const int maxx = 10000;
const int MOd = 1e9+7;
const int K = 750;
const int P = 143;

typedef long long Lint;
typedef double db;
typedef pair<Lint,Lint> ii;
typedef pair<ii,int> iii;

int a, b, T, n;
int s[maxn], ar[maxn];
//~ ii sagment[1<<16];

//~ ii merge( ii a, ii b ) {
	//~
//~ }
//~
//~ void up( int k, int x ) {
	//~ k += n-1;
	//~ segment[k].fi += x;
	//~ if( segment[k].fi == 1 ) segment[k].se = 1;
	//~ if( segment[k].fi == 0 ) segment[k].se = 0;
	//~ for(k>>=1;k;k>>=1)
		//~ segment[k] = merge( segment[k] );
//~ }

void bit() {
	printf("No solution\n");
	exit(0);
}

int main() {

	scanf("%d %d %d",&a,&b,&T);

	//~ n = 1;
	//~ while( n < a ) n <<= 1;

	for(int i=1,j,k,l;i<=a;i++) {
		char c, ch;
		scanf(" %d %c %d %c %d",&j,&c,&k,&ch,&l);
		ar[i] = j * 3600 + k * 60 + l;
	}
	sort( ar+1, ar+1+a );
	int sz = 0;
	int ans[maxn], next = 0;
	int h = 0;
	for(int i=1,j=1;i<=a;i++) {
		while( j < i && ar[j]+T <= ar[i] ) {
			s[ans[j]]--;
			if( s[ans[j]] == 0 ) sz--;
			j++;
		}
		if( sz == b ) {
			h = 1;
			s[ans[i-1]]++;
			ans[i] = ans[i-1];
		} else {
			if( next < a ) next++;
			ans[i] = next;
			s[next]++;
			sz++;
		}
	}
	if( sz == b ) h = 1;
	if( !h ) bit();

	printf("%d\n",next);

	for(int i=1;i<=a;i++)
		printf("%d\n",ans[i]);

	return 0;
}