#include <stdio.h>
#include <string.h>

int Chiselko(int count)
{
	if(count == 1) return 0;
	return (1+Chiselko(count/2));
}
int bI(int count,char str[103])
{
	if(count==0)
	{
		str=strcat(str,"{}");
		return 0;
	}
	str=strcat(str,"{");
	for(int i=0;i<count;i++)
	{
		bI(i,str);
		if(i<count-1)
		str=strcat(str,",");
	}
	str=strcat(str,"}");
	return 0;
}
int main()
{
	FILE *fin;
	FILE *fout;
	fin=fopen("input.txt","r");
	fout=fopen("output.txt","w");
	int a=0;
	int i=0;
	int count=0;
	char str[103];
	for(int j=0;j<2;j++)
	{
		fgets(str,102,fin);
		if(str[0]!='{')
		{
			a=0;
			break;
		}
		i=0;
		while(str[i]!='0')
		{
			if(str[i]=='{')
				count++;
			i++;
		}
		a=a+Chiselko(count);
		count=0;
	}
	str[0]='\0';
	bI(a,str);
	fprintf(fout,"%s",str);
	fclose(fin);
	fclose(fout);
	return 0;
}