#include <cstdio>
#include <iostream>
#include <string.h>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

vector<char> s[17], s1, s2;
char ss[100000]={0};
int i, j, ii, jj, n, k, k1=0, k2=0;
bool cmp(vector<char> a, vector<char> b)
{
	int n1, n2;
	n1 = a.size();
	n2 = b.size();
	if(n1!=n2)
		return 0;
	for(i=0; i<n1; i++)
		if(a[i]!=b[i])
			return 0;
	return 1;
}
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	s[0].push_back('{');
	s[0].push_back('}');
	for(i=1; i<=16; i++)
	{
		s[i].push_back('{');
		for(j=0; j<i; j++)
		{
			n = s[j].size();
			for(jj=0; jj<n; jj++)
			{
				ii++;
				s[i].push_back(s[j][jj]);
			}
			if(j!=i-1) s[i].push_back(',');
			else s[i].push_back('}');
		}
	}
	gets(ss);
	for(i=0; i<strlen(ss); i++)
		s1.push_back(ss[i]);
	gets(ss);
	for(i=0; i<strlen(ss); i++)
		s2.push_back(ss[i]);
	for(j=0; j<=15; j++)
	{
		if(cmp(s[j],s1)==1)
			k1 = j;
		if(cmp(s[j],s2)==1)
			k2 =  j;
	}
	k = k1 + k2;
	n = s[k].size();
	for(i=0; i<n; i++)
		printf("%c", s[k][i]);
	return 0;
}