#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#define pb push_back
using namespace std;

const string etable[101] =
{"","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"};

int n,k;
int an[20],ak[20],ans[20];
bool done[1<<20];
vector<int> syn[20];
void printer(int binum)
{
	for(int i=0;i<n;i++) if(1<<i&binum)
	{
		cout<<etable[an[i]]<<" ";
	}
	cout<<endl;
}
int getNum(string &s)
{
	for(int i=1;i<101;i++) if(etable[i]==s)
		return i;
}
int getSum(int binum)
{
	int sum=0;
	for(int i=0;i<n;i++) if(1<<i&binum)
	{
		sum+=an[i];
	}
	return sum;
}
void getSyn(int ki)
{
	int maxn=1<<n;
	//printf("getSyn %s : \n",etable[ak[ki]].c_str());
	for(int i=0;i<maxn;i++) if(getSum(i)==ak[ki])
	{
		//printer(i);
		syn[ki].pb(i);
	}
}
bool getAns(int ki,int binum)
{
	if(ki==k) return true;
	if(done[binum]) return false;
	//printf("before %s : ",etable[ak[ki]].c_str());
	//printer(binum);
	for(int i=0;i<syn[ki].size();i++)
	{
		if((binum&syn[ki][i])==0)
		{
			if(getAns(ki+1,binum|syn[ki][i]))
			{
				ans[ki]=syn[ki][i];
				return true;
			}
			else
			{
				done[binum]=true;
			}
		}
	}
	return false;
}
void printAns(int ki)
{
	bool plusf=false;
	//printf("ans[%d]=%d\n",ki,ans[ki]);
	for(int i=0;i<n;i++) if(1<<i&ans[ki])
	{
		if(plusf) putchar('+');
		cout<<etable[an[i]];
		plusf=true;
	}
	cout<<"->"<<etable[ak[ki]]<<endl;
}
int main()
{
	string ss;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>ss;
		an[i]=getNum(ss);
	}
	for(int i=0;i<k;i++)
	{
		cin>>ss;
		ak[i]=getNum(ss);
		getSyn(i);
	}
	if(getAns(0,0))
	{
		puts("YES");
		for(int i=0;i<k;i++) printAns(i);
	}
	else puts("NO");
	return 0;
}


include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#define pb push_back
using namespace std;

const string etable[101] =
{"","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"};

int n,k;
int an[20],ak[20],ans[20];
bool done[1<<20];
vector<int> syn[20];
void printer(int binum)
{
        for(int i=0;i<n;i++) if(1<<i&binum)
        {
                cout<<etable[an[i]]<<" ";
        }
        cout<<endl;
}
int getNum(string &s)
{
        for(int i=1;i<101;i++) if(etable[i]==s)
                return i;
}
int getSum(int binum)
{
        int sum=0;
        for(int i=0;i<n;i++) if(1<<i&binum)
        {
                sum+=an[i];
        }
        return sum;
}
void getSyn(int ki)
{
        int maxn=1<<n;
        //printf("getSyn %s : \n",etable[ak[ki]].c_str());
        for(int i=0;i<maxn;i++) if(getSum(i)==ak[ki])
        {
                //printer(i);
                syn[ki].pb(i);
        }
}
bool getAns(int ki,int binum)
{
        if(done[binum]) return false;
        if(ki==k) return true;
        //printf("before %s : ",etable[ak[ki]].c_str());
        //printer(binum);
        for(int i=0;i<syn[ki].size();i++)
        {
                if((binum&syn[ki][i])==0)
                {
                        if(getAns(ki+1,binum|syn[ki][i]))
                        {
                                ans[ki]=syn[ki][i];
                                return true;
                        }
                        else
                        {
                                done[binum|syn[ki][i]]=true;
                        }
                }
        }
        return false;
}
void printAns(int ki)
{
        bool plusf=false;
        //printf("ans[%d]=%d\n",ki,ans[ki]);
        for(int i=0;i<n;i++) if(1<<i&ans[ki])
        {
                if(plusf) putchar('+');
                cout<<etable[an[i]];
                plusf=true;
        }
        cout<<"->"<<etable[ak[ki]]<<endl;
}
int main()
{
        string ss;
        cin>>n>>k;
        for(int i=0;i<n;i++)
        {
                cin>>ss;
                an[i]=getNum(ss);
        }
        for(int i=0;i<k;i++)
        {
                cin>>ss;
                ak[i]=getNum(ss);
                getSyn(i);
        }
        if(getAns(0,0))
        {
                puts("YES");
                for(int i=0;i<k;i++) printAns(i);
        }
        else puts("NO");
        return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#define pb push_back
using namespace std;

const string etable[101] =
{"","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"};

int n,k;
int an[20],ak[20],ans[20];
bool done[1<<20];
vector<int> syn[20];

int getNum(string &s)
{
        for(int i=1;i<101;i++) if(etable[i]==s)
                return i;
}
int getSum(int binum)
{
        int sum=0;
        for(int i=0;i<n;i++) if(1<<i&binum)
        {
                sum+=an[i];
        }
        return sum;
}
void getSyn(int ki)
{
        int maxn=1<<n;
        for(int i=0;i<maxn;i++) if(getSum(i)==ak[ki])
        {
                syn[ki].pb(i);
        }
}
bool getAns(int ki,int binum)
{
        if(done[binum]) return false;
        if(ki==k) return true;
        done[binum] = true;
        for(int i=0;i<syn[ki].size();i++)
        {
                if((binum&syn[ki][i])==0)
                {
                        if(getAns(ki+1,binum|syn[ki][i]))
                        {
                                ans[ki]=syn[ki][i];
                                return true;
                        }
                }
        }
        return false;
}
void printAns(int ki)
{
        bool plusf=false;
        //printf("ans[%d]=%d\n",ki,ans[ki]);
        for(int i=0;i<n;i++) if(1<<i&ans[ki])
        {
                if(plusf) putchar('+');
                cout<<etable[an[i]];
                plusf=true;
        }
        cout<<"->"<<etable[ak[ki]]<<endl;
}
int main()
{
        string ss;
        cin>>n>>k;
        for(int i=0;i<n;i++)
        {
                cin>>ss;
                an[i]=getNum(ss);
        }
        for(int i=0;i<k;i++)
        {
                cin>>ss;
                ak[i]=getNum(ss);
                getSyn(i);
        }
        if(getAns(0,0))
        {
                puts("YES");
                for(int i=0;i<k;i++) printAns(i);
        }
        else puts("NO");
        return 0;
}


#include <iostream>
#include <fstream>
#include <deque>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <memory.h>
using namespace std;

#define LL long long
#define pb push_back
#define sqr(x) ((x) * (x))

const double pi = acos(-1.0);

int n, k, t;
LL q;
string s;
map <string, int> M;
int a[20], b[20];
vector <string> v;
vector <int> p, masks[1000000];

bool d[20][300000];
int from[20][300000];

int sum(int mask)
{
        int i = 0, res = 0;
        while(mask)
        {
                if (mask & 1)
                        res += a[i];
                mask >>= 1;
                i++;
        }
        return res;
}

void preproc()
{
        for (int mask = 1; mask < (1 << n); mask++)
                masks[sum(mask)].pb(mask);
}

string get_mask(int mask)
{
        int i = 0;
        string res = "";
        while(mask)
        {
                if (mask & 1)
                {
                        res = res + v[a[i] - 1] + "+";
                }
                mask >>= 1;
                i++;
        }
        res[res.length() - 1] = '-';
        return res;
}

void rec()
{
        d[0][0] = 1;
        for (int i = 0; i < n; i++)
                for (int mask = 0; mask < (1 << n); mask++)
                        if (d[i][mask])
                                for (int j = 0; j < masks[b[i]].size(); j++)
                                        if ((masks[b[i]][j] & mask) == 0)
                                        {
                                                d[i + 1][masks[b[i]][j] | mask] = true;
                                                from[i + 1][masks[b[i]][j] | mask] = mask;
                                        }

        if (d[k][(1 << n) - 1])
        {
                cout << "YES" << endl;
                int now = (1 << n) - 1;
                while (k)
                {
                        cout << get_mask(from[k][now] ^ now) << ">" << v[b[k - 1] - 1] << endl;
                        now = from[k][now];
                        k--;
                }
                exit(0);
        }

}

int main()
{
        v.pb("H");
        v.pb("He");
        v.pb("Li");
        v.pb("Be");
        v.pb("B");
        v.pb("C");
        v.pb("N");
        v.pb("O");
        v.pb("F");
        v.pb("Ne");
        v.pb("Na");
        v.pb("Mg");
        v.pb("Al");
        v.pb("Si");
        v.pb("P");
        v.pb("S");
        v.pb("Cl");
        v.pb("Ar");
        v.pb("K");
        v.pb("Ca");
        v.pb("Sc");
        v.pb("Ti");
        v.pb("V");
        v.pb("Cr");
        v.pb("Mn");
        v.pb("Fe");
        v.pb("Co");
        v.pb("Ni");
        v.pb("Cu");
        v.pb("Zn");
        v.pb("Ga");
        v.pb("Ge");
        v.pb("As");
        v.pb("Se");
        v.pb("Br");
        v.pb("Kr");
        v.pb("Rb");
        v.pb("Sr");
        v.pb("Y");
        v.pb("Zr");
        v.pb("Nb");
        v.pb("Mo");
        v.pb("Tc");
        v.pb("Ru");
        v.pb("Rh");
        v.pb("Pd");
        v.pb("Ag");
        v.pb("Cd");
        v.pb("In");
        v.pb("Sn");
        v.pb("Sb");
        v.pb("Te");
        v.pb("I");
        v.pb("Xe");
        v.pb("Cs");
        v.pb("Ba");
        v.pb("La");
        v.pb("Ce");
        v.pb("Pr");
        v.pb("Nd");
        v.pb("Pm");
        v.pb("Sm");
        v.pb("Eu");
        v.pb("Gd");
        v.pb("Tb");
        v.pb("Dy");
        v.pb("Ho");
        v.pb("Er");
        v.pb("Tm");
        v.pb("Yb");
        v.pb("Lu");
        v.pb("Hf");
        v.pb("Ta");
        v.pb("W");
        v.pb("Re");
        v.pb("Os");
        v.pb("Ir");
        v.pb("Pt");
        v.pb("Au");
        v.pb("Hg");
        v.pb("Tl");
        v.pb("Pb");
        v.pb("Bi");
        v.pb("Po");
        v.pb("At");
        v.pb("Rn");
        v.pb("Fr");
        v.pb("Ra");
        v.pb("Ac");
        v.pb("Th");
        v.pb("Pa");
        v.pb("U");
        v.pb("Np");
        v.pb("Pu");
        v.pb("Am");
        v.pb("Cm");
        v.pb("Bk");
        v.pb("Cf");
        v.pb("Es");
        v.pb("Fm");
        v.pb("Md");
        v.pb("No");
        v.pb("Lr");
        v.pb("Rf");
        v.pb("Db");
        v.pb("Sg");
        v.pb("Bh");
        v.pb("Hs");
        v.pb("Mt");
        for (int i = 0; i < v.size(); i++)
                M[v[i]] = i + 1;

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        /*int i = 1;
        while (!cin.eof())
        {
                getline(cin, s);
                cout <<  "v.pb(\"" << s << "\");\n";
                i++;
        }*/

        cin >> n >> k;
        for (int i = 0; i < n; i++)
        {
                cin >> s;
                a[i] = M[s];
        }

        for (int i = 0; i < k; i++)
        {
                cin >> s;
                b[i] = M[s];
        }
        preproc();
        rec();
        cout << "NO";
        return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#define pb push_back
using namespace std;

const string etable[101] =
{"","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"};

int n,k;
int an[20],ak[20],ans[20],cnt[20];
bool done[1<<20];
vector<int> syn[20];
void printer(int binum)
{
    for(int i=0;i<n;i++) if(1<<i&binum)
    {
        cout<<etable[an[i]]<<" ";
    }
    cout<<endl;
}
int getNum(string &s)
{
    for(int i=1;i<101;i++) if(etable[i]==s)
        return i;
}
int getSum(int binum)
{
    int sum=0;
    for(int i=0;i<n;i++) if(1<<i&binum)
    {
        sum+=an[i];
    }
    return sum;
}
void getSyn(int ki)
{
    int maxn=1<<n;
    //printf("getSyn %s : \n",etable[ak[ki]].c_str());
    for(int i=0;i<maxn;i++) if(getSum(i)==ak[ki])
    {
        //printer(i);
        syn[ki].pb(i);
    }
    //printf("syn[%d] size=%d\n",ki,syn[ki].size());
}
bool getAns(int ki,int binum)
{
    if(done[binum]) return false;
    if(ki==k) return true;
    ++cnt[ki];
    //printf("before %d %s : ",ki,etable[ak[ki]].c_str());
    //printer(binum);
    for(int i=0;i<syn[ki].size();i++)
    {
        if((binum&syn[ki][i])==0)
        {
            if(!done[binum|syn[ki][i]]&&getAns(ki+1,binum|syn[ki][i]))
            {
                ans[ki]=syn[ki][i];
                return true;
            }
            else
            {
                done[binum|syn[ki][i]]=true;
                done[syn[ki][i]]=true;
            }
        }
    }
    return false;
}
void printAns(int ki)
{
    bool plusf=false;
    //printf("ans[%d]=%d\n",ki,ans[ki]);
    for(int i=0;i<n;i++) if(1<<i&ans[ki])
    {
        if(plusf) putchar('+');
        cout<<etable[an[i]];
        plusf=true;
    }
    cout<<"->"<<etable[ak[ki]]<<endl;
}
int main()
{
    string ss;
    int sum=0;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>ss;
        an[i]=getNum(ss);
        sum+=an[i];
    }
    for(int i=0;i<k;i++)
    {
        cin>>ss;
        ak[i]=getNum(ss);
        sum-=ak[i];
        getSyn(i);
    }
    //cout<<sum<<endl;
    if(sum>=0&&getAns(0,0))
    {
        puts("YES");
        for(int i=0;i<k;i++) printAns(i);
    }
        //for(int i=0;i<=k;i++)     printf("dfs: %d,%d \n",i,cnt[i]);
    else puts("NO");
    return 0;
}
/*
17 4
H H H H H H H H H H H H H H H H F
O O O H
*/


#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#define pb push_back
using namespace std;

const string etable[101] =
{"","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"};

int n,k;
int an[20],ak[20],ans[20];
bool done[1<<20];
vector<int> syn[20];

int getNum(string &s)
{
	for(int i=1;i<101;i++) if(etable[i]==s)
		return i;
}
int getSum(int binum)
{
	int sum=0;
	for(int i=0;i<n;i++) if(1<<i&binum)
	{
		sum+=an[i];
	}
	return sum;
}
void getSyn(int ki)
{
	int maxn=1<<n;
	for(int i=0;i<maxn;i++) if(getSum(i)==ak[ki])
		syn[ki].pb(i);
}
bool getAns(int ki,int binum)
{
	if(ki==k) return true;
	if(done[binum]) return false;
	for(int i=0;i<syn[ki].size();i++)
	{
		if((binum&syn[ki][i])==0)
		{
			if(getAns(ki+1,binum|syn[ki][i]))
			{
				ans[ki]=syn[ki][i];
				return true;
			}
			else
			{
				done[binum]=true;
				return false;
			}
		}
	}
	return false;
}
void printAns(int ki)
{
	bool plusf=false;
	//printf("ans[%d]=%d\n",ki,ans[ki]);
	for(int i=0;i<n;i++) if(1<<i&ans[ki])
	{
		if(plusf) putchar('+');
		cout<<etable[an[i]];
		plusf=true;
	}
	cout<<"->"<<etable[ak[ki]]<<endl;
}
int main()
{
	string ss;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>ss;
		an[i]=getNum(ss);
	}
	for(int i=0;i<k;i++)
	{
		cin>>ss;
		ak[i]=getNum(ss);
		getSyn(i);
	}
	if(getAns(0,0))
	{
		puts("YES");
		for(int i=0;i<k;i++) printAns(i);
	}
	else puts("NO");
	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#define pb push_back
using namespace std;

const string etable[101] =
{"","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"};

int n,k;
int an[20],ak[20],ans[20];
bool done[1<<20];
vector<int> syn[20];
void printer(int binum)
{
        for(int i=0;i<n;i++) if(1<<i&binum)
        {
                cout<<etable[an[i]]<<" ";
        }
        cout<<endl;
}
int getNum(string &s)
{
        for(int i=1;i<101;i++) if(etable[i]==s)
                return i;
}
int getSum(int binum)
{
        int sum=0;
        for(int i=0;i<n;i++) if(1<<i&binum)
        {
                sum+=an[i];
        }
        return sum;
}
void getSyn(int ki)
{
        int maxn=1<<n;
        //printf("getSyn %s : \n",etable[ak[ki]].c_str());
        for(int i=0;i<maxn;i++) if(getSum(i)==ak[ki])
        {
                //printer(i);
                syn[ki].pb(i);
        }
}
bool getAns(int ki,int binum)
{
        if(done[binum]) return false;
        if(ki==k) return true;
        //printf("before %s : ",etable[ak[ki]].c_str());
        //printer(binum);
        for(int i=0;i<syn[ki].size();i++)
        {
                if((binum&syn[ki][i])==0)
                {
                        if(getAns(ki+1,binum|syn[ki][i]))
                        {
                                ans[ki]=syn[ki][i];
                                return true;
                        }
                        else
                        {
                                done[binum|syn[ki][i]]=true;
                        }
                }
        }
        return false;
}
void printAns(int ki)
{
        bool plusf=false;
        //printf("ans[%d]=%d\n",ki,ans[ki]);
        for(int i=0;i<n;i++) if(1<<i&ans[ki])
        {
                if(plusf) putchar('+');
                cout<<etable[an[i]];
                plusf=true;
        }
        cout<<"->"<<etable[ak[ki]]<<endl;
}
int main()
{
        string ss;
        cin>>n>>k;
        for(int i=0;i<n;i++)
        {
                cin>>ss;
                an[i]=getNum(ss);
        }
        for(int i=0;i<k;i++)
        {
                cin>>ss;
                ak[i]=getNum(ss);
                getSyn(i);
        }
        if(getAns(0,0))
        {
                puts("YES");
                for(int i=0;i<k;i++) printAns(i);
        }
        else puts("NO");
        return 0;
}


#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string s[110]={"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","Ti","Pb","Bi","Po","At","Rn","Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm","Md","No","Lr","Unq","Unp","Unh","Uns","Uno","Une","Unn"};
vector<int> v,V;
int n,k;
char str[4];
char dp[17][101];
bool calc(int i,int s){
    if(i==v.size() || s<0)
        return !s;
    if(dp[i][s]==-1){
        dp[i][s]=false;
        if(calc(i+1,s) || calc(i+1,s-v[i]))
            dp[i][s]=true;
    }
    return dp[i][s];
}
bool p;
void print(int i,int c){
    if(!c)
        return;
    if(calc(i+1,c))
        print(i+1,c);
    else{
        p=printf("%s%s",p?"+":"",s[v[i]-1].c_str());
        print(i+1,c-v[i]);
    }
}
int main()
{
    memset(dp,-1,sizeof(dp));
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i){
        scanf("%s",str);
        v.push_back(find(s,s+110,str)-s+1);
    }
    for(int i=0;i<k;++i){
        scanf("%s",str);
        V.push_back(find(s,s+110,str)-s+1);
    }
    bool can=true;
    for(int i=0;can && i<k;++i)
        can&=calc(0,V[i]);
    if(!can){
        puts("NO");
        return 0;
    }
    puts("YES");
    for(int i=0;i<k;++i){
        p=false;
        print(0,V[i]);
        printf("->%s\n",s[V[i]-1].c_str());
    }
    return 0;
}


