int main(){
	int max(int a[],int n);
	char a[500];
	int b[500]={0};
	int n,i,j,k,p,t;
	scanf("%d\n",&n);
	scanf("%s",a);
	/*printf("%d",strlen(a));*/
	for(i=0;i<=strlen(a)-n;i++){
		for(j=i;j<=strlen(a)-n;j++){
			p=1;
			for(k=0;k<n;k++){
				if(a[i+k]==a[j+k]) p=p*1;
				else p=p*0;
			}
			if(p==1) b[i]++;
		}
	}
	t=max(b,strlen(a)-n+1);

	if(t==1) printf("NO");
	else{
		printf("%d\n",t);
		for(i=0;i<=strlen(a)-n;i++){
		if(b[i]==t){
			for(j=0;j<n;j++){
				printf("%c",a[i+j]);
			}
			printf("\n");
		}
	}
	}
	return 0;
}

int max(int a[],int n){
	int t=a[0],i;
	for(i=0;i<n;i++){
		if(t<a[i]) t=a[i];
	}
	return t;
}


int main()
{
    int n;
    int i,j,k;
    int length;
    scanf("%d",&n);
    int p,temp;
    char a[10005];
    int b[10005]={0};
    scanf("%s",a);
    length=strlen(a);
    for(i=0;i<length-n+1;i++)
    {
       if(b[i]!=-1)
       {
           for(j=i+1;j<length-n+1;j++)
          {
             p=0;
             for(k=0;k<n;k++)
             {
                 if(a[i+k]!=a[j+k])
                 {
                     p=1;
                     break;
                 }
             }
            if(p==0)
            {
               b[i]++;
               b[j]=-1;
              //printf("%d***%d\n",i,j);
            }
           }
       }
    }
    temp=0;
    for(i=0;i<length;i++)
    {
        if(b[i]>temp)
        {
          temp=b[i];
        }
    }
    //printf("%d",temp);
    if(temp==0)
    {
        printf("NO");
    }
    else
    {
        printf("%d\n",temp+1);
    for(i=0;i<length;i++)
    {
        if(b[i]==temp)
        {
          for(k=0;k<n;k++)
          {
              printf("%c",a[i+k]);
          }
          printf("\n");
        }
    }
    }
    return 0;

}


char gram[1000][10] = {0};
int fre[1000] = {0};
int l, n;

int main ()
{
	void clear( int x );
	int i, j;
	int max = 0;
	int c = 1;

	int label[1000] = {0};
	char str[1000] = {0};
	char *p = str;
	char (*q1)[10] = gram;
	char (*q2)[10] = gram;
	cin >> n;
	cin >> str;
	l = strlen( str );
	for ( i = 1; i <= l - n + 1; i++ )
	{
		for ( j = 0; j <= n - 1; j++ )
		{
			gram[i][j] = *p;
			p++;
		}
		p = p - n + 1;
	}
	q1++, q2++;

	for ( i = 1; i <= l - n + 1; i++ )
	{
		for (j = i+1; j <= l - n + 1; j++ )
		{
			if ( strcmp(*q1, gram[j] ) == 0 && i != j)
				fre[i]++, fre[j]++;
		}
		q1++;
	}

	for (i = 1; i <= l - n + 1; i++ )
	{
		if ( fre[i] > max )
			max = fre[i];
	}

	if ( max == 0 )
	{
		cout << "NO" << endl;
		return 0;
	}

	cout << max + 1 << endl;
	for ( i = 1; i <= l - n + 1; i++ )
	{
		if ( fre[i] == max )
		{
			cout << gram[i] << endl;
			clear(i);
		}
	}
	return 0;
}

void clear ( int x)
{
	int i, j;
	for ( i = 1; i <= l - n + 1; i++ )
	{
		if ( strcmp ( gram[x], gram[i] ) == 0 )
			fre[i] = 0;
	}
	return ;
}


int main()
{
	int n,i,l,flag,sum,max,lab,len,j,b[10000];
	char a[10000],c;
	scanf("%d",&n);
	scanf("%c",&c);
	gets(a);
	len=strlen(a);
	l=0;
	lab=0;
	max=0;
	while (a[l]!=0)
	{
		sum=0;
		for (i=l;i<len;i++)
		{
			flag=1;
			for (j=0;j<n;j++)
			{
				if (a[l+j]!=a[i+j])
				{
					flag=0;
				}
			}
			if (flag==1)
				sum++;
		}
		if (sum>max)
		{
			max=sum;
		}
		b[l]=sum;
		l++;
	}
	if(max>1)
	{
	printf("%d\n",max);
	for (i=0;i<len;i++)
	{
		if(b[i]==max)
		{
			for (j=0;j<n;j++)
			{
				printf("%c",a[j+i]);
			}
			printf("\n");
		}
	}
	}
	else
		printf("NO");
	return 0;
}


int main()
{
	int n,x,i,j,again,max;
	char a[501];
	scanf("%d",&n);
	scanf("%s",a);
	x=strlen(a);
	int sum=x+1-n;
	int number[sum];
	char temp[x+1-n][n+1];
	for(i=0;i<x+1-n;i++)
	{
		for(j=0;j<n;j++)
		{
			temp[i][j]=a[i+j];
		}
		temp[i][n]='\0';
	}
	for(i=0;i<sum;i++)
		number[i]=0;
	number[0]=1;
	for(i=1;i<sum;i++)
	{
		again=0;
		for(j=0;j<i;j++)
		{
			if(strcmp(temp[i],temp[j])==0)
			{
				number[j]++;
				again=1;
				break;
			}
		}
		if(again==0)
			number[i]++;
	}
	max=number[0];
	for(i=1;i<sum;i++)
	{
		if(number[i]>max)
			max=number[i];
	}
	if(max!=1)
	{
		printf("%d\n",max);
		for(i=0;i<sum;i++)
		{
			if(number[i]==max)
				printf("%s\n",temp[i]);
		}
	}
	else
		printf("NO\n");
	return 0;
}


int main(){
    char s[502];
    int max,frequency[251],n,i,j;
    scanf("%d",&n);
    scanf("%s",s);
    max=1;
    if(n==2){
        for(i=0;i<strlen(s)-2;i++){
            frequency[i]=1;
            for(j=i+1;j<strlen(s)-1;j++){
                if(s[i]==s[j]&&s[i+1]==s[j+1])
                    frequency[i]++;
            }
            if(max<frequency[i])
                max=frequency[i];
        }
        if(max==1)
            printf("NO\n");
        else{
            printf("%d\n",max);
            for(i=0;i<strlen(s)-2;i++){
                if(frequency[i]==max)
                    printf("%c%c\n",s[i],s[i+1]);
            }
        }
    }
    if(n==3){
        for(i=0;i<strlen(s)-3;i++){
            frequency[i]=1;
            for(j=i+1;j<strlen(s)-2;j++){
                if(s[i]==s[j]&&s[i+1]==s[j+1]&&s[i+2]==s[j+2])
                    frequency[i]++;
            }
            if(max<frequency[i])
                max=frequency[i];
        }
        if(max==1)
            printf("NO\n");
        else{
            printf("%d\n",max);
            for(i=0;i<strlen(s)-3;i++){
                if(frequency[i]==max)
                    printf("%c%c%c\n",s[i],s[i+1],s[i+2]);
            }
        }
    }
    if(n==4){
        for(i=0;i<strlen(s)-4;i++){
            frequency[i]=1;
            for(j=i+1;j<strlen(s)-3;j++){
                if(s[i]==s[j]&&s[i+1]==s[j+1]&&s[i+2]==s[j+2]&&s[i+3]==s[j+3])
                    frequency[i]++;
            }
            if(max<frequency[i])
                max=frequency[i];
        }
        if(max==1)
            printf("NO\n");
        else{
            printf("%d\n",max);
            for(i=0;i<strlen(s)-4;i++){
                if(frequency[i]==max)
                    printf("%c%c%c%c\n",s[i],s[i+1],s[i+2],s[i+3]);
            }
        }
    }
    return 0;
    }


void main()
{
	char str[500];
	int n,max,i,j,k,len,t[500]={0},f;
	scanf("%d\n",&n);
	gets(str);
	len=strlen(str);
	for (i=0;i<=len-n;i++)
	{
		for (j=i;j<=len-n;j++)
		{
			f=1;
			for (k=0;k<n;k++)
				if (str[i+k]==str[j+k]) f*=1;
				else f*=0;
			if (f==1) t[i]++;
		}
	}
	max=0;
	for (i=0;i<=len-n;i++)
		if (t[i]>max) max=t[i];
	if (max<=1) printf("NO");
	else printf("%d\n",max);
	for (i=0;i<=len-n;i++)
		if (t[i]==max && t[i]>1)
		{
			for (k=0;k<n;k++)
				printf("%c",str[i+k]);
			putchar(10);
		}
}


//??????
int main()
{
	int n;
	char str[510]={'\0'};
	cin>>n;
	cin>>str;
	int len=strlen(str);
	char *p=str;
	char substr[6]={'\0'};
	substr[n]='\0';
	int fre[510]={0};
	int maxfre=0;
	for(int i=0;i<=len-n;i++)
	{
		strncpy(substr,p+i,n);
		for(int j=i;j<=len-n;j++)
			if(!strncmp(substr,p+j,n))
				fre[i]++;
		if(fre[i]>maxfre)
			maxfre=fre[i];
	}
	if(maxfre==1)
		cout<<"NO"<<endl;
	else
	{
		cout<<maxfre<<endl;
		for(int i=0;i<=len-n;i++)
			if(fre[i]==maxfre)
			{
				for(int j=i;j<i+n;j++)
					cout<<str[j];
				cout<<endl;
			}
	}
	return 0;
}


int strcmp(char *a, char *b, int n) {
	int i=0;
	for (i=0; i<n; i++)
		if (a[i] != b[i])
			return 0;
	return 1;
}
int main() {
	char a[501], b[501];
	int n, i, j, k, x, y, l, f;
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));
	scanf("%d", &n);
	scanf("%s", a);
	l = strlen(a)+1;
	f = 0;
	for (i=0; i+n<l; i++) {
		for (j=i+1; j+n<l; j++) {
			if (strcmp(&a[i], &a[j], n) == 1)
				b[i] ++;
		}
		if (b[i] > f)
			f = b[i];
	}
	if (f == 0)
		printf("NO");
	else {
		printf("%d\n", f+1);
		for (i=0; i<l; i++)
			if (b[i] == f) {
				for (j=0; j<n; j++)
					printf("%c", a[i+j]);
				printf("\n");
			}
	}
	//getchar();getchar();
	return 0;
}


int main()
{
	int n;
	char a[600];
	int ans[600]={0},mm=0;
	scanf("%d",&n);
	scanf("%s",&a);
	int i;
	i=0;
	int l=strlen(a);
	while (i+n<=l)
	{
		int j;
		ans[i]=1;
		for (j=i+1;j+n<=l;j++)
		{
			int ff=1;
			int k;
			for (k=0;k<n;k++)
			{
				if (a[i+k]!=a[j+k])
				{
					ff=0;break;
				}
			}
			if (ff) ans[i]++;
		}
		if (ans[i]>mm) mm=ans[i];
		i++;
	}
	if (mm>1)
	{
	printf("%d\n",mm);
	for (i=0;i+n<=l;i++)
	{
		if (ans[i]==mm)
		{
			int k;
			for (k=i;k<i+n;k++) printf("%c",a[k]);
			printf("\n");
		}
	}
	}
	else printf("NO");

	return 0;
}


	struct bac
{
	int num;
	int d;
	char a[5];
};
int main()
{
	struct bac abb[260];
    struct bac temp;
	int i,j,b,k,len,n;
	char str[500],dd[6]={0};
	scanf("%d",&n);
	getchar();
	gets(str);
	len=strlen(str);
	b=len-n;
	for(i=0;i<260;i++){
		abb[i].d=1;
		for(j=0;j<5;j++)
			abb[i].a[j]='\0';
	}
	for(i=0;i<=b;i++){
		k=i;
		for(j=0;j<n;j++){
			abb[i].a[j]=str[k];
			k++;
		}
	//	abb[i].a[j+1]='\0';
	}
	for(i=0;i<b;i++){
		abb[i].d=0;
		for(j=i+1;j<=b;j++){
			if(strcmp(abb[i].a,abb[j].a)==0){
				abb[i].d++;
			}
		}
	}
	for(i=0;i<b;i++){
		for(j=0;j<b-1-i;j++){
			if(abb[j].d<abb[j+1].d){
				temp=abb[j];
				abb[j]=abb[j+1];
				abb[j+1]=temp;

			}
		}
	}
	if(abb[0].d>0){
		printf("%d\n",abb[0].d+1);
		for(i=0;i<b;i++)
			if (abb[i].d==abb[0].d)printf("%s\n",abb[i].a);
	}
	else printf("NO");
	return 0;
}


void main()
{
	int n;
	scanf("%d\n",&n);
	char a[600];
	gets(a);
	int l=strlen(a);
	int i,j,k,l2=l-n+1;
	int N[600];
	for(i=0;i<l2;i++) N[i]=0;
	for(i=0;i<l2;i++)
		for(j=i+1;j<l2;j++)
		{
			int flag=1;
			for(k=0;k<n;k++)
				if(a[j+k]!=a[i+k]) {flag=0; break;}
			if(flag==0) continue;
			else N[i]=N[i]+1;
		}
	int max=N[0];

	for(i=0;i<l2;i++)
		if(N[i]>max) max=N[i];

	if(max==0) printf("NO\n");
		else{
		printf("%d\n",max+1);
	for(i=0;i<l2;i++)
		if(N[i]==max)
		{
			for(j=i;j<i+n;j++)
				printf("%c",a[j]);
			printf("\n");
	}}
}


struct chain
{
	char sp[6];
	int num;
};
void bubble(struct chain a[],int n)
{
	int i,j;
	struct chain temp;
	for(i=n-1;i>0;i--)
	{
		for(j=0;j<=i;j++)
		{
			if(a[j].num<a[j+1].num)
			{
				temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;
			}
		}
	}
}
int main()
{
	struct chain a[500];
	int i,j,k;
	char s[501];
	char c[6];
	char c1;
	for(i=0;i<=500;i++)
		a[i].num=1;
	scanf("%d",&k);
	scanf("%s",s);
	for(i=0;i<=strlen(s)-k;i++)
	{
		for(j=0;j<k;j++)
		{
			c[j]=s[i+j];
		}
		c[j]='\0';
		strcpy(a[i].sp,c);

	}
	for(i=0;i<strlen(s)-k;i++)
	{
		for(j=i+1;j<=strlen(s)-k;j++)
		{
			if(strcmp(a[i].sp,a[j].sp)==0)
			{
				a[i].num++;

			}
		}
	}
	bubble(a,strlen(s)-k);
	if(a[0].num>1)
	{
		printf("%d\n",a[0].num);
		printf("%s\n",a[0].sp);
    	for(i=1;i<=strlen(s)-k;i++)
		{
    		if(a[i].num==a[0].num&&(strcmp(a[i].sp,a[i-1].sp)!=0))
	    		printf("%s\n",a[i].sp);
		}
	}
	else printf("NO");
	return 0;
}


char a[502], b[502][6], c[502];
int main()
{
	int n, j, i, m;
	char *p=a, (*q)[6]=b, *r=c;
	cin>>n;
	cin>>a;
	int len=strlen (a);
	for(i=0; i<=len-n; i++)
		for(j=0; j<n; j++)
			q[i][j]=*(p+i+j);

	for(i=0; i<=len-n; i++)
		for(j=i+1; j<=len-n; j++)
			if(strcmp(q[i] , q[j])==0)
				r[i]++;

	int max=c[0];
	for(i=0; i<=len-n; i++)
		if(max<r[i])
			max=r[i];

	if(max<=0)
		cout<<"NO";

	else{
			cout<<max+1<<endl;
			for(i=0; i<len-n; i++)
				if(r[i]==max)
					cout<<q[i]<<endl;
		}
	return 0;
}


int main()
{
	char word[500]={'\0'},a[500][5]={'\0'};
	int i,j,n,m[500]={0},mm=0;
	scanf("%d",&n);
	scanf("%s",word);
	for(i=0;i<=strlen(word)-n;i++)
		for(j=0;j<n;j++)
			a[i][j]=word[i+j];
	for(i=0;i<=strlen(word)-n;i++)
		for(j=i;j<=strlen(word)-n;j++)
			if(strcmp(a[i],a[j])==0)
				m[i]++;
	for(i=0;i<=strlen(word)-n;i++)
		if(mm<m[i])
			mm=m[i];
	if(mm!=1)
	{
		printf("%d\n",mm);
	for(i=0;i<=strlen(word)-n;i++)
	{
		if(m[i]==mm)
		{
			for(j=0;j<n;j++)
				printf("%c",a[i][j]);
			printf("\n");
		}
	}
	}
	else printf("NO");
	return 0;
}


int main()
{
	int n,i,j,k,len,sum[500]={0},p,max=0;
	char temp[5],a[500];
	scanf("%d\n",&n);
	gets(a);
	len=strlen(a);
	for(i=0;i<len-n+1;i++)
	{
		for(j=0;j<n;j++)
			temp[j]=a[i+j];
		for(j=i;j<len-n+1;j++)
		{
			p=0;
			for(k=0;k<n;k++)
				if(temp[k]==a[j+k])
					p=1;
				else
				{
					p=0;
					break;
				}
			if(p)
				sum[i]++;
		}
	}
	for(i=0;i<len-n+1;i++)
		if(sum[i]>max)
			max=sum[i];
	if(max==1)
		printf("NO");
	else
	{
		printf("%d\n",max);
		for(i=0;i<len-n+1;i++)
			if(sum[i]==max)
			{
				for(j=0;j<n;j++)
					printf("%c",a[i+j]);
				printf("\n");
			}
	}
	return 0;
}


int i , j , n , len , sum[ 600 ] , big ;
char s[600] , ts[7];
char *p1 , *p2;

