#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>

using namespace std;

char ans[ 100 ][ 100000 ];
char str1[ 100000 ];
char str2[ 100000 ];

int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	int a[ 100 ];
	a[ 0 ] = a[ 1 ] = 0;
	for (int i = 2; i <= 15; i++)
	{
		int sum = 0;
		for (int j = 0; j < i; j++)
			sum += a[ j ];
		a[ i ] = i - 1 + sum;
	}

	cin >> str1;
	cin >> str2;

	int count1 = 0;
	int count2 = 0;
	for (int i = 0; i < strlen(str1); i++)
		if (str1[ i ] == ',')
			count1++;
	for (int i = 0; i < strlen(str2); i++)
		if (str2[ i ] == ',')
			count2++;

	int num1, num2;

	if (count1 == 0)
	{
		if (strlen(str1) == 2)
			num1 = 0;
		else 
			num1 = 1;
	}
	if (count2 == 0)
	{
		if (strlen(str2) == 2)
			num2 = 0;
		else 
			num2 = 1;
	}

	for (int i = 2; i <= 15; i++)
	{
		if (count2 == a[ i ])
			num2 = i;
		if (count1 == a[ i ])
			num1 = i;
	}

	int num = num1 + num2;

	strcpy(ans[ 0 ], "{}");
	strcpy(ans[ 1 ], "{{}}");

	for (int i = 2; i <= 15; i++)
	{
		strcat(ans[ i ], "{");
		for (int j = 0; j < i - 1; j++)
		{
			strcat(ans[ i ], ans[ j ]);
			strcat(ans[ i ], ",");
		}
		strcat(ans[ i ], ans[ i - 1 ]);
		strcat(ans[ i ], "}");
	}

	cout << ans[ num ] << endl;
	
	
	fclose(stdin);
    fclose(stdout);
	return 0;
/*
{{}}
{{},{{}}}
*/
}