#include <cstdio>
#include <cstring>
#include <vector>
#define MAX 2000
#define MAX2 200000
using namespace std;
int n,k,i,j;
char charin[20][20][20];
int ngto[20][20];
int check[20][MAX2];
vector<int> V[MAX];
int tinh[MAX];
int main()
{
    int l,kt1,kt2,tmp1;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%s",charin[0][i]);
    }
    for(i=0;i<k;i++)
    {
        scanf("%s",charin[1][i]);
    }
    j=0;
    for(i=0;i<n;i++)
    {
        if(strlen(charin[j][i])==1&&charin[j][i][0]=='H')
            ngto[j][i]=1;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='H'&&charin[j][i][1]=='e')
            ngto[j][i]=2;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='L'&&charin[j][i][1]=='i')
            ngto[j][i]=3;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='B'&&charin[j][i][1]=='e')
            ngto[j][i]=4;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='B')
            ngto[j][i]=5;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='C')
            ngto[j][i]=6;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='N')
            ngto[j][i]=7;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='O')
            ngto[j][i]=8;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='F')
            ngto[j][i]=9;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='N'&&charin[j][i][1]=='e')
            ngto[j][i]=10;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='N'&&charin[j][i][1]=='a')
            ngto[j][i]=11;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='M'&&charin[j][i][1]=='g')
            ngto[j][i]=12;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='A'&&charin[j][i][1]=='l')
            ngto[j][i]=13;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='S'&&charin[j][i][1]=='i')
            ngto[j][i]=14;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='P')
            ngto[j][i]=15;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='S')
            ngto[j][i]=16;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='l')
            ngto[j][i]=17;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='A'&&charin[j][i][1]=='r')
            ngto[j][i]=18;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='K')
            ngto[j][i]=19;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='a')
            ngto[j][i]=20;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='S'&&charin[j][i][1]=='c')
            ngto[j][i]=21;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='T'&&charin[j][i][1]=='i')
            ngto[j][i]=22;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='V')
            ngto[j][i]=23;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='r')
            ngto[j][i]=24;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='M'&&charin[j][i][1]=='n')
            ngto[j][i]=25;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='F'&&charin[j][i][1]=='e')
            ngto[j][i]=26;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='o')
            ngto[j][i]=27;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='N'&&charin[j][i][1]=='i')
            ngto[j][i]=28;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='u')
            ngto[j][i]=29;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='Z'&&charin[j][i][1]=='n')
            ngto[j][i]=30;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='G'&&charin[j][i][1]=='a')
            ngto[j][i]=31;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='G'&&charin[j][i][1]=='e')
            ngto[j][i]=32;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='A'&&charin[j][i][1]=='s')
            ngto[j][i]=33;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='S'&&charin[j][i][1]=='e')
            ngto[j][i]=34;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='B'&&charin[j][i][1]=='r')
            ngto[j][i]=35;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='K'&&charin[j][i][1]=='r')
            ngto[j][i]=36;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='R'&&charin[j][i][1]=='b')
            ngto[j][i]=37;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='S'&&charin[j][i][1]=='r')
            ngto[j][i]=38;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='Y')
            ngto[j][i]=39;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='Z'&&charin[j][i][1]=='r')
            ngto[j][i]=40;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='N'&&charin[j][i][1]=='b')
            ngto[j][i]=41;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='M'&&charin[j][i][1]=='o')
            ngto[j][i]=42;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='T'&&charin[j][i][1]=='c')
            ngto[j][i]=43;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='R'&&charin[j][i][1]=='u')
            ngto[j][i]=44;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='R'&&charin[j][i][1]=='h')
            ngto[j][i]=45;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='P'&&charin[j][i][1]=='d')
            ngto[j][i]=46;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='A'&&charin[j][i][1]=='g')
            ngto[j][i]=47;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='d')
            ngto[j][i]=48;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='I'&&charin[j][i][1]=='n')
            ngto[j][i]=49;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='S'&&charin[j][i][1]=='n')
            ngto[j][i]=50;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='S'&&charin[j][i][1]=='b')
            ngto[j][i]=51;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='T'&&charin[j][i][1]=='e')
            ngto[j][i]=52;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='I')
            ngto[j][i]=53;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='X'&&charin[j][i][1]=='e')
            ngto[j][i]=54;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='s')
            ngto[j][i]=55;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='B'&&charin[j][i][1]=='a')
            ngto[j][i]=56;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='L'&&charin[j][i][1]=='a')
            ngto[j][i]=57;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='e')
            ngto[j][i]=58;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='P'&&charin[j][i][1]=='r')
            ngto[j][i]=59;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='N'&&charin[j][i][1]=='d')
            ngto[j][i]=60;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='P'&&charin[j][i][1]=='m')
            ngto[j][i]=61;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='S'&&charin[j][i][1]=='m')
            ngto[j][i]=62;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='E'&&charin[j][i][1]=='u')
            ngto[j][i]=63;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='G'&&charin[j][i][1]=='d')
            ngto[j][i]=64;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='T'&&charin[j][i][1]=='b')
            ngto[j][i]=65;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='D'&&charin[j][i][1]=='y')
            ngto[j][i]=66;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='H'&&charin[j][i][1]=='o')
            ngto[j][i]=67;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='E'&&charin[j][i][1]=='r')
            ngto[j][i]=68;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='T'&&charin[j][i][1]=='m')
            ngto[j][i]=69;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='Y'&&charin[j][i][1]=='b')
            ngto[j][i]=70;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='L'&&charin[j][i][1]=='u')
            ngto[j][i]=71;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='H'&&charin[j][i][1]=='f')
            ngto[j][i]=72;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='T'&&charin[j][i][1]=='a')
            ngto[j][i]=73;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='W')
            ngto[j][i]=74;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='R'&&charin[j][i][1]=='e')
            ngto[j][i]=75;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='O'&&charin[j][i][1]=='s')
            ngto[j][i]=76;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='I'&&charin[j][i][1]=='r')
            ngto[j][i]=77;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='P'&&charin[j][i][1]=='t')
            ngto[j][i]=78;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='A'&&charin[j][i][1]=='u')
            ngto[j][i]=79;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='H'&&charin[j][i][1]=='g')
            ngto[j][i]=80;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='T'&&charin[j][i][1]=='l')
            ngto[j][i]=81;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='P'&&charin[j][i][1]=='b')
            ngto[j][i]=82;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='B'&&charin[j][i][1]=='i')
            ngto[j][i]=83;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='P'&&charin[j][i][1]=='o')
            ngto[j][i]=84;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='A'&&charin[j][i][1]=='t')
            ngto[j][i]=85;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='R'&&charin[j][i][1]=='n')
            ngto[j][i]=86;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='F'&&charin[j][i][1]=='r')
            ngto[j][i]=87;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='R'&&charin[j][i][1]=='a')
            ngto[j][i]=88;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='A'&&charin[j][i][1]=='c')
            ngto[j][i]=89;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='T'&&charin[j][i][1]=='h')
            ngto[j][i]=90;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='P'&&charin[j][i][1]=='a')
            ngto[j][i]=91;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='U')
            ngto[j][i]=92;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='N'&&charin[j][i][1]=='p')
            ngto[j][i]=93;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='P'&&charin[j][i][1]=='u')
            ngto[j][i]=94;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='A'&&charin[j][i][1]=='m')
            ngto[j][i]=95;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='m')
            ngto[j][i]=96;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='B'&&charin[j][i][1]=='k')
            ngto[j][i]=97;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='f')
            ngto[j][i]=98;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='E'&&charin[j][i][1]=='s')
            ngto[j][i]=99;
        else
            ngto[j][i]=100;
    }
    j=1;
    for(i=0;i<k;i++)
    {
        if(strlen(charin[j][i])==1&&charin[j][i][0]=='H')
            ngto[j][i]=1;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='H'&&charin[j][i][1]=='e')
            ngto[j][i]=2;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='L'&&charin[j][i][1]=='i')
            ngto[j][i]=3;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='B'&&charin[j][i][1]=='e')
            ngto[j][i]=4;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='B')
            ngto[j][i]=5;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='C')
            ngto[j][i]=6;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='N')
            ngto[j][i]=7;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='O')
            ngto[j][i]=8;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='F')
            ngto[j][i]=9;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='N'&&charin[j][i][1]=='e')
            ngto[j][i]=10;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='N'&&charin[j][i][1]=='a')
            ngto[j][i]=11;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='M'&&charin[j][i][1]=='g')
            ngto[j][i]=12;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='A'&&charin[j][i][1]=='l')
            ngto[j][i]=13;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='S'&&charin[j][i][1]=='i')
            ngto[j][i]=14;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='P')
            ngto[j][i]=15;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='S')
            ngto[j][i]=16;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='l')
            ngto[j][i]=17;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='A'&&charin[j][i][1]=='r')
            ngto[j][i]=18;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='K')
            ngto[j][i]=19;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='a')
            ngto[j][i]=20;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='S'&&charin[j][i][1]=='c')
            ngto[j][i]=21;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='T'&&charin[j][i][1]=='i')
            ngto[j][i]=22;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='V')
            ngto[j][i]=23;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='r')
            ngto[j][i]=24;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='M'&&charin[j][i][1]=='n')
            ngto[j][i]=25;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='F'&&charin[j][i][1]=='e')
            ngto[j][i]=26;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='o')
            ngto[j][i]=27;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='N'&&charin[j][i][1]=='i')
            ngto[j][i]=28;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='u')
            ngto[j][i]=29;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='Z'&&charin[j][i][1]=='n')
            ngto[j][i]=30;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='G'&&charin[j][i][1]=='a')
            ngto[j][i]=31;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='G'&&charin[j][i][1]=='e')
            ngto[j][i]=32;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='A'&&charin[j][i][1]=='s')
            ngto[j][i]=33;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='S'&&charin[j][i][1]=='e')
            ngto[j][i]=34;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='B'&&charin[j][i][1]=='r')
            ngto[j][i]=35;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='K'&&charin[j][i][1]=='r')
            ngto[j][i]=36;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='R'&&charin[j][i][1]=='b')
            ngto[j][i]=37;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='S'&&charin[j][i][1]=='r')
            ngto[j][i]=38;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='Y')
            ngto[j][i]=39;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='Z'&&charin[j][i][1]=='r')
            ngto[j][i]=40;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='N'&&charin[j][i][1]=='b')
            ngto[j][i]=41;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='M'&&charin[j][i][1]=='o')
            ngto[j][i]=42;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='T'&&charin[j][i][1]=='c')
            ngto[j][i]=43;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='R'&&charin[j][i][1]=='u')
            ngto[j][i]=44;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='R'&&charin[j][i][1]=='h')
            ngto[j][i]=45;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='P'&&charin[j][i][1]=='d')
            ngto[j][i]=46;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='A'&&charin[j][i][1]=='g')
            ngto[j][i]=47;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='d')
            ngto[j][i]=48;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='I'&&charin[j][i][1]=='n')
            ngto[j][i]=49;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='S'&&charin[j][i][1]=='n')
            ngto[j][i]=50;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='S'&&charin[j][i][1]=='b')
            ngto[j][i]=51;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='T'&&charin[j][i][1]=='e')
            ngto[j][i]=52;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='I')
            ngto[j][i]=53;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='X'&&charin[j][i][1]=='e')
            ngto[j][i]=54;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='s')
            ngto[j][i]=55;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='B'&&charin[j][i][1]=='a')
            ngto[j][i]=56;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='L'&&charin[j][i][1]=='a')
            ngto[j][i]=57;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='e')
            ngto[j][i]=58;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='P'&&charin[j][i][1]=='r')
            ngto[j][i]=59;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='N'&&charin[j][i][1]=='d')
            ngto[j][i]=60;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='P'&&charin[j][i][1]=='m')
            ngto[j][i]=61;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='S'&&charin[j][i][1]=='m')
            ngto[j][i]=62;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='E'&&charin[j][i][1]=='u')
            ngto[j][i]=63;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='G'&&charin[j][i][1]=='d')
            ngto[j][i]=64;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='T'&&charin[j][i][1]=='b')
            ngto[j][i]=65;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='D'&&charin[j][i][1]=='y')
            ngto[j][i]=66;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='H'&&charin[j][i][1]=='o')
            ngto[j][i]=67;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='E'&&charin[j][i][1]=='r')
            ngto[j][i]=68;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='T'&&charin[j][i][1]=='m')
            ngto[j][i]=69;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='Y'&&charin[j][i][1]=='b')
            ngto[j][i]=70;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='L'&&charin[j][i][1]=='u')
            ngto[j][i]=71;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='H'&&charin[j][i][1]=='f')
            ngto[j][i]=72;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='T'&&charin[j][i][1]=='a')
            ngto[j][i]=73;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='W')
            ngto[j][i]=74;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='R'&&charin[j][i][1]=='e')
            ngto[j][i]=75;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='O'&&charin[j][i][1]=='s')
            ngto[j][i]=76;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='I'&&charin[j][i][1]=='r')
            ngto[j][i]=77;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='P'&&charin[j][i][1]=='t')
            ngto[j][i]=78;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='A'&&charin[j][i][1]=='u')
            ngto[j][i]=79;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='H'&&charin[j][i][1]=='g')
            ngto[j][i]=80;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='T'&&charin[j][i][1]=='l')
            ngto[j][i]=81;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='P'&&charin[j][i][1]=='b')
            ngto[j][i]=82;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='B'&&charin[j][i][1]=='i')
            ngto[j][i]=83;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='P'&&charin[j][i][1]=='o')
            ngto[j][i]=84;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='A'&&charin[j][i][1]=='t')
            ngto[j][i]=85;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='R'&&charin[j][i][1]=='n')
            ngto[j][i]=86;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='F'&&charin[j][i][1]=='r')
            ngto[j][i]=87;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='R'&&charin[j][i][1]=='a')
            ngto[j][i]=88;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='A'&&charin[j][i][1]=='c')
            ngto[j][i]=89;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='T'&&charin[j][i][1]=='h')
            ngto[j][i]=90;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='P'&&charin[j][i][1]=='a')
            ngto[j][i]=91;
        else if(strlen(charin[j][i])==1&&charin[j][i][0]=='U')
            ngto[j][i]=92;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='N'&&charin[j][i][1]=='p')
            ngto[j][i]=93;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='P'&&charin[j][i][1]=='u')
            ngto[j][i]=94;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='A'&&charin[j][i][1]=='m')
            ngto[j][i]=95;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='m')
            ngto[j][i]=96;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='B'&&charin[j][i][1]=='k')
            ngto[j][i]=97;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='C'&&charin[j][i][1]=='f')
            ngto[j][i]=98;
        else if(strlen(charin[j][i])==2&&charin[j][i][0]=='E'&&charin[j][i][1]=='s')
            ngto[j][i]=99;
        else
            ngto[j][i]=100;
    }
    int sum;
    for(i=0;i<(1<<n);i++)
    {
        sum=0;
        for(j=0;j<n;j++)
        {
            if(((1<<j)&i)!=0)
            {
                sum+=ngto[0][j];
            }
        }
        V[sum].push_back(i);
        tinh[sum]++;
    }
    check[0][0]=1;
    for(i=0;i<k;i++)
    {
        for(j=0;j<(1<<n);j++)
        {
            if(check[i][j])
            {
                for(l=0;l<tinh[ngto[1][i]];l++)
                    if((V[ngto[1][i]][l]&j)==0)check[i+1][V[ngto[1][i]][l]+j]=1;
            }
        }
    }
    if(check[k][(1<<n)-1])
    {
        printf("YES\n");
        tmp1=(1<<n)-1;
        for(i=k-1;i>=0;i--)
        {
            kt1=1;
            for(j=tinh[ngto[1][i]]-1;j>=0;j--)
            {
                if(kt1&&((V[ngto[1][i]][j]&tmp1)==V[ngto[1][i]][j])&&check[i][tmp1-V[ngto[1][i]][j]])
                {
                    kt1=0;
                    kt2=1;
                    for(l=0;l<n;l++)
                    {
                        if(((1<<l)&V[ngto[1][i]][j])==(1<<l))
                        {
                            if(kt2)
                            {
                                kt2=0;
                            }
                            else
                            {
                                printf("+");
                            }
                            printf("%s",charin[0][l]);
                        }
                    }
                    printf("->%s\n",charin[1][i]);
                    tmp1-=V[ngto[1][i]][j];
                }
            }
        }
    }
    else printf("NO\n");
}