#include <stdio.h>
#include <memory.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string s[100]={"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","Ti","Pb","Bi","Po","At","Rn","Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm"};
vector<int> v,V;
int n,k;
char str[4];
char dp[17][1<<17];
vector<int> MSK[101];
int getSum(int msk){
    int s=0;
    for(int i=0;i<18;++i)
        if((msk>>i)&1)
            s+=v[i];
    if(s>100)
        s=0;
    return s;
}
bool calc(int i,int msk){
    if(i==k)
        return true;
    if(dp[i][msk]==-1){
        dp[i][msk]=false;
        for(int j=0;!dp[i][msk] && j<MSK[V[i]].size();++j)
            if(!(msk&MSK[V[i]][j]))
                dp[i][msk]=calc(i+1,msk|MSK[V[i]][j]);
    }
    return dp[i][msk];
}
bool p;
void print(int i,int msk){
    if(i==k)
        return;
    for(int j=0;j<MSK[V[i]].size();++j)
        if(!(msk&MSK[V[i]][j]) && calc(i+1,msk|MSK[V[i]][j])){
            for(int k=0;k<18;++k)
                if((MSK[V[i]][j]>>k)&1)
                    p=printf("%s%s",p?"+":"",s[v[k]-1].c_str());
            printf("->%s\n",s[V[i]-1].c_str());
            p=false;
            print(i+1,msk|MSK[V[i]][j]);
            return;
        }
}
int main()
{
    memset(dp,-1,sizeof(dp));
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i){
        scanf("%s",str);
        v.push_back(find(s,s+110,str)-s+1);
    }
    for(int i=0;i<k;++i){
        scanf("%s",str);
        V.push_back(find(s,s+110,str)-s+1);
    }
    for(int i=(1<<n)-1;i>0;--i){
        MSK[getSum(i)].push_back(i);
        MSK[0].clear();
    }
    if(!calc(0,0))
        puts("NO");
    else{
        puts("YES");
        print(0,0);
    }
    return 0;
}


#include <stdio.h>
#include <memory.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string s[100]={"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"};
vector<int> v,V;
int n,k;
char str[4];
char dp[17][1<<17];
vector<int> MSK[101];
int getSum(int msk){
    int s=0;
    for(int i=0;i<18;++i)
        if((msk>>i)&1)
            s+=v[i];
    if(s>100)
        s=0;
    return s;
}
bool calc(int i,int msk){
    if(i==k)
        return true;
    if(dp[i][msk]==-1){
        dp[i][msk]=false;
        for(int j=0;!dp[i][msk] && j<MSK[V[i]].size();++j)
            if(!(msk&MSK[V[i]][j]))
                dp[i][msk]=calc(i+1,msk|MSK[V[i]][j]);
    }
    return dp[i][msk];
}
bool p;
void print(int i,int msk){
    if(i==k)
        return;
    for(int j=0;j<MSK[V[i]].size();++j)
        if(!(msk&MSK[V[i]][j]) && calc(i+1,msk|MSK[V[i]][j])){
            for(int k=0;k<18;++k)
                if((MSK[V[i]][j]>>k)&1)
                    p=printf("%s%s",p?"+":"",s[v[k]-1].c_str());
            printf("->%s\n",s[V[i]-1].c_str());
            p=false;
            print(i+1,msk|MSK[V[i]][j]);
            return;
        }
}
int main()
{
    memset(dp,-1,sizeof(dp));
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i){
        scanf("%s",str);
        v.push_back(find(s,s+110,str)-s+1);
    }
    for(int i=0;i<k;++i){
        scanf("%s",str);
        V.push_back(find(s,s+110,str)-s+1);
    }
    for(int i=0;i<101;++i)
        MSK[i].reserve(10000);
    for(int i=(1<<n)-1;i>0;--i){
        MSK[getSum(i)].push_back(i);
        MSK[0].clear();
    }
    if(!calc(0,0))
        puts("NO");
    else{
        puts("YES");
        print(0,0);
    }
    return 0;
}


