Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".To play Mau-Mau, you need a pack of $$$52$$$ cards. Each card has a suit (Diamonds — D, Clubs — C, Spades — S, or Hearts — H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.

The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand. Each string is two characters long. The first character denotes the rank and belongs to the set $$$\{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}$$$. The second character denotes the suit and belongs to the set $$$\{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}$$$. All the cards in the input are different.

If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO". You can print each letter in any case (upper or lower).

NoteIn the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.In the second example, you cannot play any card.In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table.

#include<stdio.h>
int main()
{
    char a[3],b[3];
    int c=0;
    scanf("%s",a);
    for(int i=0;i<5;i++)
    {
        scanf("%s",b);
        if(a[0]==b[0] || a[1]==b[1])
            c++;
    }
    if(c>0)
        printf("YES");
    else
    {
        printf("NO");
    }

}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,x=0;
    char F[2] ;
    char H[2];

    scanf("%s" ,F );

    for (i=0 ;i<=4 ;i++)
    {
        scanf("%s", H);
         if ((H[0]==F[0]) || (H[1]==F[1]))

               x++;

    }
    if (x>0)
            printf("Yes");

      else
           {
            printf("No");
           }

    return 0;
}

#include<stdio.h>
int main(){
char a,b,w;
int count=0;
scanf("%c%c%c",&a,&b,&w);
for(int i=0;i<5;i++){
char c,d;
scanf("%c%c%c",&c,&d,&w);
if(a==c || b==d){
	printf("YES");
	break;}
else
	count++;
}
if(count==5)
	printf("NO");
return 0;
}