#include<stdio.h>
#define MAX 100100
int  n,i,t;
int a[MAX];
int count;
int main()
{
    scanf("%d",&n);
    for (i=1; i<=n; i++)
    {
        scanf("%d",&t);
        a[i]=t;
    }
    count=0;
    for (i=n;i>=2;i--)
    {
        if (a[i]<a[i-1])
        {
            count++;
        }
    }
    printf("%d\n",count);
}


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

char s[110][5]={"H","He","Li","Be","B","C","N","O","F","Ne","Na","Mg","Al","Si",
"P","S","Cl","Ar","K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn",
"Ga","Ge","As","Se","Br","Kr","Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd",
"Ag","Cd","In","Sn","Sb","Te","I","Xe","Cs","Ba","La","Ce","Pr","Nd","Pm","Sm",
"Eu","Gd","Tb","Dy","Ho","Er","Tm","Yb","Lu","Hf","Ta","W","Re","Os","Ir","Pt",
"Au","Hg","Tl","Pb","Bi","Po","At","Rn","Fr","Ra","Ac","Th","Pa","U","Np","Pu",
"Am","Cm","Bk","Cf","Es","Fm"};

char ch[5];
int n,m,Num,a[20],b[20],c[20][20],num[20];
bool flag[20];
bool DFS(int mm,int nn,int left)//mm中剩余的left从a[1-nn]中补充
{
	int i;
	if(!left)
	{
		if(!mm) return true;
		for(i=n-1;i>=0;i--)
			if(!flag[i])
				break;
		if(a[i]>b[mm-1]) return false;
		return DFS(mm-1,i,b[mm-1]);
	}

	if(Num<mm+1) return false;//剩余a中的个数小于要组成b的个数

	for(i=nn;i>=0;i--)
	{
		if(flag[i]) continue;
		if(left>=a[i])
		{
			Num--;
			flag[i]=true;
			c[mm][num[mm]++]=a[i];
			if(DFS(mm,i,left-a[i]))
				return true;
			num[mm]--;
			flag[i]=false;
			Num++;
		}
	}
	return false;
}
int main()
{
//    freopen("asdf","r",stdin);
	int i,j;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		for(i=0;i<n;i++)
		{
			scanf("%s",ch);
			for(j=0;j<100;j++)
				if(!strcmp(s[j],ch))
				{
					a[i]=j+1;
					break;
				}
		}
		for(i=0;i<m;i++)
		{
			scanf("%s",ch);
			for(j=0;j<100;j++)
				if(!strcmp(s[j],ch))
				{
					b[i]=j+1;
					break;
				}
		}
		sort(a,a+n);
		sort(b,b+m);

		//由a中的数组合成b中的数
		//没加这个test54 TLE
		if(b[0]<a[0])//b中最小的肯定要大于a中最小的,否则不能组合成功
		{
			printf("NO\n");
			continue;
		}
		memset(c,0,sizeof(c));//保存每个b中的数所需a中的数
		memset(num,0,sizeof(num));//对应每个b中的数由多少个a中的数组成
		memset(flag,false,sizeof(flag));//标记a中的数是否已用
		Num=n;//Num表示a中剩余的个数
		if(DFS(m-1,n-1,b[m-1]))
		{
			printf("YES\n");
			for(i=0;i<m;i++)
			{
				for(j=num[i]-1;j>0;j--)
				{
					printf("%s+",s[c[i][j]-1]);
				}
				printf("%s",s[c[i][j]-1]);
				printf("->%s\n",s[b[i]-1]);
			}
		}
		else printf("NO\n");
	}
	return 0;
}


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

char s[110][5]={"H","He","Li","Be","B","C","N","O","F","Ne","Na","Mg","Al","Si",
"P","S","Cl","Ar","K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn",
"Ga","Ge","As","Se","Br","Kr","Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd",
"Ag","Cd","In","Sn","Sb","Te","I","Xe","Cs","Ba","La","Ce","Pr","Nd","Pm","Sm",
"Eu","Gd","Tb","Dy","Ho","Er","Tm","Yb","Lu","Hf","Ta","W","Re","Os","Ir","Pt",
"Au","Hg","Tl","Pb","Bi","Po","At","Rn","Fr","Ra","Ac","Th","Pa","U","Np","Pu",
"Am","Cm","Bk","Cf","Es","Fm"};

char ch[5];
int n,m,Num,a[20],b[20],c[20][20],num[20];
bool flag[20];
bool DFS(int mm,int nn,int left)//mm中剩余的left从a[1-nn]中补充
{
	int i;
	if(!left)
	{
		if(!mm) return true;
		for(i=n-1;i>=0;i--)
			if(!flag[i])
				break;
		if(a[i]>b[mm-1]) return false;
		return DFS(mm-1,i,b[mm-1]);
	}

	if(Num<mm+1) return false;//剩余a中的个数小于要组成b的个数

	for(i=nn;i>=0;i--)
	{
		if(flag[i]) continue;
		if(left>=a[i])
		{
			Num--;
			flag[i]=true;
			c[mm][num[mm]++]=a[i];
			if(DFS(mm,i,left-a[i]))
				return true;
			num[mm]--;
			flag[i]=false;
			Num++;
		}
	}
	return false;
}
int main()
{
//    freopen("asdf","r",stdin);
	int i,j;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		for(i=0;i<n;i++)
		{
			scanf("%s",ch);
			for(j=0;j<100;j++)
				if(!strcmp(s[j],ch))
				{
					a[i]=j+1;
					break;
				}
		}
		for(i=0;i<m;i++)
		{
			scanf("%s",ch);
			for(j=0;j<100;j++)
				if(!strcmp(s[j],ch))
				{
					b[i]=j+1;
					break;
				}
		}
		sort(a,a+n);
		sort(b,b+m);

		//由a中的数组合成b中的数
		//没加这个test54 TLE
		if(b[0]<a[0])//b中最小的肯定要大于a中最小的,否则不能组合成功
		{
			printf("NO/n");
			continue;
		}
		memset(c,0,sizeof(c));//保存每个b中的数所需a中的数
		memset(num,0,sizeof(num));//对应每个b中的数由多少个a中的数组成
		memset(flag,false,sizeof(flag));//标记a中的数是否已用
		Num=n;//Num表示a中剩余的个数
		if(DFS(m-1,n-1,b[m-1]))
		{
			printf("YES\n");
			for(i=0;i<m;i++)
			{
				for(j=num[i]-1;j>0;j--)
				{
					printf("%s+",s[c[i][j]-1]);
				}
				printf("%s",s[c[i][j]-1]);
				printf("->%s\n",s[b[i]-1]);
			}
		}
		else printf("NO\n");
	}
	return 0;
}


#include <set>
#include <map>
#include <queue>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define foreach(e,x) for(__typeof(x.begin()) e=x.begin(); e!=x.end(); ++e)

const int N = 17;
const int S = 1 << N;
const int MOD = 1e9 + 7;

const char nm[][5]
{
	"H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg",
	"Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr",
	"Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr",
	"Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In",
	"Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm",
	"Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W",
	"Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr",
	"Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm",
	"Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn", "Uut",
	"Fl", "Uup", "Lv", "Uus", "Uuo"
};

int n, k;
int sn, sk;
map<string, int> cost;
int sum[S];
int f[N][S];
int pre[N][S];
vector<int> ok[N];
vector<int> a, b;

void output(int i, int j)
{
	if (i == 0) return;
	int tmp = pre[i][j];
	output(i - 1, j - tmp);
	vector<string> ss;
	for(int w = 0; w < n; ++ w) {
		if (tmp >> w & 1) {
			ss.push_back(nm[a[w] - 1]);
		}
	}
	for(int w = 0; w < ss.size(); ++ w) {
		cout << ss[w];
		if (w + 1 < ss.size()) cout << "+";
		else cout << "->";
	}
	cout << nm[b[i - 1] - 1] << endl;
}

void solve()
{
	for(int i = 0; i < 118; ++ i) {
		cost[nm[i]] = i + 1;
	}
	cin >> n >> k;
	for(int i = 0; i < n; ++ i) {
		string cur;
		cin >> cur;
		a.push_back(cost[cur]);
	}
	for(int i = 0; i < k; ++ i) {
		string cur;
		cin >> cur;
		b.push_back(cost[cur]);
	}
	/*
	for(int i = 0; i < n; ++ i) {
		cout << a[i] << ' ';
	}
	cout << endl;
	for(int i = 0; i < k; ++ i) {
		cout << b[i] << ' ';
	}
	cout << endl;
	*/
	sn = 1 << n;
	sum[0] = 0;
	for(int i = 1; i < sn; ++ i) {
		sum[i] = 0;
		for(int j = 0; j < n; ++ j) {
			if (i >> j & 1) {
				sum[i] += a[j];
			}
		}
	}

	f[0][0] = true;
	for(int i = 0; i < k; ++ i) {
		for(int j = 0; j < sn; ++ j) {
			if (f[i][j] == false) continue;
			int left = sn - 1 - j;
			for(int tmp = left; tmp; tmp = (tmp - 1) & left) {
				if (sum[tmp] == b[i]) {
					f[i + 1][j + tmp] = true;
					pre[i + 1][j + tmp] = tmp;
				}
			}
		}
	}
	if (f[k][sn - 1]) {
		puts("YES");
		output(k, sn - 1);
	} else {
		puts("NO");
	}
}

int main()
{
	solve();
	return 0;
}


#include <set>
#include <map>
#include <queue>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define foreach(e,x) for(__typeof(x.begin()) e=x.begin(); e!=x.end(); ++e)

const int N = 17;
const int S = 1 << N;
const int MOD = 1e9 + 7;

const char nm[][5]
{
    "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg",
    "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr",
    "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr",
    "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In",
    "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm",
    "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W",
    "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr",
    "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm",
    "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn", "Uut",
    "Fl", "Uup", "Lv", "Uus", "Uuo"
};

int n, k;
int sn, sk;
map<string, int> cost;
int sum[S];
int f[N + 1][S];
int pre[N][S];
vector<int> a, b;

void output(int i, int j)
{
    if (i == 0) return;
    int tmp = pre[i][j];
    output(i - 1, j - tmp);
    vector<string> ss;
    for(int w = 0; w < n; ++ w) {
        if (tmp >> w & 1) {
            ss.push_back(nm[a[w] - 1]);
        }
    }
    for(int w = 0; w < ss.size(); ++ w) {
        cout << ss[w];
        if (w + 1 < ss.size()) cout << "+";
        else cout << "->";
    }
    cout << nm[b[i - 1] - 1] << endl;
}

