#include #include #include using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); string s; cin >> s; vector st{0}; bool is_inf = false; constexpr long long thres = 1000000000000000000LL; for (int i = (int)s.size() - 1; i >= 0; --i) { if (s.at(i) == '(') { if (st.size() == 1) { st.back() += 1; break; } auto v = st.back(); st.pop_back(); if (v >= 60) { is_inf = true; v = 0; } st.back() += 1LL << v; if (st.back() > thres) { is_inf = true; st.back() = 0; } } else { st.push_back(0); } } auto ret = st.front(); if (ret > thres) is_inf = true; if (is_inf) { puts("INFTY"); } else { cout << ret << endl; } }