#include <stdio.h>
#include <memory.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string s[100]={"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"};
vector<int> v,V;
int n,k;
char str[4];
char dp[17][1<<17];
vector<int> MSK[101];
int getSum(int msk){
    int s=0;
    for(int i=0;i<18;++i)
        if((msk>>i)&1)
            s+=v[i];
    if(s>100)
        s=0;
    return s;
}
bool calc(int i,int msk){
    if(i==k)
        return true;
    if(dp[i][msk]==-1){
        dp[i][msk]=false;
        for(int j=0;!dp[i][msk] && j<MSK[V[i]].size();++j)
            if(!(msk&MSK[V[i]][j]))
                dp[i][msk]=calc(i+1,msk|MSK[V[i]][j]);
    }
    return dp[i][msk];
}
bool p;
void print(int i,int msk){
    if(i==k)
        return;
    for(int j=0;j<MSK[V[i]].size();++j)
        if(!(msk&MSK[V[i]][j]) && calc(i+1,msk|MSK[V[i]][j])){
            for(int k=0;k<18;++k)
                if((MSK[V[i]][j]>>k)&1)
                    p=printf("%s%s",p?"+":"",s[v[k]-1].c_str());
            printf("->%s\n",s[V[i]-1].c_str());
            p=false;
            print(i+1,msk|MSK[V[i]][j]);
            return;
        }
}
int main()
{
    memset(dp,-1,sizeof(dp));
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i){
        scanf("%s",str);
        v.push_back(find(s,s+110,str)-s+1);
    }
    for(int i=0;i<k;++i){
        scanf("%s",str);
        V.push_back(find(s,s+110,str)-s+1);
    }
    for(int i=(1<<n)-1;i>0;--i){
        MSK[getSum(i)].push_back(i);
        MSK[0].clear();
    }
    if(!calc(0,0))
        puts("NO");
    else{
        puts("YES");
        print(0,0);
    }
    return 0;
}


#include <stdio.h>
#include <memory.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string s[100]={"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"};
vector<int> v,V;
int n,k;
char str[4];
char dp[17][1<<17];
vector<int> MSK[101];
int getSum(int msk){
    int s=0;
    for(int i=0;i<18;++i)
        if((msk>>i)&1)
            s+=v[i];
    if(s>100)
        s=0;
    return s;
}
vector<int> sol;
bool calc(int i,int msk){
    if(i==k)
        return true;
    if(dp[i][msk]==-1){
        dp[i][msk]=false;
        for(int j=0;!dp[i][msk] && j<MSK[V[i]].size();++j)
            if(!(msk&MSK[V[i]][j]))
                if(dp[i][msk]=calc(i+1,msk|MSK[V[i]][j]))
                    sol.push_back(j);
    }
    return dp[i][msk];
}
bool p;
void print(){
    for(int i=0;i<k;++i){
        for(int k=0;k<18;++k)
            if((MSK[V[i]][sol[i]]>>k)&1)
                p=printf("%s%s",p?"+":"",s[v[k]-1].c_str());
        printf("->%s\n",s[V[i]-1].c_str());
        p=false;
    }
}
int main()
{
    memset(dp,-1,sizeof(dp));
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i){
        scanf("%s",str);
        v.push_back(find(s,s+110,str)-s+1);
    }
    for(int i=0;i<k;++i){
        scanf("%s",str);
        V.push_back(find(s,s+110,str)-s+1);
    }
    for(int i=0;i<101;++i)
        MSK[i].reserve(10000);
    for(int i=(1<<n)-1;i>0;--i){
        MSK[getSum(i)].push_back(i);
        MSK[0].clear();
    }
    if(!calc(0,0))
        puts("NO");
    else{
        puts("YES");
        reverse(sol.begin(),sol.end());
        print();
    }
    return 0;
}