#include<stdio.h>
int main()
{
	char a[2];
	char b[5];
	int i,cnt=0;
	scanf("%s",a);
	for(i=0;i<5;i++)
	{
		scanf("%s",b);
		if(a[0]==b[0]||a[1]==b[1])
		{
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
	return 0;
}

#include<stdio.h>
int main()
{
int i,cnt=0;
char a[2];
char b[2];
scanf("%s",a);
for(i=0;i<5;i++)
{
scanf("%s",b);
if(a[0]==b[0]||a[1]==b[1]){
cnt=1;
break;
}
}
if(cnt==1)
printf("YES");
else
printf("NO");
}

#include <stdio.h>

int main(){
    char tab1[3] = {0};
    char tab2[3] = {0};
    scanf("%s", tab1);

    for(int i=0; i<5; i++)
    {
        scanf("%s", tab2);
        if(tab1[0] == tab2[0] || tab1[1] == tab2[1])
        {
            printf("YES");
            return 0;
        }
    }
    printf("NO");
    return 0;
}

#include<stdio.h>
#include<strings.h>
#include<stdlib.h>
int main()
{
    int i,j;
    char s[3];
    char t[6][2];
    scanf("%s",s);
    for(i=0;i<5;i++)
    scanf("%s",t[i]);
    for(j=0;j<5;j++)
    {
      if(s[0]==t[j][0]||s[1]==t[j][1])
      {printf("YES");
      return 0;
      }

    }
    printf("NO");
    return 0;
}

#include <stdio.h>

int main()
{
	char orta[3];
	char el1[3];
	char el2[3];
	char el3[3];
	char el4[3];
	char el5[3];

	scanf("%s", orta);
	scanf("%s", el1);
	scanf("%s", el2);
	scanf("%s", el3);
	scanf("%s", el4);
	scanf("%s", el5);

	if (el1[0] == orta[0] || el1[1] == orta[1]){
		printf("YES");
		return 0;
	}

	if (el2[0] == orta[0] || el2[1] == orta[1]){
		printf("YES");
		return 0;
	}

	if (el3[0] == orta[0] || el3[1] == orta[1]){
		printf("YES");
		return 0;
	}

	if (el4[0] == orta[0] || el4[1] == orta[1]){
		printf("YES");
		return 0;
	}

	if (el5[0] == orta[0] || el5[1] == orta[1]){
		printf("YES");
		return 0;
	}

	else{
		printf("NO");
	}

}

#include <stdio.h>
#include <stdlib.h>

int main () {
    char card1[2],card2[2];
    int i=0,ans=0;
    scanf("%c%c\n",&card1[0],&card1[1]);
    while(i<10) { // 對手的牌
        scanf("%c%c\n",&card2[0],&card2[1]);
        if(card2[0] == card1[0])
            ans++;
            if(card2[1] == card1[1])
                ans++;
        i++;
    }
    if (ans > 0)
        printf("YES");
    else
        printf("NO");
    return 0;
}

#include<stdio.h>

int main()
{
    char name[3], test[3];
    int i, j, a, length, count = 0,b;

    scanf("%s", name);

    for(i=1; i<=5; i++)
    {
        scanf("%s", test);

        if(test[0] == name[0])
        {

            count = 1;
        }
        else if((test[0] == name[0]) && (test[1] == name[1]))
        {

            count = 1;
        }
        else if(test[1] == name[1])
        {
            count = 1;

        }
    }

    if(count == 1)
    {

        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }

    return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    int n,i,count=0;
    char str[2],str_[2];
    scanf("%c%c", &str_[0], &str_[1]);
    for(i=1;i<=5;i++)
    {
        scanf(" %c%c", &str[0], &str[1]);

        if(str[0]==str_[0] || str[1]==str_[1])
        {
            count++;
        }
    }
    if(count>=1)
            printf("YES\n");
            else
                printf("No\n");

    return 0;
}

#include<stdio.h>
int main(void)
{
	char b[2][3];
	char a[6][3];
	int x,y;
	int flag=0;

	scanf("%c%c",&b[1][1],&b[1][2]);
	getchar();

	for(x=0;x<5;x++)
	{
		scanf("%c%c",&a[x][1],&a[x][2]);
		getchar();
		if(a[x][1]==b[1][1]) flag=1;
		if(a[x][2]==b[1][2]) flag=1;
		if(flag==1) break;
	}

	if(flag==1) printf("YES\n");
	else printf("NO\n");

	return 0;
}

 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct liste{
    char name[30];
    struct liste *next;
};
typedef struct liste *liste ;
liste creation(int n){
    liste head,tmp,pt;
         head=malloc(sizeof(struct liste));
         scanf("%s",head->name);
        if(strlen(head->name)!=2)exit(EXIT_FAILURE);
            head->next=NULL;
            pt=head;
     for(int i=1;i<n;i++){
           tmp=malloc(sizeof(struct liste));
           scanf("%s",tmp->name);
           if(strlen(head->name)!=2)exit(EXIT_FAILURE);
           tmp->next=NULL;
           pt->next=tmp;
           pt=tmp;
     }
      return head;

}
int traitement(char card[],liste L){
    int i=0;

liste p;

    do{
        p=L;
             while(p){
                if(card[i]==p->name[i]){
                 printf("YES");
                return 0;
                                }
                                p=p->next;
             }
             i++;

    }while(i<2);

    printf("NO");
}
 int main(){
char card[2];
liste L;
 scanf("%s",card);
 if(strlen(card)!=2)return 0;
 L=creation(5);
   traitement(card,L);

}

#include<stdio.h>
#include<string.h>

int main()
{
	char a[5];
	char b[50];

	gets(a);
	gets(b);

	for(int i=0;a[i]!='\0';i++)
	{
		for(int j=0;b[j]!='\0';j++)
		{
			if(a[i]==b[j])
			{
				printf("YES");
				return 0;
			}
		}
	}
	printf("NO");

	return 0;
}

#include<stdio.h>
main()
{
	int n, i, c = 0, d = 0;
	char a[2], b[14];
	gets(a);
	gets(b);
	for (i = 0; i < 14; i++)
	{
		if (a[0] == b[i] || a[1] == b[i])
			c++;
	}
	if (c > 0)
		printf("YES\n");
	else
		printf("NO\n");
}

#include<stdio.h>
int main()
{
	char a[5],b[5];
	int i,c=0;
	scanf("%s",b);
	for(i=0;i<5;i++)
	{
		scanf("%s",a);
		if (a[0]==b[0]||a[1]==b[1])
			c=1;
	}
	if(c==1)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

#include<stdio.h>
int main()
{
    char a[3],result;
    scanf("%s",&a);
    char b[3],b1[3],b2[3],b3[3],b4[3];
    scanf("%s %s %s %s %s",&b,&b1,&b2,&b3,&b4);
    int i=0;
    while(a[i]!=0)
    {
        result=a[i];
        int j=0;
        char count;
        while(b[j]!=0)
        {
            count=b[j];
            if(result==count)
            {
                printf("YES\n");
                exit(0);
            }
            j=j+1;
        }
        int k=0;
        while(b1[k]!=0)
        {
            count=b1[k];
            if(result==count)
            {
                printf("YES\n");
                exit(0);
            }
            k=k+1;
        }
        int l=0;
        while(b2[l]!=0)
        {
            count=b2[l];
            if(result==count)
            {
                printf("YES\n");
                exit(0);
            }
            l=l+1;
        }
        int m=0;
        while(b3[m]!=0)
        {
            count=b3[m];
            if(result==count)
            {
                printf("YES\n");
                exit(0);
            }
            m=m+1;
        }
        int n=0;
        while(b4[n]!=0)
        {
            count=b4[n];
            if(result==count)
            {
                printf("YES\n");
                exit(0);
            }
            n=n+1;
        }
        i=i+1;

    }
    printf("NO\n");
}

#include<stdio.h>
int main(){
	char t[3],h[3];
	int i,count = 0;
	scanf("%s",t);
	for(i=0;i<5;i++){
		scanf("%s",h);
		if(h[0]==t[0] || h[1]==t[1]){
			count = 1;
		}
	}
	 if(count == 1){
	     printf("YES");
	 }else {
	      printf("NO");
	 }

}

#include<stdio.h>
#include<string.h>
int main(void)
{
    char r, s;
    char a, b;
    int flag = 0;
    scanf("%c%c", &a, &b);
    getchar();
    for(int i = 0; i < 5; i++)
    {
        scanf("%c%c", &r, &s);
        getchar();
        if(r == a || b == s) flag = 1;
    }
    if(flag)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

#include<stdio.h>
int main()
{
    char ch[2],c[2];
    scanf("%s",ch);
    int n=5,count=0;
    while(n--)
    {
        scanf("%s",c);
        if((c[0]==ch[0])||(c[1]==ch[1]))
        count++;
    }
    if(count>0)
    printf("YES");
    else
    printf("NO");
    return 0;
}

#include<stdio.h>
int main()

{
    int i,count=0;
   char s[3],a[3];
   scanf("%s",s);
   for(i=0;i<5;i++)
   {
     scanf("%s",a);
     if(s[0]==a[0]||s[1]==a[1])
     {
         count=1;
     }
   }
   if(count)
   {
       printf("YES");
   }
   else
   {
       printf("NO");
   }
   return 0;

}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,x=0;
    char F[2] ;
    char H[2];

    scanf("%s" ,F );

    for (i=0 ;i<=4 ;i++)
    {
        scanf("%s", H);
         if ((H[0]==F[0]) || (H[1]==F[1]))

               x++;

    }
    if (x>0)
            printf("Yes");

      else
           {
            printf("No");
           }

    return 0;
}

#include<stdio.h>
#include<string.h>
int main()

{
    int i,l,flag=0;
    char s[12];
    char a,b;
    scanf("%c%c",&a,&b);
    scanf("\n");
    scanf("%[^\n]s",&s);
    l=strlen(s);
    for(i=0;i<=l-1;i++)
    {
        if(a==s[i]||b==s[i])
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    printf("YES");
    else printf("NO");
    return 0;
}

#include<stdio.h>
int main()
{
    char a[3],b[3];
    int c=0;
    scanf("%s",a);
    for(int i=0;i<5;i++)
    {
        scanf("%s",b);
        if(a[0]==b[0] || a[1]==b[1])
            c++;
    }
    if(c>0)
        printf("YES");
    else
    {
        printf("NO");
    }

}

#include<stdio.h>
int main()
{
    int i,j,n;
    char a[3];
    char b[3];
    scanf("%s",a);
    for(i=0;i<5;i++){
        scanf("%s",b);

        if(a[0]==b[0] || a[1]==b[1]){
            printf("YES\n");
            return 0;
        }
    }

    printf("NO\n");
    return 0;
}

#include<stdio.h>
int main()
{
int i,cnt=0;
char a[2];
char b[2];
scanf("%s",a);
for(i=0;i<5;i++)
{
scanf("%s",b);
if(a[0]==b[0]||a[1]==b[1]){
cnt=1;
break;
}
}
if(cnt==1)
printf("YES");
else
printf("NO");
}

#include<stdio.h>
int main(){
char a,b,w;
int count=0;
scanf("%c%c%c",&a,&b,&w);
for(int i=0;i<5;i++){
char c,d;
scanf("%c%c%c",&c,&d,&w);
if(a==c || b==d){
	printf("YES");
	break;}
else
	count++;
}
if(count==5)
	printf("NO");
return 0;
}

#include<stdio.h>
int main()
{
int i,b=0;
	char s[5],d[5];

	scanf("%s",d);
	for(int j=0;j<5;j++)
	    {
		   scanf("%s",s);
	       if(s[0]==d[0])
	        {
		       b++;
		         break;
		     }

	    else
	   {
		  if(s[1]==d[1])
		  {
		   b++;
		   break;

     	}
    }
   }

	if(b>0)
	printf("YES");
	else
	printf("NO");

	return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{

	int i = 0, j = 0;
	char table[2];
	char hand[15];
	for(i = 0;i<2;i++)
	{
		table[i]= 0;
	}
	for(j = 0;j<15;j++)
	{
		table[j]= 0;
	}
	gets(table);
	gets(hand);

	for (j = 0; j < 2; j++)
	{
		for (i = 0; i < 15; i++)
		{
			if (table[j] == hand[i])
			{
				printf("YES");
				exit(0);
			}

		}

	}
	printf("NO");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char a[2];int temp=0;
    scanf("%s",a);
    char n[5][2];
    for(int i=0;i<5;i++)
    {
        scanf("%s",n[i]);
    }
    for(int i=0;i<5;i++)
    {

        if(a[0]==n[i][0] || a[1]==n[i][1])
        {
            temp++;break;
        }
    }
    if(temp>0)
    {

        printf("YES");

    }else{
    printf("NO");
    }
    return 0;
}

#include <stdio.h>

int main(){
    char tab1[3] = {0};
    char tab2[3] = {0};
    scanf("%s", tab1);

    for(int i=0; i<5; i++)
    {
        scanf("%s", tab2);
        if(tab1[0] == tab2[0] || tab1[1] == tab2[1])
        {
            printf("YES");
            return 0;
        }
    }
    printf("NO");
    return 0;
}

#include <stdio.h>
#include <conio.h>
#include <math.h>
int main ()
{
	char tc[3] , hc[3] ;
	int c = 0 ;
	scanf (" %s " , tc ) ;
	for ( int i = 1 ; i <= 5 ; i++ )
	{
		scanf( " %s " , hc) ;
		if ( tc[0] == hc[0] || tc[1] == hc[1] )
		{
			c++ ;
		}
	}
	if ( c == 0 )
		printf("NO");
	else
		printf("YES");
	return 0 ;
}

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
int main(){
int t=0;
char a[3],b[3];
scanf("%s",&a);
for(int i=1;i<=5;i++){
scanf("%s",&b);
if((b[0]==a[0])||(b[1]==a[1]))
    {
        t++;
    }
}
if(t==0){
    printf("NO");
}
else
    printf("YES");
return 0;
}

#include<stdio.h>
int main()
{
char str[2],str1[5];
int count=0,i,j,p;
scanf("%s",str);
for(i=0;i<5;i++)
{
    scanf("%s",str1);
    p=0;
    for(j=0;j<2;j++,p++)
    {
    if(str[p]==str1[j])
    count=count+1;
    }
    }
    if(count>0)
    printf("Yes");
    else
    printf("No");
return 0;
}

typedef struct {
    char rank,suit;
} card;
int main() {
    card c1, c2[5];
    scanf("%c%c",&c1.rank,&c1.suit);
    int i;
    for(i=0;i<5;i++) {
        scanf("%*c%c%c",&c2[i].rank,&c2[i].suit);
        if(c1.rank==c2[i].rank || c1.suit==c2[i].suit) {
            printf("YES");
            return 0;
        }
    }
    printf("NO");
    return 0;
}

#include<stdio.h>
int main()
{
    int j,c=0;
    char ac[2],pn[2];
        scanf("%s",&ac);
        for(j=0;j<5;j++)
        {
            scanf("%s",&pn);
            if(ac[0]==pn[0] || ac[1]==pn[1])
            c++;
        }

    if(c>0)
        printf("YES");
    else
        printf("NO");
    return 0;

}

#include<stdio.h>

int main()
{
	char target[2],mine[2];
	int j,i,k=0;

	gets(target);

	for (i = 0; i < 5; ++i)
	{

		scanf("%s",mine);

		if(k==0 && (target[0]==mine[0] || target[1]==mine[1]))
		{
			k=1;
		}
	}

	if(k)
		printf("YES");
	else
		printf("NO");
}

#include <stdio.h>
int main()
{
  char a[2];
  scanf("%s",a);
  char b[2];
  int i,flag=0;
  for(i=1;i<=5;i++)
  {
    scanf("%s",b);
    if(a[0]==b[0] || a[1]==b[1])
    {
      flag=1;
      break;
    }
  }
if(flag==1)
  printf("YES");
else
  printf("NO");

}

#include <stdio.h>
#include <string.h>

void fchaine(char *string)
{
    int i,n;
    char L;

    n = strlen(string);

    for(i=0;i<n/2;i++)
    {
        L = string[i];
        string[i] = string[n-i-1];
        string[n-i-1] = L;
    }
}

int main(void)

{
    int c,i;
    char c1[10],invc1[10];
    char c2[10][10],invc2[10][10];

    scanf("%s",c1);

    strcpy(invc1,c1);
    fchaine(invc1);

    c=0;

    for (i=0;i<5;i++)
    {
        scanf ("%s",c2[i]);

        if (strncmp(c1,c2[i],1)==0)
            c++;

        strcpy(invc2[i],c2[i]);
        fchaine(invc2[i]);

        if (strncmp(invc1,invc2[i],1)==0)
            c++;
    }

    if (c==0)
        printf ("NO");
    if (c>0)
        printf ("YES");

}

#include<stdio.h>
int main()
{
	int c=1;
		char first,last;
	scanf("%c",&first);
	scanf("%c",&last);
	while(c<=5)
	{
		char a,b,sp;
		scanf("%c",&sp);
		scanf("%c",&a);
		scanf("%c",&b);
		if((a==first)||(b==last))
		{
			printf("YES");
			return 0;
		}
		c++;
	}
	printf("NO");
	return 0;
}

#include <stdio.h>
int main() {
	char s[2],k[2];int m;
	m=0;
	scanf("%s",s);
	printf("\n");
	for(int i=1;i<=5;i++)
	{
		scanf("%s ",k);
		if((k[0]== s[0])||(k[1]==s[1]))
		m=1;
		}
		if(m==1)
		printf("YES");
		else
		printf("NO");
	return 0;
}

#include<stdio.h>
#include<string.h>

int main()
{
    char s[2];
    char a[2];
    char s1[2];
    scanf("%s",s);
    a[1]=s[0];
    a[2]=s[1];
    int i,count=0;
    for(i=1;i<=5;i++){
        scanf("%s",s1);
        if(a[1]==s1[0])
            count=1;
        if(a[2]==s1[1])
            count=1;
    }
    if(count)
        printf("YES");
    else
        printf("NO");
    return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{ int c=0,n=5;
   char a[3],b[3];
				scanf("%s",a);
				while(n--)
				{
			scanf("%s",b);
								if(a[0]==b[0]||a[1]==b[1])

												c=1;
				}

c?printf("YES"):printf("NO");
return 0;
}

#include<stdio.h>
int main(){
    int n = 5;
    char a,b,c,d;
    scanf("%c%c\n",&a,&c);
    while(n--){
        scanf("%c%c ",&b,&d);
        if(a == b || c == d){
            printf("YES");
            return 0;
        }
    }
    printf("NO");
    return 0;
}

#include<stdio.h>
int main(){
	char a,b,c,d;
	scanf("%c%c\n",&a,&b);
	int i,f;
	f=0;
	for(i=0;i<5;i++){
	scanf("%c%c ",&c,&d);
	if(a==c||b==d){
		f=1;
	}
	}
	if(f==1){
	printf("YES");
	}
	else{
	printf("NO");
	}
	return 0;
}

#include<stdio.h>
int main()
{
    char a[3],b[3];
    int c=0;
    scanf("%s",a);
    for(int i=0;i<5;i++)
    {
        scanf("%s",b);
        if(a[0]==b[0] || a[1]==b[1])
            c++;
    }
    if(c>0)
        printf("YES");
    else
    {
        printf("NO");
    }

}

#include<stdio.h>
#include<string.h>
char str[100];
int main()
{
    char table[3],card[3];
    int n;
    scanf("%s", table);
    for(n=0;n<5;n++)
    {
        scanf("%s", card);
        strcat(str, card);
    }
    for(n=0;str[n];n++)
    {
        if(table[0]==str[n] || table[1]==str[n])
        {
            printf("YES");
            return 0;
        }
    }
    printf("NO");
}

#include<stdio.h>
#include<string.h>
int main()
{
    int i,count=0;
    char str1[2],str2[100];
    scanf("%s",str1);
    getchar();
        gets(str2);
        for(i=0;i<strlen(str2);i++)
        {
            if(str2[i]==str1[0] || str2[i]==str1[1])
                count++;
        }
        if(count>0)
            printf("YES");
        else
            printf("NO");
        return 0;

}

#include<stdio.h>
int main()
{
int n=0;
char f,l,q;
scanf("%c",&f);
scanf("%c",&l);
scanf("%c",&q);
char a,b,c;
while(n<5)
{
scanf("%c",&a);
scanf("%c",&b);
scanf("%c",&c);
if((f==a)||(l==b))
{
printf("yes\n");
return 0;
}
n++;
}
printf("no\n");
return 0;
}

#include<stdio.h>
#include<string.h>

int main()
{
    char name[3], test[3], ans[] = "23456789TJQKA";
    int i, j, a, length, count = 0,b;

    length = strlen(ans);

    scanf("%s", name);

    for(i=1; i<=5; i++)
    {
        scanf("%s", test);

        if(test[0] == name[0]){

            count = 1;
        }
        else if(test[1] == name[1]){

            for(j=0; j<length; j++){

                if( (name[0] == ans[j])){

                    a = (j+1);
                }
                if(test[0] == ans[j]){

                    b = (j+1);
                }
            }

            if(b>=a){

                count = 1;
            }
        }
    }

    if(count == 1){

        printf("YES\n");
    }
    else{
        printf("NO\n");
    }

    return 0;
}

#include <stdio.h>

int main() {
	char T[3];
	printf("please Enter");
	scanf("%s", T);
	char hand[5][3];
	int i;
	int flag=1;
	for(i=0;i<5;i++){
		scanf("%s", hand[i]);
	}
	for(i=0;i<5;i++){
		if((hand[i][0]==T[0] )||(hand[i][1]==T[1] )){
			printf("YES");
			flag=0;
			break;

		}

	}
	if(flag){
		printf("NO");
	}
}

#include<stdio.h>
int main()
{
int n=0;
char f,l,q;
scanf("%s",&f);
scanf("%s",&l);
char a,b,c;
while(n<5)
{
scanf("%s",&a);
scanf("%s",&b);
scanf("%s",&c);
n++;
}
if((f==b)||(l==c))
{
printf("YES");
}
else
{
printf("NO");
}
}

#include<stdio.h>
#include<string.h>
int main(){
char a[2];
char b[2];
gets(a);
int i,sum=0;
for(i=1;i<6;i++){
gets(b);
if((a[0]==b[0])||(a[1]==b[1]))
{
    sum++;
}
else
{
    continue;
}
}
if(sum>0)
{
    printf("YES");
}
else{
    printf("NO");
}
return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{

	int i, j;
	char temp;
	char table[2] = { 0 };
	char hand[15] = { 0 };
	gets(table);
	gets(hand);

	for (j = 0; j < 2; j++)
	{
		temp = table[j];
		for (i = 0; i < 15; i++)
		{
			if (temp == hand[i])
			{
				printf("YES");
				break;

			}
			else
			{
				printf("NO");
				break;

			}
			break;
		}
		break;

	}

	return 0;

}

#include<stdio.h>
#include<string.h>

int main()
{
    char s[2];
    char a[2];
    char s1[2];
    scanf("%s",&s);
    s[0]==a[0];
    s[1]==a[0];
    int i,count;
    for(i=1;i<=2;i++){
        scanf("%s",s1);
        if(s1[0]==a[0])
        {
            count=1;
        }
        else if(s1[1]==a[1])
        {
            count=1;
        }
    }
    if(count)
        printf("YES");
    else
        printf("NO");
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// <<<<< Macros <<<<<
#define BUFFERSIZE 255
#define BUFFERSIZEREAD BUFFERSIZE - 1
#define STACKSIZE 4
#define STACKSIZEREAD STACKSIZE - 1
// >>>>> Macros >>>>>

// <<<<< Preparations <<<<<
#ifdef __unix__
void fflush_for_linux() {
    /*
     * This will work like "fflush()" on stdin, because the normal one doesn't work on linux.
     */

    int character;
    do {
        character = getchar();
    } while (character != '\n' && character != EOF);
}
#endif
// >>>>> Preparations >>>>>

// <<<<< Declarations <<<<<
short same_suit(const char *buffer, char suit_value);
short same_rank(const char *buffer, char rank_value);
// >>>>> Declarations >>>>>

int main() {

    char buffer[BUFFERSIZE];
    char stack[STACKSIZE];

    fgets(stack, STACKSIZEREAD, stdin);

#ifdef __unix__
    fflush_for_linux();
#else
    fflush(stdin);
#endif

    fgets(buffer, BUFFERSIZEREAD, stdin);

    if (same_suit(buffer, stack[1]) == EXIT_SUCCESS
        || same_rank(buffer, stack[0]) == EXIT_SUCCESS)
        printf("YES\n");
    else
        printf("NO\n");

    return EXIT_SUCCESS;
}

short same_suit(const char *buffer, char suit_value) {

    register short index = 0;

    while (buffer[index] != '\0') {

        if (buffer[index++] == suit_value)
            return EXIT_SUCCESS;
    }

    // Couldn't find the same suit
    return EXIT_FAILURE;
}

short same_rank(const char *buffer, char rank_value) {

    register short index = 0;

    while (buffer[index] != '\0') {

        if (buffer[index++] == rank_value)
            return EXIT_SUCCESS;
    }

    return EXIT_FAILURE;

}

#include <stdio.h>
#include <stdbool.h>
int main (void)
{
	bool test = false ;
	char card[2] , hand_cards[10];
	int i,x ;
	gets(card);
	gets(hand_cards);
	for(i=0 ; i<2 ; i++)
	{
		for(x=0; x<10 ; x++)
		{
		if(card[i]== hand_cards[x])
		{
			test = true ;
			break ;
		}
		}
	}
	if (test)
		printf("yes");
	else
		printf("no");

}

#include <stdio.h>
#include <stdbool.h>
int main (void)
{
	bool test = false ;
	char card[2] , hand_cards[20];
	int i,x ;
	scanf("%s",card);
	scanf("%s",hand_cards);
	for(i=0 ; i<2 ; i++)
	{
		for(x=0; x<10 ; x++)
		{
		if(card[i]== hand_cards[x])
		{
			test = true ;
			break ;
		}
		}
	}
	if (test)
		printf("yes");
	else
		printf("no");

}

#include<stdio.h>
int main()
{
    int i,j,f;
    char ch[5],s[3];
    scanf("%s",&ch);
   for(i=0;i<5;i++)
   {
        scanf("%s",&s);
        if((ch[0]==s[0])||(ch[1]==s[1]))
            f=1;}

    if(f==1)
        printf("YES");
    else
        printf("NO");

return 0;
}

#include<stdio.h>
#include<string.h>
int main(void)
{
    char a[2], b[2];
    int flag = 0, i;
    gets(a);
    for(i = 0; i < 5; i++)
    {
        gets(b);
       // printf("%s\n", b);
        if(b[0] == a[0] || b[1] == a[1])  flag = 1;
    }
    if(flag) printf("YES\n");
    else printf("NO\n");
    return 0;
}

#include<stdio.h>
char a[2],b[2];
int main()
{
	int i,c=0;
	scanf("%s",b);
	for(i=0;i<5;i++)
	{
		scanf("%s",a);
		if (a[0]==b[0]||a[1]==b[1])
		{
			c=1;
		}
	}
	if(c==1)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char a[2],b[11];int temp=0;
    gets(a);
    gets(b);
    for(int i=0;i<2;i++)
    {
    for(int j=0;j<11;j++)
        if(a[i]==a[j])
    {
    temp++;
    }
    }
    if(temp>0)
        printf("YES");
    else
        printf("NO");

    return 0;
}

#include<stdio.h>
#include<string.h>
int main(){
char a[2];
char b[2];
gets(a);
int i,sum=0;
for(i=1;i<6;i++){
gets(b);
if(a[0]==b[0]||a[1]==b[1])
    {
    sum++;
}
else{continue;}
}
if(sum>0){
    printf("YES");
}
else{
    printf("NO");
}

}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{

	int i, j;
	char temp;
	char table[2] = { 0 };
	char hand[15] = { 0 };
	gets(table);
	gets(hand);

	for (j = 0; j < 2; j++)
	{
		temp = table[j];
		for (i = 0; i < 16; i++)
		{
			if (temp == hand[i])
			{
				printf("YES");
				exit(0);
			}

		}

	}
	printf("NO");
	exit(0);
	return 0;

}

#include<stdio.h>
#include<string.h>
main(){
char i[5],ii[5];
int a,sum=0;
getchar();
gets(i);

for(a=0;a<5;a++){

        gets(ii);
if(i[0]==ii[0]||i[1]==ii[1]){
    sum++;
}

}
if(sum>0){
    printf("\nYES");
}
else{
    printf("\nNO");
}

}

#include<stdio.h>
int main(){
	char t[3],h[3];
	int i,count = 0;
	scanf("%s",t);
	for(i=0;i<5;i++){
		scanf("%s",h);
		if(h[0]==t[0] || h[1]==t[1]){
			count = 1;
		}
	}
	 if(count = 1){
	     printf("YES");
	 }else {
	      printf("NO");
	 }

}

typedef struct {
    char rank,suit;
} card;
int main() {
    card c1, c2[5];
    scanf("%c%c",&c1.rank,&c1.suit);
    int i;
    for(i=0;i<5;i++) {
        scanf("%c%c ",&c2[i].rank,&c2[i].suit);
        if(c1.rank==c2[i].rank || c1.suit==c2[i].rank) {
            printf("YES");
            return 0;
        }
    }
    printf("NO");
    return 0;
}

#include<stdio.h>
#include<string.h>
int main ()
{
		int x=0;
	char s[10];
	char a[10];
	int len1=strlen(s);
	int len2=strlen(a);
	scanf("%s",s);
	printf("as=%s\n",s);
	printf("aa=%c %c\n",s[0],s[1]);
	for(int i=0;i<5;i++)
	{
		scanf("%s",a);
		if(s[0]==a[0]||s[1]==a[1])
		{
			x=x+1;
    	}
    	else
    	{

		}
    }
	if(x==1)
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}

#include <stdio.h>
#include<string.h>

int main(void)
{

char str[3], str1[3], str2[3], str3[3], str4[3], str5[3];

scanf("%s",str);

scanf("%s %s %s %s %s",str1,str2,str3,str4,str5);

if(str[0]=str1[0]||str[0]==str2[0]||str[0]==str3[0]||str[0]==str4[0]||str[0]==str5[0]||str[1]==str1[1]||str[1]==str2[1]||str[1]==str3[1]||str[1]==str4[1]||str[1]==str5[1])

 printf("YES");

else

printf("NO");
	// your code goes here

return 0;
}

#include<stdio.h>
#include<strings.h>
#include<stdlib.h>
int main()
{
    int i,j;
    char s[3];
    char t[6][2];
    scanf("%s",s);
    for(i=0;i<5;i++)
    scanf("%s",t[i]);
    for(j=0;j<5;j++)
    {
      if(s[0]==t[i][0])
      {printf("YES");
      return 0;
      }
      if(s[1]==t[i][1])
      {
          printf("YES");
          return 0;
      }
    }
    printf("NO");
    return 0;
}

#include<stdio.h>
#include<string.h>
int main()

{
    int i,l,flag=0;
    char s[12];
    char a,b;
    scanf("%c%c",&a,&b);
    scanf("%[^\n]s",&s);
    l=strlen(s);
    for(i=0;i<l;i++)
    {
        if(a==s[i]||b==s[i])
        flag=1;
    }
    if(flag==1)
    printf("YES");
    else printf("NO");
    return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    char table[3],card[3],str[100];
    int n;
    scanf("%s", table);
    for(n=1;n<=5;n++)
    {
        scanf("%s", card);
        strcat(str, card);
    }
    for(n=1;str[n];n++)
    {
        if(table[0]==str[n] || table[1]==str[n])
        {
            printf("YES");
            return 0;
        }

    }
    printf("NO");
}

#include <stdio.h>

int
main ()
{
  int loop = 0, count1 = 0, count2 = 0;
  char array[100];

      scanf ("%c", array);

  printf("%c",array[0]);

    {
      if (array[1] == (array[4] || array[7] || array[10] || array[13]
	  || array[16]))
	{
	  printf ("YES");
	  return 0;
	}

      if (array[0] == (array[3] || array[6] || array[9] || array[12]
	  || array[15]))
	{
	  printf ("YES");
	  return 0;
	}

    }
  printf ("NO");
  return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    char a[3],b[6][2];
    gets(a);
    for(int i=0;i<5;i++)
        {
            gets(b[i]);

        }
    for(int i=0;i<5;i++)
    {
        if(a[0]==b[i][0])
        {
            printf("Yes");
            return 0;
        }
        if(a[1]==b[i][1])
        {
            printf("Yes");
            return 0;
        }

    }
    printf("NO");

}

#include<stdio.h>
int main()
{
    char a,b,w;
    int count=0;
    scanf("%c %c %c",&a,&b,&w);
for(int i=0;i<5;i++)
{
char c,d,w;
scanf("%c %c %c",&c,&d,&w);
if(a==c || b==d)
{ printf("YES");
 break; }
else count++ ;
}
if(count==5)
printf("NO");
return 0;
}

#include<stdio.h>
#include<stdlib.h>

int main()
{
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
 	#endif
 	int flag=0;
       char a[20];char b[10][10];
       scanf("%s",a);
       for(int i=0;i<5;i++)
       {
       	scanf("%s",b[i]);
       	if(a[0]==b[i][0]||a[1]==b[i][1])
       		flag=1;
       }
       if(flag==1)
       	printf("YES");
       else
       	printf("N0");
   }

#include<stdio.h>
main()
{
	char a[3], b[3];
	int i, c = 0;
	scanf("%s", a);
	for (i = 0; i < 5; i++)
	{
		scanf("%s", b);
		if (b[i] == a[0] || b[i] == a[1])
			c++;
	}
	if (c > 0)
		printf("YES\n");
	else
		printf("NO\n");
}

#include<stdio.h>
#include<string.h>
int main(){
int t=0;
char a[3],b[3];
gets(a);
for(int i=1;i<=5;i++){
gets(b);
if(b[0]==a[0]||b[1]==a[1])
    {
        t=1;
    }
}
(t==0?printf("NO"):printf("YES"));
return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{

	int i, j;
	char temp;
	char table[2] = { 0 };
	char hand[15] = { 0 };
	gets(table);
	gets(hand);

	for (j = 0; j < 2; j++)
	{
		temp = table[j];
		for (i = 0; i < 16; i++)
		{
			if (temp == hand[i])
			{
				printf("YES");
				exit(0);

			}

		}
	}
	printf("NO");

	return 0;

}

#include<stdio.h>
#include<string.h>
int main()
{
    int i,count=0;
    char str[10],str_[2];
    gets(str_);
    for(i=1;i<=5;i++)
    {
        gets(str);
        if(str[0]==str_[0] || str[0]==str_[1] || str[1]==str_[1])
        {
            count++;
        }
    }
    if(count>=1)
            printf("YES\n");
            else
                printf("NO\n");

    return 0;
}

#include <stdio.h>
#include <string.h>
int main()
{
	int c,k=0,t=0;
	char a,b;
	char ch[17];
	scanf("%c%c",&a,&b);
	puts(ch);
	for(int i=0;i<strlen(ch);i++)
	{
		if(a==ch[i] || b==ch[i])
		{
			k=1;

		}

	}
	if(k==1)
	printf("YES\n");
	else
	printf("NO\n");
	return 0;
}

#include<stdio.h>
int main()
{
int n=0;
char f,l,q;
scanf("%s",&f);
scanf("%s",&l);
char a,b,c;
while(n<5)
{
scanf("%s",&a);
scanf("%s",&b);
scanf("%s",&c);
n++;
}
if((f==b)||(l==c))
{
printf("YES");
}
else
{
printf("NO");
}
}

#include<stdio.h>

int main()
{
	char target[2],mine[2];
	int i,k=0;

	gets(target);
	scanf("%d",&i);

	for (i = 0; i < 5; ++i)
	{
		gets(mine);
		if(k==0 && (target[0]==mine[0] || target[1]==mine[1]))
		{
			k=1;
		}
	}

	if(k)
		printf("YES");
	else
		printf("NO");
}

#include<stdio.h>
int main(){
	char t[3],h[3];
	int i;
	scanf("%s",t);
	for(i=0;i<5;i++){
		scanf("%s",h);
		if(h[0]==t[0] || h[1]==t[1]){
			printf("YES");
			break;
		}
	 if(h == i){
	     printf("NO");
	 }
	}

}

#include<stdio.h>
char card(char a, char b)
{	int i;
	char k,l;
	for(i=0;i<10;i++)
	{ scanf("%c",&k);
	  scanf("%c",&l);
	}
	if(b==l||a==k||a==l||b==k)
	printf("YES");
	else
	printf("NO");
	return 0;
}
int main()
{	char a,b;
	scanf("%c",&a);
	scanf("%c",&b);
	card(a,b);
	return 0;
}

# include<stdio.h>

int main()
{
    int i;
    char s1[2];
    scanf("%s",&s1);

    char s2[2];
    scanf("%s",&s2);

    char s3[2];
    scanf("%s",&s3);

    char s4[2];
    scanf("%s",&s4);

    char s5[2];
    scanf("%s",&s5);

    char s6[2];
    scanf("%s",&s6);

    for(i=1; i<=2; i++)
    {
        if(s1[i]==s2[i])
        {
            printf("YES");

            return 0;
        }
        if(s1[i]==s3[i])
        {
            printf("YES");

            return 0;
        }
        if(s1[i]==s4[i])
        {
            printf("YES");

            return 0;
        }
        if(s1[i]==s5[i])
        {
            printf("YES");

            return 0;
        }
        if(s1[i]==s6[i])
        {
            printf("YES");

            return 0;
        }

    }  printf("NO");
    return 0;
}

#include<stdio.h>
main()
{
    int i,c;
    char a[2],b[2];
    scanf("%s",b);
    for(i=0;i<5;i++)
    {
        scanf("%s",a);
        if(b[0]==a[0]||b[1]==a[1])
        c=c+1;
    }
    if(c)printf("yes");
    else printf("no");
}

#include <stdio.h>
#include <stdlib.h>
/*
typedef struct Deck
{
	char club[13]= {2,3,4,5,6,7,8,9,'T','J','Q','K','A'};
	char spades[13]= {2,3,4,5,6,7,8,9,'T','J','Q','K','A'};
	char heart[13]= {2,3,4,5,6,7,8,9,'T','J','Q','K','A'};
	char diamond[13]= {2,3,4,5,6,7,8,9,'T','J','Q','K','A'};

}deck;
*/

typedef struct Card
{
	char face;
	char num;
}Card;

void write (Card a);

int main(void)
{
	int cont=0;
	Card table,hand[5];

	/*
	scanf("%c%c",&table.num,&table.face);
	*/
	scanf("%c%c%c%c%c%c%c%c%c%c",&hand[0].num,&hand[0].face,
								 &hand[1].num,&hand[1].face,
								 &hand[2].num,&hand[2].face,
								 &hand[3].num,&hand[3].face,
								 &hand[4].num,&hand[4].face);

	for(int i=0;i<5;i++)
		{
		write(hand[i]);
		}
	/*
	for(int i=0;i<5;i++)
	{
		if(hand[i].num==table.num ||hand[i].face==table.face)
		{
			printf("Yes");break;
			cont++;
		}
	}
	if(0==cont)
	{
		printf("No");
	}*/
}

void write (Card a)
{
	printf("%c%c",a.num,a.face);
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char a[2],b[2],c[2],d[2],e[2],f[2];int temp=0;
    gets(a);
    gets(b);
    gets(c);
    gets(d);
    gets(e);
    gets(f);
    for(int i=0;i<2;i++)
    {

        for(int j=0;j<2;j++)
        {
            if((a[i]==b[j])||(a[i]==c[j])||(a[i]==d[j])||(a[i]==e[j])||(a[i]==f[j]))
                temp++;
        }
    }
    if(temp>0)
    {

        printf("YES");

    }else{
    printf("NO");
    }

    return 0;
}

#include <stdio.h>
#include <stdbool.h>
int main (void)
{
	bool test = false ;
	char card[2] , hand_cards[20];
	int i,x ;
	scanf("%s",card);
	scanf("%s",hand_cards);
	for(i=0 ; i<2 ; i++)
	{
		for(x=0; x<10 ; x++)
		{
		if(card[i]== hand_cards[x])
		{
			test = true ;
			break ;
		}
		}	 //a7a
	}
	if (test)
		printf("yes");
	else
		printf("no");

}

#include<stdio.h>
main()
{
    int i,e=0;
    char a,b,c,d;
    scanf("%c%c",&a,&b);
    for(i=0;i<5;i++)
    {
        scanf("%c%c",&c,&d);
        if(a==c||a==d) e=e+1;
        if(b==c||b==d) e=e+1;
    }
    if(e!=0) {printf("yes");}
    else {printf("no");}

}

#include<stdio.h>
int main()
{
    int i,c;
    char a[2],b[2];
    scanf("%s",a);
    for(i=0;i<5;i++)
    {
    scanf("%s",b);
        if(a[0]==b[0]||a[1]==b[1])
           {
               c=1;
           }
    }
    if(c==1)
    printf("YES");
    else
    printf("NO");

    return(0);
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char table[2], hands[2];
    int s = 0;
    scanf("%s", table);

        for(int i = 0; i < 5; i++)
        {
           scanf("%c", hands);
           if(hands[s] == table[s] || hands[s+1] == table[s+1]) {printf("YES"); break; return 0;}
           else continue;
        }
    printf("NO ");
    return 0;
}

#include<stdio.h>

int main()
{
    char name[3], test[3], ans[] = "23456789TJQKA";
    int i, j, a, length, count = 0,b;

    length = strlen(ans);

    scanf("%s", name);

    for(i=1; i<=5; i++)
    {
        scanf("%s", test);

        if(test[0] == 'A' && name[0] == 'A')
        {

            count = 1;
        }
        else if((test[0] == name[0]) && (test[1] == name[1]))
        {

            count = 1;
        }
        else if(test[1] == name[1])
        {
            count = 1;

        }
    }

    if(count == 1)
    {

        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }

    return 0;
}

#include<stdio.h>
int main(void)
{
    char a[1][3],b[5][3];
    int i,j;
    for(i=0;i<1;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%c",&a[i][j]);
        }
    }
    fflush(stdin);
    int flag=0;
        for(i=0;i<5;i++)
        {
            for(j=0;j<3;j++)
            {
                //fflush(stdin);
                scanf("%c",&b[i][j]);
                if(a[1][1]==b[i][1]) flag++;
                if(a[1][2]==b[i][2]) flag++;
            }
            getchar();
        }
    if(flag==0) printf("NO\n");
    else printf("YES\n");
    return 0;
}

#include<stdio.h>
#include<string.h>
main(){
char i[5],ii[5];
int a,sum=0;
getchar();
gets(i);
for(a=0;a<5;a++){
        gets(ii);
if(i[0]==ii[0]||i[1]==i[1]){
    sum++;
}
}
if(sum>0){
    printf("YES");
}
else{
    printf("NO");
}

}

#include <stdio.h>

int
main ()
{
  int loop = 0, count1 = 0, count2 = 0;
  char array[100];

    fgets(array,100,stdin);

    {
      if (array[1] == array[4] ||array[1] == array[7] ||array[1] == array[10] ||array[1] == array[13]
	  ||array[1] == array[16])
	{
	  printf ("YES");
	  return 0;
	}

      if (array[0] == array[3] ||array[0] ==  array[6] ||array[0] ==  array[9] ||array[0] ==  array[12]
	  ||array[0] ==  array[15])
	{
	  printf ("YES");
	  return 0;
	}

    }
  printf ("NO");
  return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char onTable[3];
    char inHand[15];

    scanf("%s\n", onTable);
    fgets(inHand, 15, stdin);

    for (short i = 0; i < 15; i += 2) {
        if (onTable[0] == inHand[i] || onTable[1] == inHand[i+1]) {
            puts("YES");
            exit(0);
        }
    }
    puts("NO");
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
struct liste{
    char name[30];
    struct liste *next;
};
typedef struct liste *liste ;
liste creation(int n){
    liste head,tmp,pt;
    head=malloc(sizeof(struct liste));
    scanf("%s",head->name);
    head->next=NULL;
    pt=head;
     for(int i=1;i<n;i++){
        tmp=malloc(sizeof(struct liste));
        scanf("%s",tmp->name);
        tmp->next=NULL;
        pt->next=tmp;
        pt=tmp;
     }
      return head;

}
int traitement(char card[],liste L){
    int i=0,ok=0,j=0;
    while(L){
    j=0;
        do{
            i=0;
        while(i<2){
            if(card[j]==L->name[i]){
                printf("yes");

                return 0;
          }
            i++;
                  }
            j++;
        }while(j<2);

       L=L->next;
}
    printf("non");
}
 int main(){
char card[2];
liste L;
 scanf("%s",card);
 if(*card='\0')return 0;
 L=creation(5);
   traitement(card,L);

 }

#include<stdio.h>
#include<string.h>
main(){
char a[2];
char b[2];
int i,sum=0;
getchar();
scanf("%s",a);
for(i=1;i<6;i++){
scanf("%s",b);
if(a[1]==b[1]||a[0]==b[0])
    {
    sum++;
}

}
if(sum>0){
    printf("YES");
}
else{
    printf("NO");
}

}

#include<stdio.h>
int main()
{
    int i,c;
    char a[2],b[2];
    for(i=0;i<2;i++)
    scanf("%s",a);
    for(i=0;i<20;i++)
    scanf("%s",b);
    for(i=0;i<20;i++)
    {
        if(a[0]==b[i]||a[1]==b[i])
           {
               c=1;
               break;
           }
        else
            c=0;
    }
    if(c==1)
    printf("YES");
    else
    printf("NO");

    return(0);
}

typedef struct {
    char rank,suit;
} card;
int main() {
    card c1, c2[5];
    scanf("%c%c",&c1.rank,&c1.suit);
    int i;
    for(i=0;i<5;i++) {
        scanf("%*c%c%c",&c2[i].rank,&c2[i].suit);
        if(c1.rank==c2[i].rank || c1.suit==c2[i].rank) {
            printf("YES");
            return 0;
        }
    }
    printf("NO");
    return 0;
}

#include <stdio.h>

int main(void) {
    char str[3], str1[3], str2[3], str3[3], str4[3], str5[3];
    scanf("%s",str);
    scanf("%s %s %s %s %s",str1,str2,str3,str4,str5);
    if((str[1]==(str1[1]||str2[1]||str3[1]||str4[1]||str5[1]))||(str[2]==(str1[2]||str2[2]||str3[2]||str4[2]||str5[2])))
    printf("YES");
    else
    printf("NO");
	// your code goes here
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
/*
typedef struct Deck
{
	char club[13]= {2,3,4,5,6,7,8,9,'T','J','Q','K','A'};
	char spades[13]= {2,3,4,5,6,7,8,9,'T','J','Q','K','A'};
	char heart[13]= {2,3,4,5,6,7,8,9,'T','J','Q','K','A'};
	char diamond[13]= {2,3,4,5,6,7,8,9,'T','J','Q','K','A'};

}deck;
*/

typedef struct Card
{
	char face;
	char num;
}Card;
/*
void write (Card a);
*/
int main(void)
{
	int cont=0;
	Card table,hand[5];
	scanf("%c%c",&table.num,&table.face);

	scanf("%c%c%c%c%c%c%c%c%c%c",&hand[0].num,&hand[0].face,
								 &hand[1].num,&hand[1].face,
								 &hand[2].num,&hand[2].face,
								 &hand[3].num,&hand[3].face,
								 &hand[4].num,&hand[4].face);
	/*
	for(int i=0;i<5;i++)
		{
		write(hand[i]);
		}
	*/
	for(int i=0;i<5;i++)
	{
		if(hand[i].num==table.num ||hand[i].face==table.face)
		{
			printf("Yes");break;
			cont++;
		}
	}
	if(0==cont)
	{
		printf("No");
	}
}
/*
void write (Card a)
{
	printf("%c%c",a.num,a.face);
}
*/

#include<stdio.h>
#include<string.h>
int main()
{

    int r=0,s=0;
    char card[2];
    char cards[15];
    gets(card);
    gets(cards);
    for(int i=0;i<strlen(cards);i+=3)
    {
        if(card[0]==cards[i])
        r++;
    }

    for(int i=1;i<strlen(cards);i+=3)
    {
        if(card[1]==cards[i])
        s++;
    }
    if((r==1 && s<2) || (s==1 && r<2))
    printf("YES\n");
    else
    printf("NO\n");
    return 0;
}

#include<stdio.h>
int main()
{
char str[2],str1[5];
int count=0,i,j,p;
scanf("%s",str);
for(i=0;i<4;i++)
{
    scanf("%s",str1);
    p=0;
    for(j=0;j<2;j++,p++)
    {
    if(str[p]==str1[j])
    count=count+1;
     break;
    }
    }
    if(count>0)
    printf("Yes");
    else
    printf("No");
return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    char a[3],b[6][2];
    gets(a);
    for(int i=0;i<5;i++)
        {
            gets(b[i]);

        }
    for(int i=0;i<5;i++)
    {
        if(a[0]==b[i][0])
        {
            printf("Yes");
            return 0;
        }
        if(a[1]==b[i][1])
        {
            printf("Yes");
            return 0;
        }

    }
    printf("NO");
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct liste{
    char name[30];
    struct liste *next;
};
typedef struct liste *liste ;
liste creation(int n){
    liste head,tmp,pt;
    head=malloc(sizeof(struct liste));
    scanf("%s",head->name);
    head->next=NULL;
    pt=head;
     for(int i=1;i<n;i++){
        tmp=malloc(sizeof(struct liste));
        scanf("%s",tmp->name);
        tmp->next=NULL;
        pt->next=tmp;
        pt=tmp;
     }
      return head;

}
int traitement(char card[],liste L){
    int i=0,ok=0,j=0;
    while(L){
    j=0;
        do{
            i=0;
        while(i<2){
            if(card[j]==L->name[i]&&(card[j]>64&&card[j]<91)){
                printf("yes");

                return 0;
          }
            i++;
                  }
            j++;
        }while(j<2);

       L=L->next;
}
    printf("non");
}
 int main(){
char card[2];
liste L;
 scanf("%s",card);
 if(strlen(card)>2 )return 0;
 L=creation(5);
   traitement(card,L);

 }

#include <stdio.h>

int main() {
	char T[3];
	printf("please Enter");
	scanf("%s", T);
	char hand[5][3];
	int i;
	int flag=1;
	for(i=0;i<5;i++){
		scanf("%s", hand[i]);
	}
	for(i=0;i<5;i++){
		if((hand[i][0]==T[0] )||(hand[i][1]==T[1] )){
			printf("YES\n");
			flag=0;
			break;

		}

	}
	if(flag){
		printf("NO\n");
	}
}


Karlsson has visited Lillebror again. They found a box of chocolates and a big whipped cream cake at Lillebror's place. Karlsson immediately suggested to divide the sweets fairly between Lillebror and himself. Specifically, to play together a game he has just invented with the chocolates. The winner will get the cake as a reward.The box of chocolates has the form of a hexagon. It contains 19 cells for the chocolates, some of which contain a chocolate. The players move in turns. During one move it is allowed to eat one or several chocolates that lay in the neighboring cells on one line, parallel to one of the box's sides. The picture below shows the examples of allowed moves and of an unacceptable one. The player who cannot make a move loses.  Karlsson makes the first move as he is Lillebror's guest and not vice versa. The players play optimally. Determine who will get the cake.

The input data contains 5 lines, containing 19 words consisting of one symbol. The word "O" means that the cell contains a chocolate and a "." stands for an empty cell. It is guaranteed that the box contains at least one chocolate. See the examples for better understanding.

If Karlsson gets the cake, print "Karlsson" (without the quotes), otherwise print "Lillebror" (yet again without the quotes).

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char r[1 << 20];

int box2mask(char b[5][5]) {
	int mask = 0, i, j, k = 0;
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			if (b[i][j])
				mask |= 1 << k;
			k++;
		}

	return mask;
}

int go(int mask) {
	if (r[mask] != -1)
		return r[mask];

	// printf("mask = %d\n", mask);

	char b[5][5];
	memset(b, 0, sizeof(b));

	int i, j, k = 0;
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			if (mask & (1 << k))
				b[i][j] = 1;
			k++;
		}

	char bb[5][5];
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			memcpy(bb, b, sizeof(bb));
			int l;
			for (k = i, l = j; k < 5 && l < 5-abs(2-k) && l >= 0 && bb[k][l]; k++) {
				bb[k][l] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
				if (k >= 2)
					l--;
			}

			memcpy(bb, b, sizeof(bb));
			for (k = i, l = j; k < 5 && l < 5-abs(2-k) && bb[k][l]; k++) {
				bb[k][l] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
				if (k < 2)
					l++;
			}

			memcpy(bb, b, sizeof(bb));
			for (k = j; k < 5-abs(2-i) && bb[i][k]; k++) {
				bb[i][k] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}
		}

	return r[mask] = 0;
}

int main() {
	int i, mask = 0, j = 0;
	for (i = 0; i < 5; i++) {
		char s[100];
		gets(s);

		char *t = s;
		while (*t != '\0') {
			if (*t == 'O')
				mask |= (1 << j);
			if (*t == 'O' || *t == '.')
				j++;
			t++;
		}

	}

	if (j != 19)
		exit(1);

	memset(r, -1, sizeof(r));

	if (go(mask))
		puts("Karlsson");
	else
		puts("Lillebror");

	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char r[1 << 20];

int box2mask(char b[5][5]) {
	int mask = 0, i, j, k = 0;
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			if (b[i][j])
				mask |= 1 << k;
			k++;
		}

	return mask;
}

int go(int mask) {
	if (r[mask] != -1)
		return r[mask];

	char b[5][5];
	memset(b, 0, sizeof(b));

	int i, j, k = 0;
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			if (mask & (1 << k))
				b[i][j] = 1;
			k++;
		}

	char bb[5][5];
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			memcpy(bb, b, sizeof(bb));
			for (k = i; k < 5 && j < 5-abs(2-k) && bb[k][j]; k++) {
				bb[k][j] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}

			memcpy(bb, b, sizeof(bb));
			int l;
			for (k = i, l = j; k < 5 && l < 5-abs(2-k) && bb[k][l]; k++, l++) {
				bb[k][l] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}

			memcpy(bb, b, sizeof(bb));
			for (k = j; k < 5-abs(2-i) && bb[i][k]; k++) {
				bb[i][k] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}
		}

	return r[mask] = 0;
}

int main() {
	int i, mask = 0, j = 0;
	for (i = 0; i < 5; i++) {
		char s[100];
		gets(s);

		char *t = s;
		while (*t != '\0') {
			if (*t == 'O')
				mask |= (1 << j);
			if (*t == 'O' || *t == '.')
				j++;
			t++;
		}

	}

	if (j != 19)
		exit(1);

	memset(r, -1, sizeof(r));

	if (go(mask))
		puts("Karlsson");
	else
		puts("Lillebror");

	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char r[1 << 19];

int box2mask(char b[5][5]) {
	int mask = 0, i, j, k = 0;
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			if (b[i][j])
				mask |= 1 << k;
			k++;
		}

	return mask;
}

int go(int mask) {
	if (r[mask] != -1)
		return r[mask];

	char b[5][5];
	memset(b, 0, sizeof(b));

	int i, j, k = 0;
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			if (mask & (1 << k))
				b[i][j] = 1;
			k++;
		}

	char bb[5][5];
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			memcpy(bb, b, sizeof(bb));
			for (k = i; k < 5 && j < 5-abs(2-k) && bb[k][j]; k++) {
				bb[k][j] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}

			memcpy(bb, b, sizeof(bb));
			int l;
			for (k = i, l = j; k < 5 && l < 5-abs(2-k) && bb[k][l]; k++, l++) {
				bb[k][l] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}

			memcpy(bb, b, sizeof(bb));
			for (k = j; k < 5-abs(2-i) && bb[i][k]; k++) {
				bb[i][k] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}
		}

	return r[mask] = 0;
}

int main() {
	int i, mask = 0, j = 0;
	for (i = 0; i < 5; i++) {
		char s[100];
		gets(s);

		char *t = s;
		while (*t != '\0') {
			if (*t == 'O')
				mask |= (1 << j);
			if (*t == 'O' || *t == '.')
				j++;
			t++;
		}

	}

	memset(r, -1, sizeof(r));

	if (go(mask))
		puts("Karlsson");
	else
		puts("Lillebror");

	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char r[1 << 20];

int masksn = 0, masks[200];

int go(int m) {
	if (r[m] != -1)
		return r[m];

	int i;
	for (i = 0; i < masksn; i++)
		if (m & masks[i] == masks[i])
			if (!go(m & ~masks[i]))
					return r[m] = 1;

	return r[m] = 0;
}

int main() {
	int i, m = 0, j = 0;
	for (i = 0; i < 5; i++) {
		char s[100]; gets(s);

		char *t = s;
		while (*t != '\0') {
			if (*t == 'O')
				m |= (1 << j);
			if (*t == 'O' || *t == '.')
				j++;
			t++;
		}

	}

	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			int k, l, m = 0;
			for (k = i, l = j; k < 5 && 0 <= l && l < 5-abs(2-k); k++) {
				masks[masksn++] = m;
				if (k >= 2)
					l--;
			}

			m = 0;
			for (k = i, l = j; k < 5 && l <= 5-abs(2-k); k++) {
				masks[masksn++] = m;
				if (k < 2)
					l++;
			}

			m = 0;
			for (k = j; k < 5-abs(2-i); k++) {
				masks[masksn++] = m;
			}
		}

	memset(r, -1, sizeof(r));

	if (go(m))
		puts("Karlsson");
	else
		puts("Lillebror");

	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char r[1 << 19];

int box2mask(char b[5][5]) {
	int mask = 0, i, j, k = 0;
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			if (b[i][j])
				mask |= 1 << k;
			k++;
		}

	return mask;
}

int go(int mask) {
	if (r[mask] != -1)
		return r[mask];

	char b[5][5];
	memset(b, 0, sizeof(b));

	int i, j, k = 0;
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			if (mask & (1 << k))
				b[i][j] = 1;
			k++;
		}

	char bb[5][5];
	for (i = 0; i < 5; i++)
		for (j = 0; j < 5-abs(2-i); j++) {
			memcpy(bb, b, sizeof(bb));
			for (k = i; k < 5 && j < 5-abs(2-k) && bb[k][j]; k++) {
				bb[k][j] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}

			memcpy(bb, b, sizeof(bb));
			int l;
			for (k = i, l = j; k < 5 && l < 5-abs(2-k) && bb[k][l]; k++, l++) {
				bb[k][l] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}

			memcpy(bb, b, sizeof(bb));
			for (k = j; k < 5-abs(2-i) && bb[i][k]; k++) {
				bb[i][k] = 0;
				if (!go(box2mask(bb)))
					return r[mask] = 1;
			}
		}

	return r[mask] = 0;
}

int main() {
	int i, mask = 0, j = 0;
	for (i = 0; i < 5; i++) {
		char s[100];
		gets(s);

		char *t = s;
		while (*t != '\0') {
			if (*t == 'O')
				mask |= (1 << j);
			if (*t == '0' || *t == '.')
				j++;
			t++;
		}

	}

	memset(r, -1, sizeof(r));

	if (go(mask))
		puts("Karlsson");
	else
		puts("Lillebror");

	return 0;
}


One day Polycarpus got hold of two non-empty strings s and t, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately wondered, how many different pairs of "x y" are there, such that x is a substring of string s, y is a subsequence of string t, and the content of x and y is the same. Two pairs are considered different, if they contain different substrings of string s or different subsequences of string t. Read the whole statement to understand the definition of different substrings and subsequences.The length of string s is the number of characters in it. If we denote the length of the string s as |s|, we can write the string as s = s1s2... s|s|.A substring of s is a non-empty string x = s[a... b] = sasa + 1... sb (1 ≤ a ≤ b ≤ |s|). For example, "code" and "force" are substrings or "codeforces", while "coders" is not. Two substrings s[a... b] and s[c... d] are considered to be different if a ≠ c or b ≠ d. For example, if s="codeforces", s[2...2] and s[6...6] are different, though their content is the same.A subsequence of s is a non-empty string y = s[p1p2... p|y|] = sp1sp2... sp|y| (1 ≤ p1 < p2 < ... < p|y| ≤ |s|). For example, "coders" is a subsequence of "codeforces". Two subsequences u = s[p1p2... p|u|] and v = s[q1q2... q|v|] are considered different if the sequences p and q are different.

The input consists of two lines. The first of them contains s (1 ≤ |s| ≤ 5000), and the second one contains t (1 ≤ |t| ≤ 5000). Both strings consist of lowercase Latin letters.

Print a single number — the number of different pairs "x y" such that x is a substring of string s, y is a subsequence of string t, and the content of x and y is the same. As the answer can be rather large, print it modulo 1000000007 (109 + 7).

NoteLet's write down all pairs "x y" that form the answer in the first sample: "s[1...1] t[1]", "s[2...2] t[1]", "s[1...1] t[2]","s[2...2] t[2]", "s[1...2] t[1 2]".

#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define MAX 5010
#define MOD 1000000007
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

char S[MAX], T[MAX];
short next[MAX][MAX];
bool visited[MAX][MAX];
int n, m, dp[MAX][MAX];

int F(int i, int j){
    if (i >= n || j >= m) return 0;
    if (visited[i][j]) return dp[i][j];

    unsigned int res = 0;
    if (next[i][j] != -1){
        res = res + F(i + 1, next[i][j] + 1) + 1;
        if (res >= MOD) res -= MOD;
        res = res + F(i, next[i][j] + 1);
        if (res >= MOD) res -= MOD;
    }

    visited[i][j] = true;
    return (dp[i][j] = res);
}

int main(){
    int i, j, k;

    while (scanf("%s %s", S, T) != EOF){
        clr(visited);
        n = strlen(S), m = strlen(T);
        for (i = 0; i < n; i++){
            for (j = m - 1; j >= 0; j--){
                next[i][j] = -1;
                if (S[i] == T[j]) next[i][j] = j;
                else if ((j + 1) != m) next[i][j] = next[i][j + 1];
            }
        }

        long long res = 0;
        for (i = 0; i < n; i++){
            for (j = 0; j < m; j++){
                if (S[i] == T[j]){
                    res = res + F(i + 1, j + 1) + 1;
                }
            }
        }
        printf("%lld\n", res % MOD);
    }
    return 0;
}

#include <stdio.h>
#include <string.h>
#define MAXN 5000
#define MAXL (MAXN+1)
#define MOD 1000000007

char s[MAXL];
char t[MAXL];

int dp[MAXN][MAXN];

int main()
{
	while ( scanf("%s %s", s, t) == 2)
	{
		//printf("%s\n%s\n", s, t);
		int ls = strlen( s);
		int lt = strlen( t);

		int i, j;
		int ans = 0;
		for ( i = 0; i < ls; i++)
		{
			for ( j = 0; j < lt; j++)
			{
				dp[i][j] = s[i] == t[j];
				if ( dp[i][j] && i && j)
				{
					dp[i][j] += dp[i-1][j-1];
				}

				dp[i][j] %= MOD;
				ans += dp[i][j];
				ans %= MOD;

				dp[i][j] += j ? dp[i][j-1] : 0;
				dp[i][j] %= MOD;
			}
		}
		/*
		for ( i = 0; i < ls; i++)
		{
			for ( j = 0; j < lt; j++)
			{
				printf("%d ", dp[i][j]);
			}
			printf("\n");
		}
		*/
		printf("%d\n", ans);
	}
	return 0;
}

#include <stdio.h>

const unsigned int mod = 1000000007;
unsigned int DP[5001][5001];
char a[5001],b[5001];

int main()
{
    gets(a);gets(b);
    int len1 = strlen(a),len2 = strlen(b),i,j;
    for(i=0;i<len1;++i){
        for(j=0;j<len2;++j){
            DP[i+1][j+1] = (DP[i+1][j] + ((a[i]==b[j])? (DP[i][j]+1) : 0))%mod;
        }
    }

    unsigned int ans = 0;
    for(i=1;i<=len1;++i){
        ans+=DP[i][len2];
        ans %=mod;
    }
    printf("%d",ans);

    //system("pause");
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long ll;

#define err(...) fprintf(stderr, __VA_ARGS__)

#define N 5010
#define MOD 1000000007

void norm(ll *a) {
  if (*a >= MOD) *a -= MOD;
  if (*a < 0) *a += MOD;
}

int main() {
  static char s[N], t[N];
  scanf("%s %s", s, t);
  int n = strlen(s), m = strlen(t);

  ll ans = 0;
  static ll dp[N][N];
  for (int i = 0; i <= (n > m ? n : m); ++i) {
    dp[0][i] = 1;
    dp[i][0] = 1;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      dp[i][j] = dp[i][j - 1];
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] += dp[i - 1][j - 1];
        norm(&dp[i][j]);
      }
      if (j == m) {
        ans += dp[i][j];
        norm(&ans);
      }
    }
  }
  ans = (ans + MOD - n) % MOD;

  printf("%lld", ans);
  return 0;
}

#include <stdio.h>
#include <string.h>
#define MAXN 5000
#define MAXL (MAXN+1)
#define MOD 1000000007

char s[MAXL];
char t[MAXL];

int oct[MAXN][26];
int dp[MAXN][MAXN];

int main()
{
	while ( scanf("%s %s", s, t) == 2)
	{
		//printf("%s\n%s\n", s, t);
		int ls = strlen( s);
		int lt = strlen( t);

		int i, j;
		int ans = 0;
		memset( oct[0], 0, sizeof( oct[0]));
		++oct[0][t[0]-'a'];
		for ( i = 1; i < lt; i++)
		{
			for ( j = 0; j < 26; j++)
			{
				oct[i][j] = oct[i-1][j];
			}
			++oct[i][t[i]-'a'];
		}

		for ( i = 0; i < ls; i++)
		{
			for ( j = 0; j < lt; j++)
			{
				dp[i][j] = s[i] == t[j];
				if ( dp[i][j] && i && j)
				{
					dp[i][j] += dp[i-1][j-1];
				}

				ans += dp[i][j];
				if ( ans >= MOD)
				{
					ans -= MOD;
				}
				dp[i][j] += j ? dp[i][j-1] : 0;
			}
		}
		/*
		for ( i = 0; i < ls; i++)
		{
			for ( j = 0; j < lt; j++)
			{
				printf("%d ", dp[i][j]);
			}
			printf("\n");
		}
		*/
		printf("%d\n", ans);
	}
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long ll;

#define err(...) fprintf(stderr, __VA_ARGS__)

#define N 5010
#define MOD 1000000007

void norm(ll *a) {
  if (*a >= MOD) *a -= MOD;
  if (*a < 0) *a += MOD;
}

int main() {
  static char s[N], t[N];
  scanf("%s %s", s, t);
  int n = strlen(s), m = strlen(t);

  ll ans = 0;
  static ll dp[N][N];
  for (int i = 0; i <= n; ++i) {
    dp[0][i] = 1;
    dp[i][0] = 1;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      dp[i][j] = dp[i][j - 1];
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] += dp[i - 1][j - 1];
        norm(&dp[i][j]);
      }
      if (j == m) {
        ans += dp[i][j];
        norm(&ans);
      }
    }
  }
  ans = (ans + MOD - n) % MOD;

  printf("%lld", ans);
  return 0;
}