#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#define PQ priority_queue
#define OO 2147483647
#define Max(a, b) ((FASTBUFFER = ((a) - (b)) >> 31), ((b) & FASTBUFFER | (a) & ~FASTBUFFER))
#define Min(a, b) ((FASTBUFFER = ((a) - (b)) >> 31), ((a) & FASTBUFFER | (b) & ~FASTBUFFER))
#define Swap(a, b) (a ^= b, b ^= a, a ^= b)

int FASTBUFFER;

using namespace std;

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

map <string, int> val;
vector <int> can[105];
int v[105], a[105], vv[200005], f[20][200005], pre[20][200005];
int n, k, full;
string st[105], end[105];

void dfs(int i, int j);

int main()
{
	for (int i = 0; i < 100; i++)
		val[str[i]] = i + 1;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++)
	{
		char ss[105];
		scanf("%s", ss + 1);
		string snow = ss + 1;
		v[i] = val[snow];
		st[i] = snow;
	}

	for (int i = 1; i <= k; i++)
	{
		char ss[105];
		scanf("%s", ss + 1);
		string snow = ss + 1;
		a[i] = val[snow];
		end[i] = snow;
	}

	full = (1 << n) - 1;
	for (int i = 0; i <= full; i++)
	{
		int snow = 0;
		for (int j = 0; j < n; j++)
		{
			if (i & (1 << j))
				snow += v[j + 1];
		}

		vv[i] = snow;
	}

	f[0][0] = 1;
	for (int i = 0; i < k; i++)
	{
		for (int j = 0; j <= full; j++)
		{
			if (f[i][j] == 0)
				continue;
			for (int x = full - j; x; x = (x - 1) & (full - j))
			{
				if (vv[x] == a[i + 1])
				{
					f[i + 1][j | x] = 1;
					pre[i + 1][j | x] = x;
				}
			}
		}
	}

	if (f[k][full])
	{
		printf("YES\n");
		dfs(k, full);
	}

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