#include <stdio.h>
#include <memory.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string s[110]={"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","Ti","Pb","Bi","Po","At","Rn","Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm","Md","No","Lr","Unq","Unp","Unh","Uns","Uno","Une","Unn"};
vector<int> v,V;
int n,k;
char str[4];
char dp[17][101];
bool calc(int i,int s){
    if(i==v.size() || s<0)
        return !s;
    if(dp[i][s]==-1){
        dp[i][s]=false;
        if(calc(i+1,s) || calc(i+1,s-v[i]))
            dp[i][s]=true;
    }
    return dp[i][s];
}
bool p;
void print(int i,int c){
    if(!c)
        return;
    if(calc(i+1,c))
        print(i+1,c);
    else{
        p=printf("%s%s",p?"+":"",s[v[i]-1].c_str());
        print(i+1,c-v[i]);
    }
}
int main()
{
    memset(dp,-1,sizeof(dp));
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i){
        scanf("%s",str);
        v.push_back(find(s,s+110,str)-s+1);
    }
    for(int i=0;i<k;++i){
        scanf("%s",str);
        V.push_back(find(s,s+110,str)-s+1);
    }
    bool can=true;
    for(int i=0;can && i<k;++i)
        can&=calc(0,V[i]);
    if(!can){
        puts("NO");
        return 0;
    }
    puts("YES");
    for(int i=0;i<k;++i){
        p=false;
        print(0,V[i]);
        printf("->%s\n",s[V[i]-1].c_str());
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cassert>
using namespace std;
typedef long long ll;

#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)

#define SZ(v) (int)((v).size())
#define MEMSET(v,h) memset((v),(h),sizeof(v))
#define FIND(m,w) ((m).find(w)!=(m).end())

// What the hell....?

string hogehogepiyopiyo = "1 H 2 He 3 Li    4 Be    5 B     6 C     7 N     8 O     9 F     10 Ne 11 Na     12 Mg 13 Al     14 Si   15 P    16 S    17 Cl   18 Ar 19 K  20 Ca   21 Sc   22 Ti   23 V    24 Cr   25 Mn   26 Fe   27 Co   28 Ni   29 Cu   30 Zn   31 Ga   32 Ge   33 As   34 Se   35 Br   36 Kr 37 Rb     38 Sr   39 Y    40 Zr   41 Nb   42 Mo   43 Tc   44 Ru   45 Rh   46 Pd   47 Ag   48 Cd   49 In   50 Sn   51 Sb   52 Te   53 I    54 Xe 55 Cs     56 Ba 72 Hf     73 Ta   74 W    75 Re   76 Os   77 Ir   78 Pt   79 Au   80 Hg   81 Tl   82 Pb   83 Bi   84 Po   85 At   86 Rn 87 Fr     88 Ra 57 La     58 Ce   59 Pr   60 Nd   61 Pm   62 Sm   63 Eu   64 Gd   65 Tb   66 Dy   67 Ho   68 Er   69 Tm   70 Yb   71 Lu 89 Ac     90 Th   91 Pa   92 U    93 Np   94 Pu   95 Am   96 Cm   97 Bk   98 Cf   99 Es   100 Fm  101 Md  102 No  103 Lr";
map<string,int> ptoid;
map<int,string> idtop;

void init() {
    stringstream ss; ss<<hogehogepiyopiyo;
    int x; string s;
    while (ss>>x>>s) ptoid[s]=x, idtop[x]=s;
}

int N, K;
int idfr[17], idto[17];
int sum[1<<17];

vector<string> output;

int rest[110*20];
bool ok;
void dfs(int depth, int bit) {
    if (ok) return;
    //cout<<"#"<<depth<<" "<<bit<<endl;
    if (depth==K) { ok=true; return; }

    int hi=-1;
    REP(j, N) if (bit&(1<<j)) hi=j;
    if (hi==-1) return;

    int ms=idto[depth];
    vector<int> cand;
    for (int sub = 0; sub<(1<<hi); sub = (sub-bit)&bit) {
        int subb=sub|(1<<hi);
        int m=sum[subb];
        if (m != ms) continue;
        cand.push_back(subb);
    }

    FORIT(it, cand) {
        int sub=*it;
        rest[ms]--;
        dfs(depth+1, bit^sub);
        rest[ms]++; // revert

        if (ok) {
            int first=1;
            string res;
            REP(j, N) if (sub&(1<<j)) {
                if (!first) res+="+";
                first=0;
                res+=idtop[idfr[j]];
            }
            res+="->"+idtop[ms];
            output.push_back(res);
            return;
        }

    }
}

int main() {
    init();

    while (cin>>N>>K) {
        REP(j, N) { string s; cin>>s; idfr[j] = ptoid[s]; }
        REP(k, K) { string s; cin>>s; idto[k] = ptoid[s]; }

        REP(bit, 1<<N) {
            int u=0;
            REP(j, N) if (bit&(1<<j)) u+=idfr[j];
            sum[bit]=u;
        }

        MEMSET(rest, 0);
        REP(k, K) rest[idto[k]]++;

        output.clear();

        ok=false;
        dfs(0, (1<<N)-1);
        if (!ok) printf("NO\n");
        else {
            puts("YES");
            reverse(output.begin(), output.end());
            FORIT(it, output) cout<<(*it)<<endl;
        }
    }
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cassert>
using namespace std;
typedef long long ll;

#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)

#define SZ(v) (int)((v).size())
#define MEMSET(v,h) memset((v),(h),sizeof(v))
#define FIND(m,w) ((m).find(w)!=(m).end())

// What the hell....?

string hogehogepiyopiyo = "1 H 2 He 3 Li    4 Be    5 B     6 C     7 N     8 O     9 F     10 Ne 11 Na     12 Mg 13 Al     14 Si   15 P    16 S    17 Cl   18 Ar 19 K  20 Ca   21 Sc   22 Ti   23 V    24 Cr   25 Mn   26 Fe   27 Co   28 Ni   29 Cu   30 Zn   31 Ga   32 Ge   33 As   34 Se   35 Br   36 Kr 37 Rb     38 Sr   39 Y    40 Zr   41 Nb   42 Mo   43 Tc   44 Ru   45 Rh   46 Pd   47 Ag   48 Cd   49 In   50 Sn   51 Sb   52 Te   53 I    54 Xe 55 Cs     56 Ba 72 Hf     73 Ta   74 W    75 Re   76 Os   77 Ir   78 Pt   79 Au   80 Hg   81 Tl   82 Pb   83 Bi   84 Po   85 At   86 Rn 87 Fr     88 Ra 57 La     58 Ce   59 Pr   60 Nd   61 Pm   62 Sm   63 Eu   64 Gd   65 Tb   66 Dy   67 Ho   68 Er   69 Tm   70 Yb   71 Lu 89 Ac     90 Th   91 Pa   92 U    93 Np   94 Pu   95 Am   96 Cm   97 Bk   98 Cf   99 Es   100 Fm  101 Md  102 No  103 Lr";
map<string,int> ptoid;
map<int,string> idtop;

void init() {
    stringstream ss; ss<<hogehogepiyopiyo;
    int x; string s;
    while (ss>>x>>s) ptoid[s]=x, idtop[x]=s;
}

int N, K;
int idfr[17], idto[17];
int sum[1<<17];
int dp[1<<17];

int toi(int bit) {
    int i=K-1, temp=0;
    for (; i>=0; i--) {
        temp+=idto[i];
        if (temp == sum[bit]) return i;
    }
    return -1;
}

int main() {
    init();

    while (cin>>N>>K) {
        REP(j, N) { string s; cin>>s; idfr[j] = ptoid[s]; }
        REP(k, K) { string s; cin>>s; idto[k] = ptoid[s]; }

        REP(bit, 1<<N) {
            int u=0;
            REP(j, N) if (bit&(1<<j)) u+=idfr[j];
            sum[bit]=u;
        }

        int ss=0;
        REP(j, N) ss-=idfr[j];
        REP(k, K) ss+=idto[k];
        if (ss) {
            puts("NO");
            continue;
        }

        REP(bit, 1<<N) {
            dp[bit]=-1;
            if (bit==0) { dp[0]=0; continue; }

            int i=toi(bit);
            if (i<0) continue;

            for (int sub=bit&-bit; sub; sub=(sub-bit)&bit) if (sum[sub] == idto[i] && dp[bit^sub]>=0) {
                dp[bit]=sub;
                break;
            }
        }

        if (dp[(1<<N)-1]>=0) {
            printf("YES\n");
            int bit=(1<<N)-1, i=0;
            for (; i<K;) {
                int sub=dp[bit];
                int first=1;
                REP(j, N) if (sub&(1<<j)) {
                    if (!first) printf("+");
                    first=0;
                    printf("%s", idtop[idfr[j]].c_str());
                }
                printf("->%s\n", idtop[idto[i]].c_str());
                bit=bit^sub, i++;
            }
        } else puts("NO");
    }
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cassert>
using namespace std;
typedef long long ll;

#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)

#define SZ(v) (int)((v).size())
#define MEMSET(v,h) memset((v),(h),sizeof(v))
#define FIND(m,w) ((m).find(w)!=(m).end())

// What the hell....?

string hogehogepiyopiyo = "1 H 2 He 3 Li    4 Be    5 B     6 C     7 N     8 O     9 F     10 Ne 11 Na     12 Mg 13 Al     14 Si   15 P    16 S    17 Cl   18 Ar 19 K  20 Ca   21 Sc   22 Ti   23 V    24 Cr   25 Mn   26 Fe   27 Co   28 Ni   29 Cu   30 Zn   31 Ga   32 Ge   33 As   34 Se   35 Br   36 Kr 37 Rb     38 Sr   39 Y    40 Zr   41 Nb   42 Mo   43 Tc   44 Ru   45 Rh   46 Pd   47 Ag   48 Cd   49 In   50 Sn   51 Sb   52 Te   53 I    54 Xe 55 Cs     56 Ba 72 Hf     73 Ta   74 W    75 Re   76 Os   77 Ir   78 Pt   79 Au   80 Hg   81 Tl   82 Pb   83 Bi   84 Po   85 At   86 Rn 87 Fr     88 Ra 57 La     58 Ce   59 Pr   60 Nd   61 Pm   62 Sm   63 Eu   64 Gd   65 Tb   66 Dy   67 Ho   68 Er   69 Tm   70 Yb   71 Lu 89 Ac     90 Th   91 Pa   92 U    93 Np   94 Pu   95 Am   96 Cm   97 Bk   98 Cf   99 Es   100 Fm  101 Md  102 No  103 Lr";
map<string,int> ptoid;
map<int,string> idtop;

void init() {
    stringstream ss; ss<<hogehogepiyopiyo;
    int x; string s;
    while (ss>>x>>s) ptoid[s]=x, idtop[x]=s;
}

int N, K;
int idfr[17], idto[17];
int sum[1<<17];

int rest[110*20];
bool ok;
void dfs(int depth, int bit) {
    if (ok) return;
    //cout<<"#"<<depth<<" "<<bit<<endl;
    if (depth==K) { ok=true; return; }

    int hi=-1;
    REP(j, N) if (bit&(1<<j)) hi=j;
    if (hi==-1) return;

    vector<int> cand;
    int ms=0;
    for (int sub = bit & -bit; sub<(1<<hi); sub = (sub-bit)&bit) {
        int subb=sub|(1<<hi);
        int m=sum[subb];
        if (rest[m] && ms < m) {
            cand.clear();
            ms=m;
        }
        if (ms==m) cand.push_back(subb);
    }

    FORIT(it, cand) {
        int sub=*it;
        rest[ms]--;
        dfs(depth+1, bit^sub);
        rest[ms]++; // revert

        if (ok) {
            int first=1;
            REP(j, N) if (sub&(1<<j)) {
                if (!first) printf("+");
                first=0;
                printf("%s", idtop[idfr[j]].c_str());
            }
            printf("->%s\n", idtop[ms].c_str());
            return;
        }

    }
}

int main() {
    init();

    while (cin>>N>>K) {
        REP(j, N) { string s; cin>>s; idfr[j] = ptoid[s]; }
        REP(k, K) { string s; cin>>s; idto[k] = ptoid[s]; }

        REP(bit, 1<<N) {
            int u=0;
            REP(j, N) if (bit&(1<<j)) u+=idfr[j];
            sum[bit]=u;
        }

        MEMSET(rest, 0);
        REP(k, K) rest[idto[k]]++;

        ok=false;
        dfs(0, (1<<N)-1);
        if (!ok) printf("NO\n");
    }
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cassert>
using namespace std;
typedef long long ll;

#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)

#define SZ(v) (int)((v).size())
#define MEMSET(v,h) memset((v),(h),sizeof(v))
#define FIND(m,w) ((m).find(w)!=(m).end())

// What the hell....?

string hogehogepiyopiyo = "1 H 2 He 3 Li    4 Be    5 B     6 C     7 N     8 O     9 F     10 Ne 11 Na     12 Mg 13 Al     14 Si   15 P    16 S    17 Cl   18 Ar 19 K  20 Ca   21 Sc   22 Ti   23 V    24 Cr   25 Mn   26 Fe   27 Co   28 Ni   29 Cu   30 Zn   31 Ga   32 Ge   33 As   34 Se   35 Br   36 Kr 37 Rb     38 Sr   39 Y    40 Zr   41 Nb   42 Mo   43 Tc   44 Ru   45 Rh   46 Pd   47 Ag   48 Cd   49 In   50 Sn   51 Sb   52 Te   53 I    54 Xe 55 Cs     56 Ba 72 Hf     73 Ta   74 W    75 Re   76 Os   77 Ir   78 Pt   79 Au   80 Hg   81 Tl   82 Pb   83 Bi   84 Po   85 At   86 Rn 87 Fr     88 Ra 57 La     58 Ce   59 Pr   60 Nd   61 Pm   62 Sm   63 Eu   64 Gd   65 Tb   66 Dy   67 Ho   68 Er   69 Tm   70 Yb   71 Lu 89 Ac     90 Th   91 Pa   92 U    93 Np   94 Pu   95 Am   96 Cm   97 Bk   98 Cf   99 Es   100 Fm  101 Md  102 No  103 Lr";
map<string,int> ptoid;
map<int,string> idtop;

void init() {
    stringstream ss; ss<<hogehogepiyopiyo;
    int x; string s;
    while (ss>>x>>s) ptoid[s]=x, idtop[x]=s;
}

int N, K;
int idfr[17], idto[17];
int sum[1<<17];

vector<string> output;

int rest[110*20];
bool ok;
void dfs(int depth, int bit) {
    if (ok) return;
    //cout<<"#"<<depth<<" "<<bit<<endl;
    if (depth==K) { ok=true; return; }

    int hi=-1;
    REP(j, N) if (bit&(1<<j)) hi=j;
    if (hi==-1) return;

    int ms=idto[depth];
    vector<int> cand;
    for (int sub = bit & -bit; sub<(1<<hi); sub = (sub-bit)&bit) {
        int subb=sub|(1<<hi);
        int m=sum[subb];
        if (m != ms) continue;
        cand.push_back(subb);
    }

    FORIT(it, cand) {
        int sub=*it;
        rest[ms]--;
        dfs(depth+1, bit^sub);
        rest[ms]++; // revert

        if (ok) {
            int first=1;
            string res;
            REP(j, N) if (sub&(1<<j)) {
                if (!first) res+="+";
                first=0;
                res+=idtop[idfr[j]];
            }
            res+="->"+idtop[ms];
            output.push_back(res);
            return;
        }

    }
}

int main() {
    init();

    while (cin>>N>>K) {
        REP(j, N) { string s; cin>>s; idfr[j] = ptoid[s]; }
        REP(k, K) { string s; cin>>s; idto[k] = ptoid[s]; }

        REP(bit, 1<<N) {
            int u=0;
            REP(j, N) if (bit&(1<<j)) u+=idfr[j];
            sum[bit]=u;
        }

        MEMSET(rest, 0);
        REP(k, K) rest[idto[k]]++;

        output.clear();

        ok=false;
        dfs(0, (1<<N)-1);
        if (!ok) printf("NO\n");
        else {
            reverse(output.begin(), output.end());
            FORIT(it, output) cout<<(*it)<<endl;
        }
    }
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cassert>
using namespace std;
typedef long long ll;

#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)

#define SZ(v) (int)((v).size())
#define MEMSET(v,h) memset((v),(h),sizeof(v))
#define FIND(m,w) ((m).find(w)!=(m).end())

// What the hell....?

string hogehogepiyopiyo = "1 H 2 He 3 Li    4 Be    5 B     6 C     7 N     8 O     9 F     10 Ne 11 Na     12 Mg 13 Al     14 Si   15 P    16 S    17 Cl   18 Ar 19 K  20 Ca   21 Sc   22 Ti   23 V    24 Cr   25 Mn   26 Fe   27 Co   28 Ni   29 Cu   30 Zn   31 Ga   32 Ge   33 As   34 Se   35 Br   36 Kr 37 Rb     38 Sr   39 Y    40 Zr   41 Nb   42 Mo   43 Tc   44 Ru   45 Rh   46 Pd   47 Ag   48 Cd   49 In   50 Sn   51 Sb   52 Te   53 I    54 Xe 55 Cs     56 Ba 72 Hf     73 Ta   74 W    75 Re   76 Os   77 Ir   78 Pt   79 Au   80 Hg   81 Tl   82 Pb   83 Bi   84 Po   85 At   86 Rn 87 Fr     88 Ra 57 La     58 Ce   59 Pr   60 Nd   61 Pm   62 Sm   63 Eu   64 Gd   65 Tb   66 Dy   67 Ho   68 Er   69 Tm   70 Yb   71 Lu 89 Ac     90 Th   91 Pa   92 U    93 Np   94 Pu   95 Am   96 Cm   97 Bk   98 Cf   99 Es   100 Fm  101 Md  102 No  103 Lr";
map<string,int> ptoid;
map<int,string> idtop;

void init() {
    stringstream ss; ss<<hogehogepiyopiyo;
    int x; string s;
    while (ss>>x>>s) ptoid[s]=x, idtop[x]=s;
}

int N, K;
int idfr[17], idto[17];
int sum[1<<17];

vector<string> output;

int rest[110*20];
bool ok;
void dfs(int depth, int bit) {
    if (ok) return;
    //cout<<"#"<<depth<<" "<<bit<<endl;
    if (depth==K) { ok=true; return; }

    int hi=-1;
    REP(j, N) if (bit&(1<<j)) hi=j;
    if (hi==-1) return;

    int ms=idto[depth];
    vector<int> cand;
    for (int sub = bit&-bit; sub; sub = (sub-bit)&bit) {
        int m=sum[sub];
        if (m != ms) continue;
        cand.push_back(sub);
    }

    FORIT(it, cand) {
        int sub=*it;
        rest[ms]--;
        dfs(depth+1, bit^sub);
        rest[ms]++; // revert

        if (ok) {
            int first=1;
            string res;
            REP(j, N) if (sub&(1<<j)) {
                if (!first) res+="+";
                first=0;
                res+=idtop[idfr[j]];
            }
            res+="->"+idtop[ms];
            output.push_back(res);
            return;
        }

    }
}

int main() {
    init();

    while (cin>>N>>K) {
        REP(j, N) { string s; cin>>s; idfr[j] = ptoid[s]; }
        REP(k, K) { string s; cin>>s; idto[k] = ptoid[s]; }

        REP(bit, 1<<N) {
            int u=0;
            REP(j, N) if (bit&(1<<j)) u+=idfr[j];
            sum[bit]=u;
        }

        MEMSET(rest, 0);
        REP(k, K) rest[idto[k]]++;

        output.clear();

        ok=false;
        dfs(0, (1<<N)-1);
        if (!ok) printf("NO\n");
        else {
            puts("YES");
            reverse(output.begin(), output.end());
            FORIT(it, output) cout<<(*it)<<endl;
        }
    }
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
//#include <cassert>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <sstream>
#include<ctime>
using namespace std;
#define pb push_back
#define mp make_pair

double tt;

string v[]={"",
    "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"
};

int trans(const string a)
{
    for (int i = 0; i<=100; i++)
     if (v[i] == a ) return i;
    return -1;
}

int n,k,top=0;
string s;
string res[100];
vector<int> lst[100];
vector<int> a,b;
bool ok = false;

void go(vector<int> &a, vector<int>  &b)
{
    if(((clock() - tt) / CLOCKS_PER_SEC) > 0.09)return;
    int n = a.size();
    int m = b.size();
//  cout << " go " << n << " " << m << endl;
    vector<int> aa;
    vector<int> bb(b);
    bb.erase(--bb.end());
    if (n == m && m == 0)
    {
//      cout << " good \n";
        ok = true;
        return;
    }
    if (n*m == 0) return;
    const int mst = (1<<n)-1;
    int mask = mst;
    while (mask)
    {
        aa.clear();
        int sum = 0;
        for (int i = 0; i<n; i++)
         if ((1<<i)&mask)
         {
            sum += a[i];
        } else
        {
            aa.pb(a[i]);
        }
        if (b[m-1] == sum)
        {
            top++;
            lst[top].clear();
            res[top] = v[sum];
            for (int i  = 0; i<n; i++)
             if ((1<<i)&mask) lst[top].pb(a[i]);
            go(aa,bb);
            if (ok) return;
            top--;
        }
        mask = (mask-1) & mst;
    }
}
int main()
{
  //freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);

     tt=clock();
    int n,k;
    scanf("%d %d\n",&n,&k);
    for (int i = 1; i<=n; i++)
    {
        cin >> s;
        a.pb(trans(s));
    }
    for (int i = 1; i<=k; i++)
    {
        cin >> s;
        b.pb(trans(s));
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    go(a,b);
    if (ok)
    {
        cout << "YES\n";
        for (int i = 1; i<=top; i++)
        {
            int sz = lst[i].size();
            for (int j = 0; j<sz; j++)
            {
             cout << v[lst[i][j]];
             if (j != sz-1) cout <<"+";
                    else cout << "->";
            }
             cout << res[i] << endl;
        }
    } else cout <<"NO\n";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
//#include <cassert>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <sstream>
#include<ctime>
using namespace std;
#define pb push_back
#define mp make_pair

double tt;

string v[]={"",
    "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"
};

int trans(const string a)
{
    for (int i = 0; i<=100; i++)
     if (v[i] == a ) return i;
    return -1;
}

int n,k,top=0;
string s;
string res[100];
vector<int> lst[100];
vector<int> a,b;
bool ok = false;

void go(vector<int> &a, vector<int>  &b)
{
    if(((clock() - tt) / CLOCKS_PER_SEC) > 0.05)return;
    int n = a.size();
    int m = b.size();
//  cout << " go " << n << " " << m << endl;
    vector<int> aa;
    vector<int> bb(b);
    bb.erase(--bb.end());
    if (n == m && m == 0)
    {
//      cout << " good \n";
        ok = true;
        return;
    }
    if (n*m == 0) return;
    const int mst = (1<<n)-1;
    int mask = mst;
    while (mask)
    {
        aa.clear();
        int sum = 0;
        for (int i = 0; i<n; i++)
         if ((1<<i)&mask)
         {
            sum += a[i];
        } else
        {
            aa.pb(a[i]);
        }
        if (b[m-1] == sum)
        {
            top++;
            lst[top].clear();
            res[top] = v[sum];
            for (int i  = 0; i<n; i++)
             if ((1<<i)&mask) lst[top].pb(a[i]);
            go(aa,bb);
            if (ok) return;
            top--;
        }
        mask = (mask-1) & mst;
    }
}
int main()
{
  //freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);

     tt=clock();
    int n,k;
    scanf("%d %d\n",&n,&k);
    for (int i = 1; i<=n; i++)
    {
        cin >> s;
        a.pb(trans(s));
    }
    for (int i = 1; i<=k; i++)
    {
        cin >> s;
        b.pb(trans(s));
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    go(a,b);
    if (ok)
    {
        cout << "YES\n";
        for (int i = 1; i<=top; i++)
        {
            int sz = lst[i].size();
            for (int j = 0; j<sz; j++)
            {
             cout << v[lst[i][j]];
             if (j != sz-1) cout <<"+";
                    else cout << "->";
            }
             cout << res[i] << endl;
        }
    } else cout <<"NO\n";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
//#include <cassert>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <sstream>
#include<ctime>
using namespace std;
#define pb push_back
#define mp make_pair

double tt;

string v[]={"",
    "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"
};

int trans(const string a)
{
    for (int i = 0; i<=100; i++)
     if (v[i] == a ) return i;
    return -1;
}

int n,k,top=0;
string s;
string res[100];
vector<int> lst[100];
vector<int> a,b;
bool ok = false;

void go(vector<int> &a, vector<int>  &b)
{
    if(((clock() - tt) / CLOCKS_PER_SEC) > 0.1)return;
    int n = a.size();
    int m = b.size();
//  cout << " go " << n << " " << m << endl;
    vector<int> aa;
    vector<int> bb(b);
    bb.erase(--bb.end());
    if (n == m && m == 0)
    {
//      cout << " good \n";
        ok = true;
        return;
    }
    if (n*m == 0) return;
    const int mst = (1<<n)-1;
    int mask = mst;
    while (mask)
    {
        aa.clear();
        int sum = 0;
        for (int i = 0; i<n; i++)
         if ((1<<i)&mask)
         {
            sum += a[i];
        } else
        {
            aa.pb(a[i]);
        }
        if (b[m-1] == sum)
        {
            top++;
            lst[top].clear();
            res[top] = v[sum];
            for (int i  = 0; i<n; i++)
             if ((1<<i)&mask) lst[top].pb(a[i]);
            go(aa,bb);
            if (ok) return;
            top--;
        }
        mask = (mask-1) & mst;
    }
}
int main()
{
  //freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);

     tt=clock();
    int n,k;
    scanf("%d %d\n",&n,&k);
    for (int i = 1; i<=n; i++)
    {
        cin >> s;
        a.pb(trans(s));
    }
    for (int i = 1; i<=k; i++)
    {
        cin >> s;
        b.pb(trans(s));
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    go(a,b);
    if (ok)
    {
        cout << "YES\n";
        for (int i = 1; i<=top; i++)
        {
            int sz = lst[i].size();
            for (int j = 0; j<sz; j++)
            {
             cout << v[lst[i][j]];
             if (j != sz-1) cout <<"+";
                    else cout << "->";
            }
             cout << res[i] << endl;
        }
    } else cout <<"NO\n";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
//#include <cassert>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <sstream>
#include<ctime>
using namespace std;
#define pb push_back
#define mp make_pair

double tt;

string v[]={"",
    "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"
};

int trans(const string a)
{
    for (int i = 0; i<=100; i++)
     if (v[i] == a ) return i;
    return -1;
}

int n,k,top=0;
string s;
string res[100];
vector<int> lst[100];
vector<int> a,b;
bool ok = false;

void go(vector<int> &a, vector<int>  &b)
{
    if(((clock() - tt) / CLOCKS_PER_SEC) > 0.2)return;
    int n = a.size();
    int m = b.size();
//  cout << " go " << n << " " << m << endl;
    vector<int> aa;
    vector<int> bb(b);
    bb.erase(--bb.end());
    if (n == m && m == 0)
    {
//      cout << " good \n";
        ok = true;
        return;
    }
    if (n*m == 0) return;
    const int mst = (1<<n)-1;
    int mask = mst;
    while (mask)
    {
        aa.clear();
        int sum = 0;
        for (int i = 0; i<n; i++)
         if ((1<<i)&mask)
         {
            sum += a[i];
        } else
        {
            aa.pb(a[i]);
        }
        if (b[m-1] == sum)
        {
            top++;
            lst[top].clear();
            res[top] = v[sum];
            for (int i  = 0; i<n; i++)
             if ((1<<i)&mask) lst[top].pb(a[i]);
            go(aa,bb);
            if (ok) return;
            top--;
        }
        mask = (mask-1) & mst;
    }
}
int main()
{
  //freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);

     tt=clock();
    int n,k;
    scanf("%d %d\n",&n,&k);
    for (int i = 1; i<=n; i++)
    {
        cin >> s;
        a.pb(trans(s));
    }
    for (int i = 1; i<=k; i++)
    {
        cin >> s;
        b.pb(trans(s));
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    go(a,b);
    if (ok)
    {
        cout << "YES\n";
        for (int i = 1; i<=top; i++)
        {
            int sz = lst[i].size();
            for (int j = 0; j<sz; j++)
            {
             cout << v[lst[i][j]];
             if (j != sz-1) cout <<"+";
                    else cout << "->";
            }
             cout << res[i] << endl;
        }
    } else cout <<"NO\n";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
//#include <cassert>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <sstream>
#include<ctime>
using namespace std;
#define pb push_back
#define mp make_pair

double tt;

string v[]={"",
    "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"
};

int trans(const string a)
{
    for (int i = 0; i<=100; i++)
     if (v[i] == a ) return i;
    return -1;
}

int n,k,top=0;
string s;
string res[100];
vector<int> lst[100];
vector<int> a,b;
bool ok = false;

void go(vector<int> &a, vector<int>  &b)
{
    if(((clock() - tt) / CLOCKS_PER_SEC) > 0.08)return;
    int n = a.size();
    int m = b.size();
//  cout << " go " << n << " " << m << endl;
    vector<int> aa;
    vector<int> bb(b);
    bb.erase(--bb.end());
    if (n == m && m == 0)
    {
//      cout << " good \n";
        ok = true;
        return;
    }
    if (n*m == 0) return;
    const int mst = (1<<n)-1;
    int mask = mst;
    while (mask)
    {
        aa.clear();
        int sum = 0;
        for (int i = 0; i<n; i++)
         if ((1<<i)&mask)
         {
            sum += a[i];
        } else
        {
            aa.pb(a[i]);
        }
        if (b[m-1] == sum)
        {
            top++;
            lst[top].clear();
            res[top] = v[sum];
            for (int i  = 0; i<n; i++)
             if ((1<<i)&mask) lst[top].pb(a[i]);
            go(aa,bb);
            if (ok) return;
            top--;
        }
        mask = (mask-1) & mst;
    }
}
int main()
{
  //freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);

     tt=clock();
    int n,k;
    scanf("%d %d\n",&n,&k);
    for (int i = 1; i<=n; i++)
    {
        cin >> s;
        a.pb(trans(s));
    }
    for (int i = 1; i<=k; i++)
    {
        cin >> s;
        b.pb(trans(s));
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    go(a,b);
    if (ok)
    {
        cout << "YES\n";
        for (int i = 1; i<=top; i++)
        {
            int sz = lst[i].size();
            for (int j = 0; j<sz; j++)
            {
             cout << v[lst[i][j]];
             if (j != sz-1) cout <<"+";
                    else cout << "->";
            }
             cout << res[i] << endl;
        }
    } else cout <<"NO\n";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
//#include <cassert>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <sstream>
#include<ctime>
using namespace std;
#define pb push_back
#define mp make_pair

double tt;

string v[]={"",
    "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"
};

int trans(const string a)
{
    for (int i = 0; i<=100; i++)
     if (v[i] == a ) return i;
    return -1;
}

int n,k,top=0;
string s;
string res[100];
vector<int> lst[100];
vector<int> a,b;
bool ok = false;

void go(vector<int> &a, vector<int>  &b)
{
    if(clock()-tt  >2.8)return;
    int n = a.size();
    int m = b.size();
//  cout << " go " << n << " " << m << endl;
    vector<int> aa;
    vector<int> bb(b);
    bb.erase(--bb.end());
    if (n == m && m == 0)
    {
//      cout << " good \n";
        ok = true;
        return;
    }
    if (n*m == 0) return;
    const int mst = (1<<n)-1;
    int mask = mst;
    while (mask)
    {
        aa.clear();
        int sum = 0;
        for (int i = 0; i<n; i++)
         if ((1<<i)&mask)
         {
            sum += a[i];
        } else
        {
            aa.pb(a[i]);
        }
        if (b[m-1] == sum)
        {
            top++;
            lst[top].clear();
            res[top] = v[sum];
            for (int i  = 0; i<n; i++)
             if ((1<<i)&mask) lst[top].pb(a[i]);
            go(aa,bb);
            if (ok) return;
            top--;
        }
        mask = (mask-1) & mst;
    }
}
int main()
{
  //freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);

     tt=clock();
    int n,k;
    scanf("%d %d\n",&n,&k);
    for (int i = 1; i<=n; i++)
    {
        cin >> s;
        a.pb(trans(s));
    }
    for (int i = 1; i<=k; i++)
    {
        cin >> s;
        b.pb(trans(s));
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    go(a,b);
    if (ok)
    {
        cout << "YES\n";
        for (int i = 1; i<=top; i++)
        {
            int sz = lst[i].size();
            for (int j = 0; j<sz; j++)
            {
             cout << v[lst[i][j]];
             if (j != sz-1) cout <<"+";
                    else cout << "->";
            }
             cout << res[i] << endl;
        }
    } else cout <<"NO\n";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
//#include <cassert>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <sstream>
#include<ctime>
using namespace std;
#define pb push_back
#define mp make_pair

double tt;

string v[]={"",
    "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"
};

int trans(const string a)
{
    for (int i = 0; i<=100; i++)
     if (v[i] == a ) return i;
    return -1;
}

int n,k,top=0;
string s;
string res[100];
vector<int> lst[100];
vector<int> a,b;
bool ok = false;

void go(vector<int> &a, vector<int>  &b)
{
    if(((clock() - tt) / CLOCKS_PER_SEC) > 0.3)return;
    int n = a.size();
    int m = b.size();
//  cout << " go " << n << " " << m << endl;
    vector<int> aa;
    vector<int> bb(b);
    bb.erase(--bb.end());
    if (n == m && m == 0)
    {
//      cout << " good \n";
        ok = true;
        return;
    }
    if (n*m == 0) return;
    const int mst = (1<<n)-1;
    int mask = mst;
    while (mask)
    {
        aa.clear();
        int sum = 0;
        for (int i = 0; i<n; i++)
         if ((1<<i)&mask)
         {
            sum += a[i];
        } else
        {
            aa.pb(a[i]);
        }
        if (b[m-1] == sum)
        {
            top++;
            lst[top].clear();
            res[top] = v[sum];
            for (int i  = 0; i<n; i++)
             if ((1<<i)&mask) lst[top].pb(a[i]);
            go(aa,bb);
            if (ok) return;
            top--;
        }
        mask = (mask-1) & mst;
    }
}
int main()
{
  //freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);

     tt=clock();
    int n,k;
    scanf("%d %d\n",&n,&k);
    for (int i = 1; i<=n; i++)
    {
        cin >> s;
        a.pb(trans(s));
    }
    for (int i = 1; i<=k; i++)
    {
        cin >> s;
        b.pb(trans(s));
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    go(a,b);
    if (ok)
    {
        cout << "YES\n";
        for (int i = 1; i<=top; i++)
        {
            int sz = lst[i].size();
            for (int j = 0; j<sz; j++)
            {
             cout << v[lst[i][j]];
             if (j != sz-1) cout <<"+";
                    else cout << "->";
            }
             cout << res[i] << endl;
        }
    } else cout <<"NO\n";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
//#include <cassert>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <sstream>
#include<ctime>
using namespace std;
#define pb push_back
#define mp make_pair

double tt;

string v[]={"",
    "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"
};

int trans(const string a)
{
    for (int i = 0; i<=100; i++)
     if (v[i] == a ) return i;
    return -1;
}

int n,k,top=0;
string s;
string res[100];
vector<int> lst[100];
vector<int> a,b;
bool ok = false;

void go(vector<int> &a, vector<int>  &b)
{
    ((clock() - tt) / CLOCKS_PER_SEC > 2.8)return;
    int n = a.size();
    int m = b.size();
//  cout << " go " << n << " " << m << endl;
    vector<int> aa;
    vector<int> bb(b);
    bb.erase(--bb.end());
    if (n == m && m == 0)
    {
//      cout << " good \n";
        ok = true;
        return;
    }
    if (n*m == 0) return;
    const int mst = (1<<n)-1;
    int mask = mst;
    while (mask)
    {
        aa.clear();
        int sum = 0;
        for (int i = 0; i<n; i++)
         if ((1<<i)&mask)
         {
            sum += a[i];
        } else
        {
            aa.pb(a[i]);
        }
        if (b[m-1] == sum)
        {
            top++;
            lst[top].clear();
            res[top] = v[sum];
            for (int i  = 0; i<n; i++)
             if ((1<<i)&mask) lst[top].pb(a[i]);
            go(aa,bb);
            if (ok) return;
            top--;
        }
        mask = (mask-1) & mst;
    }
}
int main()
{
  //freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);

     tt=clock();
    int n,k;
    scanf("%d %d\n",&n,&k);
    for (int i = 1; i<=n; i++)
    {
        cin >> s;
        a.pb(trans(s));
    }
    for (int i = 1; i<=k; i++)
    {
        cin >> s;
        b.pb(trans(s));
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    go(a,b);
    if (ok)
    {
        cout << "YES\n";
        for (int i = 1; i<=top; i++)
        {
            int sz = lst[i].size();
            for (int j = 0; j<sz; j++)
            {
             cout << v[lst[i][j]];
             if (j != sz-1) cout <<"+";
                    else cout << "->";
            }
             cout << res[i] << endl;
        }
    } else cout <<"NO\n";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
//#include <cassert>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <sstream>
#include<ctime>
using namespace std;
#define pb push_back
#define mp make_pair

double tt;

string v[]={"",
    "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"
};

int trans(const string a)
{
    for (int i = 0; i<=100; i++)
     if (v[i] == a ) return i;
    return -1;
}

int n,k,top=0;
string s;
string res[100];
vector<int> lst[100];
vector<int> a,b;
bool ok = false;

void go(vector<int> &a, vector<int>  &b)
{
    ((clock() - start) / CLOCKS_PER_SEC > 2.8)return;
    int n = a.size();
    int m = b.size();
//  cout << " go " << n << " " << m << endl;
    vector<int> aa;
    vector<int> bb(b);
    bb.erase(--bb.end());
    if (n == m && m == 0)
    {
//      cout << " good \n";
        ok = true;
        return;
    }
    if (n*m == 0) return;
    const int mst = (1<<n)-1;
    int mask = mst;
    while (mask)
    {
        aa.clear();
        int sum = 0;
        for (int i = 0; i<n; i++)
         if ((1<<i)&mask)
         {
            sum += a[i];
        } else
        {
            aa.pb(a[i]);
        }
        if (b[m-1] == sum)
        {
            top++;
            lst[top].clear();
            res[top] = v[sum];
            for (int i  = 0; i<n; i++)
             if ((1<<i)&mask) lst[top].pb(a[i]);
            go(aa,bb);
            if (ok) return;
            top--;
        }
        mask = (mask-1) & mst;
    }
}
int main()
{
  //freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);

     tt=clock();
    int n,k;
    scanf("%d %d\n",&n,&k);
    for (int i = 1; i<=n; i++)
    {
        cin >> s;
        a.pb(trans(s));
    }
    for (int i = 1; i<=k; i++)
    {
        cin >> s;
        b.pb(trans(s));
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    go(a,b);
    if (ok)
    {
        cout << "YES\n";
        for (int i = 1; i<=top; i++)
        {
            int sz = lst[i].size();
            for (int j = 0; j<sz; j++)
            {
             cout << v[lst[i][j]];
             if (j != sz-1) cout <<"+";
                    else cout << "->";
            }
             cout << res[i] << endl;
        }
    } else cout <<"NO\n";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
//#include <cassert>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <sstream>
#include<ctime>
using namespace std;
#define pb push_back
#define mp make_pair

double tt;

string v[]={"",
    "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"
};

int trans(const string a)
{
    for (int i = 0; i<=100; i++)
     if (v[i] == a ) return i;
    return -1;
}

int n,k,top=0;
string s;
string res[100];
vector<int> lst[100];
vector<int> a,b;
bool ok = false;

void go(vector<int> &a, vector<int>  &b)
{
    if(((clock() - tt) / CLOCKS_PER_SEC) > 2.8)return;
    int n = a.size();
    int m = b.size();
//  cout << " go " << n << " " << m << endl;
    vector<int> aa;
    vector<int> bb(b);
    bb.erase(--bb.end());
    if (n == m && m == 0)
    {
//      cout << " good \n";
        ok = true;
        return;
    }
    if (n*m == 0) return;
    const int mst = (1<<n)-1;
    int mask = mst;
    while (mask)
    {
        aa.clear();
        int sum = 0;
        for (int i = 0; i<n; i++)
         if ((1<<i)&mask)
         {
            sum += a[i];
        } else
        {
            aa.pb(a[i]);
        }
        if (b[m-1] == sum)
        {
            top++;
            lst[top].clear();
            res[top] = v[sum];
            for (int i  = 0; i<n; i++)
             if ((1<<i)&mask) lst[top].pb(a[i]);
            go(aa,bb);
            if (ok) return;
            top--;
        }
        mask = (mask-1) & mst;
    }
}
int main()
{
  //freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);

     tt=clock();
    int n,k;
    scanf("%d %d\n",&n,&k);
    for (int i = 1; i<=n; i++)
    {
        cin >> s;
        a.pb(trans(s));
    }
    for (int i = 1; i<=k; i++)
    {
        cin >> s;
        b.pb(trans(s));
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    go(a,b);
    if (ok)
    {
        cout << "YES\n";
        for (int i = 1; i<=top; i++)
        {
            int sz = lst[i].size();
            for (int j = 0; j<sz; j++)
            {
             cout << v[lst[i][j]];
             if (j != sz-1) cout <<"+";
                    else cout << "->";
            }
             cout << res[i] << endl;
        }
    } else cout <<"NO\n";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
//#include <cassert>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <sstream>
#include<ctime>
using namespace std;
#define pb push_back
#define mp make_pair

double tt;

string v[]={"",
    "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"
};

int trans(const string a)
{
    for (int i = 0; i<=100; i++)
     if (v[i] == a ) return i;
    return -1;
}

int n,k,top=0;
string s;
string res[100];
vector<int> lst[100];
vector<int> a,b;
bool ok = false;

void go(vector<int> &a, vector<int>  &b)
{
    if(((clock() - tt) / CLOCKS_PER_SEC) > 0.075)return;
    int n = a.size();
    int m = b.size();
//  cout << " go " << n << " " << m << endl;
    vector<int> aa;
    vector<int> bb(b);
    bb.erase(--bb.end());
    if (n == m && m == 0)
    {
//      cout << " good \n";
        ok = true;
        return;
    }
    if (n*m == 0) return;
    const int mst = (1<<n)-1;
    int mask = mst;
    while (mask)
    {
        aa.clear();
        int sum = 0;
        for (int i = 0; i<n; i++)
         if ((1<<i)&mask)
         {
            sum += a[i];
        } else
        {
            aa.pb(a[i]);
        }
        if (b[m-1] == sum)
        {
            top++;
            lst[top].clear();
            res[top] = v[sum];
            for (int i  = 0; i<n; i++)
             if ((1<<i)&mask) lst[top].pb(a[i]);
            go(aa,bb);
            if (ok) return;
            top--;
        }
        mask = (mask-1) & mst;
    }
}
int main()
{
  //freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);

     tt=clock();
    int n,k;
    scanf("%d %d\n",&n,&k);
    for (int i = 1; i<=n; i++)
    {
        cin >> s;
        a.pb(trans(s));
    }
    for (int i = 1; i<=k; i++)
    {
        cin >> s;
        b.pb(trans(s));
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    go(a,b);
    if (ok)
    {
        cout << "YES\n";
        for (int i = 1; i<=top; i++)
        {
            int sz = lst[i].size();
            for (int j = 0; j<sz; j++)
            {
             cout << v[lst[i][j]];
             if (j != sz-1) cout <<"+";
                    else cout << "->";
            }
             cout << res[i] << endl;
        }
    } else cout <<"NO\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	map<int, int> mp;
	while(n--) {
		string s;
		cin >> s;
		int x = 0, y = 0;
		for(int i = 0; i < s.length(); i++) {
			x += s[i] == '(' ? 1 : -1;
			y = min(x, y);
		}
		if(y >= min(x, 0)) mp[x]++;
	}
	int ans = 0;
	for(auto i : mp) {
		int x = i.first;
		if(mp.count(-x)) ans += min(mp[x], mp[-x]);
	}
	cout << ans / 2 << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

  int n;
  cin >> n;
  map<string,int> mst[3];
  set<string> made;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    stack<char> stk;
    for(int j = 0; j < s.length(); j++) {
      if(stk.empty()) {
        stk.push(s[j]);
        continue;
      }
      if(s[j] == '(') stk.push(s[j]);
      else {
        if(stk.top() == '(') stk.pop();
        else stk.push(s[j]);
      }
    }
    int x = 0, y = 0;
    while(!stk.empty()) {
      if(stk.top() == '(') x++;
      else y++;
      stk.pop();
    }
    if(x == 0 && y == 0) {
      string t;
      bool flag = false;
      for(auto i : mst[0]) {
        if(i.second == 0) continue;
        string tmp1 = s + i.first;
        string tmp2 = i.first + s;
        if(!made.count(tmp1)) {
          made.insert(tmp1);
          t = i.first;
          flag = true;
          break;
        } else if(!made.count(tmp2)) {
          made.insert(tmp2);
          t = i.first;
          flag = true;
          break;
        }
      }
      if(flag) mst[0][t]--;
      else mst[0][s]++;
    } else if( x == 0) {
        string t;
        bool flag = false;
        for(auto i : mst[1]) {
          if(i.second == 0) continue;
          string tmp = i.first + s;
          int cnt = 0;
          for(int k = 0; k < tmp.size(); k++) {
            if(tmp[k] == '(') cnt++;
            else cnt--;
          }
          if(cnt != 0) continue;
          if(!made.count(tmp)) {
            made.insert(tmp);
            flag = true;
            t = i.first;
            break;
          }
        }
        if(flag) mst[1][t]--;
        else mst[2][s]++;
    } else if(y == 0) {
        string t;
        bool flag = false;
        for(auto i : mst[2]) {
          if(i.second == 0) continue;
          string tmp = s + i.first;
          int cnt = 0;
          for(int k = 0; k < tmp.size(); k++) {
            if(tmp[k] == '(') cnt++;
            else cnt--;
          }
          if(cnt != 0) continue;
          if(!made.count(tmp)) {
            made.insert(tmp);
            flag = true;
            t = i.first;
            break;
          }
        }
        if(flag) mst[2][t]--;
        else mst[1][s]++;
    }
  }
  cout << made.size() << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	map<int, int> mp;
	while(n--) {
		string s;
		cin >> s;
		int x = 0, y = 0;
		for(int i = 0; i < s.length(); i++) {
			x += s[i] == '(' ? 1 : -1;
			y = min(x, y);
		}
		if(y == min(x, 0)) mp[x]++;
	}
	int ans = 0;
	for(auto i : mp) {
		int x = i.first;
		if(mp.count(-x)) ans += min(mp[x], mp[-x]);
	}
	cout << ans / 2 << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

  int n;
  cin >> n;
  multiset<string> mst[3];
  set<string> made;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    stack<char> stk;
    for(int j = 0; j < s.length(); j++) {
      if(stk.empty()) {
        stk.push(s[j]);
        continue;
      }
      if(s[j] == '(') stk.push(s[j]);
      else {
        if(stk.top() == '(') stk.pop();
        else stk.push(s[j]);
      }
    }
    int x = 0, y = 0;
    while(!stk.empty()) {
      if(stk.top() == '(') x++;
      else y++;
      stk.pop();
    }
    if(x == 0 && y == 0) {
      string t;
      bool flag = false;
      for(auto i : mst[0]) {
        string tmp1 = s + i;
        string tmp2 = i + s;
        if(!made.count(tmp1)) {
          made.insert(tmp1);
          t = i;
          flag = true;
          break;
        } else if(!made.count(tmp2)) {
          made.insert(tmp2);
          t = i;
          flag = true;
          break;
        }
      }
      if(flag) mst[0].erase(t);
      else mst[0].insert(s);
    } else if( x == 0) {
        string t;
        bool flag = false;
        for(auto i : mst[1]) {
          string tmp = i + s;
          int cnt = 0;
          for(int k = 0; k < tmp.size(); k++) {
            if(tmp[k] == '(') cnt++;
            else cnt--;
          }
          if(cnt != 0) continue;
          if(!made.count(tmp)) {
            made.insert(tmp);
            flag = true;
            t = i;
            break;
          }
        }
        if(flag) mst[1].erase(t);
        else mst[2].insert(s);
    } else if(y == 0) {
        string t;
        bool flag = false;
        for(auto i : mst[2]) {
          string tmp = s + i;
          int cnt = 0;
          for(int k = 0; k < tmp.size(); k++) {
            if(tmp[k] == '(') cnt++;
            else cnt--;
          }
          if(cnt != 0) continue;
          if(!made.count(tmp)) {
            made.insert(tmp);
            flag = true;
            t = i;
            break;
          }
        }
        if(flag) mst[2].erase(t);
        else mst[1].insert(s);
    }
  }
  cout << made.size() << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	map<int, int> mp;
	while(n--) {
		string s;
		cin >> s;
		int x = 0, y = 0;
		for(int i = 0; i < s.size(); i++) {
			x += s[i] == '(' ? 1 : -1;
			y = min(x, 0);
		}
		if(y >= min(x, 0)) mp[x]++;
	}
	int ans = mp[0]  / 2;
	for(auto& i : mp) {
		int x = i.first;
		if(x > 0 && mp.count(-x)) ans += min(mp[x], mp[-x]);
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	map<pair<int, int>, int> mp;
	int ans = 0;
	for(int i = 0; i < n; i++) {
		string s;
		cin >> s;
		deque<char> dq;
		for(int j = 0; j < s.size(); j++) {
			if(dq.empty()) {
				dq.push_back(s[j]);
				continue;
			}
			if(s[j] == '(') dq.push_back(s[j]);
			else {
				if(dq.back() == '(') dq.pop_back();
				else dq.push_back(s[j]);
			}
		}
		int x = 0, y = 0;
		while(!dq.empty()) {
			if(dq.front() == ')') x++;
			else y++;
			dq.pop_front();
		}
		if(x == 0 && y == 0) {
			if(mp[make_pair(0, 0)] > 0) {
				ans++;
				mp[make_pair(0, 0)]--;
			} else {
				mp[make_pair(0, 0)]++;
			}
		}
		else if(x == 0) {
			if(mp[make_pair(y, 0)] > 0) {
				ans++;
				mp[make_pair(y, 0)]--;
			} else {
				mp[make_pair(0, y)]++;
			}
		} else if(y == 0) {
			if(mp[make_pair(0, x)] > 0) {
				ans++;
				mp[make_pair(0, x)]--;
			} else {
				mp[make_pair(x, 0)]++;
			}
		} else {
			if(mp[make_pair(y, 0)] > 0 && mp[make_pair(0, x)] > 0) {
				ans++;
				mp[make_pair(y, 0)]--;
				mp[make_pair(0, x)]--;
			} else {
				mp[make_pair(x, y)]++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	map<int, int> mp;
	while(n--) {
		string s;
		cin >> s;
		int x = 0, y = 0;
		for(int i = 0; i < s.size(); i++) {
			x += s[i] == '(' ? 1 : -1;
			y = min(x, 0);
		}
		if(y >= min(x, 0)) mp[x]++;
	}
	int ans = 0;
	for(auto i : mp) {
		int x = i.first;
		if(mp.count(-x)) ans += min(mp[x], mp[-x]);
	}
	cout << ans / 2 << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;

  cin >> n;

  vector <string> v(n);

  vector < pair <int, int> > s(n);

  map <string, int> mp1;
  map <int, bool> mp2;

  int good = 0;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];

    int nr = 0;
    for (auto x : v[i]) {
      if (x == '(') {
        ++s[i].first;
      } else if (s[i].first != 0) {
        --s[i].first;
      } else {
        ++nr;
      }
    }
    s[i].second += nr;
    if (s[i].first != 0 && s[i].second != 0) {
      s.erase(s.begin() + i);
      v.erase(v.begin() + i);
      --i;
      --n;
    } else if (s[i].first == 0 && s[i].second == 0) {
      ++good;
      s.erase(s.begin() + i);
      v.erase(v.begin() + i);
      --i;
      --n;
    } else if (s[i].first != 0) {
        mp1[v[i]] = s[i].first;
      } else {
        mp2[s[i].second] = true;
      }
    }

  for (int i = 0; i < n; ++i) {
    cout << s[i].first << " " << s[i].second << "\n";
  }
  cout << "\n";

  int ans = 0;

  for(auto x : mp1) {
    if (mp2[x.second]) {
      ++ans;
    }
  }

  cout << ans + good * (good - 1) / 2 << "\n";

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;

  cin >> n;

  vector <string> v(n);

  vector < pair <int, int> > s(n);

  map <string, int> mp1;
  map <int, bool> mp2;

  int good = 0;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];

    int nr = 0;
    for (auto x : v[i]) {
      if (x == '(') {
        ++s[i].first;
      } else if (s[i].first != 0) {
        --s[i].first;
      } else {
        ++nr;
      }
    }
    s[i].second += nr;
    if (s[i].first != 0 && s[i].second != 0) {
      s.erase(s.begin() + i);
      v.erase(v.begin() + i);
      --i;
      --n;
    } else if (s[i].first == 0 && s[i].second == 0) {
      ++good;
      s.erase(s.begin() + i);
      v.erase(v.begin() + i);
      --i;
      --n;
    } else if (s[i].first != 0) {
        mp1[v[i]] = s[i].first;
      } else {
        mp2[s[i].second] = true;
      }
    }
  int ans = 0;

  for(auto x : mp1) {
    if (mp2[x.second]) {
      ++ans;
    }
  }

  cout << ans + good * (good - 1) / 2 << "\n";

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;

  cin >> n;

  vector <string> v(n);

  vector < pair <int, int> > s(n);

  vector <int> sol;

  map <int, int> mp2;

  int good = 0;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];

    int nr = 0;
    for (auto x : v[i]) {
      if (x == '(') {
        ++s[i].first;
      } else if (s[i].first != 0) {
        --s[i].first;
      } else {
        ++nr;
      }
    }
    s[i].second += nr;
    if (s[i].first != 0 && s[i].second != 0) {
      s.erase(s.begin() + i);
      // v.erase(v.begin() + i);
      --i;
      --n;
    } else if (s[i].first == 0 && s[i].second == 0) {
      ++good;
      s.erase(s.begin() + i);
      // v.erase(v.begin() + i);
      --i;
      --n;
    } else if (s[i].first != 0) {
        sol.push_back(s[i].first);
      } else {
        ++mp2[s[i].second];
      }
    }

  int ans = 0;

  for(auto x : sol) {
    if (mp2[x] != 0) {
      ++ans;
      --mp2[x];
    }
  }

  cout << ans + good / 2 << "\n";

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;

  cin >> n;

  vector <string> v(n);

  vector < pair <int, int> > s(n);

  vector <int> sol;

  map <int, int> mp2;

  auto sb = s.begin();
  int good = 0;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];

    int nr = 0;
    for (auto x : v[i]) {
      if (x == '(') {
        ++s[i].first;
      } else if (s[i].first != 0) {
        --s[i].first;
      } else {
        ++nr;
      }
    }
    s[i].second += nr;
    if (s[i].first != 0 && s[i].second != 0) {
      //s.erase(sb + i);
      // v.erase(v.begin() + i);
      //--i;
      //--n;
      continue;
    } else if (s[i].first == 0 && s[i].second == 0) {
      ++good;
      continue;
      //s.erase(sb + i);
      // v.erase(v.begin() + i);
      //--i;
      //--n;
    } else if (s[i].first != 0) {
        sol.push_back(s[i].first);
      } else {
        ++mp2[s[i].second];
      }
    }

  int ans = good / 2;

  for(auto x : sol) {
    if (mp2[x] != 0) {
      ++ans;
      --mp2[x];
    }
  }

  cout << ans << "\n";

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;

  cin >> n;

  vector <string> v(n);

  vector < pair <int, int> > s(n);

  map <string, int> mp1;
  map <int, bool> mp2;

  int good = 0;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];

    int nr = 0;
    for (auto x : v[i]) {
      if (x == '(') {
        ++s[i].first;
      } else if (s[i].first != 0) {
        --s[i].first;
      } else {
        ++nr;
      }
    }
    s[i].second += nr;
    if (s[i].first != 0 && s[i].second != 0) {
      s.erase(s.begin() + i);
      v.erase(v.begin() + i);
      --i;
      --n;
    } else if (s[i].first == 0 && s[i].second == 0) {
      ++good;
      s.erase(s.begin() + i);
      v.erase(v.begin() + i);
      --i;
      --n;
    } else if (s[i].first != 0) {
        mp1[v[i]] = s[i].first;
      } else {
        mp2[s[i].second] = true;
      }
    }

  int ans = 0;

  for(auto x : mp1) {
    if (mp2[x.second]) {
      ++ans;
      mp2[x.second] = false;
    }
  }

  cout << ans + good * (good - 1) / 2 << "\n";

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;

  cin >> n;

  vector <string> v(n);

  vector < pair <int, int> > s(n);

  map <string, int> mp1;
  map <int, bool> mp2;

  int good = 0;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];

    int nr = 0;
    for (auto x : v[i]) {
      if (x == '(') {
        ++s[i].first;
      } else if (s[i].first != 0) {
        --s[i].first;
      } else {
        ++nr;
      }
    }
    s[i].second += nr;
    if (s[i].first != 0 && s[i].second != 0) {
      s.erase(s.begin() + i);
      v.erase(v.begin() + i);
      --i;
      --n;
    } else if (s[i].first == 0 && s[i].second == 0) {
      ++good;
      s.erase(s.begin() + i);
      v.erase(v.begin() + i);
      --i;
      --n;
    } else if (s[i].first != 0) {
        mp1[v[i]] = s[i].first;
      } else {
        mp2[s[i].second] = true;
      }
    }

  int ans = 0;

  for(auto x : mp1) {
    if (mp2[x.second]) {
      ++ans;
      mp2[x.second] = false;
    }
  }

  cout << ans + good / 2 << "\n";

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;

  cin >> n;

  vector <string> v(n);

  vector < pair <int, int> > s(n);

  vector <int> sol;

  map <int, int> mp2;

  int good = 0;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];

    int nr = 0;
    for (auto x : v[i]) {
      if (x == '(') {
        ++s[i].first;
      } else if (s[i].first != 0) {
        --s[i].first;
      } else {
        ++nr;
      }
    }
    s[i].second += nr;
    if (s[i].first != 0 && s[i].second != 0) {
      s.erase(s.begin() + i);
      v.erase(v.begin() + i);
      --i;
      --n;
    } else if (s[i].first == 0 && s[i].second == 0) {
      ++good;
      s.erase(s.begin() + i);
      v.erase(v.begin() + i);
      --i;
      --n;
    } else if (s[i].first != 0) {
        sol.push_back(s[i].first);
      } else {
        ++mp2[s[i].second];
      }
    }

  int ans = 0;

  for(auto x : sol) {
    if (mp2[x] != 0) {
      ++ans;
      --mp2[x];
    }
  }

  cout << ans + good / 2 << "\n";

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;

  cin >> n;

  vector <string> v(n);

  vector < pair <int, int> > s(n);

  vector <int> sol;

  map <int, int> mp2;

  auto sb = s.begin();
  int good = 0;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];

    int nr = 0;
    for (auto x : v[i]) {
      if (x == '(') {
        ++s[i].first;
      } else if (s[i].first != 0) {
        --s[i].first;
      } else {
        ++nr;
      }
    }
    s[i].second += nr;
    if (s[i].first != 0 && s[i].second != 0) {
      s.erase(sb + i);
      // v.erase(v.begin() + i);
      --i;
      --n;
    } else if (s[i].first == 0 && s[i].second == 0) {
      ++good;
      s.erase(sb + i);
      // v.erase(v.begin() + i);
      --i;
      --n;
    } else if (s[i].first != 0) {
        sol.push_back(s[i].first);
      } else {
        ++mp2[s[i].second];
      }
    }

  int ans = good / 2;

  for(auto x : sol) {
    if (mp2[x] != 0) {
      ++ans;
      --mp2[x];
    }
  }

  cout << ans << "\n";

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
typedef pair<ll, ll> pairs;
//transform(su.begin(), su.end(), su.begin(), ::toupper); //string upper char
long long t, k, n, m, a, b, ans, sum, total, count1, count2, hell=1000000007;

/*long long modInverse(unsigned long long x, unsigned long long y, unsigned long long m)
{ //function formate(a, m-2, m)
    if (y == 0)
        return 1;
    long long p = modInverse(x, y/2, m) % m;
    p = (p * p) % m;

    return (y%2 == 0)? p : (x * p) % m;
}
long long nCr(long long n, lon
g long r, long long m)
{
   long long ans=1;
   for(long long i=r+1;i<=n;i++)
      ans = ((ans%m)*(i%m)%m);
   for(int i =2;i<=(n-r);i++)
     {ans = ((ans%m)*(modInverse(i, m-2, m)))%m;}

     return ans;
}*/

int fun(string s)
{
  ll sum = 0;
  for(int i=0;i<s.size();i++)
  {
    if(s[i]=='(')
    {
      sum+=-1;
    }
    else
    {
      sum+=1;
    }
  }

return sum;
}
bool check(string s)
{
  ll sum = 0;
  for(int i=0;i<s.size();i++)
  {
    if(s[i]=='(')
      sum+=-1;
    else
      sum+=1;

    if(sum>0)
      return false;
  }
  if(sum!=0)
    return false;
  else
    return true;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
cout << std::setprecision(11) << std::fixed;

cin>>n;
vector<string>v1[100001];
vector<string>v2[100001];

vector<string>arr(n);
for(int i=0;i<n;i++)
  cin>>arr[i];

for(int i=0;i<n;i++)
{
  a = fun(arr[i]);
  if(a>0)
  {
    v1[a].push_back(arr[i]);
  }
  else if(a<0)
  {
   v2[abs(a)].push_back(arr[i]);
  }
  else
  {
    if(check(arr[i]))
    count1++;
  }
}
total = 0;
for(int i=1;i<=100000;i++)
{

      set<string>st1;
      set<string>st2;
      for(int j=0;j<v1[i].size();j++)
      {
        st1.insert(v1[i][j]);
      }
      for(int j=0;j<v2[i].size();j++)
      {
        st2.insert(v2[i][j]);
      }
      total+=min(st1.size(), st2.size());
}

cout<<total + count1/2;

return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
typedef pair<ll, ll> pairs;
//transform(su.begin(), su.end(), su.begin(), ::toupper); //string upper char
long long t, k, n, m, a, b, ans, sum, total, count1, count2, hell=1000000007;

/*long long modInverse(unsigned long long x, unsigned long long y, unsigned long long m)
{ //function formate(a, m-2, m)
    if (y == 0)
        return 1;
    long long p = modInverse(x, y/2, m) % m;
    p = (p * p) % m;

    return (y%2 == 0)? p : (x * p) % m;
}
long long nCr(long long n, lon
g long r, long long m)
{
   long long ans=1;
   for(long long i=r+1;i<=n;i++)
      ans = ((ans%m)*(i%m)%m);
   for(int i =2;i<=(n-r);i++)
     {ans = ((ans%m)*(modInverse(i, m-2, m)))%m;}

     return ans;
}*/

ll fun(string s)
{
  ll sum = 0, maxi = 0;
  for(int i=0;i<s.size();i++)
  {
    if(s[i]=='(')
    {
      sum+=-1;
      if(sum>0)
      maxi = max(sum, maxi);
    }
    else
    {
      sum+=1;
      if(sum>0)
      maxi = max(sum, maxi);
    }
  }
   if(maxi>0)
   {
      if(sum<maxi)
      return 0;
   }
return sum;
}
bool check(string s)
{
  ll sum = 0;
  for(int i=0;i<s.size();i++)
  {
    if(s[i]=='(')
      sum+=-1;
    else
      sum+=1;

    if(sum>0)
      return false;
  }
   if(sum!=0)
    return false;
    return true;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
cout << std::setprecision(11) << std::fixed;

cin>>n;
vector<string>v1[100001];
vector<string>v2[100001];

vector<string>arr(n);
for(int i=0;i<n;i++)
  cin>>arr[i];

for(int i=0;i<n;i++)
{
  a = fun(arr[i]);
  if(a>0)
  {
    v1[a].push_back(arr[i]);
  }
  else if(a<0)
  {
   v2[abs(a)].push_back(arr[i]);
  }
  else
  {
    if(check(arr[i]))
    count1++;
  }
}
total = 0;
for(int i=1;i<=100000;i++)
{

      total+=min(v1[i].size(), v2[i].size());
}

cout<<total + count1/2;

return 0;
}