int main(){
	scanf("%d\n", &n );
	scanf("%s" , s );
	len=strlen(s);
	memset(sum,0,sizeof(sum));
	big=-1;
	for (i=0;i+n-1<len;i++){
		if (sum[i]<0)continue;
		sum[i]=0;
		p1=&s[i];
		for (j=i+1;j+n-1<len;j++){
			p2=&s[j];
			if (strncmp(p1,p2,n)==0){
				sum[i]++;
				sum[j]=-1;
			}
		}
		if (sum[i]>big)big=sum[i];
	}
	if (big==0){
		printf("NO");
		return 0;
	}
	printf("%d\n", big+1 );
	for (i=0;i+n-1<len;i++)
		if (sum[i]==big){
			p1=&s[i];
			strncpy( ts , p1 , n );
			printf("%s\n", ts );
		}

	return 0;

}


int main()
{
	int n,len,max=1,cnt,num,sofar=1;
	char tmp,c[501],gram[5],maxc[250][5];
	int i,j,k;
	scanf("%d",&n);
	gram[n]='\0';
	tmp=getchar();
	gets(c);
	len=strlen(c);
	for (i=0;i<=len-n;i++)
	{
		for (j=0;j<n;j++) gram[j]=c[i+j];
		cnt=1;
		for (j=i+1;j<=len-n;j++)
		{
			if (c[j]==gram[0])
			{
				num=0;
				for (k=1;k<n;k++)
				{
					if (c[j+k]!=gram[k]) {num++;break;}
				}
				if (num==0) cnt++;
			}
		}
		if (cnt>max) {max=cnt;strcpy(maxc[0],gram);sofar=1;}
		else if (cnt==max) {sofar++;strcpy(maxc[sofar-1],gram);}
	}
	if (max==1) printf("NO\n");
	else
	{
		printf("%d\n",max);
		for (j=0;j<sofar;j++)
		{
			for (k=0;k<n;k++) printf("%c",maxc[j][k]);
			printf("\n");
		}
	}

	return 0;
}


char c[500][500]={{' '}};
int  a[500]={0},count=0,n,max=0;
char tp[300]={' '};
char target[501]={' '};
void getstring(int start,int n)
{int i,j,k,l,m;
 strcpy(tp," ");
 for (i=0;i<n;i++)
	 tp[i]=target[start+i];
}
void find()
{int i,j,k,l,m,flag=0;
	for (i=1;i<=count;i++)
		if(strcmp(c[i],tp)==0) {a[i]++;flag=7;break;}
	if (flag==0) {count++;strcpy(c[count],tp);a[count]++;}
}
void findmax()
{int i,j,k,l,m;
 for (i=1;i<=count;i++)
	if (a[i]>max) max=a[i];
}
void print()
{int i;
if (max<=1) printf("NO");
else {printf("%d\n",max);
      for (i=1;i<=count;i++)
		  if (a[i]==max) printf("%s\n",c[i]);
	}
}
int main()
{int i,j,k,l,m;
 scanf("%d\n",&n);
 gets(target);
 l=strlen(target);
 for (i=0;i<=l-n;i++)
 {getstring(i,n);
  find();
 }
 findmax();
 print();
 return 7;
}


int main()
{
	int n,l,i,j,m,t,count[600]={0};
	char str[600],gram[600][6],c[10];
	scanf("%d",&n);
	gets(c);
	gets(str);
	l=strlen(str);
	for(i=0;i+n<=l;i++)
	{
		for(j=0;j<n;j++)
			gram[i][j]=str[i+j];
		gram[i][n]='\0';
	}
	m=i;
	for(i=0;i<m-1;i++)
	{
		for(j=i+1;j<m;j++)
			if(gram[i][0]!='\0'&&strcmp(gram[i],gram[j])==0)
			{
				gram[j][0]='\0';
				count[i]+=1;
			}
	}
	for(i=0;i<m-1;i++)
		for(j=0;j<m-1-i;j++)
			if(count[j]<count[j+1])
			{
				t=count[j];count[j]=count[j+1];count[j+1]=t;
				strcpy(gram[500+i],gram[j]);strcpy(gram[j],gram[j+1]);strcpy(gram[j+1],gram[500+i]);
			}
	if(count[0]==0)
	{
		printf("NO\n");
	}
	else
	{
		i=0;
		printf("%d\n",count[0]+1);
		while(count[i]==count[0])
		{
			printf("%s\n",gram[i]);
			i++;
		}
	}
	return 0;
}


int main()
{
    int n, i, j, k = 0;
    cin >> n;
    char data[505], substr[505][n + 1];
    cin >> data;
    int len = strlen(data);
    for (i = 0; i <= len - n; i++) {
        for (j = 0; j < n; j++) {
            substr[k][j] = data[i + j];
        }
        substr[k][n] = '\0';
        k++;
    }

    int count[len - n + 1];
    for (i = 0; i <= len - n; i++) count[i] = 0;

    for (i = 0; i <= len - n; i++) {
        for (j = i; j <= len - n; j++) {
            if (strcmp(substr[i],substr[j]) == 0) count[i]++;
        }
    }

    int max = count[0];
    for (i = 0; i <= len - n; i++) {
        if (count[i] > max) max = count[i];
    }
    if (max == 1) {cout << "NO" << endl; return 0;}
    cout << max << endl;
    for (i = 0; i <= len - n; i++) {
        if (count[i] == max) cout << substr[i] << endl;
    }

    return 0;
}


int main()
{
	int max=0;
	int n,m,len,i,j,k,count[500]={1};
	char s1[502];
	scanf("%d %s",&n,s1);
	len=strlen(s1);
	m=len-n+1;
	for(i=0;i<m,s1[i]!='\0';i++)
	{
		count[i]=1;
		for(j=i+1;j<m;j++)
		{
			k=0;
			while(k<n)
			{
			  if(s1[i+k]==s1[j+k]) k++;
			  else break;
			}
			if(k==n) count[i]++;
		}
	}
	for(i=0;i<m;i++)
	{
		if(max<=count[i]) max=count[i];
		else max=max;
	}
	if(max==1) printf("NO");
	else
	{
		printf("%d\n",max);
	for(i=0;i<m;i++)
	{
		if(count[i]==max)
		{
			for(k=0;k<n;k++)
			{
				printf("%c",s1[i+k]);
			}
		}
		printf("\n");

	}
	}
	return 0;
}


int maximum(int a,int b)
{
	if(a>b) return a;
	else return b;
}
main()
{
	int i,j,n,k,len,sta[500]={0},x=0,max=0,num;
	char input[500];
	scanf("%d",&n);
	scanf("%s",input);
	len=strlen(input);
	for(i=0;i<len;i++)
	{
		for(k=0;k<i;k++)
		{
			x=0;
			for(j=0;j<n;j++)
			{
				if(input[i+j]==input[k+j])
					x++;
				else break;
			}
			if(x==n)
			{
				sta[k]++;
				max=maximum(max,sta[k]);
				break;
			}
		}
	}
	if(max==0) printf("NO");
	else
	{
	printf("%d\n",max+1);
	for(i=0;i<500;i++)
		if(sta[i]==max)
		{
			for(j=0;j<n;j++)
				printf("%c",input[i+j]);
			printf("\n");
		}
	}

}


main()
{
  int n,sum[500],max=0;
  int i,k,j;
  char a[501];
  scanf("%d",&n);
  scanf("%s",a);
  for(i=0;i<=strlen(a)-n;i++)
  {sum[i]=1;
    for(j=i+1;j<=strlen(a)-n;j++)
    {
       for(k=0;k<n;k++)
        if(a[i+k]!=a[j+k])
        break;
       if(k==n)
        sum[i]++;
    }
    if(max<sum[i])
    max=sum[i];
}
if(max>1)
{ printf("%d\n",max);
for(i=0;i<=strlen(a)-n;i++)
{
   if(sum[i]==max)
   for(j=0;j<n;j++)
   printf("%c",a[i+j]);
   printf("\n");
}
}
else
printf("NO");

}


int main(){
char zfc[520],chu[520][5];
int ps[520],n,m,max[520],s;
memset(zfc,'\0', sizeof(zfc));
memset(chu,'\0',sizeof (chu));
memset(ps,0,sizeof (ps));
memset(max,0,sizeof (max));
scanf("%d",&n);
scanf("%s",zfc);
for (int i=0;i<=strlen(zfc)+1-n;i++){
      m=0;
      for (int j=i;j<i+n;j++){
           chu[i][m]=zfc[j];
           m++;
       }
}
ps[0]=1;
for(int t=1;t<=strlen(zfc)+1-n;t++){
    ps[t]=1;
    for(int k=0;k<t;k++){
      if (ps[k]==0) continue;
      if(strcmp(chu[k],chu[t])==0){
               ps[k]++;
               ps[t]=0;
               break;
      }
    }
}
s=1;
for (int a=1;a<=strlen(zfc)+1-n;a++){
     if(ps[a]>ps[max[0]]){
          max[0]=a;
              for(int y=1;y<=s;y++){
                  max[y]=0;
              }
          s=1;
          continue;
     }
     if(ps[a]==ps[max[0]]){
          s++;
          max[s-1]=a;
     }
 }
if(ps[max[0]]<=1){
      printf("NO");
}
else {
      printf("%d\n",ps[max[0]]);
      for(int c=0;c<s;c++){
          printf("%s\n",chu[max[c]]);
      }
}
return 0;
}


int main(){
	int n;
	char s[505],temp[6];
	char an[505][6];
	int bn[505]={0};
	scanf("%d%s",&n,s);
	int len=strlen(s);
	int count=1,i,j;
	for(i=0;i<n;i++){
		an[0][i]=s[i];
	}
	an[0][n]='\0';
	bn[0]=1;
	for(i=1;i<=len-n;i++){
		for(j=i;j<i+n;j++)
			temp[j-i]=s[j];
		temp[n]='\0';
		int k=0;
		while(k<count&&strcmp(temp,an[k])!=0){
			k++;
		}
		if(k==count){
			strcpy(an[count],temp);
			bn[count]=1;
			count++;
		}
		else
			bn[k]++;
	}
	int max=1;
	for(i=0;i<count;i++){
		if(bn[i]>max)max=bn[i];
	}
	if(max==1){
		printf("NO");
	}
	else{
		printf("%d\n",max);
		for(i=0;i<count;i++){
			if(bn[i]==max){
				printf("%s\n",an[i]);
			}
		}
	}
	return 0;
}


int main()
{
	char words[501]={0};
	char cm[500][5]={{0}};
	int n=0;
	cin>>n;
	cin.get();
	cin.getline(words,500,'\n');
	int i=0,j=0,k=0;
	int len=strlen(words);
	for(i=0;i<=(len-n);i++) //?????????????????cm???????
	{
		k=i;
		while(j<n)
			cm[i][j++]=words[k++];
		cm[i][j]='\0';
		j=0;
	}
	int count[500]={0};
	for(i=0;i<=(len-n);i++)
	{
		for(j=i;j<=(len-n);j++)
		{
			int judge=0;
			for(k=0;k<n;k++)
			{
				if(cm[i][k]!=cm[j][k])
				{
					judge=1;
					break;
				}
			}
			if(judge==0)
				count[i]++;
		}
	}
	int max=count[0];
	for(i=0;i<=(len-n);i++)
	{
		if(max<count[i])
			max=count[i];
	}
	if(max==1)
		cout<<"NO"<<endl;
	else if(max>1)
	{
		cout<<max<<endl;
		for(i=0;i<=(len-n);i++)
			if(count[i]==max)
				cout<<cm[i]<<endl;
	}
	return 0;
}


int main()
{
	char in[510],a[255][5];
	int n=0,num[255];
	cin>>n;
	cin.get();
	cin.getline(in,510);
	int len=strlen(in),k=0,i=0,j=0;
	for(i=0;i<len;i++)
		num[i]=1;
	for(i=0;i<=len-n;i++)
	{
		strncpy(a[k],in+i,n);
		a[k][n]='\0';
		k++;
	}

//for(i=0;i<k;i++)
//	cout<<a[i]<<endl;

	for(i=0;i<k-1;i++)
	{
		for(j=i+1;j<k;j++)
		{
			if( strcmp(a[i],a[j]) ==0 )
			{
				num[j]=0;
				if(num[i])
					num[i]++;
			}
		}
	}

//for(i=0;i<k;i++)
//		cout<<num[i]<<endl;

	int max=0;
	for(i=0;i<k;i++)
	{
		if(num[i]>max)
			max=num[i];
	}

	if(max==1)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<max<<endl;
	for(i=0;i<k;i++)
	{
		if(num[i]==max)
			cout<<a[i]<<endl;
	}
	return 0;

}


luru(int i,char s[],char temp[],int k)
{
	int j;
	for(j=0;j<k;j++)
		temp[j]=s[i+j];
	temp[k]=0;
}

main()
{
	char s[510]={0},temp[10]={0};
	char gram[510][10]={{0}};
	int b[510]={0};
	int n,max=1,t=0;
	int len;
	int i,j;

	scanf("%d\n",&n);
	gets(s);
	len=strlen(s);

	for(i=0;i<len+1-n;i++){
		luru(i,s,temp,n);
		for(j=0;j<t;j++)
			if(strcmp(temp,gram[j])==0)
				b[j]++;
		if(j==t)
		{strcpy(gram[t],temp);b[t]++;t++;}
	}

	for(i=0;i<t;i++)
		if(b[i]>max) max=b[i];

	if(max==1) printf("NO");
	else
	{
		printf("%d\n",max);
		for(i=0;i<t;i++)
			if(b[i]==max) printf("%s\n",gram[i]);
	}
}


//***************************
//**???3.cpp
//**??????
//**???2013.12.11
//**?????n-gram????
//***************************

void exp(int a);
void pick();
int n;
char str[501];
int sumstr[499] = {0};
int flagstr[499] = {0};
int len;
int maximum = INT_MIN;

int main()
{
	cin >> n;
	cin.get();
	cin.getline(str, 501);
	len = strlen(str);
	exp(0);
	if (maximum <= 1)
		cout << "NO" << endl;
	else
		pick();
	return 0;
}
void exp(int a)
{
	if (a == len - n + 1)
		return;

	int flag;

	for (int i = a; i <= len - n; i++)
	{
		flag = 0;
		for (int j = 0; j <= n - 1; j++)
		{
			if (str[i + j] == str[a + j])
				flag++;
			else
				break;
		}
		if (flag == n)
			sumstr[a]++;
	}
	maximum = sumstr[a] > maximum? sumstr[a]: maximum;
	exp(a + 1);
}
void pick()
{
	cout << maximum << endl;
	for (int i = 0; i <= len - n; i++)
		if (sumstr[i] == maximum)
		{
			for (int j = 0; j <= n - 1; j++)
				cout << str[i + j];
			cout << endl;
		}
}


int main()
{
	char a[504]={0};
	char x[500][8],tmp[8];
	int times[500]={0};
	int num=0;
	int n,i,j,len;
	scanf("%d",&n);
	getchar();
	gets(a);
	len=strlen(a);
	for(i=0;i<len-n+1;i++)
	{
		for(j=0;j<n;j++)tmp[j]=a[i+j];
		tmp[n]=0;
		for(j=0;j<num;j++)
		{
			if(strcmp(x[j],tmp)==0)
			{
				times[j]++;
				break;
			}
		}
		if(j==num)
		{
			strcpy(x[num],tmp);
			times[num]=1;
			num++;
		}
	}
	int max=0;
	for(i=0;i<num;i++)if(times[i]>max)max=times[i];
	if(max==1)
	{
		printf("NO\n");
		goto Eof;
	}
	printf("%d\n",max);
	for(i=0;i<num;i++)if(times[i]==max)puts(x[i]);
Eof:;
	return 0;
}


void main(void)
{
	int n;
	scanf("%d\n",&n);
	char s[501];
	gets(s);
	int len=strlen(s);

	int i,j;
	char sub[500][5];
	for(i=0;i<=len-n;i++)
	{
		for(j=0;j<=n-1;j++)
			sub[i][j]=s[i+j];
		sub[i][n]=0;
	}

	int time[500],t=0,x=1;
	for(i=0;i<=len-n-1;i++)
	{
		time[i]=1;

		if(sub[i][0]!=0)
		{
			for(j=i+1;j<=len-n;j++)
				if(strcmp(sub[i],sub[j])==0)
				{
					time[i]++;
					sub[j][0]=0;
				}

			if(x<time[i])
				x=time[i];
		}
	}

	if(x==1)
		printf("NO\n");
	else
	{
		printf("%d\n",x);
		for(i=0;i<=len-n;i++)
			if(time[i]==x)
				printf("%s\n",sub[i]);
	}
}


int main()
{
 int n,changdu;
 scanf("%d",&n);
 char gram[501],bijiao[500];
 scanf("%s",&gram);
 changdu=strlen(gram);
 int paohui[500]={0};
 for(int i=0;i<changdu-(n-1);i++)
 {
  for(int r=0;r<n;r++)
   bijiao[r]=gram[i+r];
  if(paohui[i]!=0)
   continue;
  else
  {
   for(int r=i;r<changdu-(n-1);r++)
   {
   	for(int q=0;q<n+1;q++)
   	{
   	 if(q==n)
   	 {
   	  paohui[r]++;
	  paohui[i]++;
	  if(r==i)
	   paohui[i]--;
	  break;
   	 }
   	 else
   	 {
   	  if(bijiao[q]!=gram[r+q])
   	   break;
   	 }
   	}
   }
  }
 }
 int zuiduo[500],cishu=0,jige=0;
 for(int m=0;m<changdu-(n-1);m++)
 {
  if(cishu==paohui[m])
  {
   zuiduo[jige]=m;
   jige++;
  }
  if(cishu<paohui[m])
  {
   jige=0;
   zuiduo[jige]=m;
   jige++;
   cishu=paohui[m];
  }
 }
 if(cishu==1)
  printf("NO\n");
 else
 {
  printf("%d\n",cishu);
  for(int i=0;i<jige;i++)
  {
   for(int r=0;r<n;r++)
    printf("%c",gram[zuiduo[i]+r]);
   printf("\n");
  }
 }
 return 0;
}