void dfs(int i, int j)
{
	if (i == 0)
		return;
	dfs(i - 1, j - pre[i][j]);
	int now = pre[i][j], tag = 1;
	for (int x = 0; x < n; x++)
		if (now & (1 << x))
		{
			if (tag == 1)
				printf("%s", st[x + 1].c_str()), tag = 0;
			else
				printf("+%s", st[x + 1].c_str());
		}
	printf("->%s\n", end[i].c_str());
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#define PQ priority_queue
#define OO 2147483647
#define Max(a, b) ((FASTBUFFER = ((a) - (b)) >> 31), ((b) & FASTBUFFER | (a) & ~FASTBUFFER))
#define Min(a, b) ((FASTBUFFER = ((a) - (b)) >> 31), ((a) & FASTBUFFER | (b) & ~FASTBUFFER))
#define Swap(a, b) (a ^= b, b ^= a, a ^= b)

int FASTBUFFER;

using namespace std;

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

map <string, int> val;
vector <int> can[105];
int v[105], a[105], f[20][100005], pre[20][100005];
int n, k, full;
string st[105], end[105];

void dfs(int i, int j);

int main()
{
	for (int i = 0; i < 100; i++)
		val[str[i]] = i + 1;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++)
	{
		char ss[105];
		scanf("%s", ss + 1);
		string snow = ss + 1;
		v[i] = val[snow];
		st[i] = snow;
	}

	for (int i = 1; i <= k; i++)
	{
		char ss[105];
		scanf("%s", ss + 1);
		string snow = ss + 1;
		a[i] = val[snow];
		end[i] = snow;
	}

	full = (1 << n) - 1;
	for (int i = 0; i <= full; i++)
	{
		int snow = 0;
		for (int j = 0; j < n; j++)
		{
			if (i & (1 << j))
				snow += v[j + 1];
		}

		for (int j = 1; j <= k; j++)
			if (a[j] == snow)
				can[j].push_back(i);
	}

	f[0][0] = 1;
	for (int i = 1; i <= k; i++)
	{
		for (int j = 0; j <= full; j++)
		{
			for (vector <int> :: iterator it = can[i].begin(); it != can[i].end(); ++it)
			{
				int now = *it;
				if ((j & now) == now && f[i - 1][j - now])
				{
					f[i][j] = 1;
					pre[i][j] = now;
					break;
				}
			}
		}
	}

	if (f[k][full])
	{
		printf("YES\n");
		dfs(k, full);
	}

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

void dfs(int i, int j)
{
	if (i == 0)
		return;
	dfs(i - 1, j - pre[i][j]);
	int now = pre[i][j], tag = 1;
	for (int x = 0; x < n; x++)
		if (now & (1 << x))
		{
			if (tag == 1)
				printf("%s", st[x + 1].c_str()), tag = 0;
			else
				printf("+%s", st[x + 1].c_str());
		}
	printf("->%s\n", end[i].c_str());
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#define PQ priority_queue
#define OO 2147483647
#define Max(a, b) ((FASTBUFFER = ((a) - (b)) >> 31), ((b) & FASTBUFFER | (a) & ~FASTBUFFER))
#define Min(a, b) ((FASTBUFFER = ((a) - (b)) >> 31), ((a) & FASTBUFFER | (b) & ~FASTBUFFER))
#define Swap(a, b) (a ^= b, b ^= a, a ^= b)

int FASTBUFFER;

using namespace std;

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

map <string, int> val;
vector <int> can[105];
int v[105], a[105], f[20][200005], pre[20][200005];
int n, k, full;
string st[105], end[105];

void dfs(int i, int j);

int main()
{
	for (int i = 0; i < 100; i++)
		val[str[i]] = i + 1;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++)
	{
		char ss[105];
		scanf("%s", ss + 1);
		string snow = ss + 1;
		v[i] = val[snow];
		st[i] = snow;
	}

	for (int i = 1; i <= k; i++)
	{
		char ss[105];
		scanf("%s", ss + 1);
		string snow = ss + 1;
		a[i] = val[snow];
		end[i] = snow;
	}

	full = (1 << n) - 1;
	for (int i = 0; i <= full; i++)
	{
		int snow = 0;
		for (int j = 0; j < n; j++)
		{
			if (i & (1 << j))
				snow += v[j + 1];
		}

		for (int j = 1; j <= k; j++)
			if (a[j] == snow)
				can[j].push_back(i);
	}

	f[0][0] = 1;
	for (int i = 1; i <= k; i++)
	{
		for (int j = 0; j <= full; j++)
		{
			for (vector <int> :: iterator it = can[i].begin(); it != can[i].end(); ++it)
			{
				int now = *it;
				if ((j & now) == now && f[i - 1][j - now])
				{
					f[i][j] = 1;
					pre[i][j] = now;
					break;
				}
			}
		}
	}

	if (f[k][full])
	{
		printf("YES\n");
		dfs(k, full);
	}

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

void dfs(int i, int j)
{
	if (i == 0)
		return;
	dfs(i - 1, j - pre[i][j]);
	int now = pre[i][j], tag = 1;
	for (int x = 0; x < n; x++)
		if (now & (1 << x))
		{
			if (tag == 1)
				printf("%s", st[x + 1].c_str()), tag = 0;
			else
				printf("+%s", st[x + 1].c_str());
		}
	printf("->%s\n", end[i].c_str());
}


#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<iostream>
using namespace std;
#define For(i,x,y) for(int i=(int)x,_y=y;i<=_y;i++)
string element[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","Tl","Pb","Bi","Po","At","Rn","Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm"};
int n,m,pos[20],s1[20],s2[20];
bool flag;
string s;
vector<int>ans[20];
map<string,int>mp;
void dfs(int l,int sum,int r)
{
	if(r==m+1){flag=1;return;}
	if(s2[r]==sum){dfs(1,0,r+1);return;}
	int pre=-1;
	for(int i=l;i<=n&&!flag&&s1[i]+sum<=s2[r];i++)if(pos[i]==-1&&s1[i]!=pre)
	{
		pre=s1[i];
		pos[i]=r;
		dfs(l+1,s1[i]+sum,r);
		if(!flag)pos[i]=-1;
	}
}
int main()
{
	cin>>n>>m;
	For(i,1,100)mp[element[i]]=i;
	For(i,1,n)cin>>s,s1[i]=mp[s];
	For(i,1,m)cin>>s,s2[i]=mp[s];
	sort(s1+1,s1+n+1);sort(s2+1,s2+m+1);
	For(i,1,n)pos[i]=-1;
	dfs(1,0,1);
	if(flag)
	{
		cout<<"YES\n";
		For(i,1,n)ans[pos[i]].push_back(s1[i]);
		For(i,1,m)
		{
			cout<<element[ans[i][0]];
			For(j,1,ans[i].size()-1)cout<<"+"<<element[ans[i][j]];
			cout<<"->"<<element[s2[i]]<<endl;
		}
	}else cout<<"NO\n";
}


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


/* Wed 06 Feb 2013 10:40:24 PM ICT */
#include<cstdio>
#include<string>
#include<cstring>
#include<map>
using namespace std;

char elements[] = "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";
const int N = 17, Z_MAX = 100;
map<string, int> Z;
string name[Z_MAX+1];
int x[N], y[N], n, k, f[1 << N], g[1 << N], pre[1 << N];

void init() {
    int z = 1;
    for(char * buf = strtok(elements, " "); buf; buf = strtok(NULL, " "), ++z) {
        Z[string(buf)] = z;
        name[z] = string(buf);
    }
}

void enter() {
    char s[3]; scanf("%d%d",&n,&k);
    for(int i = 0; i < n; ++i) {
        scanf("%s", s);
        x[i] = Z[string(s)];
    }
    for(int i = 0; i < k; ++i) {
        scanf("%s", s);
        y[i] = Z[string(s)];
    }
}

void solve() {
    const int final = (1 << n) - 1;
    for(int mask = 0; mask <= final; ++mask) {
        f[mask] = 0;
        for(int i = 0; i < n; ++i) if(mask & 1 << i) f[mask] += x[i];
    }
    memset(g, -1, sizeof g); g[0] = 0;
    for(int mask = 0; mask < final; ++mask) if(g[mask] != -1) {
        int temp = mask ^ final;
        for(int newMask = temp; newMask >= 0; --newMask) {
            newMask &= temp;
            if(f[newMask] == y[g[mask]]) {
                g[newMask | mask] = g[mask] + 1;
                pre[newMask | mask] = mask;
            }
        }
    }
}

void print() {
    int final = (1 << n) - 1;
    if(g[final] < k) puts("NO");
    else {
        puts("YES");
        for(int i = k-1; i >= 0; --i, final = pre[final]) {
            int mask = final ^ pre[final], cnt = 0;
            for(int j = 0; j < n; ++j) if(mask & 1 << j) {
                if(cnt++) printf("+");
                printf("%s", name[x[j]].c_str());
            }
            printf("->%s\n", name[y[i]].c_str());
        }
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("23.inp", "r", stdin);
    freopen("23.out", "w", stdout);
#endif
    init();
    enter();
    solve();
    print();
    return 0;
}


#include<cstdio>
#include<bitset>
#include<string>
#include<cstring>
#include<map>
using namespace std;

char elements[] = "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";
const int N = 17, Z_MAX = 100;
map<string, int> Z;
string name[Z_MAX+1];
int x[N], y[N], n, k, f[1 << N], g[1 << N], pre[1 << N];

void init() {
    int z = 1;
    for(char * buf = strtok(elements, " "); buf; buf = strtok(NULL, " "), ++z) {
        Z[string(buf)] = z;
        name[z] = string(buf);
    }
}

void enter() {
    char s[3]; scanf("%d%d",&n,&k);
    for(int i = 0; i < n; ++i) {
        scanf("%s", s);
        x[i] = Z[string(s)];
    }
    for(int i = 0; i < k; ++i) {
        scanf("%s", s);
        y[i] = Z[string(s)];
    }
}

void solve() {
    const int final = (1 << n) - 1;
    for(int mask = 0; mask <= final; ++mask) {
        f[mask] = 0;
        for(int i = 0; i < n; ++i) if(mask & 1 << i) f[mask] += x[i];
    }
    memset(g, -1, sizeof g); g[0] = 0;
    for(int mask = 0; mask < final; ++mask) if(g[mask] != -1) {
        int temp = mask ^ final;
        for(int newMask = temp; newMask >= 0; --newMask) {
            newMask &= temp;
            if(f[newMask] == y[g[mask]]) {
                g[newMask | mask] = g[mask] + 1;
                pre[newMask | mask] = mask;
            }
        }
    }
}

void print() {
    int final = (1 << n) - 1;
    if(g[final] < k) puts("NO");
    else {
        puts("YES");
        for(int i = k-1; i >= 0; --i, final = pre[final]) {
            int mask = final ^ pre[final], cnt = 0;
            for(int j = 0; j < n; ++j) if(mask & 1 << j) {
                if(cnt++) printf("+");
                printf("%s", name[x[j]].c_str());
            }
            printf("->%s\n", name[y[i]].c_str());
        }
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("23.inp", "r", stdin);
    freopen("23.out", "w", stdout);
#endif
    init();
    enter();
    solve();
    print();
    return 0;
}


#include<cstdio>
#include<string>
#include<cstring>
#include<map>
#include<vector>
using namespace std;

char elements[] = "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";
const int N = 17, Z_MAX = 100;
map<string, int> Z;
string name[Z_MAX+1];
int x[N], y[N], n, k;
bool f[1 << N][N][Z_MAX+1];

void init() {
    int z = 1;
    for(char * buf = strtok(elements, " "); buf; buf = strtok(NULL, " "), ++z) {
        Z[string(buf)] = z;
        name[z] = string(buf);
    }
}

void enter() {
    char s[3]; scanf("%d%d",&n,&k);
    for(int i = 0; i < n; ++i) {
        scanf("%s", s);
        x[i] = Z[string(s)];
    }
    for(int i = 0; i < k; ++i) {
        scanf("%s", s);
        y[i] = Z[string(s)];
    }
}

void solve() {
    for(int state = 0; state < (1 << n); ++state) {
        f[state][0][0] = 1;
        for(int i = 0; i < k; ++i) {
            if(i) f[state][i][0] = f[state][i-1][y[i-1]];
            for(int j = 1; j <= y[i]; ++j)
                for(int p = 0; p < n && f[state][i][j] == 0; ++p) if((state & 1 << p) && x[p] <= j)
                    f[state][i][j] |= f[state & ~(1 << p)][i][j-x[p]];
        }
    }
}

void print() {
    if(f[(1 << n) - 1][k-1][y[k-1]]) {
        puts("YES");
        for(int i = k-1, j = y[i], state = (1 << n) - 1; i || j; ) {
            int cnt = 0;
            for(int p = 0; p < n; ++p)
                if((state & 1 << p) && x[p] <= j && f[state & ~(1 << p)][i][j-x[p]]) {
                    if(cnt++) printf("+");
                    printf("%s", name[x[p]].c_str());
                    j -= x[p]; state &= ~(1 << p);
                    if(j == 0) {
                        printf("->%s\n", name[y[i]].c_str()); cnt = 0;
                        if(i) {
                            j = y[--i];
                        }
                    }
                }
        }
    } else puts("NO");
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("23.inp", "r", stdin);
    freopen("23.out", "w", stdout);
#endif
    init();
    enter();
    solve();
    print();
    return 0;
}


#include<cstdio>
#include<string>
#include<cstring>
#include<map>
#include<vector>
using namespace std;

char elements[] = "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";
const int N = 17, Z_MAX = 100;
map<string, int> Z;
string name[Z_MAX+1];
int x[N], y[N], n, k;
bool f[1 << N][N][Z_MAX+1];

void init() {
    int z = 1;
    for(char * buf = strtok(elements, " "); buf; buf = strtok(NULL, " "), ++z) {
        Z[string(buf)] = z;
        name[z] = string(buf);
    }
}

void enter() {
    char s[3]; scanf("%d%d",&n,&k);
    for(int i = 0; i < n; ++i) {
        scanf("%s", s);
        x[i] = Z[string(s)];
    }
    for(int i = 0; i < k; ++i) {
        scanf("%s", s);
        y[i] = Z[string(s)];
    }
}

void solve() {
    for(int state = 0; state < (1 << n); ++state) {
        f[state][0][0] = 1;
        for(int i = 0; i < k; ++i) {
            if(i) f[state][i][0] = f[state][i-1][y[i-1]];
            for(int j = 1; j <= y[i]; ++j)
                for(int p = 0; p < n && f[state][i][j] == 0; ++p) if((state & 1 << p) && x[p] <= j)
                    f[state][i][j] |= f[state & ~(1 << p)][i][j-x[p]];
        }
    }
}

void print() {
    if(f[(1 << n) - 1][k-1][y[k-1]]) {
        puts("YES"); int cnt = 0;
        for(int i = k-1, j = y[i], state = (1 << n) - 1; i || j; ) {
            for(int p = 0; p < n; ++p)
                if((state & 1 << p) && x[p] <= j && f[state & ~(1 << p)][i][j-x[p]]) {
                    if(cnt++) printf("+");
                    printf("%s", name[x[p]].c_str());
                    j -= x[p]; state &= ~(1 << p);
                    if(j == 0) {
                        printf("->%s\n", name[y[i]].c_str()); cnt = 0;
                        if(i) {
                            j = y[--i];
                        }
                    }
                }
        }
    } else puts("NO");
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("23.inp", "r", stdin);
    freopen("23.out", "w", stdout);
#endif
    init();
    enter();
    solve();
    print();
    return 0;
}


#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <numeric>
#include <memory.h>
#include <cstdio>
#include <assert.h>

using namespace std;

#define pb push_back
#define INF 1011111111
#define FOR(i,a,b) for (int _n(b), i(a); i < _n; i++)
#define rep(i,n) FOR(i,0,n)
#define ford(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define CL(a,v) memset((a),(v),sizeof(a))
#define X first
#define Y second
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))

typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> pii;

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

map <string, int> mp;
string input[20],output[20];
int input2[20],output2[20];
int sum[(1<<17)];
bool dp[20][(1<<17)];
int prev[20][(1<<17)];

int main()
{
	#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
	#endif

     int N,K,i,j,x,y;

    cin >> N >> K;
    rep(i,N) cin >> input[i];
    rep(i,K) cin >> output[i];

    rep(i,100) mp[s[i]] = i + 1;
    rep(i,N) input2[i] = mp[input[i]];
    rep(i,K) output2[i] = mp[output[i]];

    rep(i,(1<<N)) rep(j,N) if(i&(1<<j)) sum[i] += input2[j];

    dp[0][0] = true;
    rep(i,K) rep(x,(1<<N)) if(sum[x] == output2[i]){
        int rem = (1<<N) - 1 - x;
        for(y=rem;y>0;y=((y-1)&rem)) if(dp[i][y]){
            dp[i+1][x|y] = true;
            prev[i+1][x|y] = y;
        }
        if(dp[i][0]){
            dp[i+1][x] = true;
            prev[i+1][x] = 0;
        }
    }

    if(!dp[K][(1<<N)-1]){
        cout << "NO" << endl;
        return 0;
    }

    cout << "YES" << endl;

    x = (1<<N) - 1;
    for(i=K-1;i>=0;i--){
        y = x - prev[i+1][x];
        string t;
        rep(j,N) if(y&(1<<j)) t += input[j] + "+";
        t = t.substr(0,t.length()-1) + "->" + output[i];
        cout << t << endl;
        x = prev[i+1][x];
    }

	return 0;
}


#include<iostream>
#include<vector>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<queue>
#include<cassert>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pi;
typedef long long ll;

const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

char *elem[]={
 "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,m,a[20],b[20];
int prev[18][1<<17];
int sum[1<<17];

void run()
{
	map<string,int> id;
	rep(i,100)id[elem[i]]=i+1;
	memset(prev,-1,sizeof(prev));

	cin>>n>>m;
	rep(i,n){
		string s; cin>>s;
		a[i]=id[s];
	}
	memset(sum,0,sizeof(sum));
	rep(i,1<<n)rep(j,n)if(i&1<<j)sum[i]+=a[j];

	rep(i,m){
		string s; cin>>s;
		b[i]=id[s];
	}
	prev[0][(1<<n)-1]=0;
	rep(i,m)rep(j,1<<n)if(prev[i][j]>=0){
		for(int k=j;k;k=k-1&j)
			if(sum[k]==b[i])prev[i+1][j^k]=j;
	}
	if(prev[m][0]==-1)cout<<"NO"<<endl;
	else{
		cout<<"YES"<<endl;
		vector<string> ans;
		int bit=0;
		for(int i=m;i>0;i--){
			int diff=bit^prev[i][bit];
			stringstream ss;
			bool first=1;
			rep(j,n)if(diff&1<<j){
				if(!first)ss<<"+";
				else first=0;
				ss<<elem[a[j]-1];
			}
			ss<<"->"<<elem[b[i-1]-1];
			bit=prev[i][bit];
			ans.pb(ss.str());
		}
		for(int i=m-1;i>=0;i--)cout<<ans[i]<<endl;
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	int cs=3;rep(i,cs)
#endif
	run();
}


#include<iostream>
#include<vector>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<queue>
#include<cassert>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pi;
typedef long long ll;

const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

char *elem[]={
 "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,m,a[20],b[20];
int prev[18][1<<17];
void run()
{
	map<string,int> id;
	rep(i,100)id[elem[i]]=i+1;
	memset(prev,-1,sizeof(prev));

	cin>>n>>m;
	rep(i,n){
		string s; cin>>s;
		a[i]=id[s];
	}
	rep(i,m){
		string s; cin>>s;
		b[i]=id[s];
	}
	prev[0][(1<<n)-1]=0;
	rep(i,m)rep(j,1<<n)if(prev[i][j]>=0){
		for(int k=j;k;k=k-1&j){
			int sum=0;
			rep(l,n)if(k&1<<l)sum+=a[l];
			if(sum==b[i])prev[i+1][j^k]=j;
		}
	}
	if(prev[m][0]==-1)cout<<"NO"<<endl;
	else{
		cout<<"YES"<<endl;
		vector<string> ans;
		int bit=0;
		for(int i=m;i>0;i--){
			int diff=bit^prev[i][bit];
			stringstream ss;
			bool first=1;
			rep(j,n)if(diff&1<<j){
				if(!first)ss<<"+";
				else first=0;
				ss<<elem[a[j]-1];
			}
			ss<<"->"<<elem[b[i-1]-1];
			bit=prev[i][bit];
			ans.pb(ss.str());
		}
		for(int i=m-1;i>=0;i--)cout<<ans[i]<<endl;
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	int cs=3;rep(i,cs)
#endif
	run();
}


#include <cctype>
#include <string>
#include <sstream>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

const char *table = "H1 "
"He2 "
"Li3	Be4 "
"B5	C6	N7	O8	F9	Ne10 "
"Na11	Mg12 "
"Al13	Si14	P15	S16	Cl17	Ar18 "
"K19	Ca20	Sc21	Ti22	V23	Cr24	Mn25	Fe26	Co27	Ni28	Cu29	Zn30	Ga31	Ge32	As33	Se34	Br35	Kr36 "
"Rb37	Sr38	Y39	Zr40	Nb41	Mo42	Tc43	Ru44	Rh45	Pd46	Ag47	Cd48	In49	Sn50	Sb51	Te52	I53	Xe54 "
"Cs55	Ba56	La57	Hf72	Ta73	W74	Re75	Os76	Ir77	Pt78	Au79	Hg80	Tl81	Pb82	Bi83	Po84	At85	Rn86 "
"Fr87	Ra88	Ac89 "
"Ce58	Pr59	Nd60	Pm61	Sm62	Eu63	Gd64	Tb65	Dy66	Ho67	Er68	Tm69	Yb70	Lu71 "
"Th90	Pa91	U92	Np93 	Pu94 	Am95	Cm96 	Bk97	Cf98 	Es99	Fm100	Md101";

map<string, int> pm;
map<int, string> mp;
int dpf[1 << 18];
int dps[1 << 18];

void init()
{
	stringstream ss, num;
	ss << table;
	string f;
	while(ss >> f) {
		int n = 0, j = (int)f.length();
		while(isdigit(f[--j]));
		num.clear();
		num << f.substr(j + 1);
		num >> n;
		f = f.substr(0, j + 1);
		pm[f] = n;
		mp[n] = f;
	}
}

struct CmpFirstLength
{
	CmpFirstLength(int n) : n_(n) { }

	bool operator() (const pair<int, int>& lhs, const pair<int, int>& rhs) const
	{
		if(lhs.first == rhs.first && n_ > 0) {
			int l = 0, r = 0;
			for(int i = 0; i < n_; ++i) {
				l += (lhs.second >> i & 1) != 0;
				r += (rhs.second >> i & 1) != 0;
			}
			return l < r;
		}
		return lhs.first < rhs.first;
	}

private:
	int n_;
};

struct CmpByCount
{
	CmpByCount(vector<int>& to, vector<int>& cnt) : to_(&to), cnt_(&cnt) { }

	bool operator() (int lhs, int rhs) const
	{
		size_t l = lower_bound(to_->begin(), to_->end(), lhs) - to_->begin();
		size_t r = lower_bound(to_->begin(), to_->end(), rhs) - to_->begin();
		return (*cnt_)[l] < (*cnt_)[r];
	}

private:
	vector<int> *to_;
	vector<int> *cnt_;
};

bool dfs(int k, const vector< pair<int, int> >& data, const vector< pair<int, int> >& ranges, int used, vector<int>& mask, const vector<int>& to)
{
	if(k == (int)to.size())
		return true;
	for(int i = ranges[k].first; i < ranges[k].second; ++i) {
		int nused = used;
		if((nused & data[i].second) != 0)
			continue;
		nused |= mask[k] = data[i].second;
		if(dfs(k + 1, data, ranges, nused, mask, to))
			return true;
		mask[k] = 0;
	}
	return false;
}

vector<int> solve(vector<int> from, vector<int> to)
{
	int n = (int)from.size(), k = (int)to.size();
	vector< pair<int, int> > data, ranges(k);
	vector<int> cnt(k);
	sort(to.begin(), to.end());
	for(int i = 0; i < (1 << n); ++i) {
		int sum = 0;
		for(int j = 0; j < n; ++j) if(i >> j & 1)
			sum += from[j];
		//dpf[i] = sum;
		if(binary_search(to.begin(), to.end(), sum)) {
			data.push_back(make_pair(sum, i));
			++cnt[lower_bound(to.begin(), to.end(), sum) - to.begin()];
		}
	}
	vector<int> tmp = to;
	sort(to.begin(), to.end(), CmpByCount(tmp, cnt));
	sort(data.begin(), data.end(), CmpFirstLength(n));
	for(int i = 0; i < k; ++i) {
		typedef vector< pair<int, int> >::iterator iter_t;
		pair<iter_t, iter_t> range = equal_range(data.begin(), data.end(), make_pair(to[i], 0), CmpFirstLength(-1));
		ranges[i] = make_pair(range.first - data.begin(), range.second - data.begin());
	}
	vector<int> ans(k, 0);
	if(!dfs(0, data, ranges, 0, ans, to))
		return vector<int>();
	return ans;
}

int main()
{
	init();
	int n, k;
	cin >> n >> k;
	string s;
	vector<int> from(n), to(k);
	for(int i = 0; i < n; ++i) {
		cin >> s;
		from[i] = pm[s];
	}
	for(int i = 0; i < k; ++i) {
		cin >> s;
		to[i] = pm[s];
	}

	if(*max_element(from.begin(), from.end()) > *max_element(to.begin(), to.end())) {
		cout << "NO" << endl;
		return 0;
	}

	vector<int> ans = solve(from, to);
	if(ans.empty()) {
		cout << "NO" << endl;
	} else {
		cout << "YES" << endl;
		for(int i = 0; i < k; ++i) {
			int sum = 0;
			for(int j = 0, g = 0; j < n; ++j) if(ans[i] >> j & 1) {
				if(g != 0) cout << "+";
				cout << mp[from[j]];
				sum += from[j], ++g;
			}
			cout << "->" << mp[sum] << endl;
		}
	}
	return 0;
}


#include <cctype>
#include <string>
#include <sstream>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

const char *table = "H1 "
"He2 "
"Li3	Be4 "
"B5	C6	N7	O8	F9	Ne10 "
"Na11	Mg12 "
"Al13	Si14	P15	S16	Cl17	Ar18 "
"K19	Ca20	Sc21	Ti22	V23	Cr24	Mn25	Fe26	Co27	Ni28	Cu29	Zn30	Ga31	Ge32	As33	Se34	Br35	Kr36 "
"Rb37	Sr38	Y39	Zr40	Nb41	Mo42	Tc43	Ru44	Rh45	Pd46	Ag47	Cd48	In49	Sn50	Sb51	Te52	I53	Xe54 "
"Cs55	Ba56	La57	Hf72	Ta73	W74	Re75	Os76	Ir77	Pt78	Au79	Hg80	Tl81	Pb82	Bi83	Po84	At85	Rn86 "
"Fr87	Ra88	Ac89 "
"Ce58	Pr59	Nd60	Pm61	Sm62	Eu63	Gd64	Tb65	Dy66	Ho67	Er68	Tm69	Yb70	Lu71 "
"Th90	Pa91	U92	Np93 	Pu94 	Am95	Cm96 	Bk97	Cf98 	Es99	Fm100	Md101";

map<string, int> pm;
map<int, string> mp;
//int dpf[1 << 18];

void init()
{
	stringstream ss, num;
	ss << table;
	string f;
	while(ss >> f) {
		int n = 0, j = (int)f.length();
		while(isdigit(f[--j]));
		num.clear();
		num << f.substr(j + 1);
		num >> n;
		f = f.substr(0, j + 1);
		pm[f] = n;
		mp[n] = f;
	}
}

struct CmpFirstLength
{
	CmpFirstLength(int n) : n_(n) { }

	bool operator() (const pair<int, int>& lhs, const pair<int, int>& rhs) const
	{
		if(lhs.first == rhs.first && n_ > 0) {
			int l = 0, r = 0;
			for(int i = 0; i < n_; ++i) {
				l += (lhs.second >> i & 1) != 0;
				r += (rhs.second >> i & 1) != 0;
			}
			return l < r;
		}
		return lhs.first < rhs.first;
	}

private:
	int n_;
};

struct CmpByCount
{
	CmpByCount(vector<int>& to, vector<int>& cnt) : to_(&to), cnt_(&cnt) { }

	bool operator() (int lhs, int rhs) const
	{
		size_t l = lower_bound(to_->begin(), to_->end(), lhs) - to_->begin();
		size_t r = lower_bound(to_->begin(), to_->end(), rhs) - to_->begin();
		return (*cnt_)[l] < (*cnt_)[r];
	}

private:
	vector<int> *to_;
	vector<int> *cnt_;
};

bool dfs(int k, const vector< pair<int, int> >& data, int used, vector<int>& mask, const vector<int>& to)
{
	if(k == (int)to.size())
		return true;
	typedef vector< pair<int, int> >::const_iterator iter_t;
	pair<iter_t, iter_t> range = equal_range(data.begin(), data.end(), make_pair(to[k], 0), CmpFirstLength(-1));
	for(iter_t i = range.first; i != range.second; ++i) {
		int nused = used;
		if((nused & i->second) != 0)
			continue;
		nused |= mask[k] = i->second;
		if(dfs(k + 1, data, nused, mask, to))
			return true;
		mask[k] = 0;
	}
	return false;
}

vector<int> solve(vector<int> from, vector<int> to)
{
	int n = (int)from.size(), k = (int)to.size();
	vector< pair<int, int> > data;
	vector<int> cnt(k);
	sort(to.begin(), to.end());
	for(int i = 0; i < (1 << n); ++i) {
		int sum = 0;
		for(int j = 0; j < n; ++j) if(i >> j & 1)
			sum += from[j];
		//dpf[i] = sum;
		if(binary_search(to.begin(), to.end(), sum)) {
			data.push_back(make_pair(sum, i));
			++cnt[lower_bound(to.begin(), to.end(), sum) - to.begin()];
		}
	}
	vector<int> tmp = to;
	sort(to.begin(), to.end(), CmpByCount(tmp, cnt));
	sort(data.begin(), data.end(), CmpFirstLength(n));
	vector<int> ans(k, 0);
	if(!dfs(0, data, 0, ans, to))
		return vector<int>();
	return ans;
}

int main()
{
	init();
	int n, k;
	cin >> n >> k;
	string s;
	vector<int> from(n), to(k);
	for(int i = 0; i < n; ++i) {
		cin >> s;
		from[i] = pm[s];
	}
	for(int i = 0; i < k; ++i) {
		cin >> s;
		to[i] = pm[s];
	}

	vector<int> ans = solve(from, to);
	if(ans.empty()) {
		cout << "NO" << endl;
	} else {
		cout << "YES" << endl;
		for(int i = 0; i < k; ++i) {
			int sum = 0;
			for(int j = 0, g = 0; j < n; ++j) if(ans[i] >> j & 1) {
				if(g != 0) cout << "+";
				cout << mp[from[j]];
				sum += from[j], ++g;
			}
			cout << "->" << mp[sum] << endl;
		}
	}
	return 0;
}


#include <cctype>
#include <string>
#include <sstream>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

const char *table = "H1 "
"He2 "
"Li3	Be4 "
"B5	C6	N7	O8	F9	Ne10 "
"Na11	Mg12 "
"Al13	Si14	P15	S16	Cl17	Ar18 "
"K19	Ca20	Sc21	Ti22	V23	Cr24	Mn25	Fe26	Co27	Ni28	Cu29	Zn30	Ga31	Ge32	As33	Se34	Br35	Kr36 "
"Rb37	Sr38	Y39	Zr40	Nb41	Mo42	Tc43	Ru44	Rh45	Pd46	Ag47	Cd48	In49	Sn50	Sb51	Te52	I53	Xe54 "
"Cs55	Ba56	La57	Hf72	Ta73	W74	Re75	Os76	Ir77	Pt78	Au79	Hg80	Tl81	Pb82	Bi83	Po84	At85	Rn86 "
"Fr87	Ra88	Ac89 "
"Ce58	Pr59	Nd60	Pm61	Sm62	Eu63	Gd64	Tb65	Dy66	Ho67	Er68	Tm69	Yb70	Lu71 "
"Th90	Pa91	U92	Np93 	Pu94 	Am95	Cm96 	Bk97	Cf98 	Es99	Fm100	Md101";

map<string, int> pm;
map<int, string> mp;
int dpf[1 << 18];
int dps[1 << 18];
int dpp[1 << 18];

void init()
{
	stringstream ss, num;
	ss << table;
	string f;
	while(ss >> f) {
		int n = 0, j = (int)f.length();
		while(isdigit(f[--j]));
		num.clear();
		num << f.substr(j + 1);
		num >> n;
		f = f.substr(0, j + 1);
		pm[f] = n;
		mp[n] = f;
	}
}

vector<int> solve2(vector<int> from, vector<int> to)
{
	int n = (int)from.size(), k = (int)to.size();
	int mask = (1 << n) - 1;
	for(int i = 0; i <= mask; ++i) {
		int sum = 0;
		for(int j = 0; j < n; ++j) if(i >> j & 1)
			sum += from[j];
		dpf[i] = sum;
		dpp[i] = dps[i] = -1;
	}

	vector<int> ans;
	for(int i = 0; i <= mask; ++i) {
		int m = ~i & mask;
		for(int j = m; j; j = (j - 1) & m) {
			if(dpf[j] == to[dps[i] + 1]) {
				dps[i | j] = dps[i] + 1;
				dpp[i | j] = i;
			}
		}
	}
	if(dps[mask] == k - 1) {
		int x = mask;
		for(int i = k - 1; i >= 0; --i) {
			ans.push_back(dpp[x] ^ x);
			x = dpp[x];
		}
	}
	return ans;
}

int main()
{
	init();
	int n, k;
	cin >> n >> k;
	string s;
	vector<int> from(n), to(k);
	for(int i = 0; i < n; ++i) {
		cin >> s;
		from[i] = pm[s];
	}
	for(int i = 0; i < k; ++i) {
		cin >> s;
		to[i] = pm[s];
	}

	if(*max_element(from.begin(), from.end()) > *max_element(to.begin(), to.end())) {
		cout << "NO" << endl;
		return 0;
	}

	vector<int> ans = solve2(from, to);
	if(ans.empty()) {
		cout << "NO" << endl;
	} else {
		cout << "YES" << endl;
		for(int i = 0; i < k; ++i) {
			int sum = 0;
			for(int j = 0, g = 0; j < n; ++j) if(ans[i] >> j & 1) {
				if(g != 0) cout << "+";
				cout << mp[from[j]];
				sum += from[j], ++g;
			}
			cout << "->" << mp[sum] << endl;
		}
	}
	return 0;
}


#include <cctype>
#include <string>
#include <sstream>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

const char *table = "H1 "
"He2 "
"Li3	Be4 "
"B5	C6	N7	O8	F9	Ne10 "
"Na11	Mg12 "
"Al13	Si14	P15	S16	Cl17	Ar18 "
"K19	Ca20	Sc21	Ti22	V23	Cr24	Mn25	Fe26	Co27	Ni28	Cu29	Zn30	Ga31	Ge32	As33	Se34	Br35	Kr36 "
"Rb37	Sr38	Y39	Zr40	Nb41	Mo42	Tc43	Ru44	Rh45	Pd46	Ag47	Cd48	In49	Sn50	Sb51	Te52	I53	Xe54 "
"Cs55	Ba56	La57	Hf72	Ta73	W74	Re75	Os76	Ir77	Pt78	Au79	Hg80	Tl81	Pb82	Bi83	Po84	At85	Rn86 "
"Fr87	Ra88	Ac89 "
"Ce58	Pr59	Nd60	Pm61	Sm62	Eu63	Gd64	Tb65	Dy66	Ho67	Er68	Tm69	Yb70	Lu71 "
"Th90	Pa91	U92	Np93 	Pu94 	Am95	Cm96 	Bk97	Cf98 	Es99	Fm100	Md101";

map<string, int> pm;
map<int, string> mp;
//int dpf[1 << 18];

void init()
{
	stringstream ss, num;
	ss << table;
	string f;
	while(ss >> f) {
		int n = 0, j = (int)f.length();
		while(isdigit(f[--j]));
		num.clear();
		num << f.substr(j + 1);
		num >> n;
		f = f.substr(0, j + 1);
		pm[f] = n;
		mp[n] = f;
	}
}

struct CmpFirstLength
{
	CmpFirstLength(int n) : n_(n) { }

	bool operator() (const pair<int, int>& lhs, const pair<int, int>& rhs) const
	{
		if(lhs.first == rhs.first && n_ > 0) {
			int l = 0, r = 0;
			for(int i = 0; i < n_; ++i) {
				l += (lhs.second >> i & 1) != 0;
				r += (rhs.second >> i & 1) != 0;
			}
			return l < r;
		}
		return lhs.first < rhs.first;
	}

private:
	int n_;
};

struct CmpByCount
{
	CmpByCount(vector<int>& to, vector<int>& cnt) : to_(&to), cnt_(&cnt) { }

	bool operator() (int lhs, int rhs) const
	{
		size_t l = lower_bound(to_->begin(), to_->end(), lhs) - to_->begin();
		size_t r = lower_bound(to_->begin(), to_->end(), rhs) - to_->begin();
		return (*cnt_)[l] < (*cnt_)[r];
	}

private:
	vector<int> *to_;
	vector<int> *cnt_;
};

bool dfs(int k, const vector< pair<int, int> >& data, const vector< pair<int, int> >& ranges, int used, vector<int>& mask, const vector<int>& to)
{
	if(k == (int)to.size())
		return true;
	for(int i = ranges[k].first; i != ranges[k].second; ++i) {
		int nused = used;
		if((nused & data[i].second) != 0)
			continue;
		nused |= mask[k] = data[i].second;
		if(dfs(k + 1, data, ranges, nused, mask, to))
			return true;
		mask[k] = 0;
	}
	return false;
}

vector<int> solve(vector<int> from, vector<int> to)
{
	int n = (int)from.size(), k = (int)to.size();
	vector< pair<int, int> > data, ranges(k);
	vector<int> cnt(k);
	sort(to.begin(), to.end());
	for(int i = 0; i < (1 << n); ++i) {
		int sum = 0;
		for(int j = 0; j < n; ++j) if(i >> j & 1)
			sum += from[j];
		//dpf[i] = sum;
		if(binary_search(to.begin(), to.end(), sum)) {
			data.push_back(make_pair(sum, i));
			++cnt[lower_bound(to.begin(), to.end(), sum) - to.begin()];
		}
	}
	vector<int> tmp = to;
	sort(to.begin(), to.end(), CmpByCount(tmp, cnt));
	sort(data.begin(), data.end(), CmpFirstLength(n));
	for(int i = 0; i < k; ++i) {
		typedef vector< pair<int, int> >::iterator iter_t;
		pair<iter_t, iter_t> range = equal_range(data.begin(), data.end(), make_pair(to[i], 0), CmpFirstLength(-1));
		ranges[i] = make_pair(range.first - data.begin(), range.second - data.end());
	}
	vector<int> ans(k, 0);
	if(!dfs(0, data, ranges, 0, ans, to))
		return vector<int>();
	return ans;
}

int main()
{
	init();
	int n, k;
	cin >> n >> k;
	string s;
	vector<int> from(n), to(k);
	for(int i = 0; i < n; ++i) {
		cin >> s;
		from[i] = pm[s];
	}
	for(int i = 0; i < k; ++i) {
		cin >> s;
		to[i] = pm[s];
	}

	vector<int> ans = solve(from, to);
	if(ans.empty()) {
		cout << "NO" << endl;
	} else {
		cout << "YES" << endl;
		for(int i = 0; i < k; ++i) {
			int sum = 0;
			for(int j = 0, g = 0; j < n; ++j) if(ans[i] >> j & 1) {
				if(g != 0) cout << "+";
				cout << mp[from[j]];
				sum += from[j], ++g;
			}
			cout << "->" << mp[sum] << endl;
		}
	}
	return 0;
}


#include <cctype>
#include <string>
#include <sstream>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

const char *table = "H1 "
"He2 "
"Li3	Be4 "
"B5	C6	N7	O8	F9	Ne10 "
"Na11	Mg12 "
"Al13	Si14	P15	S16	Cl17	Ar18 "
"K19	Ca20	Sc21	Ti22	V23	Cr24	Mn25	Fe26	Co27	Ni28	Cu29	Zn30	Ga31	Ge32	As33	Se34	Br35	Kr36 "
"Rb37	Sr38	Y39	Zr40	Nb41	Mo42	Tc43	Ru44	Rh45	Pd46	Ag47	Cd48	In49	Sn50	Sb51	Te52	I53	Xe54 "
"Cs55	Ba56	La57	Hf72	Ta73	W74	Re75	Os76	Ir77	Pt78	Au79	Hg80	Tl81	Pb82	Bi83	Po84	At85	Rn86 "
"Fr87	Ra88	Ac89 "
"Ce58	Pr59	Nd60	Pm61	Sm62	Eu63	Gd64	Tb65	Dy66	Ho67	Er68	Tm69	Yb70	Lu71 "
"Th90	Pa91	U92	Np93 	Pu94 	Am95	Cm96 	Bk97	Cf98 	Es99	Fm100	Md101";

map<string, int> pm;
map<int, string> mp;
int dpf[1 << 18];
int dps[1 << 18];

void init()
{
	stringstream ss, num;
	ss << table;
	string f;
	while(ss >> f) {
		int n = 0, j = (int)f.length();
		while(isdigit(f[--j]));
		num.clear();
		num << f.substr(j + 1);
		num >> n;
		f = f.substr(0, j + 1);
		pm[f] = n;
		mp[n] = f;
	}
}

vector<int> solve2(vector<int> from, vector<int> to)
{
	int n = (int)from.size(), k = (int)to.size();
	for(int i = 0; i < (1 << n); ++i) {
		int sum = 0;
		for(int j = 0; j < n; ++j) if(i >> j & 1)
			sum += from[j];
		dpf[i] = sum;
		dps[i] = -1;
	}

	vector<int> ans(k, 0);
	int mask = (1 << n) - 1;
	for(int i = 0; i < (1 << n); ++i) {
		int m = ~i & mask;
		for(int j = m; j; j = (j - 1) & m) {
			if(dpf[j] == to[dps[i] + 1]) {
				dps[i | j] = dps[i] + 1;
				ans[dps[i] + 1] = j;
			}
		}
	}
	return dps[mask] == k - 1 ? ans : vector<int>();
}

int main()
{
	init();
	int n, k;
	cin >> n >> k;
	string s;
	vector<int> from(n), to(k);
	for(int i = 0; i < n; ++i) {
		cin >> s;
		from[i] = pm[s];
	}
	for(int i = 0; i < k; ++i) {
		cin >> s;
		to[i] = pm[s];
	}

	if(*max_element(from.begin(), from.end()) > *max_element(to.begin(), to.end())) {
		cout << "NO" << endl;
		return 0;
	}

	vector<int> ans = solve2(from, to);
	if(ans.empty()) {
		cout << "NO" << endl;
	} else {
		cout << "YES" << endl;
		for(int i = 0; i < k; ++i) {
			int sum = 0;
			for(int j = 0, g = 0; j < n; ++j) if(ans[i] >> j & 1) {
				if(g != 0) cout << "+";
				cout << mp[from[j]];
				sum += from[j], ++g;
			}
			cout << "->" << mp[sum] << endl;
		}
	}
	return 0;
}


#include <cctype>
#include <string>
#include <sstream>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

const char *table = "H1 "
"He2 "
"Li3	Be4 "
"B5	C6	N7	O8	F9	Ne10 "
"Na11	Mg12 "
"Al13	Si14	P15	S16	Cl17	Ar18 "
"K19	Ca20	Sc21	Ti22	V23	Cr24	Mn25	Fe26	Co27	Ni28	Cu29	Zn30	Ga31	Ge32	As33	Se34	Br35	Kr36 "
"Rb37	Sr38	Y39	Zr40	Nb41	Mo42	Tc43	Ru44	Rh45	Pd46	Ag47	Cd48	In49	Sn50	Sb51	Te52	I53	Xe54 "
"Cs55	Ba56	La57	Hf72	Ta73	W74	Re75	Os76	Ir77	Pt78	Au79	Hg80	Tl81	Pb82	Bi83	Po84	At85	Rn86 "
"Fr87	Ra88	Ac89 "
"Ce58	Pr59	Nd60	Pm61	Sm62	Eu63	Gd64	Tb65	Dy66	Ho67	Er68	Tm69	Yb70	Lu71 "
"Th90	Pa91	U92	Np93 	Pu94 	Am95	Cm96 	Bk97	Cf98 	Es99	Fm100	Md101";

map<string, int> pm;
map<int, string> mp;
//int dpf[1 << 18];

void init()
{
	stringstream ss, num;
	ss << table;
	string f;
	while(ss >> f) {
		int n = 0, j = (int)f.length();
		while(isdigit(f[--j]));
		num.clear();
		num << f.substr(j + 1);
		num >> n;
		f = f.substr(0, j + 1);
		pm[f] = n;
		mp[n] = f;
	}
}

struct CmpFirstLength
{
	CmpFirstLength(int n) : n_(n) { }

	bool operator() (const pair<int, int>& lhs, const pair<int, int>& rhs) const
	{
		if(lhs.first == rhs.first && n_ > 0) {
			int l = 0, r = 0;
			for(int i = 0; i < n_; ++i) {
				l += (lhs.second >> i & 1) != 0;
				r += (rhs.second >> i & 1) != 0;
			}
			return l < r;
		}
		return lhs.first < rhs.first;
	}

private:
	int n_;
};

struct CmpByCount
{
	CmpByCount(vector<int>& to, vector<int>& cnt) : to_(&to), cnt_(&cnt) { }

	bool operator() (int lhs, int rhs) const
	{
		size_t l = lower_bound(to_->begin(), to_->end(), lhs) - to_->begin();
		size_t r = lower_bound(to_->begin(), to_->end(), rhs) - to_->begin();
		return (*cnt_)[l] < (*cnt_)[r];
	}

private:
	vector<int> *to_;
	vector<int> *cnt_;
};

bool dfs(int k, const vector< pair<int, int> >& data, const vector< pair<int, int> >& ranges, int used, vector<int>& mask, const vector<int>& to)
{
	if(k == (int)to.size())
		return true;
	for(int i = ranges[k].first; i < ranges[k].second; ++i) {
		int nused = used;
		if((nused & data[i].second) != 0)
			continue;
		nused |= mask[k] = data[i].second;
		if(dfs(k + 1, data, ranges, nused, mask, to))
			return true;
		mask[k] = 0;
	}
	return false;
}

vector<int> solve(vector<int> from, vector<int> to)
{
	int n = (int)from.size(), k = (int)to.size();
	vector< pair<int, int> > data, ranges(k);
	vector<int> cnt(k);
	sort(to.begin(), to.end());
	for(int i = 0; i < (1 << n); ++i) {
		int sum = 0;
		for(int j = 0; j < n; ++j) if(i >> j & 1)
			sum += from[j];
		//dpf[i] = sum;
		if(binary_search(to.begin(), to.end(), sum)) {
			data.push_back(make_pair(sum, i));
			++cnt[lower_bound(to.begin(), to.end(), sum) - to.begin()];
		}
	}
	vector<int> tmp = to;
	sort(to.begin(), to.end(), CmpByCount(tmp, cnt));
	sort(data.begin(), data.end(), CmpFirstLength(n));
	for(int i = 0; i < k; ++i) {
		typedef vector< pair<int, int> >::iterator iter_t;
		pair<iter_t, iter_t> range = equal_range(data.begin(), data.end(), make_pair(to[i], 0), CmpFirstLength(-1));
		ranges[i] = make_pair(range.first - data.begin(), range.second - data.begin());
	}
	vector<int> ans(k, 0);
	if(!dfs(0, data, ranges, 0, ans, to))
		return vector<int>();
	return ans;
}

int main()
{
	init();
	int n, k;
	cin >> n >> k;
	string s;
	vector<int> from(n), to(k);
	for(int i = 0; i < n; ++i) {
		cin >> s;
		from[i] = pm[s];
	}
	for(int i = 0; i < k; ++i) {
		cin >> s;
		to[i] = pm[s];
	}

	vector<int> ans = solve(from, to);
	if(ans.empty()) {
		cout << "NO" << endl;
	} else {
		cout << "YES" << endl;
		for(int i = 0; i < k; ++i) {
			int sum = 0;
			for(int j = 0, g = 0; j < n; ++j) if(ans[i] >> j & 1) {
				if(g != 0) cout << "+";
				cout << mp[from[j]];
				sum += from[j], ++g;
			}
			cout << "->" << mp[sum] << endl;
		}
	}
	return 0;
}


#include <cctype>
#include <string>
#include <sstream>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

const char *table = "H1 "
"He2 "
"Li3	Be4 "
"B5	C6	N7	O8	F9	Ne10 "
"Na11	Mg12 "
"Al13	Si14	P15	S16	Cl17	Ar18 "
"K19	Ca20	Sc21	Ti22	V23	Cr24	Mn25	Fe26	Co27	Ni28	Cu29	Zn30	Ga31	Ge32	As33	Se34	Br35	Kr36 "
"Rb37	Sr38	Y39	Zr40	Nb41	Mo42	Tc43	Ru44	Rh45	Pd46	Ag47	Cd48	In49	Sn50	Sb51	Te52	I53	Xe54 "
"Cs55	Ba56	La57	Hf72	Ta73	W74	Re75	Os76	Ir77	Pt78	Au79	Hg80	Tl81	Pb82	Bi83	Po84	At85	Rn86 "
"Fr87	Ra88	Ac89 "
"Ce58	Pr59	Nd60	Pm61	Sm62	Eu63	Gd64	Tb65	Dy66	Ho67	Er68	Tm69	Yb70	Lu71 "
"Th90	Pa91	U92	Np93 	Pu94 	Am95	Cm96 	Bk97	Cf98 	Es99	Fm100	Md101";

map<string, int> pm;
map<int, string> mp;
int dpf[1 << 18];
int dps[1 << 18];
int dpp[1 << 18];

void init()
{
	stringstream ss, num;
	ss << table;
	string f;
	while(ss >> f) {
		int n = 0, j = (int)f.length();
		while(isdigit(f[--j]));
		num.clear();
		num << f.substr(j + 1);
		num >> n;
		f = f.substr(0, j + 1);
		pm[f] = n;
		mp[n] = f;
	}
}

vector<int> solve2(vector<int> from, vector<int> to)
{
	int n = (int)from.size(), k = (int)to.size();
	int mask = (1 << n) - 1;
	for(int i = 0; i <= mask; ++i) {
		int sum = 0;
		for(int j = 0; j < n; ++j) if(i >> j & 1)
			sum += from[j];
		dpf[i] = sum;
		dpp[i] = dps[i] = -1;
	}

	dps[0] = 0;
	for(int i = 0; i <= mask; ++i) if(dps[i] != -1) {
		int m = ~i & mask;
		for(int j = m; j; j = (j - 1) & m) {
			if(dpf[j] == to[dps[i]]) {
				dps[i | j] = dps[i] + 1;
				dpp[i | j] = i;
			}
		}
	}

	vector<int> ans;
	if(dps[mask] == k) {
		int x = mask;
		for(int i = 0; i < k; ++i) {
			ans.push_back(dpp[x] ^ x);
			x = dpp[x];
		}
	}
	return ans;
}

int main()
{
	init();
	int n, k;
	cin >> n >> k;
	string s;
	vector<int> from(n), to(k);
	for(int i = 0; i < n; ++i) {
		cin >> s;
		from[i] = pm[s];
	}
	for(int i = 0; i < k; ++i) {
		cin >> s;
		to[i] = pm[s];
	}

	if(*max_element(from.begin(), from.end()) > *max_element(to.begin(), to.end())) {
		cout << "NO" << endl;
		return 0;
	}

	vector<int> ans = solve2(from, to);
	if(ans.empty()) {
		cout << "NO" << endl;
	} else {
		cout << "YES" << endl;
		for(int i = 0; i < k; ++i) {
			int sum = 0;
			for(int j = 0, g = 0; j < n; ++j) if(ans[i] >> j & 1) {
				if(g != 0) cout << "+";
				cout << mp[from[j]];
				sum += from[j], ++g;
			}
			cout << "->" << mp[sum] << endl;
		}
	}
	return 0;
}


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

int n,m,x[20],y[20],state,s[1<<17],h[105],t[1<<17][2],w,f[20][1<<17],out[20];
char r1[20][5],r2[20][5];
bool b[105],dp[20][1<<17];

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

void adde(int x, int y)
{
	t[w][0]=y;
	t[w][1]=h[x];
	h[x]=w++;
}

void output()
{
	for (int i=0; i<state; i++)
	{
		if (dp[m-1][i])
		{
			printf("YES\n");
			for (int j=m-1; j>=0; j--)
			{
				out[j]=f[j][i];
				i^=f[j][i];
			}
			for (int j=0; j<m; j++)
			{
				for (int k=0; k<n; k++)
				{
					if (out[j]&(1<<k))
					{
						printf("%s",r1[k]);
						out[j]^=1<<k;
						if (out[j])
						{
							printf("+");
						}
					}
				}
				printf("->%s\n",r2[j]);
			}
			return ;
		}
	}
	printf("NO\n");
}

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=0; i<n; i++)
	{
		scanf("%s",r1[i]);
		x[i]=ref(r1[i]);
	}
	for (int i=0; i<=100; i++)
	{
		b[i]=false;
	}
	for (int i=0; i<m; i++)
	{
		scanf("%s",r2[i]);
		y[i]=ref(r2[i]);
		b[y[i]]=true;
	}
	for (int i=0; i<=100; i++)
	{
		h[i]=-1;
	}
	w=0;
	state=(1<<n);
	s[0]=0;
/*for (int i=0; i<n; i++)
{
	printf("%3s",r1[i]);
}printf("\n");
for (int i=0; i<n; i++)
{
	printf("%3d",x[i]);
}printf("\n");
for (int i=0; i<m; i++)
{
	printf("%3s",r2[i]);
}printf("\n");
for (int i=0; i<m; i++)
{
	printf("%3d",y[i]);
}printf("\n");*/
	for (int i=1; i<state; i++)
	{
		for (int j=0; ; j++)
		{
			if (i&(1<<j))
			{
				s[i]=s[i^(1<<j)]+x[j];
				if ((s[i]<=100)&&(b[s[i]]))
				{
//if (i<600) printf("%d %d\n",i,s[i]);
					adde(s[i],i);
				}
				break;
			}
		}
	}
	for (int i=0; i<m; i++)
	{
		for (int j=0; j<state; j++)
		{
			dp[i][j]=false;
		}
	}
	for (int k=h[y[0]]; k!=-1; k=t[k][1])
	{
//printf("%d\n",(state-1)^t[k][0]);
		dp[0][(state-1)^t[k][0]]=true;
		f[0][(state-1)^t[k][0]]=t[k][0];
	}
	for (int i=1; i<m; i++)
	{
		for (int j=0; j<state; j++)
		{
			for (int k=h[y[i]]; k!=-1; k=t[k][1])
			{
//if ((i==1)&&(j==108)) printf("%d   %d %d\n",t[k][0],j&t[k][0]==0,dp[i-1][j^t[k][0]]);
				if (((j&t[k][0])==0)&&(dp[i-1][j^t[k][0]]))
				{
					dp[i][j]=true;
					f[i][j]=t[k][0];
					break;
				}
			}
		}
	}
	output();
	return 0;
}


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

int n,m,x[20],y[20],state,s[1<<17],h[105],t[1<<17][2],w,f[20][1<<17],out[20];
char r1[20][5],r2[20][5];
bool b[105],dp[20][1<<17];

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

void adde(int x, int y)
{
    t[w][0]=y;
    t[w][1]=h[x];
    h[x]=w++;
}

void output()
{
    for (int i=0; i<state; i++)
    {
        if (dp[m-1][i])
        {
            printf("YES\n");
            for (int j=m-1; j>=0; j--)
            {
                out[j]=f[j][i];
                i^=f[j][i];
            }
            for (int j=0; j<m; j++)
            {
                for (int k=0; k<n; k++)
                {
                    if (out[j]&(1<<k))
                    {
                        printf("%s",r1[k]);
                        out[j]^=1<<k;
                        if (out[j])
                        {
                            printf("+");
                        }
                    }
                }
                printf("->%s\n",r2[j]);
            }
            return ;
        }
    }
    printf("NO\n");
}

int main()
{
    scanf("%d%d",&n,&m);
    for (int i=0; i<n; i++)
    {
        scanf("%s",r1[i]);
        x[i]=ref(r1[i]);
    }
    for (int i=0; i<=100; i++)
    {
        b[i]=false;
    }
    for (int i=0; i<m; i++)
    {
        scanf("%s",r2[i]);
        y[i]=ref(r2[i]);
        b[y[i]]=true;
    }
    for (int i=0; i<=100; i++)
    {
        h[i]=-1;
    }
    w=0;
    state=(1<<n);
    s[0]=0;
/*for (int i=0; i<n; i++)
{
    printf("%3s",r1[i]);
}printf("\n");
for (int i=0; i<n; i++)
{
    printf("%3d",x[i]);
}printf("\n");
for (int i=0; i<m; i++)
{
    printf("%3s",r2[i]);
}printf("\n");
for (int i=0; i<m; i++)
{
    printf("%3d",y[i]);
}printf("\n");*/
    for (int i=1; i<state; i++)
    {
        for (int j=0; ; j++)
        {
            if (i&(1<<j))
            {
                s[i]=s[i^(1<<j)]+x[j];
                if ((s[i]<=100)&&(b[s[i]]))
                {
//if (s[i]==12) printf("%d\n",i);
//if (i<600) printf("%d %d\n",i,s[i]);
                    adde(s[i],i);
                }
                break;
            }
        }
    }
    for (int i=0; i<m; i++)
    {
        for (int j=0; j<state; j++)
        {
            dp[i][j]=false;
        }
    }
    for (int k=h[y[0]]; k!=-1; k=t[k][1])
    {
//printf("%d\n",(state-1)^t[k][0]);
        dp[0][(state-1)^t[k][0]]=true;
        f[0][(state-1)^t[k][0]]=t[k][0];
    }
    for (int i=0; i+1<m; i++)
    {
        for (int j=0; j<state; j++)
        {
            if (dp[i][j])
            {
                for (int k=h[y[i+1]]; k!=-1; k=t[k][1])
                {
//if (i==0) printf("t[k][0]  %d\n",t[k][0]);
                    if ((j&t[k][0])==t[k][0])
                    {
//printf("%d %d\n",i,t[k][0]);
                        dp[i+1][j^t[k][0]]=true;
                        f[i+1][j^t[k][0]]=t[k][0];
                    }
                }
            }
        }
    }
    output();
    return 0;
}


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

int n,m,x[20],y[20],state,s[1<<17],h[105],t[1<<17][2],w,f[20][1<<17],out[20];
char r1[20][5],r2[20][5];
bool b[105],dp[20][1<<17];

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

void adde(int x, int y)
{
    t[w][0]=y;
    t[w][1]=h[x];
    h[x]=w++;
}

void output()
{
    for (int i=0; i<state; i++)
    {
        if (dp[m-1][i])
        {
            printf("YES\n");
            for (int j=m-1; j>=0; j--)
            {
                out[j]=f[j][i];
                i^=f[j][i];
            }
            for (int j=0; j<m; j++)
            {
                for (int k=0; k<n; k++)
                {
                    if (out[j]&(1<<k))
                    {
                        printf("%s",r1[k]);
                        out[j]^=1<<k;
                        if (out[j])
                        {
                            printf("+");
                        }
                    }
                }
                printf("->%s\n",r2[j]);
            }
            return ;
        }
    }
    printf("NO\n");
}

int main()
{
    scanf("%d%d",&n,&m);
    for (int i=0; i<n; i++)
    {
        scanf("%s",r1[i]);
        x[i]=ref(r1[i]);
    }
    for (int i=0; i<=100; i++)
    {
        b[i]=false;
    }
    for (int i=0; i<m; i++)
    {
        scanf("%s",r2[i]);
        y[i]=ref(r2[i]);
        b[y[i]]=true;
    }
    for (int i=0; i<=100; i++)
    {
        h[i]=-1;
    }
    w=0;
    state=(1<<n);
    s[0]=0;
/*for (int i=0; i<n; i++)
{
    printf("%3s",r1[i]);
}printf("\n");
for (int i=0; i<n; i++)
{
    printf("%3d",x[i]);
}printf("\n");
for (int i=0; i<m; i++)
{
    printf("%3s",r2[i]);
}printf("\n");
for (int i=0; i<m; i++)
{
    printf("%3d",y[i]);
}printf("\n");*/
    for (int i=1; i<state; i++)
    {
        for (int j=0; ; j++)
        {
            if (i&(1<<j))
            {
                s[i]=s[i^(1<<j)]+x[j];
                if ((s[i]<=100)&&(b[s[i]]))
                {
//if (i<600) printf("%d %d\n",i,s[i]);
                    adde(s[i],i);
                }
                break;
            }
        }
    }
    for (int i=0; i<m; i++)
    {
        for (int j=0; j<state; j++)
        {
            dp[i][j]=false;
        }
    }
    for (int k=h[y[0]]; k!=-1; k=t[k][1])
    {
//printf("%d\n",(state-1)^t[k][0]);
        dp[0][(state-1)^t[k][0]]=true;
        f[0][(state-1)^t[k][0]]=t[k][0];
    }
    for (int i=0; i+1<m; i++)
    {
        for (int j=0; j<state; j++)
        {
            if (dp[i][j])
            {
                for (int k=h[y[i+1]]; k!=-1; k=t[k][1])
                {
//if ((i==1)&&(j==108)) printf("%d   %d %d\n",t[k][0],j&t[k][0]==0,dp[i-1][j^t[k][0]]);
                    if ((j&t[k][0])==t[k][0])
                    {
                        dp[i+1][j^t[k][0]]=true;
                        f[i+1][j^t[k][0]]=t[k][0];
                        break;
                    }
                }
            }
        }
    }
    output();
    return 0;
}


#pragma comment(linker, "/STACK:16777216")

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <climits>
#include <cctype>
#include <cmath>
#include <cassert>
#include <ctime>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

using namespace std;

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }

typedef long long ll;

#define eps 1e-10
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fLL

#define fr(x,y,z) for(int(x)=(y);(x)<(z);(x)++)
#define cast(x,t) *({stringstream ss;static t __ret;ss<<x,ss>>__ret;&__ret;})

#define dbg(x) cout << #x << " == " << x << endl
#define print(x) cout << x << endl

// var
string elem[] = { "1 H", "2 He", "3 Li", "4 Be", "5 B", "6 C", "7 /", "8 O", "9 F", "10 Ne", "11 Na", "12 Mg", "13 Al", "14 Si", "15 P", "16 S", "17 Cl", "18 /", "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", "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", "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", "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", "104 Rf", "105 Db", "106 Sg", "107 Bh", "108 Hs", "109 Mt", "110 Ds", "111 Rg", "112 Cn", "113 Uut", "114 Uuq", "115 Uup", "116 Uuh", "117 Uus", "118 Uuo" };

map<string,int> m;
map<int,string> rm;

int a[20], b[20], n, k;

char f[1<<18][18];
int who[1<<18][18];
int sum[1<<18];

char go(int mask, int pos) {
	if(pos >= k) return 1;
	char &res = f[mask][pos];
	if(res == -1) {
		res = 0;
		for(int sub = mask; sub != 0; sub = (sub-1) & mask) {
			if(sum[sub] == b[pos] && go(mask&~sub,pos+1) ) {
				res = 1;
				who[mask][pos] = sub;
				break;
			}
		}
	}
	//printf("f[%d][%d] = %d\n",mask,pos,(int)res);
	return res;
}

void imp(int mask, int to) {
	for(int i = 0, foi = 0; i < n; i++) if(mask >> i & 1) {
		if(foi++) cout << "+";
		cout << rm[a[i]];
	}
	cout << "->" << rm[b[to]] << endl;
}

int main() {

	for(int i = 0; i < 117; i++) {
		stringstream s(elem[i]);
		string a, b;
		s >> a >> b;
		m[b] = cast(a,int);
		rm[cast(a,int)] = b;
	}

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

	for(int i = 0; i < k; i++) {
		string s;
		cin >> s;
		b[i] = m[s];
	}

	for(int i = 0; i < (1<<n); i++) {
		sum[i] = 0;
		for(int j = 0; j < n; j++) if(i >> j & 1) {
			sum[i] += a[j];
		}
	}

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

	int all= (1<<n) - 1;
	if( go(all,0) ) {
		puts("YES");
		for(int i = 0; i < k; i++) {
			imp( who[all][i], i );
			all = all & ~who[all][i];
		}
	}
	else {
		puts("NO");
	}

	return 0;
}


#pragma comment(linker, "/STACK:16777216")

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <climits>
#include <cctype>
#include <cmath>
#include <cassert>
#include <ctime>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

using namespace std;

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }

typedef long long ll;

#define eps 1e-10
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fLL

#define fr(x,y,z) for(int(x)=(y);(x)<(z);(x)++)
#define cast(x,t) *({stringstream ss;static t __ret;ss<<x,ss>>__ret;&__ret;})

#define dbg(x) cout << #x << " == " << x << endl
#define print(x) cout << x << endl

// var
string elem[] = { "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", "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", "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", "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", "104 Rf", "105 Db", "106 Sg", "107 Bh", "108 Hs", "109 Mt", "110 Ds", "111 Rg", "112 Cn", "113 Uut", "114 Uuq", "115 Uup", "116 Uuh", "117 Uus", "118 Uuo" };

map<string,int> m;
map<int,string> rm;

int a[20], b[20], n, k;

char f[1<<18][18];
int who[1<<18][18];
int sum[1<<18];

char go(int mask, int pos) {
	if(pos >= k) return 1;
	char &res = f[mask][pos];
	if(res == -1) {
		res = 0;
		for(int sub = mask; sub != 0; sub = (sub-1) & mask) {
			if(sum[sub] == b[pos] && go(mask&~sub,pos+1) ) {
				res = 1;
				who[mask][pos] = sub;
				break;
			}
		}
	}
	//printf("f[%d][%d] = %d\n",mask,pos,(int)res);
	return res;
}

void imp(int mask, int to) {
	for(int i = 0, foi = 0; i < n; i++) if(mask >> i & 1) {
		if(foi++) cout << "+";
		cout << rm[a[i]];
	}
	cout << "->" << rm[b[to]] << endl;
}

int main() {

	for(int i = 0; i < 117; i++) {
		stringstream s(elem[i]);
		string a, b;
		s >> a >> b;
		m[b] = cast(a,int);
		rm[cast(a,int)] = b;
	}

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

	for(int i = 0; i < k; i++) {
		string s;
		cin >> s;
		b[i] = m[s];
	}

	for(int i = 0; i < (1<<n); i++) {
		sum[i] = 0;
		for(int j = 0; j < n; j++) if(i >> j & 1) {
			sum[i] += a[j];
		}
	}

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

	int all= (1<<n) - 1;
	if( go(all,0) ) {
		puts("YES");
		for(int i = 0; i < k; i++) {
			imp( who[all][i], i );
			all = all & ~who[all][i];
		}
	}
	else {
		puts("NO");
	}

	return 0;
}


/* DP, O(n*2^n + 3^n) */

#include<map>
#include<string>
#include<cstring>
#include<iostream>

#define	rep(i,n)	for(int i=0;i<(n);i++)

using namespace std;

int main(){
	string name[]={"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"};
	map<string,int> table;
	rep(i,100)	table[name[i]]=i+1;

	int n,k,w[17],w2[17];	cin>>n>>k;
	string atom[17],atom2[17];
	rep(i,n){
		cin>>atom[i];
		w[i]=table[atom[i]];
	}
	rep(i,k){
		cin>>atom2[i];
		w2[i]=table[atom2[i]];
	}

	static int sum[1<<17];
	rep(S,1<<n) rep(j,n) if(S&(1<<j)) sum[S]+=w[j];

	static int dp[1<<17],root[1<<17];
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
	const int Omega=(1<<n)-1;	// universal set
	rep(S,1<<n){
		int T=Omega^S,num=dp[S];
		if(num==-1 || k<=num)	continue;
		for(int subT=T;subT>=0;subT--){	// foreach subset in T
			subT&=T;
			if(sum[subT]==w2[num]){
				dp[S|subT]=num+1;
				root[S|subT]=S;
			}
		}
	}

	if(dp[Omega]<k)	cout<<"NO"<<endl;
	else{
		cout<<"YES"<<endl;
		for(int i=k-1,S=Omega;S!=0;S=root[S]){
			string s;
			int T=S^root[S];
			rep(j,n)if(T&(1<<j)){
				if(s.length()>0)	s+='+';
				s+=atom[j];
			}
			cout<<s<<"->"<<atom2[i--]<<endl;
		}
	}

	return 0;
}


/* DP, O(n*2^n + 3^n) */

#include<map>
#include<string>
#include<cstring>
#include<iostream>

#define	rep(i,n)	for(int i=0;i<(n);i++)

using namespace std;

int main(){
	string name[]={"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"};
	map<string,int> table;
	rep(i,100)	table[name[i]]=i+1;

	int n,k,w[17],w2[17];	cin>>n>>k;
	string atom[17],atom2[17];
	rep(i,n){
		cin>>atom[i];
		w[i]=table[atom[i]];
	}
	rep(i,k){
		cin>>atom2[i];
		w2[i]=table[atom2[i]];
	}

	static int sum[1<<17];
	rep(S,1<<n) rep(j,n) if(S&(1<<j)) sum[S]+=w[j];

	static int dp[1<<17],route[1<<17];
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
	const int Omega=(1<<n)-1;	// universal set
	rep(S,1<<n)if(~dp[S]){
		int T=Omega^S,num=dp[S];
		for(int subT=T;subT>=0;subT--){	// foreach subset in T
			subT&=T;
			if(sum[subT]==w2[num]){
				dp[S|subT]=num+1;
				route[S|subT]=S;
			}
		}
	}

	if(dp[(1<<n)-1]<k)	cout<<"NO"<<endl;
	else{
		cout<<"YES"<<endl;
		for(int i=k-1,S=(1<<n)-1;S!=0;S=route[S]){
			string s;
			int T=S^route[S];
			rep(j,n)if(T&(1<<j)){
				if(s.length()>0)	s+='+';
				s+=atom[j];
			}
			cout<<s<<"->"<<atom2[i--]<<endl;
		}
	}

	return 0;
}


#include<map>
#include<string>
#include<cstring>
#include<iostream>

#define	rep(i,n)	for(int i=0;i<(n);i++)

using namespace std;

int main(){
	string name[]={"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"};
	map<string,int> table;
	rep(i,100)	table[name[i]]=i+1;

	int n,k,w[17],w2[17];	cin>>n>>k;
	string atom[17],atom2[17];
	rep(i,n){
		cin>>atom[i];
		w[i]=table[atom[i]];
	}
	rep(i,k){
		cin>>atom2[i];
		w2[i]=table[atom2[i]];
	}

	static int sum[1<<17];
	rep(S,1<<n) rep(j,n) if(S&(1<<j)) sum[S]+=w[j];

	static int dp[1<<17],route[1<<17];
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
	const int Omega=(1<<n)-1;	// universal set
	rep(S,1<<n)if(~dp[S]){
		int T=Omega^S,num=dp[S];
		rep(subT,T+1)if((T|subT)==T){	// foreach subset in T
			if(sum[subT]==w2[num]){
				dp[S|subT]=num+1;
				route[S|subT]=S;
			}
		}
	}

	if(dp[(1<<n)-1]<k)	cout<<"NO"<<endl;
	else{
		cout<<"YES"<<endl;
		for(int i=k-1,S=(1<<n)-1;S!=0;S=route[S]){
			string s;
			int T=S^route[S];
			rep(j,n)if(T&(1<<j)){
				if(s.length()>0)	s+='+';
				s+=atom[j];
			}
			cout<<s<<"->"<<atom2[i--]<<endl;
		}
	}

	return 0;
}


/* DP, O(n*2^n + 3^n) */

#include<map>
#include<string>
#include<cstring>
#include<iostream>

#define	rep(i,n)	for(int i=0;i<(n);i++)

using namespace std;

int main(){
	string name[]={"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"};
	map<string,int> table;
	rep(i,100)	table[name[i]]=i+1;

	int n,k,w[17],w2[17];	cin>>n>>k;
	string atom[17],atom2[17];
	rep(i,n){
		cin>>atom[i];
		w[i]=table[atom[i]];
	}
	rep(i,k){
		cin>>atom2[i];
		w2[i]=table[atom2[i]];
	}

	static int sum[1<<17];
	rep(S,1<<n) rep(j,n) if(S&(1<<j)) sum[S]+=w[j];

	static int dp[1<<17],route[1<<17];
	memset(dp,-1,sizeof(dp));
	memset(route,0,sizeof(route));
	dp[0]=0;
	const int Omega=(1<<n)-1;	// universal set
	rep(S,1<<n)if(~dp[S]){
		int T=Omega^S,num=dp[S];
		for(int subT=T;subT>=0;subT--){	// foreach subset in T
			subT&=T;
			if(sum[subT]==w2[num]){
				dp[S|subT]=num+1;
				route[S|subT]=S;
			}
		}
	}

	if(dp[(1<<n)-1]<k)	cout<<"NO"<<endl;
	else{
		cout<<"YES"<<endl;
		for(int i=k-1,S=Omega;S!=0;S=route[S]){
			string s;
			int T=S^route[S];
			rep(j,n)if(T&(1<<j)){
				if(s.length()>0)	s+='+';
				s+=atom[j];
			}
			cout<<s<<"->"<<atom2[i--]<<endl;
		}
	}

	return 0;
}