#include using namespace std; string advance(string &S, int &p){ int cnt = 0; string ans; while (true){ ans += S[p]; if (S[p] == '('){ cnt++; } if (S[p] == ')'){ cnt--; } p++; if (cnt == 0 && S[p] != '('){ break; } } return ans; } tuple parse(string S){ int p = 1; string s1; if (S[p] == '('){ s1 = advance(S, p); } p++; string s2; if (S[p] == '('){ s2 = advance(S, p); } p++; string s3 = S.substr(p); return make_tuple(s1, s2, s3); } int comp(string S, string T){ if (S == "" && T == ""){ return 0; } if (S == ""){ return -1; } if (T == ""){ return 1; } vector s; while (true){ string S1, S2, S3; tie(S1, S2, S3) = parse(S); s.push_back("(" + S1 + "|" + S2 + ")"); if (S3 == ""){ break; } S = S3; } vector t; while (true){ string T1, T2, T3; tie(T1, T2, T3) = parse(T); t.push_back("(" + T1 + "|" + T2 + ")"); if (T3 == ""){ break; } T = T3; } int N = s.size(); int M = t.size(); vector s2; s2.push_back(s[0]); for (int i = 1; i < N; i++){ while (!s2.empty()){ if (comp(s2.back(), s[i]) == -1){ s2.pop_back(); } else { break; } } s2.push_back(s[i]); } vector t2; t2.push_back(t[0]); for (int i = 1; i < M; i++){ while (!t2.empty()){ if (comp(t2.back(), t[i]) == -1){ t2.pop_back(); } else { break; } } t2.push_back(t[i]); } N = s2.size(); M = t2.size(); if (N == 1 && M == 1){ string S1 = get<0>(parse(s2[0])); string S2 = get<1>(parse(s2[0])); string T1 = get<0>(parse(t2[0])); string T2 = get<1>(parse(t2[0])); int p = comp(S1, T1); if (p == 0){ return comp(S2, T2); } if (p == -1){ return comp(S2, t2[0]); } if (p == 1){ return comp(s2[0], T2); } } else { s2.push_back(""); t2.push_back(""); int p = 0; while (true){ int r = comp(s2[p], t2[p]); if (r != 0){ return r; } if (s2[p] == "" && t2[p] == ""){ return 0; } p++; } } } int main(){ string T1; cin >> T1; string T2; cin >> T2; int ans = comp(T1, T2); if (ans == 1){ cout << 0 << endl; } else { cout << 1 << endl; } }