int main()
{
	char a[550];
	int n=0;
	cin>>n;
	cin.get();
	cin.getline(a,550);
	int len=strlen(a);
	char *p=a,b[550][6]={0},c[550][6]={0};
	int num[550]={0};
	for(int i=0;i<=len-n;i++)
	{
		int j=0;
		for(;j<n;j++)
		{
			b[i][j]=a[j+i];
		}
		b[i][j]='\0';
		//cout<<b[i]<<endl;
	}
	for(int i=0;i<len-n;i++)
	{
		for(int j=i+1;j<=len-n;j++)
		{
			if(strcmp(b[i],b[j])==0)
				num[i]++;
		}
	}
	int max=0;
	for(int i=0;i<len-n;i++)
	{
		if(max<num[i])
			max=num[i];
	}
	if(max==0)cout<<"NO";
	else
	{
		cout<<max+1<<endl;
		for(int i=0;i<len-n;i++)
		{
			if(num[i]==max)
			{
				cout<<b[i]<<endl;
			}
		}
	}
	return 0;
}


int n,m,i,j,ans,f[510];
char ss[510],s[510][510];
int main()
{
	cin >> n >> ss;
	m=strlen(ss)-n+1;
	for (i=0;i<m;i++)
		strncpy(s[i],ss+i,n);
	for (i=0;i<m;i++)
	{
		for (j=i;j<m;j++)
			if (strcmp(s[i],s[j])==0)
				f[i]++;
		if (ans<f[i]) ans=f[i];
	}
	if (ans>1) {
		cout << ans << endl << endl;
		for (i=0;i<m;i++)
			if (f[i]==ans)
				cout << s[i] << endl << endl;
	} else cout << "NO" << endl;
	return 0;
}


void main()
{
	int n, len, a[501], sign, max, *pa;
	char str[501]={'\0'}, *ps,*pj, *pk;
	scanf("%d",&n);
	scanf("%s",str);
	len=strlen(str);
	for(ps=str, pa=a; ps<(str+len); ps++, pa++)
	{
		*pa=1;
		for(pj=ps+1; pj<(ps+1+len); pj++)
		{
			sign=0;
			for(pk=pj; pk<pj+n; pk++)
			{
				if(*pk != *(ps + (pk-pj) ) )
				{
					sign=1;
					break;
				}
			}
			if(sign==0)
				(*pa)++;
		}
	}//????
	for(max=0, pa=a; pa<(a+len); pa++)
	{
		if(*pa>max)
			max = *pa;
	}
	if(max<=1)
		printf("NO\n");
	else
	{
		printf("%d\n",max);
		for(ps=str, pa=a; ps<(str+len); ps++, pa++)
		{
			if(*pa==max)
			{
				for(pk=ps; pk<(ps+n); pk++)
					printf("%c",*pk);
				printf("\n");
			}
		}
	}
}


int main()
{
	char sen[501], gram[500][6];
	int n, temp[500] = {0}, max = 1;
	cin >> n;
	cin.get();
	cin.getline(sen, 501);
	int l = strlen(sen);
	for(int i = 0; i <= l - n; i++)
	{
		for(int j = 0; j < n; j++)
			gram[i][j] = sen[i + j];
		gram[i][n] = '\0';
	}
	for(int i = 0; i < l - n;  i++)
	{
		if(temp[i])
			continue;
		temp[i] ++;
		for(int j = i + 1; j <= l - n; j++)
		{
			if(temp[j])
				continue;
			if(strcmp(gram[i], gram[j]))
				continue;
			temp[i] ++;
			temp[j] ++;
		}
		if(temp[i] > max)
			max = temp[i];
	}
	if(max == 1)
		cout << "NO" << endl;
	else
	{
		cout << max << endl;
		for(int i = 0; i <= l - n; i++)
			if(temp[i] == max)
				cout << gram[i] << endl;
	}
	return 0;
}


struct T
{
       char s[10],n;
}s[300]={0};
int m=0,max=1;
void search(char t[])
{
     int i,b,j;
     for (i=0;i<m;i++)
     {
         b=strcmp(t,s[i].s);
         if (b==0)
         {
            s[i].n++;
            if (s[i].n>max)
               max=s[i].n;
            return;
         }
     }
     m++;
     strcpy(s[i].s,t);
     s[i].n=1;
     return;
}
int main()
{
    int i,j,n,l;
    char S[600],t[10];
    scanf("%d",&n);
    scanf("%s",S);
    l=strlen(S);
    for (i=0;i<l-n+1;i++)
    {
        for (j=0;j<n;j++)
            t[j]=S[i+j];
        t[n]='\0';
        search(t);
    }
    if (max==1)
    {
       printf("NO\n");
       return 0;
    }
    printf("%d\n",max);
    for (i=0;i<m;i++)
        if (s[i].n==max)
           printf("%s\n",s[i].s);
    getchar();
    getchar();
    return 0;
}


int main()
{
	char str[510];
	char word[300][5];
	int n;
	int i,j,k;
	int len;
	int count;
	int max=1;
	scanf("%d\n",&n);
	gets(str);
	len=strlen(str);
	for (i=0,j=0;i<=len-n;i++)
	{
		for (k=0;k<n;k++)
		{
			word[j][k]=str[i+k];
		}
		word[j][n]='\0';
		j++;
	}
	for (i=0;i<j;i++)
	{
		count=0;
		for (k=i;k<j;k++)
		{
			if (strcmp(word[i],word[k])==0)
			{
				count++;
			}
		}
		max=(count>max)? count:max;
	}
	if (max==1)
	{
		printf("NO\n");
		return 0;
	}
	else
	{
		printf("%d\n",max);
		for (i=0;i<j;i++)
		{
			count=0;
			for (k=i;k<j;k++)
			{
				if (strcmp(word[i],word[k])==0)
				{
					count++;
				}
			}
			if (count==max)
			{
				printf("%s\n",word[i]);
			}
		}
		return 0;
	}
}


int main()
{
    int m=0;
    cin>>m;
    cin.get();
    char word[500];
    cin.getline(word,500);
    int l=0;
    l=strlen(word);
    char chuan[500][500];
    int i=0;
    int j=0;
    //int p=0;
    for (i=0;i<l-m+1;i++)
    {
        for (j=0;j<m;j++)
        {
            chuan[i][j]=word[i+j];
        }
        chuan[i][j]='\0';
        //p++;
    }
    /*for (int k=0;k<l-m+1;k++)
    {
        cout<<chuan[k]<<endl;
    }
cout<<p<<endl;
    */int num[500]={0};
    for (int x=0;x<l-m+1;x++)
    {
        for (int y=x;y<l-m+1;y++)
        {
            int sum=0;
                for (int p=0;p<m;p++)
                {
                    if (chuan[y][p]!=chuan[x][p])
                    {
                        sum++;
                        break;
                    }
                    //num[x]++;
                }
                if (sum==0)
                {
                    num[x]++;
                }
        }
    }

        /*for (int k=0;k<l-m+1;k++)
        {
            cout<<num[k]<<endl;
        }

        */int temp=num[0];
        int tempx=0;
        for (int i=1;i<l;i++)
        {
            if (num[i]>temp)
            {
                temp=num[i];
                tempx=i;
            }
        }
        if (temp==1) cout<<"NO"<<endl;
        else
        {
        cout<<num[tempx]<<endl;
        for (int i=0;i<l;i++)
        {
            if (num[i]==num[tempx])
            {
                cout<<chuan[i]<<endl;
            }
        }
        }
    return 0;
}


int main()
{
	int count[600]={0};
	int n;
	char a[600]="";
	char b[600][10]={""};
	scanf("%d\n",&n);
	gets(a);
	int s=strlen(a);
	int i,j;
	for(i=0;i+n<=s;i++)
	{
         for(j=0;j<n;j++)
			 b[i][j]=a[i+j];
	}

	int k=s-n+1;
	for(i=0;i<k;i++)
		for(j=i+1;j<k;j++)
			if(strcmp(b[i],b[j])==0)
				count[i]++;
	int max=0;
	int y=0;
	for(i=0;i<k;i++)
		if(count[i]>max)  max=count[i];
		if(max==0) {printf("NO");return 0;}
     printf("%d\n",max+1);
	 for(i=0;i<k;i++)
		 if(max==count[i])
			 puts(b[i]);
	return 0;
}


int compare(char str1[],char str2[],int x)
{
	int i,l;
	l=strlen(str1);
	for (i=0;i<l;i++)
	{
		if (str1[i]==str2[i+x])
			continue;
		else
			return 1;
	}
	return 0;
}

void main()
{
	int i,j,l,k,n,sum,max=0;
	char a[501]={'\0'},b[6]={'\0'},c[100][6]={'\0'};
	scanf ("%d\n",&n);
	gets (a);
	l=strlen(a);
	for (i=0;i<=l-n;i++)
	{
		sum=0;
		for (j=0;j<n;j++)
			b[j]=a[i+j];
		b[n]='\0';
		for (j=0;j<=l-n;j++)
		{
			if (compare(b,a,j)==0)
				sum++;
		}
		if (sum>max)
			max=sum;
	}
	for (k=0,i=0;i<=l-n;i++)
	{
		sum=0;
		for (j=0;j<n;j++)
			b[j]=a[i+j];
		b[n]='\0';
		for (j=i;j<=l-n;j++)
		{
			if (compare(b,a,j)==0)
				sum++;
		}
		if (sum==max)
		{
			strcpy(c[k],b);
			k++;
		}
	}
	if (max==1)
	{
		printf ("NO");
		return ;
	}
	printf ("%d\n",max);
	for (i=0;i<k;i++)
		printf ("%s\n",c[i]);
}


int main(void)
{
    char a[SIZE], b[SIZE],r;
    int bn[SIZE], i, n, l, j, k, ok, max=0;
    scanf("%d",&l);
    while ((r=getchar())!='\n');
    gets(a);
    n = strlen(a);
    for (i=0;i+l<=n;i++)
        bn[i]=0;
    for (i=0;i+l<=n;i++)
    {

        for (j=0;j<l;j++)
            b[j]=a[i+j];
        for (k=i+1;k+l<=n;k++)
        {
            ok=1;
            for (j=0;j<l;j++)
                if (b[j]!=a[k+j])
                {
                    ok=0;
                    break;
                }
            if (ok)
                bn[i]++;
        }
        if (bn[i]>max)
            max=bn[i];
    }
    if(max>0){
    printf("%d\n",max+1);
    for (i=0;i+l<=n;i++)
        if (bn[i]==max)
            {for (j=0;j<l;j++)

                printf("%c",a[i+j]);
                printf("\n");}}
                else
                printf("NO");

                return 0;
            }


int record(char str[][6],char curstr[], int count[],int num)
{
	int k=0;
	while((k<num)&&(strcmp(str[k],curstr)!=0))
		++k;
	if(k<num)
	{
		count[k]++;
		return num;
	}
	else
	{
		strcpy(str[num],curstr);
		count[num]=1;
		return num+1;
	}
}
int sub_count(char s[],char str[][6], int count[],int n)
{
	int m,k,len=strlen(s),num=0;
	char curstr[6];
	for(m=0;m<=len-n;m++)
	{
		for(k=0;k<n;k++)
		{
			curstr[k]=s[m+k];
		}
		curstr[k]='\0';
		num=record(str,curstr,count,num);
	}
	return num;
}
void main()
{
	char s[1000],str[1000][6];
	int count[1000],num,n,i,max;
	scanf("%d%s",&n,s);
	num=sub_count(s,str,count,n);
	max=count[0];
	for(i=0;i<num-1;i++)
	{
        if(max<count[i+1])
			max=count[i+1];
	}
	if(max<=1)
		printf("NO");
	else
	{
	printf("%d\n",max);
	for(i=0;i<num;i++)
	{
		if(count[i]==max)
			printf("%s\n",str[i]);
	}
	}
}


int main()
{
	int n,len,i,j,k,time[M]={0},max,flag;
	char s[M],son[M-1][5]={""};
	scanf("%d",&len);
	scanf("%s",s);
	n=strlen(s);
	for(i=0;i<=n-len;i++)
	{
		for(j=i;j<i+len;j++)
		{
			son[i][j-i]=s[j];
		}
	}
	for(k=0;k<=n-len;k++)
	{
		for(i=0;i<=n-len;i++)
		{
			if(strcmp(son[k],son[i])==0)
				time[k]++;
		}
	}
	max=time[0];
	for(k=0;k<=n-len;k++)
	{
		if(time[k]>max)
			max=time[k];
	}
	if(max>1)
	{
	printf("%d\n",max);
	for(k=0;k<=n-len;k++)
	{
		flag=1;
		if(time[k]==max)
		{
			for(i=0;i<k;i++)
			{
				if(strcmp(son[k],son[i])==0)
				{
					flag=0;
					break;
				}
			}
			if(flag==1)
				printf("%s\n",son[k]);
		}
	}
	}
	else
		printf("NO");
	return 0;
}


int main()
{
	int i, j, t, k, n, m=0;
	int flag = 1;
	char str[500];
	char *p;
	int a[500] = {0};
	cin >> n;
	cin >> str;
	k = strlen(str);
	for ( i = 0 ; i < k - n ; i++ )
	{
		for ( t = 0 ; t <= k - i - n  ; t++ )
		{
			for ( j = i ; j < n + i ; j++ )
			{
				if ( str[j] != str[j+t] )
				{
					flag = 0;
					break;
				}
			}
			if ( flag == 1 )
				a[i]++;
			flag = 1;
		}
	}
	for ( i = 0 ; i < k - n ; i++ )
	{
		if ( a[i] > m )
			m = a[i];
	}
	if ( m == 1 )
		cout << "NO" << endl;
	else
	{
		cout << m << endl;
		for ( i = 0 ; i < k - n ; i++ )
		{
			if ( a[i] == m )
			{
				p = &str[i-1];
				for (j = i ; j < i + n ; j++ )
					cout << *++p;
				cout << endl;
			}
		}
	}
	cin>>n;
	return 0;
}


int main()
{
    int n = 0;
    char s[501] = {0};
    char word[501][6] = {0};
    int count[501] = {0};
    int top = 0;
    scanf("%d\n", &n);
    gets(s);
    int i = 0, j = 0, len = strlen(s);
    int maxcount = 0;
    for ( i = 0; i < len - n+1; i++ )
    {
        for ( j = 0; j < n; j++ )
            word[top][j] = s[j+i];
        word[top][n] = '\0';
        for ( j = top -1; j >= 0; j-- )
        {
            if ( strcmp( word[j], word[top] ) == 0 )
            {
                count[j]++;
                if ( maxcount < count[j] )
                    maxcount = count[j];
                break;
            }
        }
        if ( j < 0 )
        {
            count[top] = 1;
            if ( maxcount < count[top] )
                maxcount = count[top];
            top++;
        }
    }
    if ( maxcount <= 1 )
    {
        printf("NO");
        return 0;
    }
    printf("%d", maxcount);
    for ( i = 0; i < len - n + 1; i++ )
    {
        if ( count[i] == maxcount )
            printf("\n%s", word[i] );
    }
    return 0;
}


int main()
{
    char ch[500], *p, *q, *record[250];
    int n, l, num = 1, r, k, i, j, d = 0;

    cin >> n;

    cin >> ch;

    l = strlen(ch);

    for(p = ch; p < ch + l - 1; p++)
    {
        r = 1;

        for(q = p + 1; q < ch + l; q++)
        {
            k = 0;
            for(i = 0; i < n; i++)
            {
                if(*(q + i) == *(p + i)) k++;
            }
            if(k == n) r++;
        }

        if(r > num)
        {
            d = 0;
            num = r;
            record[d] = p;
            d++;
        }
        else if(r == num && num > 1)
        {
            record[d] = p;
            d++;
        }
    }

    if(num == 1) cout << "NO" << endl;
    else
    {
        cout << num << endl;
        for(i = 0; i < d; i++)
        {
            for(j = 0; j < n; j++)
            {
                cout << *(record[i] + j);
            }
            cout << endl;
        }
    }

    return 0;
}


int main()
{
	int n,i,k,j=0,max=0,sum[500]={0};
	char str[500],smallstr[500][5];
	cin >> n;
	cin >> str;
	char *p=str,*q;
	for( ;p<=str+strlen(str)-n;p++)
	{
		q=smallstr[j];
		for(i=0;i<n;i++)
			*q++=*p++;
		*q='\0';
		p=p-n;
		j++;
	}
	for(i=0;i<j-1;i++)
	{
		for(k=i+1;k<j;k++)
		{
			if(strcmp(smallstr[i],smallstr[k])==0)sum[i]=sum[i]+1;
		}
	}
	for(i=0;i<j-1;i++)
		max=(max>=sum[i]?max:sum[i]);
	if(max==0)cout<<"NO"<<endl;
	else
		{
			cout<< max+1 <<endl;
			for(i=0;i<j-1;i++)
		    if(sum[i]==max)
					cout<<smallstr[i]<<endl;
	    }
    return 0;
}


int main()
{
	char string1[500];
	char array[500][5];
	int n,i,j,t=0;
	cin>>n;
	cin>>string1;

	int num[500]={0};

	for(i=0;i<=strlen(string1)-n;i++)
		{
		for(j=0;j<n;j++)
		{array[i][j]=string1[i+j];}
		array[i][j]='\0';
		//cout<<array[i]<<endl;
		}
	for(i=0;i<=strlen(string1)-n;i++)
		for(j=i+1;j<=strlen(string1)-n;j++)
		if(strcmp(array[i],array[j])==0)
		{num[i]++;}
	for(i=0;i<=strlen(string1)-n;i++)
		if(num[i]>t)
		{t=num[i];}

	if(t==0)
		cout<<"NO"<<endl;
	else
	{cout<<t+1<<endl;
	for(i=0;i<=strlen(string1)-n;i++)
		if(num[i]==t)
		cout<<array[i]<<endl;}
	return 0;
}


struct word
{
	char b[6];
	int count;
}p[600],tmp;