void solve()
{
    for(int i = 0; i < 118; ++ i) {
        cost[nm[i]] = i + 1;
    }
    cin >> n >> k;
    for(int i = 0; i < n; ++ i) {
        string cur;
        cin >> cur;
        a.push_back(cost[cur]);
    }
    for(int i = 0; i < k; ++ i) {
        string cur;
        cin >> cur;
        b.push_back(cost[cur]);
    }
    /*
    for(int i = 0; i < n; ++ i) {
        cout << a[i] << ' ';
    }
    cout << endl;
    for(int i = 0; i < k; ++ i) {
        cout << b[i] << ' ';
    }
    cout << endl;
    */
    sn = 1 << n;
    sum[0] = 0;
    for(int i = 1; i < sn; ++ i) {
        sum[i] = 0;
        for(int j = 0; j < n; ++ j) {
            if (i >> j & 1) {
                sum[i] += a[j];
            }
        }
    }

    f[0][0] = true;
    for(int i = 0; i < k; ++ i) {
        for(int j = 0; j < sn; ++ j) {
            if (f[i][j] == false) continue;
            int left = sn - 1 - j;
            for(int tmp = left; tmp; tmp = (tmp - 1) & left) {
                if (sum[tmp] == b[i]) {
                    f[i + 1][j + tmp] = true;
                    pre[i + 1][j + tmp] = tmp;
                }
            }
        }
    }
    if (f[k][sn - 1]) {
        puts("YES");
        output(k, sn - 1);
    } else {
        puts("NO");
    }
}

int main()
{
    solve();
    return 0;
}


#include <set>
#include <map>
#include <queue>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define foreach(e,x) for(__typeof(x.begin()) e=x.begin(); e!=x.end(); ++e)

const int N = 17;
const int S = 1 << N;
const int MOD = 1e9 + 7;

const char nm[][5]
{
    "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg",
    "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr",
    "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr",
    "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In",
    "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm",
    "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W",
    "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr",
    "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm",
    "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn", "Uut",
    "Fl", "Uup", "Lv", "Uus", "Uuo"
};

int n, k;
int sn, sk;
map<string, int> cost;
int sum[S];
int f[N][S];
int pre[N][S];
vector<int> ok[N];
vector<int> a, b;

void output(int i, int j)
{
    if (i == 0) return;
    int tmp = pre[i][j];
    output(i - 1, j - tmp);
    vector<string> ss;
    for(int w = 0; w < n; ++ w) {
        if (tmp >> w & 1) {
            ss.push_back(nm[a[w] - 1]);
        }
    }
    for(int w = 0; w < ss.size(); ++ w) {
        cout << ss[w];
        if (w + 1 < ss.size()) cout << "+";
        else cout << "->";
    }
    cout << nm[b[i - 1] - 1] << endl;
}

void solve()
{
    for(int i = 0; i < 118; ++ i) {
        cost[nm[i]] = i + 1;
    }
    cin >> n >> k;
    for(int i = 0; i < n; ++ i) {
        string cur;
        cin >> cur;
        a.push_back(cost[cur]);
    }
    for(int i = 0; i < k; ++ i) {
        string cur;
        cin >> cur;
        b.push_back(cost[cur]);
    }
    /*
    for(int i = 0; i < n; ++ i) {
        cout << a[i] << ' ';
    }
    cout << endl;
    for(int i = 0; i < k; ++ i) {
        cout << b[i] << ' ';
    }
    cout << endl;
    */
    sn = 1 << n;
    sum[0] = 0;
    for(int i = 1; i < sn; ++ i) {
        sum[i] = 0;
        for(int j = 0; j < n; ++ j) {
            if (i >> j & 1) {
                sum[i] += a[j];
            }
        }
    }

    f[0][0] = true;
    for(int i = 0; i < k; ++ i) {
        for(int j = 0; j < sn; ++ j) {
            if (f[i][j] == false) continue;
            int left = sn - 1 - j;
            for(int tmp = left; tmp; tmp = (tmp - 1) & left) {
                if (sum[tmp] == b[i]) {
                    f[i + 1][j + tmp] = true;
                    pre[i + 1][j + tmp] = tmp;
                }
            }
        }
    }
    if (f[k][sn - 1]) {
        puts("YES");
        output(k, sn - 1);
    } else {
        puts("NO");
    }
}

