#line 1 "nachia\\math\\ordinal.hpp" #include #include #include namespace nachia{ // (X|Y)Z = φ_X (Y) + Z struct Ordinal { std::shared_ptr p; Ordinal() : p(nullptr) {} Ordinal(Ordinal phisuf, Ordinal phiarg, Ordinal plus); const struct OrdinalCore* operator->() const { return p.get(); } static Ordinal Zero(){ return Ordinal(); } static Ordinal One(){ return Ordinal(Zero(), Zero(), Zero()); } bool isZero(){ return !p; } Ordinal(Ordinal omega_to, Ordinal plus) : Ordinal(Zero(), omega_to, plus) {} }; struct OrdinalCore { Ordinal phisuf; Ordinal phiarg; Ordinal plus; OrdinalCore(Ordinal _phisuf, Ordinal _phiarg, Ordinal _plus) : phisuf(_phisuf) , phiarg(_phiarg) , plus(_plus) {} }; Ordinal::Ordinal(Ordinal phisuf, Ordinal phiarg, Ordinal plus) : p(std::make_shared(phisuf, phiarg, plus)) {} bool operator<(Ordinal l, Ordinal r){ if(r.isZero()) return false; if(l.isZero()) return true; auto ltp = [](Ordinal l, Ordinal r) -> bool { if(l->phisuf < r->phisuf) return l->phiarg < r; if(r->phisuf < l->phisuf) return l < r->phiarg; return l->phiarg < r->phiarg; }; std::vector L, R; for(int x=0; x<2; x++){ while(!l.isZero()){ auto nx = Ordinal(l->phisuf, l->phiarg, Ordinal::Zero()); while(L.size() && ltp(L.back(), nx)) L.pop_back(); L.push_back(nx); l = l->plus; } std::swap(l,r); std::swap(L,R); } return lexicographical_compare(L.begin(), L.end(), R.begin(), R.end(), ltp); } } // namespace nachia #line 2 "Main.cpp" #include #include #define rep(i,n) for(int i=0; i<(int)(n); i++) nachia::Ordinal construct(std::string s){ using Ty = nachia::Ordinal; auto mid = [&](auto& mid, int& p) -> Ty { if(p == (int)s.size() || s[p] != '(') return Ty::Zero(); Ty t[3]; rep(i,3) t[i] = mid(mid, ++p); return Ty(t[0], t[1], t[2]); }; int p = 0; return mid(mid, p); } int main(){ std::string T0, T1; std::cin >> T0 >> T1; auto t0 = construct(T0); auto t1 = construct(T1); if(t1 < t0) std::cout << "0\n"; else std::cout << "1\n"; return 0; }