#include #include #include #include using namespace std; long long st[101010]; // Single line reading functions for multi-case & NO final case notification inputs // Verified: https://codeforces.com/gym/100162/problem/G std::vector read_ints() { std::string s; std::getline(std::cin, s); if (s.empty()) return {}; std::stringstream ss(s); std::vector ret; while (!ss.eof()) { int t; ss >> t; ret.push_back(t); } return ret; } std::string read_str() { std::string s; std::getline(std::cin, s); return s; } int main() { cin.tie(nullptr)->sync_with_stdio(false); string s = read_str(); // vector st{0}; // bool is_inf = false; constexpr long long thres = 1000000000000000000LL; int rr = 0; for (int i = (int)s.size() - 1; i >= 0; --i) { if (s.at(i) == '(') { if (rr == 0) { st[rr] += 1; break; } const auto v = st[rr--]; // st.pop_back(); if (v >= 60) { puts("INFTY"); return 0; // is_inf = true; // v = 0; } st[rr] += 1LL << v; if (st[rr] > thres) { puts("INFTY"); return 0; // is_inf = true; // st.back() = 0; } } else { st[++rr] = 0; // st.push_back(0); } } // while (st.size() > 1) st[0] += 1; if (rr) st[0] += 1; // auto ret = st.front(); // if (ret > thres) is_inf = true; if (st[0] > thres) { puts("INFTY"); } else { printf("%lld\n", st[0]); } }