int main()
{
	char a[600]={0},x[6];
	int n,len,sign=0,m=0;
	int i,j,k;
	scanf("%d",&n);
	scanf("%s",a);
	len=strlen(a);
	for(i=0;i<=len-n;i++)
	{
		for(j=0;j<6;j++)
		{
			x[j]='\0';
		}
		sign=0;
		for(j=0;j<n;j++)
		{	x[j]=a[i+j];}

		for(k=0;k<=m;k++)
		{
			if(strcmp(x,p[k].b)==0)
			{
				p[k].count++;
				sign=1;
				break;
			}
		}
			if(sign==0)
			{
				strcpy(p[m].b,x);
				p[m].count=1;
				m++;

			}

	}

	for(i=0;i<m;i++)
	{
		for(j=m-1;j>0;j--)
		{
			if(p[j].count>p[j-1].count)
			{
				tmp=p[j];
				p[j]=p[j-1];
				p[j-1]=tmp;
			}

		}
	}
	if(p[0].count<=1)
	{
		printf("NO\n");
	}
	else{

	printf("%d\n%s\n",p[0].count,p[0].b);
	for(i=1;i<m;i++)
	{
		if(p[i].count==p[i-1].count)
		{
			printf("%s\n",p[i].b);
		}
		else
			break;
	}
	}
	return 0;
}


int main()
{
    char c[510][7],wenben[510];
    int n,m,i,j,k,cishu[510]={0},max,zd,pinshu=0;
    scanf("%d",&m);
    getchar();
    scanf("%s",wenben);
    n=strlen(wenben);
    for(i=0;i<n-m+1;i++)
    {
                        for(j=i;j<i+m;j++)
                        {
                                        c[i][j-i]=wenben[j];
                        }
                        c[i][m]='\0';
    }
    for(i=0;i<n-m+1;i++)
    {
                        for(j=i;j<n-m+1;j++)
                        {
                                            if(strcmp(c[i],c[j])==0) cishu[i]+=1;
                        }
    }
    max=cishu[0];zd=0;
    for(i=0;i<n-m+1;i++)
    {
                        if(cishu[i]>max)
                        {
                                         max=cishu[i];
                                         zd=i;
                        }
    }
    if(max<=1) printf("NO");
    else
    {
    printf("%d\n",max);
    for(i=0;i<n-m+1;i++)
    {
                        if(cishu[i]==max) printf("%s\n",c[i]);
    }
    }
    return 0;
}


int main()
{
	int n;
	char s[501];
	scanf("%d",&n);
	scanf("%s",s);
	char c[500][5];
	int i,count[500]={0},j,k,t,len;
	len=strlen(s);
	int m=0;
	for(i=0;i<=len-n;i++,m++)
	{
		k=i;
		for(j=0;j<n;j++,k++)
			c[m][j]=s[k];
		c[m][j]='\0';
		for(t=0;t<m;t++)
			if(strcmp(c[m],c[t])==0)
			{
				m--;
				count[t]++;
				break;
			}
	}
	int max=count[0];
	for(j=1;j<i;j++)
		if(count[j]>max)
			max=count[j];
	if(max==0)
		printf("NO");
	else
		{
			printf("%d\n",max+1);
			for(j=0;j<i;j++)
				if(count[j]==max)
					printf("%s\n",c[j]);
	}
}


//***************************
//**???3.cpp
//**??????
//**???2013.12.11
//**?????n-gram????
//***************************

void exp(int a);
void pick();
int n;
char str[501];
int sumstr[499] = {0};
int flagstr[499] = {0};
int len;
int maximum = INT_MIN;

int main()
{
	cin >> n;
	cin.get();
	cin.getline(str, 501);
	len = strlen(str);
	exp(0);
	if (maximum <= 1)
		cout << "NO" << endl;
	else
		pick();
	return 0;
}
void exp(int a)
{
	if (a == len - n + 1)
		return;

	int *q = NULL;
	int flag;

	q = sumstr + a;
	for (int i = a; i <= len - n; i++)
	{
		flag = 0;
		for (int j = 0; j <= n - 1; j++)
		{
			if (*(str + i + j) == *(str + a + j))
				flag++;
			else
				break;
		}
		if (flag == n)
			(*q)++;
	}
	maximum = *q > maximum? *q: maximum;
	exp(a + 1);
}
void pick()
{
	char *p = NULL;
	int *q = NULL;

	p = str;
	q = sumstr;
	cout << maximum << endl;
	for (int i = 0; i <= len - n; i++)
		if (*(q + i) == maximum)
		{
			for (int j = 0; j <= n - 1; j++)
				cout << *(p + i + j);
			cout << endl;
		}
}


int main()
{
	int i,j,k,n,chsum=0,l=0,t=0,maxnum=1,a[600]={0};
	char ch[600][10],ch1[700],temp[10];
	cin>>n>>ch1;
	l=strlen(ch1);
	for(k=0;k<=l-n;k++)
	{
		for(j=0;j<n;j++)
			temp[j]=ch1[k+j];
		t=0;
		for(i=1;i<=chsum;i++)
		{
			t=1;
			for(j=0;j<n;j++)
			{
				if(ch[i][j]!=temp[j])
				{
					t=0;
					break;
				}
			}
			if(t==1)
			{
				a[i]++;
				if(a[i]>maxnum)maxnum=a[i];
				break;
			}
		}
		if(t==0)
		{
			chsum++;
			for(i=0;i<n;i++)
				ch[chsum][i]=temp[i];
			a[chsum]++;
		}
	}
	if(maxnum>1)
	{
	cout<<maxnum<<endl;
	for(i=1;i<=chsum;i++)
		if(a[i]==maxnum)
		{
			for(j=0;j<n;j++)
			    cout<<ch[i][j];
			cout<<endl;
		}
	}
	else cout<<"NO";
	return 0;
}


void main()
{
	char a[510],mark[6];
	struct cc{
		char w[6];
		int num;
	}b[500];
	int n,i,j,flag=0,len,q=0,max=0,sum=0;
	scanf("%d %s",&n,a);
	len=strlen(a);
	for(i=0;i<=len-n;i++){
		for(j=0;j<n;j++){
			mark[j]=a[j+i];
		}
		mark[j]=0;
		if(q==0){
			strcpy(b[0].w,mark);
			q++;
			b[0].num=1;
		}
		else{
			for(j=0;j<q;j++){
				if(strcmp(mark,b[j].w)==0){
					b[j].num++;
					break;
				}
			}
			if(j==q){
				strcpy(b[q].w,mark);
				b[q].num=1;
				q++;
			}
		}
	}
	for(i=0;i<q;i++){
		if(b[i].num>max){
			max=b[i].num;
		}
	}
	if(max==1)printf("NO\n");
	else{
	printf("%d\n",max);
	for(i=0;i<q;i++){
		if(b[i].num==max){
			printf("%s\n",b[i].w);
		}
	}
}}


int main()
{
	int n, j, k, changdu,i, max = 0;
    cin >> n;
	char str[501];
	int num[501] = {0};
	int *p = num;
	cin >> str;
	changdu = strlen(str);
	for(i = 0; i <= changdu - n; i++)
	{
		for(j = i; j <= changdu - n; j++)
		{
            for(k = 0; k <= n - 1; k++)
				if(str[i + k] != str[j + k]) break;
			if(k == n)
				*(p + i) = *(p + i) + 1;
			if(num[i] >= max)
				max = *(p + i);
		}
	}
	if(max <= 1)
		cout << "NO";
	else
	{
		cout << max << endl;
        for(i = 0; i <= changdu - 1 - n; i++)
		    if(*(p + i) == max)
			{
			    for(j = 0; j <= n - 1; j++)
				{
				    cout << str[i + j];
				}
			    cout << endl;
			}
	}
	return 0;
}


typedef struct
{
  char ch[10];
  int ord;
  int times;
  int sign;
}gram;
int cmp(const void* a,const void* b)
{
  gram* pa;
  gram* pb;
  pa=(gram*)a;
  pb=(gram*)b;
  if(pa->times!=pb->times)return ((pa->times<pb->times))?1:-1;
  //if(strcmp(pa->ch,pb->ch))return (strcmp(pa->ch,pb->ch)>0)?1:-1;
  return ((pa->ord)>(pb->ord))?1:-1;
}
int main()
{
  char c[1000];
  gram d[1000];
  char *p;
  int n,i,j,k;
  scanf("%d%s",&n,c);
  p=c;
  for(i=0;i<strlen(c)+1-n;i++)
  {
    d[i].ord=i;
    d[i].sign=1;
    for(j=0;j<n;j++)
    d[i].ch[j]=*(p+j);
    d[i].ch[n]='\0';
    p++;
  }
  for(i=0;i<strlen(c)+1-n;i++)
  {
    k=1;
    for(j=0;j<strlen(c)+1-n;j++)
    if(i!=j&&strcmp(d[i].ch,d[j].ch)==0)k++;
    d[i].times=k;
  }
  qsort(d,strlen(c)+1-n,sizeof(d[0]),cmp);
  int m=d[0].times;
  if(m==1){printf("NO");return 0;}
  printf("%d\n",m);
  for(i=0;i<strlen(c)+1-n;i++)
  if(d[i].times==m&&d[i].sign)
  {
    printf("%s\n",d[i].ch);
    for(j=0;j<strlen(c)+1-n;j++)
    if(i!=j&&strcmp(d[i].ch,d[j].ch)==0)d[j].sign=0;
  }
  return 0;
}


void ngram(char str[],int n)
{
	char ng[2000][5]={'\0'};
	int i;
	int Len=strlen(str);
	for(i=0;i<Len-n+1;i++)
	{
		strncpy(ng[i],str+i,n);
	}
	int j;int max=1,count;
	for(i=0;i<Len-n+1;i++)
	{
		count=1;
		for(j=i+1;j<Len-n+1;j++)
		{
			if(strcmp(ng[i],ng[j])==0)
				count++;
		}
		if(count>=max)
			max=count;
	}
	if(max==1)
		printf("NO");
	else
	{
		printf("%d\n",max);
		for(i=0;i<Len-n+1;i++)
		{
			count=1;
			for(j=i+1;j<Len-n+1;j++)
			{
				if(strcmp(ng[i],ng[j])==0)
					count++;
			}
			if(count==max)
				printf("%s\n",ng[i]);
		}
	}
}
void main()
{
	int n;
	char str[500];
	scanf("%d%s",&n,str);
	ngram(str,n);
}


int main()
{
	int n,i,j,k,len,max=1,mark=0;
	char s[505],temp[5];
	struct example
	{
		int word;
		int num;
	}a[505];
	scanf("%d",&n);
	scanf("%s",s);
	len=strlen(s);
	for(i=0;i<len-n+1;i++)
	{
		a[i].word=0;a[i].num=1;
		for(j=0;j<n;j++)
		{
			a[i].word=a[i].word*100+s[i+j]-32;
		}
	}
	i=0;
	for(i=0;i<len-n+1;i++)
	{
		for(j=i+1;j<len-n+1;j++)
		{
			if(a[i].word!=0&&a[i].word==a[j].word)
			{
				a[i].num++;
				a[j].word=0;
			}
		}

	}
	for(i=0;i<len-n+1;i++)
	{
		if(a[i].num>max)
			max=a[i].num;
	}
	if(max==1)
		printf("NO");
	else
	{
		printf("%d\n",max);

	for(i=0;i<len-n+1;i++)
	{
		if(a[i].num==max)
		{
			for(j=0;j<n;j++)
			{
				printf("%c",s[i+j]);
			}
			printf("\n");
		}
	}
	}

	return 0;
}


main()
{
      int n,i,j,len;
      char a[600],c;
      scanf("%d",&n);
      scanf("%c",&c);
      scanf("%s",a);
      len=strlen(a);
      char b[600][5]={0};
      int outcome[600]={0};
      for(i=0;i<=len-n;i++)
      {
                           for(j=0;j<=n-1;j++)
                           {
                                              b[i][j]=a[i+j];
                           }
                           for(j=n;j<=5;j++) b[i][j]=0;

      }//??len-n+1?n-gram
      for(i=0;i<=len-n;i++)
      {
                           outcome[i]=1;
                           for(j=i+1;j<=len-n;j++)
                           if(strcmp(b[i],b[j])==0) outcome[i]+=1;
      }
      int max=0;
      for(i=0;i<=len-n;i++)
      if(outcome[i]>max) max=outcome[i];
      if(max==1) printf("NO");
      else
      {
      printf("%d\n",max);
      for(i=0;i<=len-n;i++)
      {
                           if(outcome[i]==max) printf("%s\n",b[i]);
      }
      }

}


int main()
{
	char *p = NULL;
	char c[510];
	int n, len, i, cnt[510] = {0}, t[510], s, j, max;
	cin >> n;
	cin.get();
	cin.getline(c, 510);
	len = strlen(c);
	for ( i = 0; i < len - n; i++ )
	{
		/*cout<<cnt[2]<<endl;*/
		p = c + i + 1;
		for ( ; p <= c + len - n + 1; p++ )
		{
			for ( s = 0; s <= n - 1; s++ )
			{
				if ( c[i+s] != *(p+s) )
					break;
			}
			if ( s == n )
				cnt[i]++;
		}
	}
	max = 0;
	s = 0;
	/*for (i = 0; i < len; i++)
		cout<<cnt[i]<<" ";
	cout<<endl;*/
	for ( j = 0; j < len; j++ )
	{
		if ( cnt[j] > max )
		{
			s = 0;
			max = cnt[j];
			t[s] = j;
		}
		else
			if ( cnt[j] == max )
			{
				s++;
				t[s] = j;
			}
	}
	if ( max )
	{
		cout << max + 1 << endl;
		for ( i = 0; i <= s; i++ )
		{
			/*cout << i<<endl;
			cout << t[i]<<endl;*/
			for ( j = 0; j < n - 1; j++ )
				cout << c[t[i]+j];
			cout << c[t[i]+j] << endl;
		}
	}
	else
		cout << "NO" << endl;
	return 0;
}


struct
{
	char str[10];
	int count;
}ngram[500];
void main()
{
	int n,m,len,i,j;
	scanf("%d",&n);
	char s[510];
	scanf("%s",s);
	len=strlen(s);
	m=len-n+1;
	for(i=0;i<len-n+1;i++)
		for(j=0;j<n;j++)
			ngram[i].str[j]=s[i+j];
	for(i=0;i<m;i++)
		ngram[i].count=1;
	for(i=0;i<m;i++)
		for(j=i+1;j<m;j++)
			if(strcmp(ngram[i].str,ngram[j].str)==0)
			{
				ngram[i].count++;
				ngram[j].count=0;
			}
	int max=1;
	for(i=0;i<m;i++)
		if(ngram[i].count>max)max=ngram[i].count;
	if(max==1)
		printf("NO");
	else
	{i=0;
	while(ngram[i].count!=max)
		i++;
	printf("%d\n",max);
	printf("%s\n",ngram[i].str);
	for(i++;i<m;i++)
		if(ngram[i].count==max)
			printf("%s\n",ngram[i].str);}

}


void main()
{
	char str[MAX];
	int n,len,i,j=0,k,flag,max;
	struct subs{
		char s[5];
		int num;
	}sub[MAX];

	scanf("%d",&n);
	getchar();
	gets(str);
	len=strlen(str);

	for(i=0;i<=len-n;i++){
		(sub+i)->num=0;
		if(i==0){
			strncpy((sub+j)->s,str+i,n);
			(sub+j)->s[n]='\0';
			(sub+j)->num++;
			j++;
		}
		else{
			flag=1;
			for(k=0;k<j;k++){
				if( strncmp((sub+k)->s,str+i,n)==0 ){
					(sub+k)->num++;
					flag=0;
					break;
				}
			}

			if(flag){
				strncpy((sub+j)->s,str+i,n);
				(sub+j)->s[n]='\0';
				(sub+j)->num++;
				j++;
			}
		}
	}

	for(i=0;i<j;i++){
		if(i==0)
			max=(sub+i)->num;
		else if( (sub+i)->num>max )
			max=(sub+i)->num;
	}

	if(max==1)
		printf("NO\n");
	else{
		printf("%d\n",max);
		for(i=0;i<j;i++)
			if((sub+i)->num==max)
				puts((sub+i)->s);
	}
}


int mark=1, n, b[1000]={0}, c[1000]={0}, max=0;
char a[1000];
int work(int i, int j)
{
	int k=0;
	while(a[i+k]==a[j+k])
	{
      if (k<n-1)
		  k++;
	  else
		  return 1;
	}
	return 0;

}
int main()
{
	int i, j;
	scanf("%d%s", &n,a);
	for (i=0; i<=strlen(a)-n; i++)
	{
		mark=1;
		for(j=i+1; j<=strlen(a)-n; j++)
		{
			if (work(i, j)==1 && b[j]!=1)
			{
				mark+=1;

				b[j]=1;
			}

		}
			if (mark>max)
				{
					max=mark;
				}

	}
	if (max>1)
	printf("%d\n", max);

		for (i=0; i<=strlen(a)-n; i++)
	{
		mark=1;
		for(j=i+1; j<=strlen(a)-n; j++)
		{
			if (work(i, j)==1 && c[j]!=1)
			{
				mark+=1;
				c[j]=1;
			}

		}
			if (mark==max)
			{
				if (mark>1)
				{
				for (int k=0; k<n; k++)
				{
				printf("%c" , a[i+k]);
				}
				printf("\n");
				}

			}

	}
		if (max==1)
				printf("NO");
		return 0;
}


int main()
{
	int n;
	scanf("%d",&n);
	getchar();
	char str[501];
	gets(str);
	int len,q[501];
	for(len=0;str[len]!=0;len++);
	int i,j,u,v,V,max=0;
	for(i=0;i<=len-n;i++)
	{
		q[i]=1;
		for(u=i+1;u<=len-n;u++)
		{
			V=1;
			for(v=0;v<n;v++)
			{
				if(str[i+v]!=str[u+v])
				{
					V=0;
					break;
				}
			}
			if(V==1)
			{
				q[i]=q[i]+1;
				if(q[i]>max)
					max=q[i];
			}
		}
	}
	if(max==0)
	{
		printf("NO\n");
		return 0;
	}
	printf("%d\n",max);
	for(i=0;i<len-n;i++)
	{
		if(q[i]==max)
		{
			for(j=0;j<n;j++)
			{
				printf("%c",str[i+j]);
			}
			putchar('\n');
		}
	}
	return 0;
}


