import java.util.*;
import java.io.*;

public class taskI {
	
	// Stepanov Iliya

	Scanner in;
	PrintWriter out;
	
	class Num {
		int val;
		int tmp;		
		
		Num (int value, int temp) {
			val = value;
			tmp = temp;
		}
	}

	Num readNumber(char[] a, int number, boolean firstRun, int length, int val) {
		// boolean stop = false;
		//if (firstRun) {
		
		//	firstRun = false;
		//}
		
		boolean once = true;
		for (int j = 0; j < length; j++) {
			//out.print(a[j]);
			if (once) {
				//number++;
				val++;
				//out.println(number);
				once = false;
			}
		}
		//out.println(val);

		int i = length - 2;
		if (i == 0 || i == 2) {
			Num num = new Num(val, number);
			return num;
		} else {
			//if (firstRun) {
			//	number = 0;
			//	firstRun = false;
			//}
			int scope = 0;
			int cnt = 0;
			char[] b = new char[length];
			// StringBuilder b = new StringBuilder(a.toString());
			boolean found = false;
			while (!found && cnt < length) {
				// b.setCharAt(cnt, a[i]);
				b[cnt] = a[i];
				// out.print(b[cnt]);
				if (a[i] == '}') {
					scope--;
				} else if (a[i] == '{') {
					scope++;
				}
				if (scope == 0) {
					found = true;
				}
				i--;
				cnt++;
			}
			// b.reverse();
			for (int m = 0; m < cnt / 2; m++) {
				char buf = b[m];
				b[m] = b[cnt - m - 1];
				b[cnt - m - 1] = buf;
				// out.print(b[m]);
			}
			
			//number++;
			
			//for (int j = 0; j < cnt; j++) {
			//	out.print(b[j]);
			//}
			//out.println();
			
			return readNumber(b, number, firstRun, cnt, val);
			//out.println(val);
			//return val;
		}
		/*for (int i = a.length - 1; i < a.length; i++) {
			if (a[i] == '{') {
				
			}
		}*/
		
		//return 0;
	}
	
	//void writeTmpNum(int tmpNum) {
	//	
	//}
	
	void writeNumber(int num) {
		if (num == 0) {
			out.print("{}");
		} else if (num == 1) {
			out.print("{{}}");
		} else {
			out.print("{");
			writeNumber(0);
			for (int i = 1; i < num; i++) {
				out.print(",");
				writeNumber(i);
			}
			out.print("}");
		}
	}
	
	void solve() {
		//StringBuilder a1 = new StringBuilder(in.next());
		//StringBuilder a2 = new StringBuilder(in.next());
		
		int num1 = 0;
		char[] a1 = in.next().toCharArray();
		int number = a1.length/2 - 1;
		//char[] a2 = in.next().toCharArray();
		boolean firstRun = true;
		//out.println(number);
		int cnt = 0;
		if (a1.length > 2) {
			num1 = readNumber(a1, number, firstRun, a1.length, 0).val;
			//out.println(num1);
			//out.println(readNumber(a1, number, firstRun, a1.length, 0).val);
		}
		//out.println(readNumber(a1, number, firstRun, a1.length));
		
		int num2 = 0;
		char[] a2 = in.next().toCharArray();
		number = a2.length/2 - 1;
		firstRun = true;
		cnt = 0;
		if (a2.length > 2) {
			num2 = readNumber(a2, number, firstRun, a2.length, 0).val;
			//out.println(num2);
			//out.println(readNumber(a1, number, firstRun, a1.length, 0).val);
		}
		
		int sum = num1 + num2;
		//out.println(sum);
		
		writeNumber(sum);
	}
	
	void run() {
		try {
			in = new Scanner(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		} catch (Exception e) {
			in = new Scanner(System.in);
			out = new PrintWriter(System.out);
		}
		try {
			solve();
		} finally {
			out.close();
		}
	}
	
	public static void main (String args[]) {
		new taskI().run();
	}
}