#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
FILE *fin,*fout;
char *s[2];
int l1,l2,lmax=0,i,j;
fin=fopen("subsir.in","r");
s[0]=(char *)malloc(501*sizeof(char));
s[1]=(char *)malloc(501*sizeof(char));
fgets(s[0],501,fin);
s[0][strcspn(s[0],"\n")]='\0';
fgets(s[1],501,fin);
s[1][strcspn(s[1],"\n")]='\0';
fclose(fin);
l1=strlen(s[0]);
l2=strlen(s[1]);
for(i=0;i<l1;i++){
for(j=0;j<l2;j++){
int k=0;
while((i+k<l1)&& (j+k<l2)&&(s[0][i+k]==s[1][j+k])){
k++;
}
if(k>lmax){
lmax=k;
}
}
}
if (lmax==0){
printf("Siruri total diferite");
fout=fopen("subsir.out","w");
fprintf(fout,"0");
fclose(fout);
return 0;
}
int cautare=0;
for(i=0;i<l1-lmax;i++){
int dup = 0;
for(int c = 0; c < i; c++){
if(strncmp(&s[0][c], &s[0][i], lmax) == 0){
dup = 1;
break;
}
}
if(dup == 0){
for(j = 0; j <= l2 - lmax; j++){
if(strncmp(&s[0][i], &s[1][j], lmax) == 0){
cautare++;
break;
}
}
}
}
fout=fopen("subsir.out","w");
fprintf(fout,"%d",cautare%666013);
fclose(fout);
free(s[0]);
free(s[1]);
return 0;
}