void main()
{
	char str[MAX];
	int n,len,i,j=0,k,flag,max;
	struct subs{
		char s[5];
		int num;
	}sub[MAX];

	scanf("%d",&n);
	getchar();
	gets(str);
	len=strlen(str);

	for(i=0;i<=len-n;i++){
		(sub+i)->num=0;
		if(i==0){
			strncpy((sub+j)->s,str+i,n);
			*((sub+j)->s+n)='\0';
			(sub+j)->num++;
			j++;
		}
		else{
			flag=1;
			for(k=0;k<j;k++){
				if( strncmp((sub+k)->s,str+i,n)==0 ){
					(sub+k)->num++;
					flag=0;
					break;
				}
			}

			if(flag){
				strncpy((sub+j)->s,str+i,n);
				*((sub+j)->s+n)='\0';
				(sub+j)->num++;
				j++;
			}
		}
	}

	for(i=0;i<j;i++){
		if(i==0)
			max=(sub+i)->num;
		else if( (sub+i)->num>max )
			max=(sub+i)->num;
	}

	if(max==1)
		printf("NO\n");
	else{
		printf("%d\n",max);
		for(i=0;i<j;i++)
			if((sub+i)->num==max)
				puts((sub+i)->s);
	}
}


int main()
{
	int n, j, k, leng;
	cin >> n;
	char str[501];
	int num[501] = {0};
	cin >> str;
	leng = strlen(str);
	int i, max = 0;
	for(i = 0; i <= leng - n; i++)
	{
		for(j = i; j <= leng - n; j++)
		{
            for(k = 0; k <= n - 1; k++)
				if(str[i + k] != str[j + k]) break;
			if(k == n)
				num[i]++;
			if(num[i] >= max)
				max = num[i];
		}
	}
	if(max <= 1)
		cout << "NO";
	else
	{
		cout << max << endl;
        for(i = 0; i <= leng - 1 - n; i++)
		    if(num[i] == max)
			{
			    for(j = 0; j <= n - 1; j++)
				{
				    cout << str[i + j];
				}
			    cout << endl;
			}
	}
	return 0;
}


void move(int *a,int n,int m);
void main()
{
	int n,m,a[200];
	scanf("%d %d",&n,&m);
	int i;
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	move(a,n,m);
	for(i=0;i<n-1;i++)
		printf("%d ",a[i]);
	printf("%d\n",a[n-1]);
}

void move(int *a,int n,int m)
{
	int i;
	for(i=n-1;i>=0;i--)
		a[i+m]=a[i];
	for(i=n;i<n+m;i++)
		a[i-n]=a[i];
}


struct term
{
	int num;
	struct term *next;
};

struct term *creat(int n)
{
	struct term *head;
	struct term *p1,*p2;
	int i=1;
	p1=p2=(struct term *)malloc(LEN);
	scanf("%d",&p1->num);
	head=p1;
	while(i<n)
	{
		p1=(struct term *)malloc(LEN);
		scanf("%d",&p1->num);
		p2->next=p1;
		p2=p1;
		i++;
	}
	p1->next=NULL;
	return(head);
}

void main()
{
	struct term *head,*p1,*p2,*p;
	int i,n,m;
	scanf("%d %d",&n,&m);
	head=creat(n);
	p1=p2=head;
	for(i=1;i<n;i++)
	{
		p1=p2->next;
		p2=p1;
	}
	p1->next=head;
	p1=p2=head;
	for(i=1;i<n-m;i++)
	{
		p1=p2->next;
		p2=p1;
	}
	head=p1->next;
	p2->next=NULL;
	for(p=head,i=0;i<n;i++)
	{
		if(i==0) printf("%d",p->num);
		else printf(" %d",p->num);
		p=p->next;
	}
	printf("\n");
}


void main()
{
	void move(int num[],int m,int n);
	int num[100],m,n,i;
	scanf("%d%d",&m,&n);
	for(i=0;i<m;i++)
	{
		scanf("%d",&num[i]);
	}
	move(num,m,n);
	printf("%d",num[0]);
	for(i=1;i<m;i++)
	{
		printf(" %d",num[i]);
	}
	printf("\n");
}
void move(int num[],int m,int n)
{
	int *p,end;
	end=*(num+m-1);
	for(p=num+m-1;p>num;p--)
		*p=*(p-1);
	*num=end;
	n--;
	if(n>0)
		move(num,m,n);
}


void move(int *p,int n)
{
	int i,temp;
	temp=*(p+n-1);
	for(i=n-2;i>=0;i--)
		*(p+i+1)=*(p+i);
	*p=temp;
}

void main()
{
	int i,n,m,*p;
	scanf("%d%d",&n,&m);
	p=(int *)malloc(n*sizeof(int));
	for(i=0;i<n;i++)
		scanf("%d",p+i);
	for(i=0;i<m;i++)
		move(p,n);
	for(i=0;i<n;i++)
	{
		printf("%d",*(p+i));
		if(i!=n-1)
			printf(" ");
		else
			printf("\n");
	}
}


int main() {
	int sz[100],n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&sz[i]);
	}
	int e;
	for(int k=n-m;k<n;k++){
		for(int j=k;j>k-n+m;j--){
			e=sz[j];
			sz[j]=sz[j-1];
			sz[j-1]=e;
		}
	}
	for(int c=0;c<n-1;c++){
		printf("%d ",sz[c]);
	}
	printf("%d",sz[n-1]);
	return 0;
}


void move(int *,int,int);

int main()
{
	int i,a[100]={0},m,n;
	cin>>n>>m;
	for(i=0;i<n;i++)
		cin>>a[i];
	move(a,n,m);
	cout<<a[0];
	for(i=1;i<n;i++)
		cout<<" "<<a[i];
	return 0;
}
void move(int *num,int n,int m)
{
	int *p;
	int end,i;
	p=num;
	end=*(p+n-1);
	for(p=p+n-1;p>num;p--)
		*p=*(p-1);
	*p=end;
	m--;
	if(m>0)
		move(num,n,m);
}


int main()
{
	int m,n;
	scanf("%d %d\n",&n,&m);
    int i,a[100];
	for(i=0;i<n;i++)
	{
	    scanf("%d",&a[i]);
	}
    int*point;
	//for(i=n-m;i<n;i++)
	//{
      //  printf("%d",a[i]);
	//}
	//for(i=0;i<n-m-1;i++)
	//{
	//	printf("%d",a[i]);
	//}
	//printf("%d\n",a[n-m-1]);
	for(point=&a[n-m];point<a+n;point++)
	{
		printf("%d ",*point);
	}
	for(point=a;point<a+n-m-1;point++)
	{
		printf("%d ",*point);
	}
	printf("%d\n",a[n-m-1]);
	return 0;
}


void main()
{
	void inv(int *a,int n,int m);
	int a[100];
	int m,n,i;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);//??
	inv(a,n,m);
	for(i=0;i<n;i++)
	{
		if(i!=0)
			printf(" ");
		printf("%d",a[i]);
	}
	printf("\n");
}
void inv(int *a,int n,int m)
{
	int *p,a_end;
	a_end=*(a+n-1);
	for(p=a+n-1;p>a;p--)
		*p=*(p-1);
	*a=a_end;
	m--;
	if(m>0)
		inv(a,n,m);
}


void main()
{
	void loop(int a[],int b);
	int n,m,i;
	int c[100];
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)
	{
		scanf("%d",&c[i]);
	}
	for(i=0;i<n-m;i++)
		loop(c,n);
	printf("%d",c[0]);
	for(i=1;i<n;i++)
		printf(" %d",c[i]);
}
void loop(int a[],int b)
{
	int i,temp=a[0];
	for(i=0;i<b-1;i++)
		a[i]=a[i+1];
	a[b-1]=temp;
}


int main()
{
int a,b;
int m[102];
cin>>a>>b;
for(int i = 0;i<a;i++)
{
cin>>m[i];
}
for(int i = a - b;i < a;i++)
cout<<m[i]<<" ";
for(int i = 0;i<a-b;i++)
{
cout<<m[i];
if(i != a - b -1)
cout<<" ";
}
}


struct Node;
typedef struct Node *pNode;
struct Node
{
    int x;
	pNode next;
};

pNode create()/*??head*/
{
	pNode p;
	p=(pNode)malloc(sizeof(struct Node));
	p->next=NULL;
	return p;
}

void sort(pNode head,int n)/*head???????n???*/
{
	pNode p=NULL,q=NULL,s=NULL;
    int i;
	for (i=1;i<=n;i++)
	{
	s=(pNode)malloc(sizeof(struct Node));
	scanf("%d",&s->x);
    q=head;
	p=head->next;
	while (p)
	{
        if (p->x>=s->x)
			break;
		q=p;
		p=p->next;
	}
	q->next=s;
	s->next=p;
	}

}

void outputdata(pNode p)/*??head*/
{
    p=p->next;
	while(p->next)
	{
      printf("%d ",p->x);
	  p=p->next;
    }
	printf("%d",p->x);
}

pNode inputdata(int n)/*??head?????n???*/
{
	pNode q=NULL,p=NULL,head=NULL;
	int i;
	head=create();
	q=head;
	for (i=1;i<=n;i++)
	{p=(pNode)malloc(sizeof(struct Node));
	if (p!=NULL)
	 {
	 scanf("%d",&p->x);
     p->next=NULL;
	 q->next=p;
	 q=p;
	}
	}
	return head;
}

void del(pNode p,int k)/*??head??k???*/
{
	pNode q=NULL;
	q=p;
	p=p->next;
	while(p)
		if (p->x==k)
		{
			q->next=p->next;
			free(p);
			p=q->next;
		}
		else
		{q=p;p=p->next;}
}

pNode rinputdata(int n)/*??head,????n???*/
{
	pNode q=NULL,p=NULL,head=NULL;
    int i;
	head=create();
	for (i=1;i<=n;i++)
	{
		p=(pNode)malloc(sizeof(struct Node));
		if (p!=NULL)
		{
			scanf("%d",&p->x);
			p->next=q;
			q=p;
		}
	}
    head->next=q;
    return head;
}

void outputk(pNode p,int k)/*???k???*/
{
	int i=1;
    p=p->next;
	while(p)
	{
      if (i==k)
		 printf("%d",p->x);
	  p=p->next;
      i++;
	}
}

void change(pNode p,int n,int m)/*?head?n?????m???????*/
{
	int i=1;
	pNode q=NULL,s=NULL,head=NULL;
	q=p;
	head=p;
	p=p->next;
	while(p)
	{
		if (i==n-m+1)
			break;
		i++;
		q=p;
		p=p->next;
	}
	s=head;
	while(s->next)
		s=s->next;
	q->next=NULL;
	s->next=head->next;
	head->next=p;
}

void found(pNode p,int k)/*??head???k???*/
{
   pNode head=p;
   int ok=1;
   p=head->next;
   while(p)
   {
	   if (k==p->x)
	   {
		   printf("%d\n",p->x);
           ok=0;
	   }
	   p=p->next;
   }
   if (ok)
	   printf("No Found!");
}

int main()
{
    int m,n;
    pNode head=NULL;
    scanf("%d %d",&n,&m);
    head=inputdata(n);
    change(head,n,m);
	outputdata(head);

	return 0;
}


struct number
{
	int num;struct number *next;
};

struct number * creat(int n)
{
	struct number *head;
	struct number *p1,*p2;
	int i;
	p1=p2=(struct number *)malloc(LEN);
	scanf("%d",&p1->num);
	head=p1;
	i=1;
	while(i<n-1)
	{
		p1=(struct number *)malloc(LEN);
		scanf("%d",&p1->num);
		p2->next=p1;
		p2=p1;
		i=i+1;
	}

	p1=(struct number *)malloc(LEN);
	scanf("%d",&p1->num);
	p2->next=p1;
	p2=p1;
	p2->next=head;
	return head;
}
void print(struct number *head,int n,int m)
{
	int i;
	struct number *p;
	struct number *t;
	p=head;
	for(i=0;i<n-m;i++)
	{   t=p;
	    p=p->next;
	}
	t->next=NULL;
	if(p!=NULL)
	{
      do
	  {printf("%d",p->num);
	  printf((p->next!=NULL)?" ":"\n");
	  p=p->next;
	  }while(p!=NULL);
	}

}

void main()
{
	int n,m;
	struct number * p;
	scanf("%d%d",&n,&m);
	p=creat(n);
	print(p,n,m);
}


//      resort.c
//
//      Copyright 2009 JacksonTB <jacksontb@jacksontb-laptop>
//
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.

typedef struct NODE{
	int value;
	struct NODE *fwd;
	struct NODE *bwd;
}node;

int main(int argc, char** argv)
{
	int m, n, i;
	node *rootp, *recp, *prep,*lastp;

	rootp = (node*) malloc(sizeof(node));
	rootp -> fwd = NULL;
	prep = rootp;

	scanf("%d %d", &n, &m);
	for(i = 1;i <= n;i ++)
	{
		recp = (node*) malloc(sizeof(node));
		if(recp == NULL)
		{
			printf("Not enough memory");
			return EXIT_FAILURE;
		}
		scanf("%d", &(recp -> value));
		recp -> bwd = prep;
		prep -> fwd = recp;
		recp -> fwd = NULL;
		prep = recp;
	}

	recp = rootp;
	for(i = 1;i <= n - m + 1;i ++)
	{
		recp = recp -> fwd;
	}

	lastp = rootp;
	while(lastp -> fwd != NULL)
	{
		lastp = lastp -> fwd;
	}

	lastp -> fwd = rootp -> fwd;
	rootp -> fwd -> bwd = lastp;
	rootp -> fwd = recp;
	recp -> bwd -> fwd = NULL;
	recp = rootp -> fwd;
	while(recp != NULL)
	{
		printf("%d", recp -> value);
		prep = recp;
		recp = recp -> fwd;
		if(recp != NULL) printf(" ");
		free(prep);
	}

	return 0;
}


int main(){
	int n,m;
	scanf("%d %d", &n, &m);
	int num[100];
	int *p=num;
	int i;
	for(i=0;i<n;i++){
		scanf("%d",&num[i]);
	}
	for(i=0;i<m;i++){
		int templast=*(p+n-1);
		int j;
		for(j=n-1;j>=1;j--){
			*(p+j)=*(p+j-1);
		}
		*p=templast;
	}
	printf("%d",*p);
	for(i=1;i<n;i++){
		printf(" %d",*(p+i));
	}
	printf("\n");

	return 0;
}


int main()
{
	int a[1000];
	int m,len;
	int i;
	int temp,temp1;
	int wz,counts=0;
	scanf("%d %d",&len,&m);
	for(i=0;i<len;i++)
	{
		scanf("%d",&a[i]);
	}
	temp=a[0];
	for(i=0;counts<=len;i=i+m)
	{

		wz=i+m;
		if(wz>len-1)
		{
			wz=wz-len;
			i=wz-m;
		}
		temp1=a[wz];
		a[wz]=temp;
		temp=temp1;
		counts++;
	}
	printf("%d",a[0]);
	for(i=1;i<len;i++)
	{
		printf(" %d",a[i]);
	}
	return 0;
}


void main()
{void move(int [20],int,int);
int num[20],n,m,i;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
scanf("%d",&num[i]);
move(num,n,m);
for(i=0;i<n;i++)
printf("%d%c",num[i],(i<n-1)?' ':'\n');
}
void move(int a[20],int n,int m)
{int *p,end;
end=*(a+n-1);
for(p=a+n-1;p>a;p--)
*p=*(p-1);
*a=end;
m--;
if(m>0)move(a,n,m);
}


int main()
{
	void move(int*,int,int);
	int n,i,m;
	int a[N];
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++)
	scanf("%d",&a[i]);
	move(a,n,m);
	printf("%d",*(a+1));
	for(i=2;i<=n;i++)
	printf(" %d",*(a+i));
}
void move(int* a,int n,int m)
{
	int b[N],i;
	for(i=1;i<=n-m;i++)
	b[i+m]=a[i];
	for(i=n-m+1;i<=n;i++)
	b[i+m-n]=a[i];
	for(i=1;i<=n;i++)
	*(a+i)=*(b+i);
}


/*
 * CycleRemove.cpp
 *
 *  Created on: 2013-12-5
 *      Author: 111
 */

int main()
{
	int str[102];
	int n,m;
	cin >> n >> m;
	int *p=NULL;
	for (p=str;p<str+n;p++)
	cin >> *p;
	cout << str[n-m];
	for (p=str+n-m+1;p<str+n;p++)
		cout << ' ' << *p;
	for (p=str;p<str+n-m;p++)
		cout << ' ' << *p;
	return 0;
}


void main()
{
     void change(int *p,int n,int m);
     int a[100],n,m,i,*p=a;
     scanf("%d%d",&n,&m);
     printf("\n");
     for(i=0;i<n;i++,p++)
         scanf("%d",p);
	 p=a;
     change(p,n,m);
}

void change(int *p,int n,int m)
{
     int *i,*j,b[100];
     j=b;
     i=p;
     for(j=b,i=p;i<p+n;i++,j++)
     {

         if(i<p+n-m)
         *(j+m)=*i;
         else
          *(j-n+m)=*i;
     }
     for(j=b;j<b+n-1;j++)
	 { printf("%d ",*j);}
         printf("%d",*(b+n-1));

}


/*
 * yidongshuzu.cpp
 *
 *  Created on: 2011-12-9
 *      Author: Dai Guangda
 */