int main()
{
    solve();
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<math.h>
using namespace std;
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define sint(i) scanf("%d",&i)
#define ss(s) scanf("%s",s)
#define pii pair<int,int>
#define mp(i,j) make_pair(i,j)
#define ll long long
#define MAX 1000000000
#define MOD 1000000007
#define vi vector<int>
#define vvi vector < vi >
#define pb(i) push_back(i);
#define tr(v,it) for(it=v.begin();it!=v.end();it++)
int main()
{
    map<string,int> Map;
    Map["H"] = 1;
    Map["He"] = 2;
    Map["Li"] = 3;
    Map["Be"] = 4;
    Map["B"] = 5;
    Map["C"] = 6;
    Map["N"] = 7;
    Map["O"] = 8;
    Map["F"] = 9;
    Map["Ne"] = 10;
    Map["Na"] = 11;
    Map["Mg"] = 12;
    Map["Al"] = 13;
    Map["Si"] = 14;
    Map["P"] = 15;
    Map["S"] = 16;
    Map["Cl"] = 17;
    Map["Ar"] = 18;
    Map["K"] = 19;
    Map["Ca"] = 20;
    Map["Sc"] = 21;
    Map["Ti"] = 22;
    Map["V"] = 23;
    Map["Cr"] = 24;
    Map["Mn"] = 25;
    Map["Fe"] = 26;
    Map["Co"] = 27;
    Map["Ni"] = 28;
    Map["Cu"] = 29;
    Map["Zn"] = 30;
    Map["Ga"] = 31;
    Map["Ge"] = 32;
    Map["As"] = 33;
    Map["Se"] = 34;
    Map["Br"] = 35;
    Map["Kr"] = 36;
    Map["Rb"] = 37;
    Map["Sr"] = 38;
    Map["Y"] = 39;
    Map["Zr"] = 40;
    Map["Nb"] = 41;
    Map["Mo"] = 42;
    Map["Tc"] = 43;
    Map["Ru"] = 44;
    Map["Rh"] = 45;
    Map["Pd"] = 46;
    Map["Ag"] = 47;
    Map["Cd"] = 48;
    Map["In"] = 49;
    Map["Sn"] = 50;
    Map["Sb"] = 51;
    Map["Te"] = 52;
    Map["I"] = 53;
    Map["Xe"] = 54;
    Map["Cs"] = 55;
    Map["Ba"] = 56;
    Map["La"] = 57;
    Map["Ce"] = 58;
    Map["Pr"] = 59;
    Map["Nd"] = 60;
    Map["Pm"] = 61;
    Map["Sm"] = 62;
    Map["Eu"] = 63;
    Map["Gd"] = 64;
    Map["Tb"] = 65;
    Map["Dy"] = 66;
    Map["Ho"] = 67;
    Map["Er"] = 68;
    Map["Tm"] = 69;
    Map["Yb"] = 70;
    Map["Lu"] = 71;
    Map["Hf"] = 72;
    Map["Ta"] = 73;
    Map["W"] = 74;
    Map["Re"] = 75;
    Map["Os"] = 76;
    Map["Ir"] = 77;
    Map["Pt"] = 78;
    Map["Au"] = 79;
    Map["Hg"] = 80;
    Map["Tl"] = 81;
    Map["Pb"] = 82;
    Map["Bi"] = 83;
    Map["Po"] = 84;
    Map["At"] = 85;
    Map["Rn"] = 86;
    Map["Fr"] = 87;
    Map["Ra"] = 88;
    Map["Ac"] = 89;
    Map["Th"] = 90;
    Map["Pa"] = 91;
    Map["U"] = 92;
    Map["Np"] = 93;
    Map["Pu"] = 94;
    Map["Am"] = 95;
    Map["Cm"] = 96;
    Map["Bk"] = 97;
    Map["Cf"] = 98;
    Map["Es"] = 99;
    Map["Fm"] = 100;
    map<int,string> rev_Map;
    map<string,int>::iterator it1;
    tr(Map,it1)
    {
        rev_Map[it1->second]=it1->first;
    }
    int i,j;
    map<int,int> m;
    FOR(i,0,25)
    m[1<<i]=i;
    int n,k;
    int num,curr,start;
    cin>>n>>k;
    string s;
    int arr1[n],arr2[k];
    FOR(i,0,n-1)
    {
    cin>>s;
    arr1[i]=Map[s];
   // cout<<arr1[i]<<" ";
    }
    //cout<<"\n";
    FOR(i,0,k-1)
    {
    cin>>s;
    arr2[i]=Map[s];
   // cout<<arr2[i]<<" ";
    }
  //  cout<<"\n";
    int dp[(1<<n)];
    vector<int> can_make[k];
    bool check[1<<n];
    int pre[1<<n];
    int sum=0;
    FOR(i,0,(1<<n)-1)
    {
        dp[i]=0;
        check[i]=false;
        num=i;
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            sum=sum+arr1[m[curr]];
        }
        FOR(j,0,k-1)
        {
            if(arr2[j]==sum)
            {
            can_make[j].pb(i);
            }
        }
    }
        dp[0]=0;
        check[0]=true;
        int k1;
        vector<int>::iterator it;
    FOR(i,0,k-1)
    {
        for(j=(1<<n)-1;j>=0;j--)
        {
            if(!check[j])
            tr(can_make[i],it)
            {
                k1=*it;
                if((k1&j)==k1)
                {
                    if((dp[j-k1]+1)>dp[j])
                    {
                       // cout<<"hey"<<j<<" ";
                        dp[j]=dp[j-k1]+1;
                        if(check[j-k1])
                        check[j]=true;
                        pre[j]=j-k1;
                    }
                }
            }
        }

    }
    if(dp[(1<<n)-1]==k)
    {
        cout<<"YES\n";
    start=(1<<n)-1;
    int sum;
    while(start)
    {
        //cout<<start<<" ";
        num=start-pre[start];
        start=pre[start];
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            cout<<rev_Map[arr1[m[curr]]];
            sum=sum+arr1[m[curr]];
            if(num)
            cout<<"+";
        }
        cout<<"->";
        cout<<rev_Map[sum]<<"\n";
    }
    }
    else
    cout<<"NO";
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<math.h>
using namespace std;
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define sint(i) scanf("%d",&i)
#define ss(s) scanf("%s",s)
#define pii pair<int,int>
#define mp(i,j) make_pair(i,j)
#define ll long long
#define MAX 1000000000
#define MOD 1000000007
#define vi vector<int>
#define vvi vector < vi >
#define pb(i) push_back(i);
#define tr(v,it) for(it=v.begin();it!=v.end();it++)
int main()
{
    map<string,int> Map;
    Map["H"] = 1;
    Map["He"] = 2;
    Map["Li"] = 3;
    Map["Be"] = 4;
    Map["B"] = 5;
    Map["C"] = 6;
    Map["N"] = 7;
    Map["O"] = 8;
    Map["F"] = 9;
    Map["Ne"] = 10;
    Map["Na"] = 11;
    Map["Mg"] = 12;
    Map["Al"] = 13;
    Map["Si"] = 14;
    Map["P"] = 15;
    Map["S"] = 16;
    Map["Cl"] = 17;
    Map["Ar"] = 18;
    Map["K"] = 19;
    Map["Ca"] = 20;
    Map["Sc"] = 21;
    Map["Ti"] = 22;
    Map["V"] = 23;
    Map["Cr"] = 24;
    Map["Mn"] = 25;
    Map["Fe"] = 26;
    Map["Co"] = 27;
    Map["Ni"] = 28;
    Map["Cu"] = 29;
    Map["Zn"] = 30;
    Map["Ga"] = 31;
    Map["Ge"] = 32;
    Map["As"] = 33;
    Map["Se"] = 34;
    Map["Br"] = 35;
    Map["Kr"] = 36;
    Map["Rb"] = 37;
    Map["Sr"] = 38;
    Map["Y"] = 39;
    Map["Zr"] = 40;
    Map["Nb"] = 41;
    Map["Mo"] = 42;
    Map["Tc"] = 43;
    Map["Ru"] = 44;
    Map["Rh"] = 45;
    Map["Pd"] = 46;
    Map["Ag"] = 47;
    Map["Cd"] = 48;
    Map["In"] = 49;
    Map["Sn"] = 50;
    Map["Sb"] = 51;
    Map["Te"] = 52;
    Map["I"] = 53;
    Map["Xe"] = 54;
    Map["Cs"] = 55;
    Map["Ba"] = 56;
    Map["La"] = 57;
    Map["Ce"] = 58;
    Map["Pr"] = 59;
    Map["Nd"] = 60;
    Map["Pm"] = 61;
    Map["Sm"] = 62;
    Map["Eu"] = 63;
    Map["Gd"] = 64;
    Map["Tb"] = 65;
    Map["Dy"] = 66;
    Map["Ho"] = 67;
    Map["Er"] = 68;
    Map["Tm"] = 69;
    Map["Yb"] = 70;
    Map["Lu"] = 71;
    Map["Hf"] = 72;
    Map["Ta"] = 73;
    Map["W"] = 74;
    Map["Re"] = 75;
    Map["Os"] = 76;
    Map["Ir"] = 77;
    Map["Pt"] = 78;
    Map["Au"] = 79;
    Map["Hg"] = 80;
    Map["Tl"] = 81;
    Map["Pb"] = 82;
    Map["Bi"] = 83;
    Map["Po"] = 84;
    Map["At"] = 85;
    Map["Rn"] = 86;
    Map["Fr"] = 87;
    Map["Ra"] = 88;
    Map["Ac"] = 89;
    Map["Th"] = 90;
    Map["Pa"] = 91;
    Map["U"] = 92;
    Map["Np"] = 93;
    Map["Pu"] = 94;
    Map["Am"] = 95;
    Map["Cm"] = 96;
    Map["Bk"] = 97;
    Map["Cf"] = 98;
    Map["Es"] = 99;
    Map["Fm"] = 100;
    map<int,string> rev_Map;
    map<string,int>::iterator it;
    tr(Map,it)
    {
        rev_Map[it->second]=it->first;
    }
    int i,j;
    map<int,int> m;
    FOR(i,0,25)
    m[1<<i]=i;
    int n,k;
    int num,curr,start;
    cin>>n>>k;
    string s;
    int arr1[n],arr2[k];
    FOR(i,0,n-1)
    {
    cin>>s;
    arr1[i]=Map[s];
    }
    FOR(i,0,k-1)
    {
    cin>>s;
    arr2[i]=Map[s];
    }
    int dp[(1<<n)];
    sort(arr1,arr1+n);
    sort(arr2,arr2+k);
    bool use[1<<n][101];
    int ans[1<<n][101];
    int pre[1<<n];
    FOR(i,1,100)
    use[0][i]=false;
    FOR(i,0,(1<<n)-1)
    {
        use[i][0]=true;
    }
    FOR(i,1,(1<<n)-1)
    {
        FOR(j,1,100)
        {
           num=i;
           use[i][j]=false;
           while(num)
           {
                curr=num-(num&(num-1));
                num=num-curr;
                curr=m[curr];
                if(arr1[curr]>j)
                break;
                if(use[i^(1<<curr)][j-arr1[curr]])
                {
                    use[i][j]=true;
                    ans[i][j]=curr;
                    break;
                }
           }
        }
    }
        dp[0]=0;
    FOR(i,1,(1<<n)-1)
    {
          dp[i]=0;
            pre[i]=0;
        FOR(j,0,k-1)
        {

            //check if possible
            num=i;
            if(use[i][arr2[j]])
            {
                int k1=arr2[j];
                int start=ans[num][k1];
                while(k1)
                {
                    k1=k1-arr1[start];
                    num=num^(1<<start);
                    start=ans[num][k1];
                }
                if((dp[num]+1)>dp[i])
                {
                    dp[i]=dp[num]+1;
                    pre[i]=num;
                }
            }
        }
      // cout<<i<<" "<<dp[i]<<"\n";
    }
    if(dp[(1<<n)-1]==k)
    {
        cout<<"YES\n";
    start=(1<<n)-1;
    int sum;
    while(start)
    {
        num=start-pre[start];
        start=pre[start];
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            cout<<rev_Map[arr1[m[curr]]];
            sum=sum+arr1[m[curr]];
            if(num)
            cout<<"+";
        }
        cout<<"->";
        cout<<rev_Map[sum]<<"\n";
    }
    }
    else
    cout<<"NO";
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<math.h>
using namespace std;
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define sint(i) scanf("%d",&i)
#define ss(s) scanf("%s",s)
#define pii pair<int,int>
#define mp(i,j) make_pair(i,j)
#define ll long long
#define MAX 1000000000
#define MOD 1000000007
#define vi vector<int>
#define vvi vector < vi >
#define pb(i) push_back(i);
#define tr(v,it) for(it=v.begin();it!=v.end();it++)
int main()
{
    map<string,int> Map;
    Map["H"] = 1;
    Map["He"] = 2;
    Map["Li"] = 3;
    Map["Be"] = 4;
    Map["B"] = 5;
    Map["C"] = 6;
    Map["N"] = 7;
    Map["O"] = 8;
    Map["F"] = 9;
    Map["Ne"] = 10;
    Map["Na"] = 11;
    Map["Mg"] = 12;
    Map["Al"] = 13;
    Map["Si"] = 14;
    Map["P"] = 15;
    Map["S"] = 16;
    Map["Cl"] = 17;
    Map["Ar"] = 18;
    Map["K"] = 19;
    Map["Ca"] = 20;
    Map["Sc"] = 21;
    Map["Ti"] = 22;
    Map["V"] = 23;
    Map["Cr"] = 24;
    Map["Mn"] = 25;
    Map["Fe"] = 26;
    Map["Co"] = 27;
    Map["Ni"] = 28;
    Map["Cu"] = 29;
    Map["Zn"] = 30;
    Map["Ga"] = 31;
    Map["Ge"] = 32;
    Map["As"] = 33;
    Map["Se"] = 34;
    Map["Br"] = 35;
    Map["Kr"] = 36;
    Map["Rb"] = 37;
    Map["Sr"] = 38;
    Map["Y"] = 39;
    Map["Zr"] = 40;
    Map["Nb"] = 41;
    Map["Mo"] = 42;
    Map["Tc"] = 43;
    Map["Ru"] = 44;
    Map["Rh"] = 45;
    Map["Pd"] = 46;
    Map["Ag"] = 47;
    Map["Cd"] = 48;
    Map["In"] = 49;
    Map["Sn"] = 50;
    Map["Sb"] = 51;
    Map["Te"] = 52;
    Map["I"] = 53;
    Map["Xe"] = 54;
    Map["Cs"] = 55;
    Map["Ba"] = 56;
    Map["La"] = 57;
    Map["Ce"] = 58;
    Map["Pr"] = 59;
    Map["Nd"] = 60;
    Map["Pm"] = 61;
    Map["Sm"] = 62;
    Map["Eu"] = 63;
    Map["Gd"] = 64;
    Map["Tb"] = 65;
    Map["Dy"] = 66;
    Map["Ho"] = 67;
    Map["Er"] = 68;
    Map["Tm"] = 69;
    Map["Yb"] = 70;
    Map["Lu"] = 71;
    Map["Hf"] = 72;
    Map["Ta"] = 73;
    Map["W"] = 74;
    Map["Re"] = 75;
    Map["Os"] = 76;
    Map["Ir"] = 77;
    Map["Pt"] = 78;
    Map["Au"] = 79;
    Map["Hg"] = 80;
    Map["Tl"] = 81;
    Map["Pb"] = 82;
    Map["Bi"] = 83;
    Map["Po"] = 84;
    Map["At"] = 85;
    Map["Rn"] = 86;
    Map["Fr"] = 87;
    Map["Ra"] = 88;
    Map["Ac"] = 89;
    Map["Th"] = 90;
    Map["Pa"] = 91;
    Map["U"] = 92;
    Map["Np"] = 93;
    Map["Pu"] = 94;
    Map["Am"] = 95;
    Map["Cm"] = 96;
    Map["Bk"] = 97;
    Map["Cf"] = 98;
    Map["Es"] = 99;
    Map["Fm"] = 100;
    map<int,string> rev_Map;
    map<string,int>::iterator it1;
    tr(Map,it1)
    {
        rev_Map[it1->second]=it1->first;
    }
    int i,j;
    map<int,int> m;
    FOR(i,0,25)
    m[1<<i]=i;
    int n,k;
    int num,curr,start;
    cin>>n>>k;
    string s;
    int arr1[n],arr2[k];
    FOR(i,0,n-1)
    {
    cin>>s;
    arr1[i]=Map[s];
   // cout<<arr1[i]<<" ";
    }
    //cout<<"\n";
    FOR(i,0,k-1)
    {
    cin>>s;
    arr2[i]=Map[s];
   // cout<<arr2[i]<<" ";
    }
  //  cout<<"\n";
    int dp[(1<<n)];
    sort(arr1,arr1+n);
    sort(arr2,arr2+k);
    vector<int> can_make[k];
    bool check[1<<n];
    int pre[1<<n];
    int sum=0;
    FOR(i,0,(1<<n)-1)
    {
        dp[i]=0;
        check[i]=false;
        num=i;
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            sum=sum+arr1[m[curr]];
        }
        FOR(j,0,k-1)
        {
            if(arr2[j]==sum)
            {
            can_make[j].pb(i);
            }
        }
    }
        dp[0]=0;
        check[0]=true;
        int k1;
        vector<int>::iterator it;
    FOR(i,0,k-1)
    {
        for(j=(1<<n)-1;j>=0;j--)
        {
            if(!check[j])
            tr(can_make[i],it)
            {
                k1=*it;
                if((k1&j)==k1)
                {
                    if((dp[j-k1]+1)>dp[j])
                    {
                       // cout<<"hey"<<j<<" ";
                        dp[j]=dp[j-k1]+1;
                        if(check[j-k1])
                        {
                            check[j]=true;
                            goto out;
                        }
                        pre[j]=j-k1;
                    }
                }
            }
            out:
            ;
        }

    }
    if(dp[(1<<n)-1]==k)
    {
        cout<<"YES\n";
    start=(1<<n)-1;
    int sum;
    while(start)
    {
        //cout<<start<<" ";
        num=start-pre[start];
        start=pre[start];
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            cout<<rev_Map[arr1[m[curr]]];
            sum=sum+arr1[m[curr]];
            if(num)
            cout<<"+";
        }
        cout<<"->";
        cout<<rev_Map[sum]<<"\n";
    }
    }
    else
    cout<<"NO";
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<math.h>
using namespace std;
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define sint(i) scanf("%d",&i)
#define ss(s) scanf("%s",s)
#define pii pair<int,int>
#define mp(i,j) make_pair(i,j)
#define ll long long
#define MAX 1000000000
#define MOD 1000000007
#define vi vector<int>
#define vvi vector < vi >
#define pb(i) push_back(i);
#define tr(v,it) for(it=v.begin();it!=v.end();it++)
int main()
{
    map<string,int> Map;
    Map["H"] = 1;
    Map["He"] = 2;
    Map["Li"] = 3;
    Map["Be"] = 4;
    Map["B"] = 5;
    Map["C"] = 6;
    Map["N"] = 7;
    Map["O"] = 8;
    Map["F"] = 9;
    Map["Ne"] = 10;
    Map["Na"] = 11;
    Map["Mg"] = 12;
    Map["Al"] = 13;
    Map["Si"] = 14;
    Map["P"] = 15;
    Map["S"] = 16;
    Map["Cl"] = 17;
    Map["Ar"] = 18;
    Map["K"] = 19;
    Map["Ca"] = 20;
    Map["Sc"] = 21;
    Map["Ti"] = 22;
    Map["V"] = 23;
    Map["Cr"] = 24;
    Map["Mn"] = 25;
    Map["Fe"] = 26;
    Map["Co"] = 27;
    Map["Ni"] = 28;
    Map["Cu"] = 29;
    Map["Zn"] = 30;
    Map["Ga"] = 31;
    Map["Ge"] = 32;
    Map["As"] = 33;
    Map["Se"] = 34;
    Map["Br"] = 35;
    Map["Kr"] = 36;
    Map["Rb"] = 37;
    Map["Sr"] = 38;
    Map["Y"] = 39;
    Map["Zr"] = 40;
    Map["Nb"] = 41;
    Map["Mo"] = 42;
    Map["Tc"] = 43;
    Map["Ru"] = 44;
    Map["Rh"] = 45;
    Map["Pd"] = 46;
    Map["Ag"] = 47;
    Map["Cd"] = 48;
    Map["In"] = 49;
    Map["Sn"] = 50;
    Map["Sb"] = 51;
    Map["Te"] = 52;
    Map["I"] = 53;
    Map["Xe"] = 54;
    Map["Cs"] = 55;
    Map["Ba"] = 56;
    Map["La"] = 57;
    Map["Ce"] = 58;
    Map["Pr"] = 59;
    Map["Nd"] = 60;
    Map["Pm"] = 61;
    Map["Sm"] = 62;
    Map["Eu"] = 63;
    Map["Gd"] = 64;
    Map["Tb"] = 65;
    Map["Dy"] = 66;
    Map["Ho"] = 67;
    Map["Er"] = 68;
    Map["Tm"] = 69;
    Map["Yb"] = 70;
    Map["Lu"] = 71;
    Map["Hf"] = 72;
    Map["Ta"] = 73;
    Map["W"] = 74;
    Map["Re"] = 75;
    Map["Os"] = 76;
    Map["Ir"] = 77;
    Map["Pt"] = 78;
    Map["Au"] = 79;
    Map["Hg"] = 80;
    Map["Tl"] = 81;
    Map["Pb"] = 82;
    Map["Bi"] = 83;
    Map["Po"] = 84;
    Map["At"] = 85;
    Map["Rn"] = 86;
    Map["Fr"] = 87;
    Map["Ra"] = 88;
    Map["Ac"] = 89;
    Map["Th"] = 90;
    Map["Pa"] = 91;
    Map["U"] = 92;
    Map["Np"] = 93;
    Map["Pu"] = 94;
    Map["Am"] = 95;
    Map["Cm"] = 96;
    Map["Bk"] = 97;
    Map["Cf"] = 98;
    Map["Es"] = 99;
    Map["Fm"] = 100;
    map<int,string> rev_Map;
    map<string,int>::iterator it1;
    tr(Map,it1)
    {
        rev_Map[it1->second]=it1->first;
    }
    int i,j;
    map<int,int> m;
    FOR(i,0,25)
    m[1<<i]=i;
    int n,k;
    int num,curr,start;
    cin>>n>>k;
    string s;
    int arr1[n],arr2[k];
    FOR(i,0,n-1)
    {
    cin>>s;
    arr1[i]=Map[s];
   // cout<<arr1[i]<<" ";
    }
    //cout<<"\n";
    FOR(i,0,k-1)
    {
    cin>>s;
    arr2[i]=Map[s];
   // cout<<arr2[i]<<" ";
    }
  //  cout<<"\n";
    int dp[(1<<n)];
    sort(arr1,arr1+n);
    sort(arr2,arr2+k);
    vector<int> can_make[k];
    bool check[1<<n];
    int pre[1<<n];
    int sum=0;
    FOR(i,0,(1<<n)-1)
    {
        dp[i]=0;
        check[i]=false;
        num=i;
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            sum=sum+arr1[m[curr]];
        }
        FOR(j,0,k-1)
        {
            if(arr2[j]==sum)
            {
            can_make[j].pb(i);
            }
        }
    }
        dp[0]=0;
        check[0]=true;
        int k1;
        vector<int>::iterator it;
    FOR(i,0,k-1)
    {
        for(j=(1<<n)-1;j>=0;j--)
        {
            for(it=can_make[i].begin();it!=can_make[i].end() && !check[j];it++)
            {
                k1=*it;
                if((k1&j)==k1)
                {
                    if((dp[j-k1]+1)>dp[j])
                    {
                       // cout<<"hey"<<j<<" ";
                        dp[j]=dp[j-k1]+1;
                        if(check[j-k])
                        check[j]=true;
                        pre[j]=j-k1;
                    }
                }
            }
        }

    }
    if(dp[(1<<n)-1]==k)
    {
        cout<<"YES\n";
    start=(1<<n)-1;
    int sum;
    while(start)
    {
        //cout<<start<<" ";
        num=start-pre[start];
        start=pre[start];
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            cout<<rev_Map[arr1[m[curr]]];
            sum=sum+arr1[m[curr]];
            if(num)
            cout<<"+";
        }
        cout<<"->";
        cout<<rev_Map[sum]<<"\n";
    }
    }
    else
    cout<<"NO";
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<math.h>
using namespace std;
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define sint(i) scanf("%d",&i)
#define ss(s) scanf("%s",s)
#define pii pair<int,int>
#define mp(i,j) make_pair(i,j)
#define ll long long
#define MAX 1000000000
#define MOD 1000000007
#define vi vector<int>
#define vvi vector < vi >
#define pb(i) push_back(i);
#define tr(v,it) for(it=v.begin();it!=v.end();it++)
int main()
{
    map<string,int> Map;
    Map["H"] = 1;
    Map["He"] = 2;
    Map["Li"] = 3;
    Map["Be"] = 4;
    Map["B"] = 5;
    Map["C"] = 6;
    Map["N"] = 7;
    Map["O"] = 8;
    Map["F"] = 9;
    Map["Ne"] = 10;
    Map["Na"] = 11;
    Map["Mg"] = 12;
    Map["Al"] = 13;
    Map["Si"] = 14;
    Map["P"] = 15;
    Map["S"] = 16;
    Map["Cl"] = 17;
    Map["Ar"] = 18;
    Map["K"] = 19;
    Map["Ca"] = 20;
    Map["Sc"] = 21;
    Map["Ti"] = 22;
    Map["V"] = 23;
    Map["Cr"] = 24;
    Map["Mn"] = 25;
    Map["Fe"] = 26;
    Map["Co"] = 27;
    Map["Ni"] = 28;
    Map["Cu"] = 29;
    Map["Zn"] = 30;
    Map["Ga"] = 31;
    Map["Ge"] = 32;
    Map["As"] = 33;
    Map["Se"] = 34;
    Map["Br"] = 35;
    Map["Kr"] = 36;
    Map["Rb"] = 37;
    Map["Sr"] = 38;
    Map["Y"] = 39;
    Map["Zr"] = 40;
    Map["Nb"] = 41;
    Map["Mo"] = 42;
    Map["Tc"] = 43;
    Map["Ru"] = 44;
    Map["Rh"] = 45;
    Map["Pd"] = 46;
    Map["Ag"] = 47;
    Map["Cd"] = 48;
    Map["In"] = 49;
    Map["Sn"] = 50;
    Map["Sb"] = 51;
    Map["Te"] = 52;
    Map["I"] = 53;
    Map["Xe"] = 54;
    Map["Cs"] = 55;
    Map["Ba"] = 56;
    Map["La"] = 57;
    Map["Ce"] = 58;
    Map["Pr"] = 59;
    Map["Nd"] = 60;
    Map["Pm"] = 61;
    Map["Sm"] = 62;
    Map["Eu"] = 63;
    Map["Gd"] = 64;
    Map["Tb"] = 65;
    Map["Dy"] = 66;
    Map["Ho"] = 67;
    Map["Er"] = 68;
    Map["Tm"] = 69;
    Map["Yb"] = 70;
    Map["Lu"] = 71;
    Map["Hf"] = 72;
    Map["Ta"] = 73;
    Map["W"] = 74;
    Map["Re"] = 75;
    Map["Os"] = 76;
    Map["Ir"] = 77;
    Map["Pt"] = 78;
    Map["Au"] = 79;
    Map["Hg"] = 80;
    Map["Tl"] = 81;
    Map["Pb"] = 82;
    Map["Bi"] = 83;
    Map["Po"] = 84;
    Map["At"] = 85;
    Map["Rn"] = 86;
    Map["Fr"] = 87;
    Map["Ra"] = 88;
    Map["Ac"] = 89;
    Map["Th"] = 90;
    Map["Pa"] = 91;
    Map["U"] = 92;
    Map["Np"] = 93;
    Map["Pu"] = 94;
    Map["Am"] = 95;
    Map["Cm"] = 96;
    Map["Bk"] = 97;
    Map["Cf"] = 98;
    Map["Es"] = 99;
    Map["Fm"] = 100;
    map<int,string> rev_Map;
    map<string,int>::iterator it1;
    tr(Map,it1)
    {
        rev_Map[it1->second]=it1->first;
    }
    int i,j;
    map<int,int> m;
    FOR(i,0,25)
    m[1<<i]=i;
    int n,k;
    int num,curr,start;
    cin>>n>>k;
    string s;
    int arr1[n],arr2[k];
    FOR(i,0,n-1)
    {
    cin>>s;
    arr1[i]=Map[s];
   // cout<<arr1[i]<<" ";
    }
    //cout<<"\n";
    FOR(i,0,k-1)
    {
    cin>>s;
    arr2[i]=Map[s];
   // cout<<arr2[i]<<" ";
    }
  //  cout<<"\n";
    int dp[(1<<n)];
    sort(arr1,arr1+n);
    sort(arr2,arr2+k);
    vector<int> can_make[k];
    bool check[1<<n];
    int pre[1<<n];
    int sum=0;
    FOR(i,0,(1<<n)-1)
    {
        dp[i]=0;
        check[i]=false;
        num=i;
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            sum=sum+arr1[m[curr]];
        }
        FOR(j,0,k-1)
        {
            if(arr2[j]==sum)
            {
            can_make[j].pb(i);
            }
        }
    }
        dp[0]=0;
        check[0]=true;
        int k1;
        vector<int>::iterator it;
    FOR(i,0,k-1)
    {
        for(j=(1<<n)-1;j>=0;j--)
        {
            if(!check[j])
            tr(can_make[i],it)
            {
                k1=*it;
                if((k1&j)==k1)
                {
                    if((dp[j-k1]+1)>dp[j])
                    {
                       // cout<<"hey"<<j<<" ";
                        dp[j]=dp[j-k1]+1;
                        if(check[j-k1])
                        check[j]=true;
                        pre[j]=j-k1;
                    }
                }
            }
        }

    }
    if(dp[(1<<n)-1]==k)
    {
        cout<<"YES\n";
    start=(1<<n)-1;
    int sum;
    while(start)
    {
        //cout<<start<<" ";
        num=start-pre[start];
        start=pre[start];
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            cout<<rev_Map[arr1[m[curr]]];
            sum=sum+arr1[m[curr]];
            if(num)
            cout<<"+";
        }
        cout<<"->";
        cout<<rev_Map[sum]<<"\n";
    }
    }
    else
    cout<<"NO";
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<math.h>
using namespace std;
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define sint(i) scanf("%d",&i)
#define ss(s) scanf("%s",s)
#define pii pair<int,int>
#define mp(i,j) make_pair(i,j)
#define ll long long
#define MAX 1000000000
#define MOD 1000000007
#define vi vector<int>
#define vvi vector < vi >
#define pb(i) push_back(i);
#define tr(v,it) for(it=v.begin();it!=v.end();it++)
int main()
{
    map<string,int> Map;
    Map["H"] = 1;
    Map["He"] = 2;
    Map["Li"] = 3;
    Map["Be"] = 4;
    Map["B"] = 5;
    Map["C"] = 6;
    Map["N"] = 7;
    Map["O"] = 8;
    Map["F"] = 9;
    Map["Ne"] = 10;
    Map["Na"] = 11;
    Map["Mg"] = 12;
    Map["Al"] = 13;
    Map["Si"] = 14;
    Map["P"] = 15;
    Map["S"] = 16;
    Map["Cl"] = 17;
    Map["Ar"] = 18;
    Map["K"] = 19;
    Map["Ca"] = 20;
    Map["Sc"] = 21;
    Map["Ti"] = 22;
    Map["V"] = 23;
    Map["Cr"] = 24;
    Map["Mn"] = 25;
    Map["Fe"] = 26;
    Map["Co"] = 27;
    Map["Ni"] = 28;
    Map["Cu"] = 29;
    Map["Zn"] = 30;
    Map["Ga"] = 31;
    Map["Ge"] = 32;
    Map["As"] = 33;
    Map["Se"] = 34;
    Map["Br"] = 35;
    Map["Kr"] = 36;
    Map["Rb"] = 37;
    Map["Sr"] = 38;
    Map["Y"] = 39;
    Map["Zr"] = 40;
    Map["Nb"] = 41;
    Map["Mo"] = 42;
    Map["Tc"] = 43;
    Map["Ru"] = 44;
    Map["Rh"] = 45;
    Map["Pd"] = 46;
    Map["Ag"] = 47;
    Map["Cd"] = 48;
    Map["In"] = 49;
    Map["Sn"] = 50;
    Map["Sb"] = 51;
    Map["Te"] = 52;
    Map["I"] = 53;
    Map["Xe"] = 54;
    Map["Cs"] = 55;
    Map["Ba"] = 56;
    Map["La"] = 57;
    Map["Ce"] = 58;
    Map["Pr"] = 59;
    Map["Nd"] = 60;
    Map["Pm"] = 61;
    Map["Sm"] = 62;
    Map["Eu"] = 63;
    Map["Gd"] = 64;
    Map["Tb"] = 65;
    Map["Dy"] = 66;
    Map["Ho"] = 67;
    Map["Er"] = 68;
    Map["Tm"] = 69;
    Map["Yb"] = 70;
    Map["Lu"] = 71;
    Map["Hf"] = 72;
    Map["Ta"] = 73;
    Map["W"] = 74;
    Map["Re"] = 75;
    Map["Os"] = 76;
    Map["Ir"] = 77;
    Map["Pt"] = 78;
    Map["Au"] = 79;
    Map["Hg"] = 80;
    Map["Tl"] = 81;
    Map["Pb"] = 82;
    Map["Bi"] = 83;
    Map["Po"] = 84;
    Map["At"] = 85;
    Map["Rn"] = 86;
    Map["Fr"] = 87;
    Map["Ra"] = 88;
    Map["Ac"] = 89;
    Map["Th"] = 90;
    Map["Pa"] = 91;
    Map["U"] = 92;
    Map["Np"] = 93;
    Map["Pu"] = 94;
    Map["Am"] = 95;
    Map["Cm"] = 96;
    Map["Bk"] = 97;
    Map["Cf"] = 98;
    Map["Es"] = 99;
    Map["Fm"] = 100;
    map<int,string> rev_Map;
    map<string,int>::iterator it1;
    tr(Map,it1)
    {
        rev_Map[it1->second]=it1->first;
    }
    int i,j;
    map<int,int> m;
    FOR(i,0,25)
    m[1<<i]=i;
    int n,k;
    int num,curr,start;
    cin>>n>>k;
    string s;
    int arr1[n],arr2[k];
    FOR(i,0,n-1)
    {
    cin>>s;
    arr1[i]=Map[s];
   // cout<<arr1[i]<<" ";
    }
    //cout<<"\n";
    FOR(i,0,k-1)
    {
    cin>>s;
    arr2[i]=Map[s];
   // cout<<arr2[i]<<" ";
    }
  //  cout<<"\n";
    int dp[(1<<n)];
    sort(arr1,arr1+n);
    sort(arr2,arr2+k);
    vector<int> can_make[k];
    bool check[1<<n];
    int pre[1<<n];
    int sum=0;
    FOR(i,0,(1<<n)-1)
    {
        dp[i]=0;
        check[i]=false;
        num=i;
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            sum=sum+arr1[m[curr]];
        }
        FOR(j,0,k-1)
        {
            if(arr2[j]==sum)
            {
            can_make[j].pb(i);
            }
        }
    }
        dp[0]=0;
        check[0]=true;
        int k1;
        vector<int>::iterator it;
    FOR(i,0,k-1)
    {
        for(j=(1<<n)-1;j>=0;j--)
        {
            for(it=can_make[i].begin();it!=can_make[i].end() && !check[j];it++)
            {
                k1=*it;
                if((k1&j)==k1)
                {
                    if((dp[j-k1]+1)>dp[j])
                    {
                       // cout<<"hey"<<j<<" ";
                        dp[j]=dp[j-k1]+1;
                        if(dp[j-k1])
                        check[j]=true;
                        pre[j]=j-k1;
                    }
                }
            }
        }

    }
    if(dp[(1<<n)-1]==k)
    {
        cout<<"YES\n";
    start=(1<<n)-1;
    int sum;
    while(start)
    {
        //cout<<start<<" ";
        num=start-pre[start];
        start=pre[start];
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            cout<<rev_Map[arr1[m[curr]]];
            sum=sum+arr1[m[curr]];
            if(num)
            cout<<"+";
        }
        cout<<"->";
        cout<<rev_Map[sum]<<"\n";
    }
    }
    else
    cout<<"NO";
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<math.h>
using namespace std;
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define sint(i) scanf("%d",&i)
#define ss(s) scanf("%s",s)
#define pii pair<int,int>
#define mp(i,j) make_pair(i,j)
#define ll long long
#define MAX 1000000000
#define MOD 1000000007
#define vi vector<int>
#define vvi vector < vi >
#define pb(i) push_back(i);
#define tr(v,it) for(it=v.begin();it!=v.end();it++)
int main()
{
    map<string,int> Map;
    Map["H"] = 1;
    Map["He"] = 2;
    Map["Li"] = 3;
    Map["Be"] = 4;
    Map["B"] = 5;
    Map["C"] = 6;
    Map["N"] = 7;
    Map["O"] = 8;
    Map["F"] = 9;
    Map["Ne"] = 10;
    Map["Na"] = 11;
    Map["Mg"] = 12;
    Map["Al"] = 13;
    Map["Si"] = 14;
    Map["P"] = 15;
    Map["S"] = 16;
    Map["Cl"] = 17;
    Map["Ar"] = 18;
    Map["K"] = 19;
    Map["Ca"] = 20;
    Map["Sc"] = 21;
    Map["Ti"] = 22;
    Map["V"] = 23;
    Map["Cr"] = 24;
    Map["Mn"] = 25;
    Map["Fe"] = 26;
    Map["Co"] = 27;
    Map["Ni"] = 28;
    Map["Cu"] = 29;
    Map["Zn"] = 30;
    Map["Ga"] = 31;
    Map["Ge"] = 32;
    Map["As"] = 33;
    Map["Se"] = 34;
    Map["Br"] = 35;
    Map["Kr"] = 36;
    Map["Rb"] = 37;
    Map["Sr"] = 38;
    Map["Y"] = 39;
    Map["Zr"] = 40;
    Map["Nb"] = 41;
    Map["Mo"] = 42;
    Map["Tc"] = 43;
    Map["Ru"] = 44;
    Map["Rh"] = 45;
    Map["Pd"] = 46;
    Map["Ag"] = 47;
    Map["Cd"] = 48;
    Map["In"] = 49;
    Map["Sn"] = 50;
    Map["Sb"] = 51;
    Map["Te"] = 52;
    Map["I"] = 53;
    Map["Xe"] = 54;
    Map["Cs"] = 55;
    Map["Ba"] = 56;
    Map["La"] = 57;
    Map["Ce"] = 58;
    Map["Pr"] = 59;
    Map["Nd"] = 60;
    Map["Pm"] = 61;
    Map["Sm"] = 62;
    Map["Eu"] = 63;
    Map["Gd"] = 64;
    Map["Tb"] = 65;
    Map["Dy"] = 66;
    Map["Ho"] = 67;
    Map["Er"] = 68;
    Map["Tm"] = 69;
    Map["Yb"] = 70;
    Map["Lu"] = 71;
    Map["Hf"] = 72;
    Map["Ta"] = 73;
    Map["W"] = 74;
    Map["Re"] = 75;
    Map["Os"] = 76;
    Map["Ir"] = 77;
    Map["Pt"] = 78;
    Map["Au"] = 79;
    Map["Hg"] = 80;
    Map["Tl"] = 81;
    Map["Pb"] = 82;
    Map["Bi"] = 83;
    Map["Po"] = 84;
    Map["At"] = 85;
    Map["Rn"] = 86;
    Map["Fr"] = 87;
    Map["Ra"] = 88;
    Map["Ac"] = 89;
    Map["Th"] = 90;
    Map["Pa"] = 91;
    Map["U"] = 92;
    Map["Np"] = 93;
    Map["Pu"] = 94;
    Map["Am"] = 95;
    Map["Cm"] = 96;
    Map["Bk"] = 97;
    Map["Cf"] = 98;
    Map["Es"] = 99;
    Map["Fm"] = 100;
    map<int,string> rev_Map;
    map<string,int>::iterator it1;
    tr(Map,it1)
    {
        rev_Map[it1->second]=it1->first;
    }
    int i,j;
    map<int,int> m;
    FOR(i,0,25)
    m[1<<i]=i;
    int n,k;
    int num,curr,start;
    cin>>n>>k;
    string s;
    int arr1[n],arr2[k];
    FOR(i,0,n-1)
    {
    cin>>s;
    arr1[i]=Map[s];
    cout<<arr1[i]<<" ";
    }
    cout<<"\n";
    FOR(i,0,k-1)
    {
    cin>>s;
    arr2[i]=Map[s];
    cout<<arr2[i]<<" ";
    }
    cout<<"\n";
    int dp[(1<<n)];
    vector<int> can_make[k];
    int pre[1<<n];
    int sum=0;
    FOR(i,0,(1<<n)-1)
    {
        dp[i]=0;
        num=i;
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            sum=sum+arr1[m[curr]];
        }
        FOR(j,0,k-1)
        {
            if(arr2[j]==sum)
            {
            can_make[j].pb(i);
            }
        }
    }
        dp[0]=0;
        int k1;
        vector<int>::iterator it;
    FOR(i,0,k-1)
    {
        for(j=(1<<n)-1;j>=0;j--)
        {
            //check if possible
            tr(can_make[i],it)
            {
                k1=*it;
                if((k1&j)==k1)
                {
                    if((dp[j-k1]+1)>dp[j])
                    {
                       // cout<<"hey"<<j<<" ";
                        dp[j]=dp[j-k1]+1;
                        pre[j]=j-k1;
                    }
                }
            }
        }

    }
    if(dp[(1<<n)-1]==k)
    {
        cout<<"YES\n";
    start=(1<<n)-1;
    int sum;
    while(start)
    {
        //cout<<start<<" ";
        num=start-pre[start];
        start=pre[start];
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            cout<<rev_Map[arr1[m[curr]]];
            sum=sum+arr1[m[curr]];
            if(num)
            cout<<"+";
        }
        cout<<"->";
        cout<<rev_Map[sum]<<"\n";
    }
    }
    else
    cout<<"NO";
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<math.h>
using namespace std;
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define sint(i) scanf("%d",&i)
#define ss(s) scanf("%s",s)
#define pii pair<int,int>
#define mp(i,j) make_pair(i,j)
#define ll long long
#define MAX 1000000000
#define MOD 1000000007
#define vi vector<int>
#define vvi vector < vi >
#define pb(i) push_back(i);
#define tr(v,it) for(it=v.begin();it!=v.end();it++)
int main()
{
    map<string,int> Map;
    Map["H"] = 1;
    Map["He"] = 2;
    Map["Li"] = 3;
    Map["Be"] = 4;
    Map["B"] = 5;
    Map["C"] = 6;
    Map["N"] = 7;
    Map["O"] = 8;
    Map["F"] = 9;
    Map["Ne"] = 10;
    Map["Na"] = 11;
    Map["Mg"] = 12;
    Map["Al"] = 13;
    Map["Si"] = 14;
    Map["P"] = 15;
    Map["S"] = 16;
    Map["Cl"] = 17;
    Map["Ar"] = 18;
    Map["K"] = 19;
    Map["Ca"] = 20;
    Map["Sc"] = 21;
    Map["Ti"] = 22;
    Map["V"] = 23;
    Map["Cr"] = 24;
    Map["Mn"] = 25;
    Map["Fe"] = 26;
    Map["Co"] = 27;
    Map["Ni"] = 28;
    Map["Cu"] = 29;
    Map["Zn"] = 30;
    Map["Ga"] = 31;
    Map["Ge"] = 32;
    Map["As"] = 33;
    Map["Se"] = 34;
    Map["Br"] = 35;
    Map["Kr"] = 36;
    Map["Rb"] = 37;
    Map["Sr"] = 38;
    Map["Y"] = 39;
    Map["Zr"] = 40;
    Map["Nb"] = 41;
    Map["Mo"] = 42;
    Map["Tc"] = 43;
    Map["Ru"] = 44;
    Map["Rh"] = 45;
    Map["Pd"] = 46;
    Map["Ag"] = 47;
    Map["Cd"] = 48;
    Map["In"] = 49;
    Map["Sn"] = 50;
    Map["Sb"] = 51;
    Map["Te"] = 52;
    Map["I"] = 53;
    Map["Xe"] = 54;
    Map["Cs"] = 55;
    Map["Ba"] = 56;
    Map["La"] = 57;
    Map["Ce"] = 58;
    Map["Pr"] = 59;
    Map["Nd"] = 60;
    Map["Pm"] = 61;
    Map["Sm"] = 62;
    Map["Eu"] = 63;
    Map["Gd"] = 64;
    Map["Tb"] = 65;
    Map["Dy"] = 66;
    Map["Ho"] = 67;
    Map["Er"] = 68;
    Map["Tm"] = 69;
    Map["Yb"] = 70;
    Map["Lu"] = 71;
    Map["Hf"] = 72;
    Map["Ta"] = 73;
    Map["W"] = 74;
    Map["Re"] = 75;
    Map["Os"] = 76;
    Map["Ir"] = 77;
    Map["Pt"] = 78;
    Map["Au"] = 79;
    Map["Hg"] = 80;
    Map["Tl"] = 81;
    Map["Pb"] = 82;
    Map["Bi"] = 83;
    Map["Po"] = 84;
    Map["At"] = 85;
    Map["Rn"] = 86;
    Map["Fr"] = 87;
    Map["Ra"] = 88;
    Map["Ac"] = 89;
    Map["Th"] = 90;
    Map["Pa"] = 91;
    Map["U"] = 92;
    Map["Np"] = 93;
    Map["Pu"] = 94;
    Map["Am"] = 95;
    Map["Cm"] = 96;
    Map["Bk"] = 97;
    Map["Cf"] = 98;
    Map["Es"] = 99;
    Map["Fm"] = 100;
    map<int,string> rev_Map;
    map<string,int>::iterator it1;
    tr(Map,it1)
    {
        rev_Map[it1->second]=it1->first;
    }
    int i,j;
    map<int,int> m;
    FOR(i,0,25)
    m[1<<i]=i;
    int n,k;
    int num,curr,start;
    cin>>n>>k;
    string s;
    int arr1[n],arr2[k];
    FOR(i,0,n-1)
    {
    cin>>s;
    arr1[i]=Map[s];
   // cout<<arr1[i]<<" ";
    }
    //cout<<"\n";
    FOR(i,0,k-1)
    {
    cin>>s;
    arr2[i]=Map[s];
   // cout<<arr2[i]<<" ";
    }
  //  cout<<"\n";
    bool dp[(1<<n)];
    sort(arr1,arr1+n);
    sort(arr2,arr2+k);
    vector<int> can_make[k];
    int pre[1<<n];
    int sum=0;
    FOR(i,0,(1<<n)-1)
    {
        dp[i]=false;
        num=i;
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            sum=sum+arr1[m[curr]];
        }
        FOR(j,0,k-1)
        {
            if(arr2[j]==sum)
            {
            can_make[j].pb(i);
            }
        }
    }
        dp[0]=true;
        int k1;
        vector<int>::iterator it;
    FOR(i,0,k-1)
    {
        for(j=(1<<n)-1;j>=0;j--)
        {
            if(!dp[j])
            continue;
            for(it=can_make[i].begin();it!=can_make[i].end();it++)
            {
                k1=*it;
                if((k1&j)==0)
                {
                       // cout<<"hey"<<j<<" ";
                        dp[j+k1]=true;
                        pre[j+k1]=j;
                }
            }
        }

    }
    if(dp[(1<<n)-1])
    {
        cout<<"YES\n";
    start=(1<<n)-1;
    int sum;
    while(start)
    {
        //cout<<start<<" ";
        num=start-pre[start];
        start=pre[start];
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            cout<<rev_Map[arr1[m[curr]]];
            sum=sum+arr1[m[curr]];
            if(num)
            cout<<"+";
        }
        cout<<"->";
        cout<<rev_Map[sum]<<"\n";
    }
    }
    else
    cout<<"NO";
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<math.h>
using namespace std;
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define sint(i) scanf("%d",&i)
#define ss(s) scanf("%s",s)
#define pii pair<int,int>
#define mp(i,j) make_pair(i,j)
#define ll long long
#define MAX 1000000000
#define MOD 1000000007
#define vi vector<int>
#define vvi vector < vi >
#define pb(i) push_back(i);
#define tr(v,it) for(it=v.begin();it!=v.end();it++)
bool dp[135000][19];
int main()
{
    map<string,int> Map;
    Map["H"] = 1;
    Map["He"] = 2;
    Map["Li"] = 3;
    Map["Be"] = 4;
    Map["B"] = 5;
    Map["C"] = 6;
    Map["N"] = 7;
    Map["O"] = 8;
    Map["F"] = 9;
    Map["Ne"] = 10;
    Map["Na"] = 11;
    Map["Mg"] = 12;
    Map["Al"] = 13;
    Map["Si"] = 14;
    Map["P"] = 15;
    Map["S"] = 16;
    Map["Cl"] = 17;
    Map["Ar"] = 18;
    Map["K"] = 19;
    Map["Ca"] = 20;
    Map["Sc"] = 21;
    Map["Ti"] = 22;
    Map["V"] = 23;
    Map["Cr"] = 24;
    Map["Mn"] = 25;
    Map["Fe"] = 26;
    Map["Co"] = 27;
    Map["Ni"] = 28;
    Map["Cu"] = 29;
    Map["Zn"] = 30;
    Map["Ga"] = 31;
    Map["Ge"] = 32;
    Map["As"] = 33;
    Map["Se"] = 34;
    Map["Br"] = 35;
    Map["Kr"] = 36;
    Map["Rb"] = 37;
    Map["Sr"] = 38;
    Map["Y"] = 39;
    Map["Zr"] = 40;
    Map["Nb"] = 41;
    Map["Mo"] = 42;
    Map["Tc"] = 43;
    Map["Ru"] = 44;
    Map["Rh"] = 45;
    Map["Pd"] = 46;
    Map["Ag"] = 47;
    Map["Cd"] = 48;
    Map["In"] = 49;
    Map["Sn"] = 50;
    Map["Sb"] = 51;
    Map["Te"] = 52;
    Map["I"] = 53;
    Map["Xe"] = 54;
    Map["Cs"] = 55;
    Map["Ba"] = 56;
    Map["La"] = 57;
    Map["Ce"] = 58;
    Map["Pr"] = 59;
    Map["Nd"] = 60;
    Map["Pm"] = 61;
    Map["Sm"] = 62;
    Map["Eu"] = 63;
    Map["Gd"] = 64;
    Map["Tb"] = 65;
    Map["Dy"] = 66;
    Map["Ho"] = 67;
    Map["Er"] = 68;
    Map["Tm"] = 69;
    Map["Yb"] = 70;
    Map["Lu"] = 71;
    Map["Hf"] = 72;
    Map["Ta"] = 73;
    Map["W"] = 74;
    Map["Re"] = 75;
    Map["Os"] = 76;
    Map["Ir"] = 77;
    Map["Pt"] = 78;
    Map["Au"] = 79;
    Map["Hg"] = 80;
    Map["Tl"] = 81;
    Map["Pb"] = 82;
    Map["Bi"] = 83;
    Map["Po"] = 84;
    Map["At"] = 85;
    Map["Rn"] = 86;
    Map["Fr"] = 87;
    Map["Ra"] = 88;
    Map["Ac"] = 89;
    Map["Th"] = 90;
    Map["Pa"] = 91;
    Map["U"] = 92;
    Map["Np"] = 93;
    Map["Pu"] = 94;
    Map["Am"] = 95;
    Map["Cm"] = 96;
    Map["Bk"] = 97;
    Map["Cf"] = 98;
    Map["Es"] = 99;
    Map["Fm"] = 100;
    map<int,string> rev_Map;
    map<string,int>::iterator it1;
    tr(Map,it1)
    {
        rev_Map[it1->second]=it1->first;
    }
    int i,j;
    map<int,int> m;
    FOR(i,0,25)
    m[1<<i]=i;
    int n,k;
    int num,curr,start;
    cin>>n>>k;
    string s;
    int arr1[n],arr2[k];
    FOR(i,0,n-1)
    {
    cin>>s;
    arr1[i]=Map[s];
   // cout<<arr1[i]<<" ";
    }
    //cout<<"\n";
    FOR(i,0,k-1)
    {
    cin>>s;
    arr2[i]=Map[s];
   // cout<<arr2[i]<<" ";
    }
  //  cout<<"\n";
    sort(arr1,arr1+n);
    sort(arr2,arr2+k);
    vector<int> can_make[k];
    int pre[1<<n];
    int sum=0;
    FOR(i,0,(1<<n)-1)
    {
        num=i;
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            sum=sum+arr1[m[curr]];
        }
        FOR(j,0,k-1)
        {
            dp[i][j+1]=false;
            if(arr2[j]==sum)
            {
            can_make[j].pb(i);
            }
        }
    }
        dp[0][0]=true;
        FOR(j,1,k)
        dp[0][j]=false;
        int k1;
        vector<int>::iterator it;
    FOR(i,0,k-1)
    {
        for(j=0;j<(1<<n);j++)
        {
            if(!dp[j][i])
            continue;
            for(it=can_make[i].begin();it!=can_make[i].end();it++)
            {
                k1=*it;
                if((k1&j)==0)
                {
                       // cout<<"hey"<<j<<" ";
                        dp[j+k1][i+1]=true;
                        pre[j+k1]=j;
                }
            }
        }

    }
    if(dp[(1<<n)-1][k])
    {
        cout<<"YES\n";
    start=(1<<n)-1;
    int sum;
    while(start)
    {
        //cout<<start<<" ";
        num=start-pre[start];
        start=pre[start];
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            cout<<rev_Map[arr1[m[curr]]];
            sum=sum+arr1[m[curr]];
            if(num)
            cout<<"+";
        }
        cout<<"->";
        cout<<rev_Map[sum]<<"\n";
    }
    }
    else
    cout<<"NO";
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<math.h>
using namespace std;
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define sint(i) scanf("%d",&i)
#define ss(s) scanf("%s",s)
#define pii pair<int,int>
#define mp(i,j) make_pair(i,j)
#define ll long long
#define MAX 1000000000
#define MOD 1000000007
#define vi vector<int>
#define vvi vector < vi >
#define pb(i) push_back(i);
#define tr(v,it) for(it=v.begin();it!=v.end();it++)
int main()
{
    map<string,int> Map;
    Map["H"] = 1;
    Map["He"] = 2;
    Map["Li"] = 3;
    Map["Be"] = 4;
    Map["B"] = 5;
    Map["C"] = 6;
    Map["N"] = 7;
    Map["O"] = 8;
    Map["F"] = 9;
    Map["Ne"] = 10;
    Map["Na"] = 11;
    Map["Mg"] = 12;
    Map["Al"] = 13;
    Map["Si"] = 14;
    Map["P"] = 15;
    Map["S"] = 16;
    Map["Cl"] = 17;
    Map["Ar"] = 18;
    Map["K"] = 19;
    Map["Ca"] = 20;
    Map["Sc"] = 21;
    Map["Ti"] = 22;
    Map["V"] = 23;
    Map["Cr"] = 24;
    Map["Mn"] = 25;
    Map["Fe"] = 26;
    Map["Co"] = 27;
    Map["Ni"] = 28;
    Map["Cu"] = 29;
    Map["Zn"] = 30;
    Map["Ga"] = 31;
    Map["Ge"] = 32;
    Map["As"] = 33;
    Map["Se"] = 34;
    Map["Br"] = 35;
    Map["Kr"] = 36;
    Map["Rb"] = 37;
    Map["Sr"] = 38;
    Map["Y"] = 39;
    Map["Zr"] = 40;
    Map["Nb"] = 41;
    Map["Mo"] = 42;
    Map["Tc"] = 43;
    Map["Ru"] = 44;
    Map["Rh"] = 45;
    Map["Pd"] = 46;
    Map["Ag"] = 47;
    Map["Cd"] = 48;
    Map["In"] = 49;
    Map["Sn"] = 50;
    Map["Sb"] = 51;
    Map["Te"] = 52;
    Map["I"] = 53;
    Map["Xe"] = 54;
    Map["Cs"] = 55;
    Map["Ba"] = 56;
    Map["La"] = 57;
    Map["Ce"] = 58;
    Map["Pr"] = 59;
    Map["Nd"] = 60;
    Map["Pm"] = 61;
    Map["Sm"] = 62;
    Map["Eu"] = 63;
    Map["Gd"] = 64;
    Map["Tb"] = 65;
    Map["Dy"] = 66;
    Map["Ho"] = 67;
    Map["Er"] = 68;
    Map["Tm"] = 69;
    Map["Yb"] = 70;
    Map["Lu"] = 71;
    Map["Hf"] = 72;
    Map["Ta"] = 73;
    Map["W"] = 74;
    Map["Re"] = 75;
    Map["Os"] = 76;
    Map["Ir"] = 77;
    Map["Pt"] = 78;
    Map["Au"] = 79;
    Map["Hg"] = 80;
    Map["Tl"] = 81;
    Map["Pb"] = 82;
    Map["Bi"] = 83;
    Map["Po"] = 84;
    Map["At"] = 85;
    Map["Rn"] = 86;
    Map["Fr"] = 87;
    Map["Ra"] = 88;
    Map["Ac"] = 89;
    Map["Th"] = 90;
    Map["Pa"] = 91;
    Map["U"] = 92;
    Map["Np"] = 93;
    Map["Pu"] = 94;
    Map["Am"] = 95;
    Map["Cm"] = 96;
    Map["Bk"] = 97;
    Map["Cf"] = 98;
    Map["Es"] = 99;
    Map["Fm"] = 100;
    map<int,string> rev_Map;
    map<string,int>::iterator it1;
    tr(Map,it1)
    {
        rev_Map[it1->second]=it1->first;
    }
    int i,j;
    map<int,int> m;
    FOR(i,0,25)
    m[1<<i]=i;
    int n,k;
    int num,curr,start;
    cin>>n>>k;
    string s;
    int arr1[n],arr2[k];
    FOR(i,0,n-1)
    {
    cin>>s;
    arr1[i]=Map[s];
   // cout<<arr1[i]<<" ";
    }
    //cout<<"\n";
    FOR(i,0,k-1)
    {
    cin>>s;
    arr2[i]=Map[s];
   // cout<<arr2[i]<<" ";
    }
  //  cout<<"\n";
    bool dp[(1<<n)];
    sort(arr1,arr1+n);
    sort(arr2,arr2+k);
    vector<int> can_make[k];
    int pre[1<<n];
    int sum=0;
    FOR(i,0,(1<<n)-1)
    {
        dp[i]=false;
        num=i;
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            sum=sum+arr1[m[curr]];
        }
        FOR(j,0,k-1)
        {
            if(arr2[j]==sum)
            {
            can_make[j].pb(i);
            }
        }
    }
        dp[0]=true;
        int k1;
        vector<int>::iterator it;
    FOR(i,0,k-1)
    {
        for(j=0;j<(1<<n);j++)
        {
            if(!dp[j])
            continue;
            for(it=can_make[i].begin();it!=can_make[i].end();it++)
            {
                k1=*it;
                if((k1&j)==0)
                {
                       // cout<<"hey"<<j<<" ";
                        dp[j+k1]=true;
                        pre[j+k1]=j;
                }
            }
        }

    }
    if(dp[(1<<n)-1])
    {
        cout<<"YES\n";
    start=(1<<n)-1;
    int sum;
    while(start)
    {
        //cout<<start<<" ";
        num=start-pre[start];
        start=pre[start];
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            cout<<rev_Map[arr1[m[curr]]];
            sum=sum+arr1[m[curr]];
            if(num)
            cout<<"+";
        }
        cout<<"->";
        cout<<rev_Map[sum]<<"\n";
    }
    }
    else
    cout<<"NO";
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<math.h>
using namespace std;
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define sint(i) scanf("%d",&i)
#define ss(s) scanf("%s",s)
#define pii pair<int,int>
#define mp(i,j) make_pair(i,j)
#define ll long long
#define MAX 1000000000
#define MOD 1000000007
#define vi vector<int>
#define vvi vector < vi >
#define pb(i) push_back(i);
#define tr(v,it) for(it=v.begin();it!=v.end();it++)
int main()
{
    map<string,int> Map;
    Map["H"] = 1;
    Map["He"] = 2;
    Map["Li"] = 3;
    Map["Be"] = 4;
    Map["B"] = 5;
    Map["C"] = 6;
    Map["N"] = 7;
    Map["O"] = 8;
    Map["F"] = 9;
    Map["Ne"] = 10;
    Map["Na"] = 11;
    Map["Mg"] = 12;
    Map["Al"] = 13;
    Map["Si"] = 14;
    Map["P"] = 15;
    Map["S"] = 16;
    Map["Cl"] = 17;
    Map["Ar"] = 18;
    Map["K"] = 19;
    Map["Ca"] = 20;
    Map["Sc"] = 21;
    Map["Ti"] = 22;
    Map["V"] = 23;
    Map["Cr"] = 24;
    Map["Mn"] = 25;
    Map["Fe"] = 26;
    Map["Co"] = 27;
    Map["Ni"] = 28;
    Map["Cu"] = 29;
    Map["Zn"] = 30;
    Map["Ga"] = 31;
    Map["Ge"] = 32;
    Map["As"] = 33;
    Map["Se"] = 34;
    Map["Br"] = 35;
    Map["Kr"] = 36;
    Map["Rb"] = 37;
    Map["Sr"] = 38;
    Map["Y"] = 39;
    Map["Zr"] = 40;
    Map["Nb"] = 41;
    Map["Mo"] = 42;
    Map["Tc"] = 43;
    Map["Ru"] = 44;
    Map["Rh"] = 45;
    Map["Pd"] = 46;
    Map["Ag"] = 47;
    Map["Cd"] = 48;
    Map["In"] = 49;
    Map["Sn"] = 50;
    Map["Sb"] = 51;
    Map["Te"] = 52;
    Map["I"] = 53;
    Map["Xe"] = 54;
    Map["Cs"] = 55;
    Map["Ba"] = 56;
    Map["La"] = 57;
    Map["Ce"] = 58;
    Map["Pr"] = 59;
    Map["Nd"] = 60;
    Map["Pm"] = 61;
    Map["Sm"] = 62;
    Map["Eu"] = 63;
    Map["Gd"] = 64;
    Map["Tb"] = 65;
    Map["Dy"] = 66;
    Map["Ho"] = 67;
    Map["Er"] = 68;
    Map["Tm"] = 69;
    Map["Yb"] = 70;
    Map["Lu"] = 71;
    Map["Hf"] = 72;
    Map["Ta"] = 73;
    Map["W"] = 74;
    Map["Re"] = 75;
    Map["Os"] = 76;
    Map["Ir"] = 77;
    Map["Pt"] = 78;
    Map["Au"] = 79;
    Map["Hg"] = 80;
    Map["Tl"] = 81;
    Map["Pb"] = 82;
    Map["Bi"] = 83;
    Map["Po"] = 84;
    Map["At"] = 85;
    Map["Rn"] = 86;
    Map["Fr"] = 87;
    Map["Ra"] = 88;
    Map["Ac"] = 89;
    Map["Th"] = 90;
    Map["Pa"] = 91;
    Map["U"] = 92;
    Map["Np"] = 93;
    Map["Pu"] = 94;
    Map["Am"] = 95;
    Map["Cm"] = 96;
    Map["Bk"] = 97;
    Map["Cf"] = 98;
    Map["Es"] = 99;
    Map["Fm"] = 100;
    map<int,string> rev_Map;
    map<string,int>::iterator it1;
    tr(Map,it1)
    {
        rev_Map[it1->second]=it1->first;
    }
    int i,j;
    map<int,int> m;
    FOR(i,0,25)
    m[1<<i]=i;
    int n,k;
    int num,curr,start;
    cin>>n>>k;
    string s;
    int arr1[n],arr2[k];
    FOR(i,0,n-1)
    {
    cin>>s;
    arr1[i]=Map[s];
   // cout<<arr1[i]<<" ";
    }
    //cout<<"\n";
    FOR(i,0,k-1)
    {
    cin>>s;
    arr2[i]=Map[s];
   // cout<<arr2[i]<<" ";
    }
  //  cout<<"\n";
    int dp[(1<<n)];
    sort(arr1,arr1+n);
    sort(arr2,arr2+k);
    vector<int> can_make[k];
    bool check[1<<n];
    int pre[1<<n];
    int sum=0;
    FOR(i,0,(1<<n)-1)
    {
        dp[i]=0;
        check[i]=false;
        num=i;
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            sum=sum+arr1[m[curr]];
        }
        FOR(j,0,k-1)
        {
            if(arr2[j]==sum)
            {
            can_make[j].pb(i);
            }
        }
    }
        dp[0]=0;
        check[0]=true;
        int k1;
        vector<int>::iterator it;
    FOR(i,0,k-1)
    {
        for(j=(1<<n)-1;j>=0;j--)
        {
            for(it=can_make[i].begin();it!=can_make[i].end() && !check[j];it++)
            {
                k1=*it;
                if((k1&j)==k1)
                {
                    if((dp[j-k1]+1)>dp[j])
                    {
                       // cout<<"hey"<<j<<" ";
                        dp[j]=dp[j-k1]+1;
                        pre[j]=j-k1;
                    }
                }
            }
        }

    }
    if(dp[(1<<n)-1]==k)
    {
        cout<<"YES\n";
    start=(1<<n)-1;
    int sum;
    while(start)
    {
        //cout<<start<<" ";
        num=start-pre[start];
        start=pre[start];
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            cout<<rev_Map[arr1[m[curr]]];
            sum=sum+arr1[m[curr]];
            if(num)
            cout<<"+";
        }
        cout<<"->";
        cout<<rev_Map[sum]<<"\n";
    }
    }
    else
    cout<<"NO";
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<math.h>
using namespace std;
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define sint(i) scanf("%d",&i)
#define ss(s) scanf("%s",s)
#define pii pair<int,int>
#define mp(i,j) make_pair(i,j)
#define ll long long
#define MAX 1000000000
#define MOD 1000000007
#define vi vector<int>
#define vvi vector < vi >
#define pb(i) push_back(i);
#define tr(v,it) for(it=v.begin();it!=v.end();it++)
int main()
{
    map<string,int> Map;
    Map["H"] = 1;
    Map["He"] = 2;
    Map["Li"] = 3;
    Map["Be"] = 4;
    Map["B"] = 5;
    Map["C"] = 6;
    Map["N"] = 7;
    Map["O"] = 8;
    Map["F"] = 9;
    Map["Ne"] = 10;
    Map["Na"] = 11;
    Map["Mg"] = 12;
    Map["Al"] = 13;
    Map["Si"] = 14;
    Map["P"] = 15;
    Map["S"] = 16;
    Map["Cl"] = 17;
    Map["Ar"] = 18;
    Map["K"] = 19;
    Map["Ca"] = 20;
    Map["Sc"] = 21;
    Map["Ti"] = 22;
    Map["V"] = 23;
    Map["Cr"] = 24;
    Map["Mn"] = 25;
    Map["Fe"] = 26;
    Map["Co"] = 27;
    Map["Ni"] = 28;
    Map["Cu"] = 29;
    Map["Zn"] = 30;
    Map["Ga"] = 31;
    Map["Ge"] = 32;
    Map["As"] = 33;
    Map["Se"] = 34;
    Map["Br"] = 35;
    Map["Kr"] = 36;
    Map["Rb"] = 37;
    Map["Sr"] = 38;
    Map["Y"] = 39;
    Map["Zr"] = 40;
    Map["Nb"] = 41;
    Map["Mo"] = 42;
    Map["Tc"] = 43;
    Map["Ru"] = 44;
    Map["Rh"] = 45;
    Map["Pd"] = 46;
    Map["Ag"] = 47;
    Map["Cd"] = 48;
    Map["In"] = 49;
    Map["Sn"] = 50;
    Map["Sb"] = 51;
    Map["Te"] = 52;
    Map["I"] = 53;
    Map["Xe"] = 54;
    Map["Cs"] = 55;
    Map["Ba"] = 56;
    Map["La"] = 57;
    Map["Ce"] = 58;
    Map["Pr"] = 59;
    Map["Nd"] = 60;
    Map["Pm"] = 61;
    Map["Sm"] = 62;
    Map["Eu"] = 63;
    Map["Gd"] = 64;
    Map["Tb"] = 65;
    Map["Dy"] = 66;
    Map["Ho"] = 67;
    Map["Er"] = 68;
    Map["Tm"] = 69;
    Map["Yb"] = 70;
    Map["Lu"] = 71;
    Map["Hf"] = 72;
    Map["Ta"] = 73;
    Map["W"] = 74;
    Map["Re"] = 75;
    Map["Os"] = 76;
    Map["Ir"] = 77;
    Map["Pt"] = 78;
    Map["Au"] = 79;
    Map["Hg"] = 80;
    Map["Tl"] = 81;
    Map["Pb"] = 82;
    Map["Bi"] = 83;
    Map["Po"] = 84;
    Map["At"] = 85;
    Map["Rn"] = 86;
    Map["Fr"] = 87;
    Map["Ra"] = 88;
    Map["Ac"] = 89;
    Map["Th"] = 90;
    Map["Pa"] = 91;
    Map["U"] = 92;
    Map["Np"] = 93;
    Map["Pu"] = 94;
    Map["Am"] = 95;
    Map["Cm"] = 96;
    Map["Bk"] = 97;
    Map["Cf"] = 98;
    Map["Es"] = 99;
    Map["Fm"] = 100;
    map<int,string> rev_Map;
    map<string,int>::iterator it1;
    tr(Map,it1)
    {
        rev_Map[it1->second]=it1->first;
    }
    int i,j;
    map<int,int> m;
    FOR(i,0,25)
    m[1<<i]=i;
    int n,k;
    int num,curr,start;
    cin>>n>>k;
    string s;
    int arr1[n],arr2[k];
    FOR(i,0,n-1)
    {
    cin>>s;
    arr1[i]=Map[s];
   // cout<<arr1[i]<<" ";
    }
    //cout<<"\n";
    FOR(i,0,k-1)
    {
    cin>>s;
    arr2[i]=Map[s];
   // cout<<arr2[i]<<" ";
    }
  //  cout<<"\n";
    bool dp[(1<<n)];
    sort(arr1,arr1+n);
    sort(arr2,arr2+k);
    vector<int> can_make[k];
    int pre[1<<n];
    int sum=0;
    FOR(i,0,(1<<n)-1)
    {
        dp[i]=false;
        num=i;
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            sum=sum+arr1[m[curr]];
        }
        FOR(j,0,k-1)
        {
            if(arr2[j]==sum)
            {
            can_make[j].pb(i);
            }
        }
    }
        dp[0]=true;
        int k1;
        vector<int>::iterator it;
    FOR(i,0,k-1)
    {
        for(j=(1<<n)-1;j>=0;j--)
        {
            if(dp[j])
            continue;
            for(it=can_make[i].begin();it!=can_make[i].end() && !dp[j];it++)
            {
                k1=*it;
                if((k1&j)==k1)
                {
                    if(dp[j-k1])
                    {
                       // cout<<"hey"<<j<<" ";
                        dp[j]=true;
                        pre[j]=j-k1;
                    }
                }
            }
        }

    }
    if(dp[(1<<n)-1])
    {
        cout<<"YES\n";
    start=(1<<n)-1;
    int sum;
    while(start)
    {
        //cout<<start<<" ";
        num=start-pre[start];
        start=pre[start];
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            cout<<rev_Map[arr1[m[curr]]];
            sum=sum+arr1[m[curr]];
            if(num)
            cout<<"+";
        }
        cout<<"->";
        cout<<rev_Map[sum]<<"\n";
    }
    }
    else
    cout<<"NO";
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<math.h>
using namespace std;
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define sint(i) scanf("%d",&i)
#define ss(s) scanf("%s",s)
#define pii pair<int,int>
#define mp(i,j) make_pair(i,j)
#define ll long long
#define MAX 1000000000
#define MOD 1000000007
#define vi vector<int>
#define vvi vector < vi >
#define pb(i) push_back(i);
#define tr(v,it) for(it=v.begin();it!=v.end();it++)
int main()
{
    map<string,int> Map;
    Map["H"] = 1;
    Map["He"] = 2;
    Map["Li"] = 3;
    Map["Be"] = 4;
    Map["B"] = 5;
    Map["C"] = 6;
    Map["N"] = 7;
    Map["O"] = 8;
    Map["F"] = 9;
    Map["Ne"] = 10;
    Map["Na"] = 11;
    Map["Mg"] = 12;
    Map["Al"] = 13;
    Map["Si"] = 14;
    Map["P"] = 15;
    Map["S"] = 16;
    Map["Cl"] = 17;
    Map["Ar"] = 18;
    Map["K"] = 19;
    Map["Ca"] = 20;
    Map["Sc"] = 21;
    Map["Ti"] = 22;
    Map["V"] = 23;
    Map["Cr"] = 24;
    Map["Mn"] = 25;
    Map["Fe"] = 26;
    Map["Co"] = 27;
    Map["Ni"] = 28;
    Map["Cu"] = 29;
    Map["Zn"] = 30;
    Map["Ga"] = 31;
    Map["Ge"] = 32;
    Map["As"] = 33;
    Map["Se"] = 34;
    Map["Br"] = 35;
    Map["Kr"] = 36;
    Map["Rb"] = 37;
    Map["Sr"] = 38;
    Map["Y"] = 39;
    Map["Zr"] = 40;
    Map["Nb"] = 41;
    Map["Mo"] = 42;
    Map["Tc"] = 43;
    Map["Ru"] = 44;
    Map["Rh"] = 45;
    Map["Pd"] = 46;
    Map["Ag"] = 47;
    Map["Cd"] = 48;
    Map["In"] = 49;
    Map["Sn"] = 50;
    Map["Sb"] = 51;
    Map["Te"] = 52;
    Map["I"] = 53;
    Map["Xe"] = 54;
    Map["Cs"] = 55;
    Map["Ba"] = 56;
    Map["La"] = 57;
    Map["Ce"] = 58;
    Map["Pr"] = 59;
    Map["Nd"] = 60;
    Map["Pm"] = 61;
    Map["Sm"] = 62;
    Map["Eu"] = 63;
    Map["Gd"] = 64;
    Map["Tb"] = 65;
    Map["Dy"] = 66;
    Map["Ho"] = 67;
    Map["Er"] = 68;
    Map["Tm"] = 69;
    Map["Yb"] = 70;
    Map["Lu"] = 71;
    Map["Hf"] = 72;
    Map["Ta"] = 73;
    Map["W"] = 74;
    Map["Re"] = 75;
    Map["Os"] = 76;
    Map["Ir"] = 77;
    Map["Pt"] = 78;
    Map["Au"] = 79;
    Map["Hg"] = 80;
    Map["Tl"] = 81;
    Map["Pb"] = 82;
    Map["Bi"] = 83;
    Map["Po"] = 84;
    Map["At"] = 85;
    Map["Rn"] = 86;
    Map["Fr"] = 87;
    Map["Ra"] = 88;
    Map["Ac"] = 89;
    Map["Th"] = 90;
    Map["Pa"] = 91;
    Map["U"] = 92;
    Map["Np"] = 93;
    Map["Pu"] = 94;
    Map["Am"] = 95;
    Map["Cm"] = 96;
    Map["Bk"] = 97;
    Map["Cf"] = 98;
    Map["Es"] = 99;
    Map["Fm"] = 100;
    map<int,string> rev_Map;
    map<string,int>::iterator it1;
    tr(Map,it1)
    {
        rev_Map[it1->second]=it1->first;
    }
    int i,j;
    map<int,int> m;
    FOR(i,0,25)
    m[1<<i]=i;
    int n,k;
    int num,curr,start;
    cin>>n>>k;
    string s;
    int arr1[n],arr2[k];
    FOR(i,0,n-1)
    {
    cin>>s;
    arr1[i]=Map[s];
   // cout<<arr1[i]<<" ";
    }
    //cout<<"\n";
    FOR(i,0,k-1)
    {
    cin>>s;
    arr2[i]=Map[s];
   // cout<<arr2[i]<<" ";
    }
  //  cout<<"\n";
    int dp[(1<<n)];
    vector<int> can_make[k];
    int pre[1<<n];
    int sum=0;
    FOR(i,0,(1<<n)-1)
    {
        dp[i]=0;
        num=i;
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            sum=sum+arr1[m[curr]];
        }
        FOR(j,0,k-1)
        {
            if(arr2[j]==sum)
            {
            can_make[j].pb(i);
            }
        }
    }
        dp[0]=0;
        int k1;
        vector<int>::iterator it;
    FOR(i,0,k-1)
    {
        for(j=(1<<n)-1;j>=0;j--)
        {
            //check if possible
            tr(can_make[i],it)
            {
                k1=*it;
                if((k1&j)==k1)
                {
                    if((dp[j-k1]+1)>dp[j])
                    {
                       // cout<<"hey"<<j<<" ";
                        dp[j]=dp[j-k1]+1;
                        pre[j]=j-k1;
                    }
                }
            }
        }

    }
    if(dp[(1<<n)-1]==k)
    {
        cout<<"YES\n";
    start=(1<<n)-1;
    int sum;
    while(start)
    {
        //cout<<start<<" ";
        num=start-pre[start];
        start=pre[start];
        sum=0;
        while(num)
        {
            curr=num-(num&(num-1));
            num=num-curr;
            cout<<rev_Map[arr1[m[curr]]];
            sum=sum+arr1[m[curr]];
            if(num)
            cout<<"+";
        }
        cout<<"->";
        cout<<rev_Map[sum]<<"\n";
    }
    }
    else
    cout<<"NO";
    return 0;
}