// LUOGU_RID: 115684560
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int M = 20;
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"};
int n,m,a[M],b[M],f[M][1<<18];
string t;vector<int> v;
int work(string x){
for(int i=1;i<=100;i++)
if(s[i]==x) return i;
}
void print(){
int sum=0,j=0;
for(int i=0;i<v.size();i++){
sum+=v[i];
cout<<s[v[i]];
if(sum==b[j]){
printf("->");
cout<<s[b[j++]];
puts("");sum=0;
}
else printf("+");
}
exit(0);
}
void dfs(int x,int sum,int s){
if(sum==b[x]){
if(x==m){
puts("YES");
print();
}
else dfs(x+1,0,s);
return ;
}
if(sum>b[x]) return ;
if(f[x][s]) return ;
for(int i=0;i<n;i++){
if(s&(1<<i)) continue;
v.push_back(a[i]);
dfs(x,sum+a[i],s|(1<<i));
v.pop_back();
}
f[x][s]=1;
}
signed main(){
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>t;
a[i]=work(t);
}
for(int i=0;i<m;i++){
cin>>t;
b[i]=work(t);
}
dfs(0,0,0);cout<<"NO";
return 0;
}
933A - A Twisty Movement | 1722F - L-shapes |
1196B - Odd Sum Segments | 1325D - Ehab the Xorcist |
552B - Vanya and Books | 1722E - Counting Rectangles |
168A - Wizards and Demonstration | 168B - Wizards and Minimal Spell |
7A - Kalevitch and Chess | 912B - New Year's Eve |
1537C - Challenging Cliffs | 879B - Table Tennis |
1674E - Breaking the Wall | 1282A - Temporarily unavailable |
1366C - Palindromic Paths | 336A - Vasily the Bear and Triangle |
926A - 2-3-numbers | 276D - Little Girl and Maximum XOR |
1253C - Sweets Eating | 1047A - Little C Loves 3 I |
758D - Ability To Convert | 733A - Grasshopper And the String |
216A - Tiling with Hexagons | 1351B - Square |
1225A - Forgetting Things | 1717A - Madoka and Strange Thoughts |
1717B - Madoka and Underground Competitions | 61B - Hard Work |
959B - Mahmoud and Ehab and the message | 802G - Fake News (easy) |