int main()
{
	int n,m,a[200],*p;
	cin >>n >>m;
	for (p=a; p<a+n; p++)
		cin >>*p;
	for (p=a+n-1; p>=a; p--)
		*(p+m) = *p;
	for (p=a; p<a+m; p++)
		*p = *(p+n);
	for (p=a; p<a+n-1; p++)
		cout <<*p <<' ';
	cout <<*p;
	return 0;
}


int main()
{
  int n,m,i,t;
  scanf("%d%d",&n,&m);
  int *p=(int *)malloc(n*sizeof(int));
  int *q=(int *)malloc(n*sizeof(int));
  for(i=0;i<n;i++)
  {
   scanf("%d",&p[i]);
   q[i] = i+1;
  }
  q[n-1] = 0;
  q[n-m-1] = n;
  t = n-m;
  while(1)
  {
    printf("%d",p[t]);
    t = q[t];
    if(t == n) break;
    printf(" ");
  }
 return 0;
}


trans(int a[],int m,int n)
{
	int temp;
	int i;
	if(m==1){
		temp=a[n-1];
		for(i=n-1;i>0;i--)
			a[i]=a[i-1];
		a[0]=temp;
	}
	else
	{
		trans(a,1,n);
		trans(a,m-1,n);
	}
	return 0;
}

main()
{
	int n,m;
	int a[110];
	int i;

	scanf("%d%d\n",&n,&m);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);

	trans(a,m,n);

	printf("%d",a[0]);
	for(i=1;i<n;i++)
		printf(" %d",a[i]);
}


int main()
{
    void move(int *pa,int m,int n);
    int a[110],*pa=a;
    int n,m,i,j;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
        scanf("%d",&*(pa+i));
    move(pa,m,n);
    for(i=0;i<n-1;i++)
    printf("%d ",*(a+i));
    printf("%d\n",*(a+n-1));
    getchar();
    getchar();
}
void move(int *a,int m,int n)
{
    int temp,i,j;
    for(i=n-m;i<n;i++)
    {
        for(j=i-1;j>=m-n+i;j--)
        {
            temp=*(a+j);
            *(a+j)=*(a+j+1);
            *(a+j+1)=temp;
        }
    }
}


int main()
{
	int a,b,i;
	scanf("%d%d",&a,&b);
	int *pint;
	pint=(int*)malloc(sizeof(int)*a);
	for(i=0;i<a;i++)
	{
		scanf("%d",pint+i);
	}
	for(i=a-b;i<a;i++)
	{
		printf("%d ",*(pint+i));
	}
	for(i=0;i<a-b;i++)
	{
		printf("%d",*(pint+i));
		if(i!=a-b-1)
			printf(" ");
	}
	return 0;
}


int main()
{
	int i,n,m,num[100]={0};
	cin>>n>>m;
	for(i=0;i<n;i++)
		cin>>num[i];
	int temp=0;
	while(m--)
	{
		temp=num[n-1];
		for(i=n-1;i>=0;i--)
			num[i+1]=num[i];
		num[0]=temp;
	}
	cout<<num[0];
	for(i=1;i<n;i++)
		cout<<' '<<num[i];
	return 0;
}


	struct num
	{
		int a;
		struct num *next;
	};
void main()
{
	struct num *head,*p1,*p2;
	int n,i,m;
	scanf("%d%d",&n,&m);
	p1=(struct num *)malloc(sizeof(struct num));
	scanf("%d",&p1->a);
	head=p1;
	p2=head;
	for(i=1;i<n;i++)
	{
		p1=(struct num *)malloc(sizeof(struct num));
		scanf("%d",&p1->a);
		p2->next=p1;
		p2=p2->next;
	}
	p1->next=head;
	for(i=0;i<=n-m;i++)
	{
		p2=p2->next;
	}
	for(i=1;i<n;i++)
	{
		printf("%d ",p2->a);
		p2=p2->next;
	}
	printf("%d",p2->a);
}


struct shu
{
	int num;
	struct shu *next;
} shu[100];
int main()
{
	struct shu *head, *p;
	int n,m,i;
	scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
		scanf("%d",&shu[i].num);

    head=&shu[n-m];
	for(i=n-m;i<n;i++)
		shu[i].next=&shu[i+1];
	shu[n-1].next=&shu[0];
	for(i=0;i<n-m-1;i++)
		shu[i].next=&shu[i+1];
    shu[n-m-1].next=NULL;

	p=head;
	{
		printf("%d",p->num);
	    	p=p->next;
	   do
	   {
		    printf(" %d",p->num);
	    	p=p->next;
	   }while(p!=NULL);
	}

	 printf("\n");
}


int main()
{

	int input[100]={0};
	int *stop, *cut;
	int n, m;

	cin>>n>>m;
	for(int i=0; i<n; i++)
	{
		cin>>input[i];
	}

	cut=input;
	stop=input+n-m;

	for(int i=0; i<m; i++)
	{
		cout<<*(stop++)<<" ";

	}

	for(int i=0; i<n-m; i++)
	{
		cout<<*(cut++);
		if(i!=(n-m-1))
			cout<<" ";

	}

return 0;
}


void swap(int a[],int n,int m)
{
	int temp;
    temp=a[m];
	a[m]=a[n];
	a[n]=temp;
}
void circle(int a[],int l)
{
	int i;
	for(i=0;i<l;i++)
		swap(a,0,i);
}
void main()
{
	int l,k,i;
	int a[100];
	scanf("%d %d",&l,&k);
	for(i=0;i<l;i++)
		scanf("%d",&a[i]);
	for(i=0;i<k;i++)
		circle(a,l);
	for(i=0;i<l-1;i++)
		printf("%d ",a[i]);
	printf("%d\n",a[i]);
}


int main()
{
	int n;
	int num[1000];
	int *p;
	int i,m;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
	{
		scanf("%d",&num[i]);
	}
	p=num;
	for(i=0;i<m;i++)
	{for(p=num+n;p>=num;p--)
	{

		*(p+1)=*p;
	}
	p=num;
	*p=*(num+n);}
	for(i=0;i<n-1;i++)
	printf("%d ",num[i]);
	printf("%d",num[i]);

	return 0;
}


void Input(int a[],int n)
{
	int i;
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
}
void Turn(int a[],int n,int m)
{
	int i,j,temp;
	for(i=n-m;i<n;i++)
	{
		for(j=i-1;j>=i-n+m;j--)
		{
		    temp=a[j];
		    a[j]=a[j+1];
		    a[j+1]=temp;
		}
	}
}
Output(int a[],int n)
{
	int i;
	printf("%d",a[0]);
    for(i=1;i<n;i++)
		printf(" %d",a[i]);
	printf("\n");
}
void main()
{
	int n,m,num[100];
	scanf("%d%d",&n,&m);
	Input(num,n);
	Turn(num,n,m);
	Output(num,n);
}


int main()
{
     void move(int array[],int x,int y);
     int n,m,i,*p,a[100]={0};
     scanf("%d %d",&n,&m);
     for(p=a;p<=a+n-1;p++)
     scanf("%d",p);
     move(a,n,m);
     for(p=a;p<=a+n-2;p++)
     printf("%d ",*p);
     printf("%d",*(a+n-1));
     return 0;
}
void move(int array[100],int x,int y)
{
     int *p,arrayend=*(array+x-1);//?arrayend????????????????

       for(p=array+x-1;p>=array+1;p--)
       *p=*(p-1);
       *array=arrayend;
       y--;
       if(y>0) move(array,x,y);
}


int a[100];
void move(int n,int m)
{
	int *p,last;
	last=a[n-1];
	for(p=a+n-1;p>a;p--)
		*p=*(p-1);
	*a=last;
	m--;
	if(m>0) move(n,m);
}

void main()
{
	int i,m,n;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	move(n,m);
	for(i=0;i<n-1;i++)
		printf("%d ",a[i]);
	printf("%d",a[n-1]);
}


int main()
{
	int n,m,i,a[100];
	int *p;
	cin>>n>>m;
	for(i = 0;i < n;i ++)
	{
		cin>>a[i];
	}
	p = a + n - m;
	do
	{
		cout<<*p<<" ";
		p ++;
		if(p > a + n - 1)
			p = a;
		if(p == a + n - m - 1)
			break;
	}
	while(p <= a + n -1);
	cout<< *p <<endl;
	return 0;
}


int main()
{
	int n, where;
	cin >> n >> where;
	int num[max];
	for (int i = 0; i < n; i++)
		cin >> num[i];
	int *p = num;
	for (int i = 0; i < n - where; i++)
		*(p + n + i) = *(p + i);
	p = p + n-where;
	for (int i = 0; i < n;i++)
	if (i == 0)
		cout << *(p + i);
	else
		cout << " " << *(p + i);

}


void swap(int *pa,int n,int m)
{
	int a[100];
	int i;
	for(i=0;i<m;i++) a[i]=pa[n-m+i];
	for(i=0;i<n-m;i++) pa[n-1-i]=pa[n-1-i-m];
	for(i=0;i<m;i++) pa[i]=a[i];
	return;
}
void main()
{
	int c[100];
	int i,n,m,*p=c;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++) scanf("%d",&c[i]);
	swap(p,n,m);
	for(i=0;i<n-1;i++) printf("%d ",c[i]);
	printf("%d",c[n-1]);
}


void main()
{
	int i,n,m;
	scanf("%d %d",&n,&m);
	int *p[100];
	for(i=0;i<n-m;i++)
	{p[i+m]=(int *)calloc(1,sizeof(int));
	scanf("%d",p[i+m]);}
	for(i=0;i<m;i++)
	{
		p[i]=(int *)calloc(1,sizeof(int));
		scanf("%d",p[i]);
	}
	for(i=0;i<n;i++)
	if(i!=0) printf(" %d",*p[i]);else printf("%d",*p[i]);

}


int main(){
	int n,m;
	cin>>n>>m;
	int a[n],b[n];
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)b[i]=a[i];
	for(int k=0;k<n;k++){
		if(n-m+k<=n-1)a[k]=b[n-m+k];
		else a[k]=b[k-m];
	}
	for(int i=0;i<n;i++){
		if(i==0)cout<<a[i];
		else cout<<" "<<a[i];
	}
	return 0;
}


int main()
{
	void move(int a[],int n,int m);
	int n,m;
	int i;
	int a[100];
	int *p;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	move(a,n,m);
	for (i=0;i<n;i++)
		if(i!=n-1)
		printf("%d ",a[i]);
		else
		printf("%d",a[i]);
	return 0;
}

void move(int a[],int n,int m)
{
	int *p;
	int al;
	al=*(a+n-1);
	for(p=a+n-1;p>a;p--)
		*p=*(p-1);
		*a=al;
		m=m-1;
		if (m>0)
			move(a,n,m);
}


void move(int *shu,int n)
{
	int t1,t2;
	int *ptr=shu;
	t1=*ptr;
	*ptr=*(ptr+n-1);
	ptr++;
	do
	{
		t2=*ptr;
		*ptr=t1;
		t1=t2;
		ptr++;
	}while(ptr-shu<=n);
}
void main()
{
	int n,a,i;
	int shu[100];
	scanf("%d %d",&n,&a);
	for(i=0;i<n;i++)
		scanf("%d",shu+i);
	for(i=0;i<a;i++)
		move(shu,n);
	for(i=0;i<n;i++)
	{
		if(i!=n-1)
		printf("%d ",*(shu+i));
		else
			printf("%d",*(shu+i));
	}

}


void main()
{
	int i,n,m;
	int a[100]={0};
	scanf("%d %d",&n,&m);
	int *p;
	p=(int*)malloc(n*sizeof(int));
    for(i=0;i<=n-1;i++)
	scanf("%d",&a[i]);
   if(p=&a[n-m])
     printf("%d",*p);
   for(i=1;i<n;i++)
	{
	    if(n-m+i<n)
		p=&a[n-m+i];
	    else
		p=&a[i-m];
	    printf(" %d",*p);
	}
}


int main()
{
	int n,m;
	cin>>n>>m;
	int a[n];
	for( int i = 0; i < n; i++)
	{
		cin>>a[i];
	}
	int *p = a + n - m;
	for( ; p < a + n ; p++)
	{
		cout<< *p<<' ';
	}
	int *q = a;
	for(; q < a + n - m ; q++)
	{
		if( q != a + n - m - 1)
			cout<< *q << ' ';
		else
			cout<< *q<<endl;
	}

	return 0;
}


int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    int a[100],i;
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    printf("%d",a[n-m]);
    for(i=n-m+1;i<n;i++)
    printf(" %d",a[i]);
    for(i=0;i<(n-m);i++)
    printf(" %d",a[i]);
    getchar();
    getchar();
}


int main()
{
	int *p,*q;
	int m,n,i;
	scanf("%d%d",&n,&m);
	p=(int*)malloc((sizeof(int))*n);
	q=(int*)malloc((sizeof(int))*n);
	for (i=0;i<n;i++)
		scanf("%d",&p[i]);
	for(i=0;i<n-1;i++)
	{
		*q=p[(n-m+i)%n];
		printf("%d ",*q);
		q++;
	}
	printf("%d",p[n-m-1]);
	return 1;
}


int main(int argc, char* argv[])
{
	int a,b,c,d,n,i,e;
	scanf("%d%d",&n,&a);
	int score[100];
	for(i=0;i<n;i++)
	{
		scanf("%d",&b);
		score[i]=b;
	}
	for(i=0;i<a;i++)
	{

		d=score[1];
		score[1]=score[0];
		for(c=1;c<n-1;c++)
		{
			e=score[c+1];
			score[c+1]=d;
			d=e;
		}
		score[0]=e;

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


/*
 * move.cpp
 *
 *  Created on: 2011-1-8
 *      Author: Administrator
 */
int main(){
	int *p = NULL,*q = NULL;
	int n,m,i;
	cin>>n>>m;
	int a[n];
	for(i=0;i<n;i++)  cin>>a[i];
	p=a;
	q=a+n;
	for(i=0;i<n-m;i++){
		*(q+i)=*(p+i);
	}
	p=a+n-m;
	for(i=0;i<n-1;i++){
		cout<<*(p++)<<" ";
	}
	cout<<*p<<endl;
	return 0;
}


int main(){
	int n,m,temp;
	cin>>n>>m;
	int a[101];
	int *p=a;
	for(p=a;p<a+n;p++)
		cin>>*p;
	for(int i=0;i<m;i++){
		p=a+n-1;
		temp=*p;
		for(p--;p>=a;p--)
			*(p+1)=*p;
		p++;
		*p=temp;
	}
	for(p=a;p<a+n;p++){
		if(p==a) cout<<*p;
		else cout<<' '<<*p;
	}
	return 0;
}


void main()
{
	int n,m,i;
	int *p;
	scanf("%d%d",&n,&m);
	p=(int *)malloc( n *sizeof(int) );
	for(i=0;i<n;i++)
		scanf("%d", p+(i+m)%n );
	for(i=0;i<n;i++){
		printf("%d", *(p+i) );
		if(i<n-1)
			printf(" ");
	}
}


int main()
{
   int m,n,i;
   cin>>n>>m;
    int a[n];
    for(i=m;i<n;i++)
    cin>>*(a+i);
    for(i=0;i<m;i++)
    cin>>*(a+i);
    cout<<*a;
    for(i=1;i<n;i++)
    cout<<' '<<*(a+i);
    return 0;
}


int main()
{
    void stand(int a[],int M,int N,int x);
    int s[100],n,m,i,z;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    scanf("%d",&s[i]);
    z=m;
    while(m!=0)
    {
    stand (s,m,n,z);
    m--;
    }
    printf("%d",s[0]);
    for(i=1;i<n;i++)
    printf(" %d",s[i]);
}
void stand(int a[],int M,int N,int x)
{
    int k,t,q;
    for(k=N-M;k>x-M;k--)
    {
    t=a[k];
    a[k]=a[k-1];
    a[k-1]=t;
    }
}


//
//  main.cpp
//  xunhuan
//
//  Created by blues cookie on 12-12-9.
//  Copyright (c) 2012? blues cookie. All rights reserved.
//

int main(int argc, const char * argv[])
{
    int m,n,i,j,k;
    int a[100];
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(i=n-m+1;i<=n;i++) *(a+i+m)=*(a+i);//??m????m
    for(i=n-m;i>=1;i--) *(a+i+m)=*(a+i);//?n-m?????
    for(i=1;i<=m;i++) *(a+i)=*(a+i+n);//?M?????
    for(i=1;i<=n-1;i++) cout<<a[i]<<' ';//?? ???
    cout<<a[n];
    return 0;

}


void tz(int a[],int n,int m);
void main()
{
	int a[20];
	int m,n,i;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	tz(a,n,m);
}
void tz(int a[],int n,int m)
{
	int *p;
	for(p=a+n-m+1;p<=a+n;p++)
		printf("%d ",*p);
	for(p=a+1;p<a+n-m;p++)
		printf("%d ",*p);
         printf("%d\n",*p);
}


int main(int argc, char* argv[])
{
	int*p,*point,*start,*begin,*temp,i,n,m;
	scanf("%d%d",&n,&m);
	p=(int*)malloc(sizeof(int)*n);
	point=p;
	start=p;
	begin=p;
	for(i=0;i<n;i++,start++)
	{
		scanf("%d",start);
	}
	point+=(n-m);
	temp=point;
	for(;point<start;point++)
	{
		printf("%d ",*point);
	}
	for(;begin<temp-1;begin++)
	{
		printf("%d ",*begin);
	}
	printf("%d",*begin);
	free(p);
	return 0;
}


int main()
{
	int *ptr1,*ptr2,i,n,number,a[1000];
	scanf("%d%d",&number,&n);
	for(i = 0; i < number; i++)
	{
		scanf("%d",&a[i]);
	}
	ptr1 = a;
	ptr2 = ptr1 + number - n;
	for(i = 1; i <= n; i++)
	{
		printf("%d ",*ptr2);
		ptr2++;
	}
	for(i = 1; i < (number - n); i++)
	{
		printf("%d ",*ptr1);
		ptr1++;
	}
	printf("%d", *(ptr1));
}


void right_shift_one(int* a,int n);
void right_shift_array(int* a,int n,int m);

int main() {
	int n,m;
	scanf("%d %d",&n,&m);
	int* a=(int *)calloc(n,sizeof(int));
	int i;
	for(i=0;i<n;i++)
		scanf("%d",&(a[i]));
	right_shift_array(a,n,m);
	for(i=0;i<n-1;i++)
		printf("%d ",a[i]);
	printf("%d",a[n-1]);
	free(a);
	return 0;
}

void right_shift_array(int* a,int n,int m) {
	int i;
	for(i=0;i<m;i++)
		right_shift_one(a,n);
}

void right_shift_one(int* a,int n) {
	int temp=a[n-1];
	int i;
	for(i=n-1;i>0;i--) {
		a[i]=a[i-1];
	}
	a[0]=temp;
}


int main()
{
	void move(int*p, int n, int m);
	int n, m;
	scanf("%d %d", &n, &m);
	int i;
	int a[100];
	int *p;
	p=a;
	scanf("%d", &a[0]);
	for(i=1;i<n;i++)
	{
		scanf(" %d", &a[i]);
	}
	move(p, n, m);
	return 0;
}

void move(int*p, int n, int m)
{
	int *p1;
	p1=(int *)malloc(n*sizeof(int));
	int i, j=0;

	for(i=0;i<m;i++)
	{
		p1[i]=p[i+n-m];
	}
	for(i=m;i<n;i++,j++)
	{
		p1[i]=p[j];
	}
	for(i=0;i<n-1;i++)
	{
		printf("%d ", p1[i]);
	}
	printf("%d\n", p1[n-1]);
	free(p1);
}


void Move(int *num,int n)
{
    int *p;
    for(p=num+n-1;p>=num;p--)
       {
        *(p+1)=*p;
        }
    num[0]=num[n];
}

int main()
{
    int m,n,num[101];
    int i;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
       scanf("%d",num+i);
    for(i=0;i<m;i++)
       Move(num,n);
    for(i=0;i<n-1;i++)
       printf("%d ",num[i]);
    printf("%d",num[i]);
    return 1;
}


void move(int a[],int n,int m);
void main()
{
	int n,m,i,a[100],*p;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
	{scanf("%d",&a[i]);}
	move(a,n,m);
	for(i=0;i<n-1;i++)printf("%d ",a[i]);
	printf("%d",a[n-1]);
	printf("\n");
}
void move(int a[],int n,int m)
{
	int *p,i,t;
	t=a[n-1];
	for(p=(a+n-1);p>a;p--)
	*p=*(p-1);
	*a=t;
	m--;
	if(m>0)move(a,n,m);
}


int main()
{
    int num[1000],n,m,i;
    scanf("%d",&n);
    scanf("%d",&m);
    for(i=1;i<=n;i++)
{scanf("%d",&num[i]);}
    for(i=n+1;i<=2*n;i++)
    {num[i]=num[i-n];}
    for(i=n+1-m;i<=2*n-m;i++)
    {if(i==n+1-m)
    printf("%d",num[i]);
    else
    printf(" %d",num[i]);}
    getchar();
    getchar();
    return 0;}


void yid(int *p,int x,int y)
{
    int i,j,temp;
	for(i=0;i<y;i++)
	{
		temp=*(p+x-1);
		for(j=x-1;j>0;j--)
			*(p+j)=*(p+j-1);
		*p=temp;
	}
}
int main()
{
    int *arr,l,a[100],n,m;
    scanf("%d %d",&n,&m);
	for(l=0;l<n;l++)
		scanf("%d",&a[l]);
	arr=a;
	yid(arr,n,m);
	printf("%d",*arr);
    for(arr=(a+1);arr<(a+n);arr++)
		printf(" %d",*arr);
}


int main ()
{
    int n,m,i,a[100],x=0,k,c=0,temp,count=0;
    scanf("%d%d",&n,&m);
    for  (i=0;i<n;i++)
    {
         scanf("%d",&a[i]);
    }
    if (n%m==0)
    {
          k=n/m;
          for (i=0;i<m;i++)
          {
                      x=i;
                      while (c!=i||count==0)
                         {
                         count=1;
                         if (x+m<n)
                        c=x+m;
                        else c=x+m-n;
                        // printf("c=%d",c);
                         temp=a[c];
                         a[c]=a[i];
                         a[i]=temp;
                         x=c;
                          }
                          //printf("break");
                          count=0;
                          x=0;
                          c=0;

          }
    }

    else
    {
         count=0;
         x=0;
         while (count!=n)
         {
                        if (x+m<n)
                        c=x+m;
                        else c=x+m-n;
                         temp=a[c];
                         a[c]=a[0];
                         a[0]=temp;
                         x=c;
                         count++;
         }
    }
    printf("%d",a[0]);
    for (i=1;i<n;i++)
    printf(" %d",a[i]);
          return 0;
}


void swap(int a[], int h, int t) {
  int i, j, te;
  for (i = h, j = t; i < j; i++, j--) {
	te = a[i];
    a[i] = a[j];
	a[j] = te;
  }
}

void dump(int a[], int n) {
  int i;
  for (i = 0; i < n; i++) {
    printf("%d", a[i]);
	if (i != n-1)
		printf(" ");
  }

}

int main() {
  int n, m;
  int a[100];
  scanf("%d %d", &n, &m);
  m = n - m;
  int i;
  for (i = 0; i < n; i++)
     scanf("%d", &a[i]);
  swap(a, 0, m - 1);
  swap(a, m, n - 1);
  swap(a, 0, n - 1);
  dump(a, n);
  return 0;
}


struct Node;
typedef struct Node *pNode;
struct Node
{
    int x;
	pNode next;
};

pNode create()/*??head*/
{
	pNode p;
	p=(pNode)malloc(sizeof(struct Node));
	p->next=NULL;
	return p;
}

void sort(pNode head,int n)/*head???????n???*/
{
	pNode p=NULL,q=NULL,s=NULL;
    int i;
	for (i=1;i<=n;i++)
	{
	s=(pNode)malloc(sizeof(struct Node));
	scanf("%d",s->x);
    q=head;
	p=head->next;
	while (p)
	{
        if (p->x>=s->x)
			break;
		q=p;
		p=p->next;
	}
	q->next=s;
	s->next=p;
	}

}

void outputdata(pNode p)/*??head*/
{
    p=p->next;
	while(p->next)
	{
      printf("%d ",p->x);
	  p=p->next;
    }
	printf("%d",p->x);
}

pNode inputdata(int n)/*??head?????n???*/
{
	pNode q=NULL,p=NULL,head=NULL;
	int i;
	head=create();
	q=head;
	for (i=1;i<=n;i++)
	{p=(pNode)malloc(sizeof(struct Node));
	if (p!=NULL)
	 {
	 scanf("%d",&p->x);
     p->next=NULL;
	 q->next=p;
	 q=p;
	}
	}
	return head;
}

void del(pNode p,int k)/*??head??k???*/
{
	pNode q=NULL;
	q=p;
	p=p->next;
	while(p)
		if (p->x==k)
		{
			q->next=p->next;
			free(p);
			p=q->next;
		}
		else
		{q=p;p=p->next;}
}

pNode rinputdata(int n)/*??head,????n???*/
{
	pNode q=NULL,p=NULL,head=NULL;
    int i;
	head=create();
	for (i=1;i<=n;i++)
	{
		p=(pNode)malloc(sizeof(struct Node));
		if (p!=NULL)
		{
			scanf("%d",&p->x);
			p->next=q;
			q=p;
		}
	}
    head->next=q;
    return head;
}

void outputk(pNode p,int k)/*???k???*/
{
	int i=1;
    p=p->next;
	while(p)
	{
      if (i==k)
		 printf("%d",p->x);
	  p=p->next;
      i++;
	}
}

void change(pNode p,int n,int m)/*?head?n?????m???????*/
{
	int i=1;
	pNode q=NULL,s=NULL,head=NULL;
	q=p;
	head=p;
	p=p->next;
	while(p)
	{
		if (i==n-m+1)
			break;
		i++;
		q=p;
		p=p->next;
	}
	s=head;
	while(s->next)
		s=s->next;
	q->next=NULL;
	s->next=head->next;
	head->next=p;
}

int main()
{
    int m,n;
    pNode head=NULL;
    scanf("%d %d",&n,&m);
    head=inputdata(n);
    change(head,n,m);
	outputdata(head);

	return 0;
}


int main()
{ const int max=100;
  int i,n,m,a[max];

  cin>>n>>m;
  for(i=m;i<n;i++) cin>>a[i];
  for(i=0;i<m;i++) cin>>a[i];
  cout<<a[0];
  for(i=1;i<n;i++) cout<<" "<<a[i];
  return 0;
}


int main()
{
	int n, m, a[1000];
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	cout << a[n - m];
	for (int i = n - m + 1; i < 2*n - m; i++)
		cout << ' ' << a[i % n];
	cout << endl;
    return 0;
}


int  main()
{
void change (int a[100],int n,int m);
int a[100],n,m,i;

scanf("%d",&n);
scanf("%d",&m);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}

change (a,n,m);
for(i=0;i<n-1;i++){
printf("%d ",a[i]);
}
printf("%d",a[n-1]);
return 0;
}

void change (int a[100],int n,int m){
    int i,j,temp;
	for(i=0;i<m;i++){
            temp=a[n-1];
		for(j=0;j<n;j++){

			a[n-j-1]=a[n-j-2];
		}
	      a[0]=temp;
	}

}


void main()
{
	int i,n,m,num[100];
	void move(int num[100],int n);
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%d",&num[i]);
	for(i=0;i<m;i++)
		move(num,n);
	for(i=0;i<n-1;i++)
		printf("%d ",num[i]);
	printf("%d",num[n-1]);
}
void move(int num[100],int n)
{
	int t,j;
	t=num[n-1];
	for(j=n-1;j>0;j--)
		num[j]=num[j-1];
	num[0]=t;
}


int main()
{
	int n,m,num[100],k[100],t,p;
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>num[i];
	for(int i=0;i<m;i++)
	{
		p=num[n-1];
	for(int j=n-1;j>0;j--)
		num[j]=num[j-1];
	num[0]=p;
	}
    for(int i=0;i<n-1;i++)
		cout<<num[i]<<" ";
	cout<<num[n-1];
	return 0;
}


void change ( int * ,int * );
int main()
{
	int a[999];
	int n,m;
	int i;
	cin >> n >>m;
	for( i=0;i<n;i++)
		cin >> a[i];

	change(a,  a+n-1);
	change(a,  a+m-1);
	change(a+m,a+n-1);

	for(i=0;i<n;i++)
	{
		if( i==n-1 )
			cout<< a[i]<< endl;
		else
			cout << a[i] << ' ';
	}
	return 0;
}

void change( int  * a,int * b )
{
	int t;
	for(;a<b;a++,b--)
	{
		t=*a;
		*a=*b;
		*b=t;
	}
}


int main()
{
	int n,m;
	cin>>n>>m;
	int A[100];
	int B[100];
	for (int i=0;i<n-m;++i)
		cin>>A[i];
	for (int i=0;i<m;++i)
		cin>>B[i];
	for (int i=0;i<m;++i)
		cout<<B[i]<<" ";
	for (int i=0;i<n-m;++i)
	{
		if (i==n-m-1)
			cout<<A[i];
		else
		    cout<<A[i]<<" ";
	}
	return 0;
}


struct Node;
typedef struct Node *pNode;
struct Node
{
    int x;
	pNode next;
};

pNode create()/*??head*/
{
	pNode p;
	p=(pNode)malloc(sizeof(struct Node));
	p->next=NULL;
	return p;
}

void sort(pNode head,int n)/*head???????n???*/
{
	pNode p=NULL,q=NULL,s=NULL;
    int i;
	for (i=1;i<=n;i++)
	{
	s=(pNode)malloc(sizeof(struct Node));
	scanf("%d",&s->x);
    q=head;
	p=head->next;
	while (p)
	{
        if (p->x>=s->x)
			break;
		q=p;
		p=p->next;
	}
	q->next=s;
	s->next=p;
	}

}

void outputdata(pNode p)/*??head*/
{
    p=p->next;
	while(p->next)
	{
      printf("%d ",p->x);
	  p=p->next;
    }
	printf("%d",p->x);
}

pNode inputdata(int n)/*??head?????n???*/
{
	pNode q=NULL,p=NULL,head=NULL;
	int i;
	head=create();
	q=head;
	for (i=1;i<=n;i++)
	{p=(pNode)malloc(sizeof(struct Node));
	if (p!=NULL)
	 {
	 scanf("%d",&p->x);
     p->next=NULL;
	 q->next=p;
	 q=p;
	}
	}
	return head;
}

void del(pNode p,int k)/*??head??k???*/
{
	pNode q=NULL;
	q=p;
	p=p->next;
	while(p)
		if (p->x==k)
		{
			q->next=p->next;
			free(p);
			p=q->next;
		}
		else
		{q=p;p=p->next;}
}

pNode rinputdata(int n)/*??head,????n???*/
{
	pNode q=NULL,p=NULL,head=NULL;
    int i;
	head=create();
	for (i=1;i<=n;i++)
	{
		p=(pNode)malloc(sizeof(struct Node));
		if (p!=NULL)
		{
			scanf("%d",&p->x);
			p->next=q;
			q=p;
		}
	}
    head->next=q;
    return head;
}

void outputk(pNode p,int k)/*???k???*/
{
	int i=1;
    p=p->next;
	while(p)
	{
      if (i==k)
		 printf("%d",p->x);
	  p=p->next;
      i++;
	}
}

void change(pNode p,int n,int m)/*?head?n?????m???????*/
{
	int i=1;
	pNode q=NULL,s=NULL,head=NULL;
	q=p;
	head=p;
	p=p->next;
	while(p)
	{
		if (i==n-m+1)
			break;
		i++;
		q=p;
		p=p->next;
	}
	s=head;
	while(s->next)
		s=s->next;
	q->next=NULL;
	s->next=head->next;
	head->next=p;
}

void found(pNode p,int k)/*??head???k???*/
{
   pNode head=p;
   int ok=1;
   p=head->next;
   while(p)
   {
	   if (k==p->x)
	   {
		   printf("%d\n",p->x);
           ok=0;
	   }
	   p=p->next;
   }
   if (ok)
	   printf("No Found!");
}

pNode arrange(pNode p)
{
	pNode q=NULL,head=NULL,min=NULL,headnew=NULL,ppre=NULL,minpre=NULL,s=NULL;
	headnew=create();
	q=headnew;
	head=p;
    while (head->next)
	{
       	min=p=head->next;
		ppre=minpre=head;
		while(p)
	{
		 if (min->x>p->x)
		 {
			 min=p;
			 minpre=ppre;
		 }
		 ppre=p;
		 p=p->next;
	}
	s=(pNode)malloc(sizeof(struct Node));
	s->x=min->x;
    q->next=s;
	s->next=NULL;
	q=s;
	minpre->next=min->next;
	free(min);
    }
	return headnew;
}

int main()
{
    int m,n;
    pNode head=NULL;
    scanf("%d %d",&n,&m);
    head=inputdata(n);
    change(head,n,m);
	outputdata(head);

	return 0;
}


void move(int a[100],int n,int m)
{
	int temp,i;
	temp=a[n-1];
	for(i=n-1;i>=1;i--)
		a[i]=a[i-1];
	a[0]=temp;

	m--;
	if(m>0) move(a,n,m);
}

void main()
{
	int number[100],n,m,i;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%d",&number[i]);
	move(number,n,m);
	printf("%d",number[0]);
	for(i=1;i<n;i++)
		printf(" %d",number[i]);
}


int reserve(int *self,int start,int end)
{
    int temp;
    if(end-start>0)
    {
        temp=self[start];
        self[start]=self[end];
        self[end]=temp;
        reserve(self,start+1,end-1);
    }
}

void main()
{
    int n,m,i;
    int num[50];
    scanf("%d%d",&n,&m);
    for (i=0;i<n;i++)
        scanf("%d",&num[i]);
    reserve(num,0,n-1);
    reserve(num,0,m-1);
    reserve(num,m,n-1);
    printf("%d",num[0]);
    for (i=1;i<n;i++)
        printf(" %d",num[i]);
}


int main()
{
	int n, m;
	scanf("%d%d", &n,&m);
	int*num=(int*)malloc(sizeof(int)*(n+m));
	for(int i=m;i<m+n;i++) {
		scanf("%d", &num[i]); }
	for(int i=n;i<m+n;i++) {
		num[i-n]=num[i]; }
	printf("%d", num[0]);
	for(int i=1;i<n;i++) {
		printf(" %d", num[i]); }
	free(num);
	return 0;
}


void move(int a[],int n,int m)
{
	int last,*p;
	last=*(a+n-1);
	for(p=a+n-1;p>a;p--)
	*p=*(p-1);
	*p=last;
	m--;
	if(m>0) move(a,n,m);
}
void main()
{
	int i,a[100],*p=a,n,m;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	move(a,n,m);
	for(i=0;i<n-1;i++)
	printf("%d ",a[i]);
	printf("%d\n",a[i]);
}


void main()
{         void change(int x[],int y,int z);
	      int a[100],n,m,i;
		  scanf("%d %d",&n,&m);
		  for(i=0;i<n;i++)
			  scanf("%d",&a[i]);
			  change(a,n,m);
		  for(i=0;i<n-1;i++)
			  printf("%d ",a[i]);
		  printf("%d",a[n-1]);
}
void change(int x[],int y,int z)
{
	int *p,*h;
	h=x;
	for(p=h+y-1;p>=h;p--)
		*(p+z)=*p;
	for(p=h;p<=h+z-1;p++)
		*p=*(p+y);
}


int main(){
    int n,l,i,an[1000];
    int *p;
    cin>>n>>l;
    for(i = 0;i < n;i ++){
        cin>>an[i];
    }
    p = an + n - l;
    do{
        cout<<*p<<" ";
        p ++;
        if(p > an + n - 1){
            p = an;
        }
        if(p == an + n - l-1){
            break;
        }
    }while(p <= an + n -1);
    cout<<*(an+n-l-1)<<endl;
    return 0;
}


void change(int *a,int n)
{
	int *p,t;
	p=a+n-1;
	t=*p;
	for(;p!=a;p--)
		*p=*(p-1);
	*p=t;
}

void main()
{
	int n,m,i,j;
	scanf("%d %d",&n,&m);
	int *a;
	a=LEN;
	for(i=0;i<n;i++)
		scanf("%d",a+i);
	for(j=0;j<m;j++)
		change(a,n);
	for(i=0;i<n-1;i++)
		printf("%d ",*(a+i));
	printf("%d\n",*(a+i));
}


void sort(int array[],int n,int m)
{
	int i,r;
	for(i=1;i<=m;i++)
	{
		int k,j;
		k=array[n-1];
		for(j=n-1;j>=1;j--)
			array[j]=array[j-1];
		array[0]=k;
	}
	printf("%d",array[0]);
	for(r=1;r<n;r++)
		printf(" %d",array[r]);
}
void main()
{
	int n,m,a,f[100];
	scanf("%d %d",&n,&m);
	for(a=0;a<n;a++)
		scanf("%d",&f[a]);
	sort(f,n,m);
}


void swap(int * a,int * b,int n){
    int *c=a;
    a=b;
    b=c;

}

void backward(int * pointer,int n){
    for (int i=n-1; i>0; i--) {
        swap(*(pointer+i), *(pointer+i-1));
    }
}

int main(){
    int n,time;
    cin>>n>>time;
    int line[120];
    for (int i=0; i<n; i++) {
        cin>>line[i];
    }
    int *p_1=line;
    for (int i=1; i<=time; i++) {
        backward(p_1, n);
    }
    cout<<*p_1;
    for (int i=1; i<n; i++) {
        cout<<' '<<*(p_1+i);
    }
}


int main(int argc, char* argv[])
{
int n,m;
scanf("%d%d",&n,&m);
int a[100];
int i;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
int pos=n-m;
for(i=0;i<n-1;i++){
printf("%d ",a[(pos+i)%n]);}
printf("%d\n",a[(pos+i)%n]);
	return 0;
}


int arrange(int a[],int q,int p)
{
	int i,j,b[100];
	for(i=0;i<q;i++)
		b[i]=a[p-q+i];
	for(i=p-q-1;i>=0;i--)
		a[i+q]=a[i];
	for(i=0;i<q;i++)
		a[i]=b[i];

	return 0;
}

int main()
{
	int n,m,i;
	int a[100];
	scanf("%d %d\n",&n,&m);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	arrange(a,m,n);
	printf("%d",a[0]);
	for(i=1;i<n;i++)
		printf(" %d",a[i]);

}


int main(){
   int n,i,m;
   scanf("%d %d\n",&n,&m);
   int *sz=(int*)malloc(sizeof(int)*n);
     for(i=0;i<n-1;i++){
       scanf("%d",&sz[i]);
     }
       scanf("%d",&sz[n-1]);
       m=m%n;
   for(i=n-m;i<n;i++){
     printf("%d ",sz[i]);
   }
    for(i=0;i<n-m-1;i++){
       printf("%d ",sz[i]);
    }
      printf("%d",sz[n-m-1]);
  free(sz);
  return 0;
}


int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int shu[100];
    for(int i=0;i<n;i++)
    {
            scanf("%d",&shu[i]);
    }
    int*p;
    p=&shu[n-1];
    int a;
    a=n-m;
    for(int i=0;i<m+n;i++)
    {
        p++;
        *p=shu[i];
    }
    for(int i=a;i<2*n-m-1;i++)
    {
        printf("%d ",shu[i]);
    }
    printf("%d",shu[2*n-m-1]);
    getchar();
    getchar();
    getchar();
    return 0;
}


// Using recursive method

int data[1000] = {0};
int n = 0, m = 0;

void cir_move(int dir, int left, int right, int step) // moving direction, 0 for left, 1 for right
{
	/*
	cout << dir << ' ' << left << ' ' << right << ' ' << step << endl;
	for(int i = 1; i <= n; i++) cout << data[i] << ' ';
	cout << endl;
	cin.get();
	*/ // for Debuging
	if((left == right)||(step == 0)) return;
	int len = right - left + 1; // calculate length
	step = step % len;
	if(step > len / 2) // Equivalent Transformation of Problem
	{
		cir_move(dir ^ 1, left, right, len - step);
		return;
	}
	int j = 0, k = len - step;
	for(int i = left; i < left + step; i++)
	{
		j = data[i];
		data[i] = data[i + k];
		data[i + k] = j;
	}
	if(dir == 0) // move leftward
	{
		cir_move(dir, left, right - step, step);
	}else // move rightward
	{
		cir_move(dir, left + step, right, step);
	}
}

int main()
{
	cin >> n >> m;
	m = m % n;
	for(int i = 1; i <= n; i++) cin >> data[i];
	cir_move(1,1,n,m);
	cout << data[1];
	for(int i = 2; i <= n; i++) cout << ' ' << data[i];
}


int main()
{
	int n, m, i, j, temp;
	int * array;
	scanf("%d %d", &n, &m);
	array = (int *)malloc(sizeof(int)*n);
	for (i=0; i<n; i++) {
		scanf("%d", &array[i]);
	}
	m = m % n;
	for (i=0; i<m; i++) {
		temp = *(array+(n-1));
		for (j=n-1; j>0; j--) {
			*(array+j) = *(array+(j-1));
		}
		*(array+0) = temp;
	}
	for (i=0; i<n-1; i++) {
		printf("%d ", *(array+i));
	}
	printf("%d\n", *(array+i));
	free(array);
	return 0;
}


int a[100];
int main ( )
{
	void f(int *p,int n,int m);
	int *p,n,m;
	scanf("%d %d",&n,&m);
	for(p=a;p<a+n;p++)
		scanf("%d",p);
	p=a;
	f(p,n,m);
	for(p=a;p<a+n;p++)
	{
		if(p<a+n-1)
			printf("%d ",*p);
		else
			printf("%d\n",*p);
	}
	return 0;
}
void f(int *p,int n,int m)
{
	int t;
	p+=n-1;
	t=*p;
	for(;p>a;p--)
		*p=*(p-1);
	*p=t;
	m-=1;
	if(m>0)
		f(p,n,m);
}


int main(int argc, char* argv[])
{
	int n,m,i,j;
	int *p,*q;
	scanf("%d%d",&n,&m);
	p=(int*)malloc(sizeof(int)*n);
    q=(int*)malloc(sizeof(int)*n);
	for (i=0;i<n;i++){
		scanf("%d",&p[i]);
	}
    for (i=n-m,j=0;i<n;i++,j++){
		q[j]=p[i];
		printf("%d ",q[j]);
	}
	for (i=0;i<n-m;i++){
		q[m+i]=p[i];
		if (i!=n-m-1)
        printf("%d ",q[m+i]);
	}
    printf("%d",q[n-1]);
	return 0;
}


void main()
{
	int m,n;
	int a[100];int *p;
	void move(int *,int,int);
	int i;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	p=a;
	move(p,n,m);
	for(i=0;i<n-1;i++,p++)
		printf("%d ",*p);printf("%d\n",*p);
}

void move(int *p,int n,int m)
{
	int i,t;
	t=*(p+n-1);
	for(i=n-1;i>0;i--)
		*(p+i)=*(p+i-1);
	*p=t;
	m--;
	if(m>0)
		move(p,n,m);

}


void main()
{int f(int a,int n,int m);
	int a[100],i,j=1,n,m;
scanf("%d%d",&n,&m);for(i=1;i<=n;i++) scanf("%d",&a[i]);
a[0]=a[1];for(i=1;i<=n-1;i++){a[j]=a[f(j,n,m)];j=f(j,n,m);}a[j]=a[0];
printf("%d",a[1]);for(i=2;i<=n;i++)printf(" %d",a[i]);printf("\n");

}
int f(int a,int n,int m)
{if(a<=m) return (a+n-m);
else return (a-m);}


void UpsideDown (int *, int);
int main()
{
    int a[105], n, m,i;
    int *p=NULL;
     scanf("%d %d",&n,&m);
   for(i=0;i<n;i++)
      scanf("%d",&a[i]);
    p = a;
    UpsideDown(p, n);
    UpsideDown(p, m);
    UpsideDown(p+m, n-m);
    for(i=0;i<n-1;i++)
     printf("%d ",a[i]);
	printf("%d",a[n-1]);
    return 0;
}
void UpsideDown(int *a, int k)
{
    int temp;
    int *p, *q;
    for (p = a, q = a + k; p < q; p++, q--)
    {
        temp = *p; *p = *q; *q = temp;
    }
}


int main()
{
    int n, m;
    cin >> n >> m;
    int a[2*n];
    int *p = NULL, *q = NULL;
    for ( p = a; p < a+n; p++ )
        cin >> *p;
    for ( q = a, p = a+n; q < a+n-m; p++, q++ )
        *p = *q;
    p = a+n-m;
    cout << *p;
    for ( p = a+n-m+1; p < a+n+n-m; p++ )
        cout << " " << *p;

    return 0;
}


void move(int a[],int n,int m);
int main ()
{
	int n,m;
	int a[100];
	scanf("%d%d",&n,&m);
	getchar();

	int *p;
	for(p=a;p<(a+n);p++)
		scanf("%d",p);
	move (a,n,m);
	for(p=a;p<(a+n-1);p++)
		printf("%d ",*p);
	printf("%d",*p);
	return 0;
}
void move(int a[],int n,int m)
{
	int *p,temp;
	temp=*(a+n-1);
	for(p=a+n-1;p>a;p--)
		*p=*(p-1);
	*a=temp;
	m--;
	if (m>0)
		move(a,n,m);
}


void main(){
int i,n,m;
	scanf("%d %d",&n,&m);
int *p=(int*)malloc(sizeof(int)*n);
for(i=0;i<n;i++)
scanf("%d",p+i);
for(i=n-m;i<2*n-m;i++){
	printf("%d",*(p+i%n));
if(i==2*n-m-1)
break;
else printf(" ");
}
free(p);
}


//????????????
void move(int num[30],int n,int m)
{
	int *p;
	int end,j;
	end=*(num+n-1);
	for(j=1;j<=m;j++)
	{

		end=*(num+n-1);
		for(p=num+n-1;p>num;p--)
		{
			*p=*(p-1);
		}
			*num=end;
	}

}
/*void move(int num[30],int n,int m)
{
	int *p;
	int end;
	end=*(num+n-1);
	for(p=num+n-1;p>num;p--)
	{
		*p=*(p-1);
	}
		*num=end;
	m--;
	if(m>0)
	{
		move(num,n,m);
	}

}*/

int main()
{
	int n,m,i;
	int a[30];
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	move(a,n,m);
	for(i=0;i<n;i++)
	{
		printf("%d",a[i]);
		if(i!=n-1)
		{
			printf(" ");
		}
	}
	return 0;
}


int main()
{
     int n,m,i,j;
     cin>>n>>m;
     int a[n];
     for (i=0;i<n;i++)
          cin>>a[i];
     int *p=a,*q=&a[n-m],*t=NULL;
     for (t=q;t<q+m;t++)
         cout<<*t<<' ';
     for (t=p;t<p+n-m-1;t++)
         cout<<*t<<' ';
     cout<<*t<<endl;
     return 0;
}


void main()
{
	int num[100];
	int i,n,m,temp;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)scanf("%d",&num[i]);
	for(i=0;i<n-m;i++)
	{
		temp=num[i];
		num[i]=num[n+i];
		num[n+i]=temp;
	}
	for(i=0;i<n;i++)num[i]=num[n-m+i];
	printf("%d",num[0]);
	for(i=1;i<n;i++)printf(" %d",num[i]);
}


int main()
{
     int m,n,i;
     scanf("%d%d",&n,&m);
	 int *pi;
     pi=(int*)malloc(sizeof(int)*(2*n-m));
	 for (i=0;i<n;i++)
	 {
		 scanf("%d",pi+i);
	 }
     for (i=0;i<n-m;i++)
	 {
		 *(pi+i+n)=pi[i];
	 }
	 printf("%d",pi[n-m]);
	 for(i=n-m+1;i<2*n-m;i++)
	 {
		 printf(" %d",pi[i]);
	 }
	 free (pi);
	return 0;
}


int main(int argc, char* argv[])
{
	int n,m,i,j,k;
	scanf("%d %d",&n,&m);
	int *p,*D;
	p=(int *)malloc(sizeof(int) * n);
	D=(int *)malloc(sizeof(int) * n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&p[i]);
	}

	for(j=0;j<n;j++)
	{
		if(j<=(m-1))
			D[j]=p[n-m+j];
		if(j>(m-1))
			D[j]=p[j-m];
	}

	for(k=0;k<n;k++)
	{
		if(k<(n-1))
		printf("%d ",D[k]);
		else
			printf("%d",D[k]);

	}

	return 0;
}


void main()
{
	int n,m,huan,i;

	int *p,*t;
	scanf("%d %d",&n,&m);
    if((t=(int *)malloc((2*n-m)*sizeof(int)))==NULL)
	{
		printf("No space avaible!");

	}
	for (p=t;p<t+n;p++)
	{
		scanf("%d",p);
	}
	for (i=0;i<n-m;i++)
	{

		t[n+i]=t[i];
	}
	for (p=t+n-m;p<t+(2*n-m-1);p++)
		printf("%d ",*p);
	printf("%d",*p);
}


void play(int n[],int l);

int main()
{
	int n,m,i;
	int num[100];
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%d",&num[i]);
	for(i=1;i<=m;i++)
	    play(num,n);
	for(i=0;i<n;i++)
	{
		if(i!=0)
			printf(" ");
		printf("%d",num[i]);
	}
	printf("\n");
	return 0;
}

void play(int n[],int l)
{
	int k,t;
	t=n[l-1];
	for(k=l-1;k>0;k--)
		n[k]=n[k-1];
	n[0]=t;
}


void convert(int n,int a[30])
{
 int i,t;
 for(i=n;i>1;i--)
 {
  t=a[i];
     a[i]=a[i-1];
     a[i-1]=t;
 }
}
void main()
{
 int m,n,i,j,a[30];
 scanf("%d %d",&m,&n);
 for(i=1;i<=m;i++)
  scanf("%d",&a[i]);
 for(j=0;j<n;j++)
  convert(m,a);
 for(i=1;i<=m;i++)
	 if(i==m)
		 printf("%d",a[i]);
	 else
  printf("%d ",a[i]);
}


void *malloc(unsigned int size);
void main()
{
	int m,n,*p,*a,i=0;
	a = (int *)malloc(200*sizeof(int));
	scanf("%d%d",&n,&m);
	while(i<n)scanf("%d",a+(i++));
	p=a+n,i=0;
	while(i<n-m)*(p+i++)=*(a+i);
	p=a+n-m;
	for(i=0;i<n;i++)
	{
		if(i>0)printf(" ");
		printf("%d",*(p+i));
	}
}


int main()
{
  int i,j,x[100],n,m;
  void px(int n,int array[100]);
  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++)
    scanf("%d",&x[i]);
  for(i=1;i<=m;i++)
    px(n-1,x);
  printf("%d",x[0]);
  for(i=1;i<n;i++)
   printf(" %d",x[i]);

  return 0;
}

void px(int n,int array[100])
{
 int t,i;
 t=array[n];
 for(i=n-1;i>=0;i--)
   array[i+1]=array[i];
 array[0]=t;
}


int main(int argc, char *argv[])
{
    int m,n;       int i,j,k;
    cin >> m >> n;
    int ary[m];
    for(i=0; i<m; i++){
             cin >> ary[i];
    }
    for(j=1; j<=n; j++){
             int temp;
             temp= ary[m-1];
             for(k= m-1; k>0; k--){
                      ary[k] =ary[k-1];
             }
             ary[0] = temp;
    }
    for(i=0; i<m; i++){
             cout << ary[i];
             if(i!=m-1)
             {         cout << " ";}
    }

    return EXIT_SUCCESS;
}


void swap(int *p,int *q)//???????
{
	int *temp=p;
	p=q;
	q=temp;
	return;
}
int main()
{
	int m,n,a[100],temper=0;//????
	cin>>n>>m;//??
	for(int i=0;i<n;i++)
		cin>>a[i];
	int s=m;
	while(m>0)//??????
	{
		swap(a[n-m],temper);
		for(int j=n-m;j>s-m;j--)
			swap(a[j],a[j-1]);
		swap(a[s-m],temper);
		m--;
	}
	for(int i=0;i<n-1;i++)//??
		cout<<a[i]<<" ";
	cout<<a[n-1]<<endl;
	return 0;
}


void main()
{
	int m,n;
	int num[100];
	int temp;
	int i,k,j;

	scanf("%d %d",&n,&m);
	for (i=0;i<n;i++)
		scanf("%d",&num[i]);
	for (i=0,k=1;k<=m;i++,k++)
	{
		temp=num[i];
		num[i]=num[n-m+k-1];
		for (j=0;j<n-m;j++)
		{
			num[n-m+k-1-j]=num[n-m+k-1-j-1];
		}
		num[i+1]=temp;
	}
	for (i=0;i<n;i++)
	{
		if (i!=0)
			printf(" %d",num[i]);
		else if (i==0)
			printf("%d",num[i]);
	}
}


void main()
{
	int i,m,n;
	int zz[1000];
	cin>>n>>m;
	for(i=m;i<m+n;i++)
		cin>>zz[i];
	for(i=n;i<m+n;i++)
		zz[i-n]=zz[i];
	for(i=0;i<n-1;i++)
		cout<<zz[i]<<" ";
	cout<<zz[n-1]<<endl;

}


int main()
{
    int n,m,temp;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for (int i=0;i<m;i++)
    {
        for (int j=0;j<n-1;j++)
        {
            temp=a[n-1];
            a[n-1]=a[j];
            a[j]=temp;
        }
    }
    for(int i=0;i<n;i++)
    {
            cout<<a[i];
            if(i!=n-1)
            cout<<" ";
    }
}