Problem:
失われし数
時は3xxx年、高度に発達した文明は停滞期を迎えていた。歴史家たちはこの状況を打開しようと過去の叡智を学ぶことにした。注目したのはコンピュータ創世期の天才が残した資料である。この資料には計算式が書かれておりその計算結果が知りたいのだが、残念ながらその一部の文字が薄れて読めなくなっている。仕方がないので計算結果としてありえる最も大きい数を求めることにした。

計算式は2進数で書かれており、演算は足し算・引き算・掛け算の3種類である。括弧も用いられているが括弧内が数字のみであることはない。正確には以下のBNFで定義された文法を満たしている必要がある。
<expression> ::= <number> | <expression> <operation> <expression>
| ( <expression> <operation> <expression> )
<number> ::= <digit> | <number> <digit>
<operation> ::= + | - | *
<digit> ::= 0 | 1
当時のコンピュータの計算能力の限界により、数字は0以上
2
10
未満の整数であり計算中もこの範囲を出ることはない。ただし計算は括弧内を先に行い、掛け算は足し算・引き算より先に行う。それ以外の場合は左から順に計算する。
Input
入力は1行からなり、解読すべき数式が1つ与えられる。数式は1文字以上100文字以下である。1つの数式について最大5文字が読めなくなっていて、「.」で表現されている。与えられる数式に含まれる文字は01+-*().のいずれかである。
Constraints
数式は1文字以上100文字以下
改行を除くすべての文字は01+-*().のいずれか
.の個数は5個以下
Output
元の数式として考えられるものの内、計算結果が最大となるものを求め、計算結果を10進法で出力せよ。読めなくなっている文字をどのように埋めても元の数式と考えられるものを作れないときは-1を出力せよ。
Sample Input 1
000
Output for the Sample Input 1
0
Sample Input 2
0.0
Output for the Sample Input 2
2
Sample Input 3
...
Output for the Sample Input 3
7
Sample Input 4
(1.1)
Output for the Sample Input 4
2
Sample Input 5
0-1.
Output for the Sample Input 5
-1

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
 
constexpr ll M = 1e9+7;

const string w = "01+-*()";

constexpr int mi = 0;
constexpr int ma = 1023;

bool isrange(int n) {
    return mi <= n && n <= ma;
}

int expr(string const& s, int& p);
int term(string const& s, int& p);
int factor(string const& s, int& p);
int number(string const& s, int& p);

int expr(string const& s, int& p) {
    int res = term(s, p);
    while(p < s.size() && (s[p] == '+' || s[p] == '-')) {
        if(s[p] == '+') {
            res += term(s, ++p);
        } else if(s[p] == '-') {
            res -= term(s, ++p);
        }
        if(!isrange(res)) {
            throw runtime_error("");
        }
    }
    return res;
}

int term(string const& s, int& p) {
    int res = factor(s, p);
    while(p < s.size() && s[p] == '*') {
        res *= factor(s, ++p);
        if(!isrange(res)) {
            throw runtime_error("");
        }
    }
    return res;
}

int factor(string const& s, int& p) {
    if(isdigit(s[p])) {
        return number(s, p);
    }
    if(s[p] == '-') {
        int res = -factor(s, ++p);
        if(!isrange(res)) {
            throw runtime_error("");
        }
        return res;
    } else if(s[p] == '(') {
        int res = expr(s, ++p);
        if(p < s.size() && s[p] != ')') {
            throw runtime_error("");
        }
        ++p;
        return res;
    } else {
        throw runtime_error("");
    }
}

int number(string const& s, int& p) {
    int res = 0;
    while(p < s.size() && isdigit(s[p])) {
        res <<= 1;
        res |= s[p] == '1';
        ++p;
    }
    if(!isrange(res)) {
        throw runtime_error("");
    }
    return res;
}

bool check(string const& s) {
    stack<int> st;
    vector<vector<bool>> par(s.size(), vector<bool>(s.size()));
    bool ok = true;
    for(int i=0; i<s.size(); ++i) {
        if(s[i] == '(') {
            st.push(i);
        }
        if(s[i] == ')') {
            if(st.empty()) {
                ok = false;
                break;
            }
            if(s[st.top()+1] == '(' && s[i-1] == ')' && par[st.top()+1][i-1]) {
                ok = false;
                break;
            }
            par[st.top()][i] = true;
            bool f = false;
            for(int j=st.top()+1; j<i; ++j) {
                f |= !isdigit(s[j]);
            }
            st.pop();
            ok &= f;
        }
    }
    return st.empty() && ok;
}

int solve(int i, string& s, vector<int> const& lost) {
    int res = -1;
    if(i == lost.size()) {
        try {
            int p = 0;
            if(check(s)) {
                res = expr(s, p);
            }
            return (p == s.size() ? res : -1);
        } catch(...) {
            return -1;
        }
    }
    for(int j=0; j<w.size(); ++j) {
        s[lost[i]] = w[j];
        res = max(res, solve(i+1, s, lost));
    }
    return res;
}

int main() {
    string s;
    cin >> s;
    vector<int> pos;
    for(int i=0; i<s.size(); ++i) {
        if(s[i] == '.') {
            pos.push_back(i);
        }
    }
    cout << solve(0, s, pos) << endl;
}
accuracy: 1
time_ms: 110
memory_kb: 3532
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto&& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;

bool isin(char c, string t) {
	foa(e, t) if(c == e) return true;
	return false;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
	string C = "01+-*()";

	string s; cin >> s;
	vector<int> vec;
	int n = s.size();
	rep(i, n) {
		if(s[i] == '.') {
			vec.pb(i);
		}
	}
	int sz = vec.size();
	int ans = -1;
	
	auto solve = [&](string t) -> void {
		string u = "";
		vector<string> v;
		int sum = -1;
		foa(e, t) {
			if(e == '0' or e == '1') {
				if(sum == -1) sum = e - '0';
				else {
					sum *= 2;
					sum += e - '0';
				}
				if(sum >= 1024) return;
			} else {
				if(sum == -1) {
					u += e;
					v.push_back(string(1, e));
				}
				else {
					u += to_string(sum);
					v.pb(to_string(sum));
					sum = -1;
					u += e;
					v.push_back(string(1, e));
				}
			}
			if(sum >= 1024) return;
		}
		
		if(sum != -1) {
			u += to_string(sum);
			v.pb(to_string(sum));
		}
		int num = 0;
		foa(e, u) {
			if(e == '(') num ++;
			else if(e == ')') {
				num --;
				if(num < 0) return;
			}
		}
		if(num) return;
		int usz = u.size() - 1;
		rep(i, usz) if(isin(u[i], "*+-") and isin(u[i + 1], "*+-")) return;
		rep(i, usz) if(isin(u[i], "*+-") and isin(u[i + 1], ")")) return;
		rep(i, usz) if(isin(u[i], "(") and isin(u[i + 1], "*+-")) return;
		rep(i, usz) if(isin(u[i], ")") and isin(u[i + 1], "(")) return;
		rep(i, usz) if(isin(u[i], "(") and isin(u[i + 1], ")")) return;

		int szv = v.size();
		rep(j, szv - 2) {
			if(isin(v[j][0], "(") and isin(v[j + 2][0], ")")) return;
		}
		bool ng = 0;
		auto dfs = [&](auto dfs, int i, bool flag) -> pair<int, int> {
			int K = i;
			vector<char> a;
			vector<int> b;
			int p = -1;
			while(i < szv and v[i] != ")") {
				if(v[i] == "(") {
					auto [val, id] = dfs(dfs, i + 1, 1);
					if(!(0 <= val and val < 1024)) {
						ng = 1;
						val = 0;
					}
					i = id + 1;
					if(p == 0) ng = 1;
					p = 0;
					b.pb(val);
					continue;
				}
				assert(v[i] != ")");
				if(isin(v[i][0], "*+-")) {
					if(p != 0) ng = 1;
					p = 1;
					a.pb(v[i][0]);
				} else {
					if(p == 0) ng = 1;
					p = 0;
					b.pb(stoi(v[i]));
				}
				i ++;
			}
			vector<char> A;
			vector<int> B;
			int ss = a.size();
			if(flag and ss == 0) ng = 1;
			if(ss + 1 != (int)b.size()) {
				ng = 1;
				a.clear();
				ss = 0;
				b.pb(0);
			}
			B.pb(b[0]);
			rep(j, ss) {
				if(a[j] == '*') {
					B.back() *= b[j + 1];
					if(B.back() >= 1024) {
						B.back() = 0;
						ng = 1;
					}
				} else {
					A.pb(a[j]);
					B.pb(b[j + 1]);
				}
			}
			int sum = B[0];
			ss = A.size();
			rep(j, ss) {
				if(A[j] == '-') {
					sum -= B[j + 1];
					if(sum < 0 or sum >= 1024) {
						ng = 1;
						sum = 0;
					}
				} else {
					sum += B[j + 1];
					if(sum < 0 or sum >= 1024) {
						ng = 1;
						sum = 0;
					}
				}
			}
			return {sum, i};
		};
		auto [val, i] = dfs(dfs, 0, 0);
		if(!ng) ans = max(ans, val);
	};
	auto dfs1 = [&](auto dfs1, int vec_i, string in) -> void {
		if(vec_i == sz) {
			string t = s;
			rep(i, sz) t[vec[i]] = in[i];
			solve(t);
			return;
		}
		foa(e, C) {
			dfs1(dfs1, vec_i + 1, in + e);
		}
	};
	dfs1(dfs1, 0, "");
	cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3548
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define srep(i, s, t) for(int i = (s); i < (t); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
using i64 = long long;
using f64 = long double;
i64 floor_div(const i64 n, const i64 d) { assert(d != 0); return n / d - static_cast<i64>((n ^ d) <  0 && n % d != 0); }
i64  ceil_div(const i64 n, const i64 d) { assert(d != 0); return n / d + static_cast<i64>((n ^ d) >= 0 && n % d != 0); }

int n, i;
string s;
constexpr int L = 1 << 10;
#define RANGE if(not (0 <= res and res < L)) throw logic_error("! 0 <= x < L")

int expression();
int term();
int factor();
int number();

int expression() {
    int res = term(); RANGE;
    while(i < n) {
        if(s[i] == '+') {
            i++;
            res += term(); RANGE;
        } else if(s[i] == '-') {
            i++;
            res -= term(); RANGE;
        } else break;
    }
    return res;
}

int term() {
    int res = factor(); RANGE;
    while(i < n) {
        if(s[i] == '*') {
            i++;
            res *= factor(); RANGE;
        } else break;
    }
    return res;
}

int factor() {
    if(i == n) throw logic_error("index");
    if(s[i] == '(') {
        i++;
        int res = expression(); RANGE;
        if(i == n or i < n and s[i] != ')') throw logic_error("braket");
        i++;
        return res;
    } else if(isdigit(s[i])) {
        return number();
    } else {
        throw logic_error("symbol");
    }
}

int number() {
    if(i == n) throw logic_error("index");
    int res = 0;
    while(i < n and isdigit(s[i])) {
        res <<= 1;
        res += (s[i] - '0');
        RANGE;
        i++;
    }
    return res;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    
    string org; cin >> org;
    n = org.size();
    int ans = -1;
    vector<int> I;
    rep(p, n) if(org[p] == '.') I.push_back(p);
    auto dfs = [&](auto&& dfs, int p) -> void {
        if(p == I.size()) {
            s = org;
            i = 0;

            try {
                int cur = expression();
                if(i != n) throw logic_error("i!=n");
                bool value_only = [&] {
                    vector<vector<char>> v = {{}};
                    for(char c : org) {
                        if(c == '(') {
                            v.push_back({c});
                        } else if(c == ')') {
                            if(v.back().size() <= 1) return true;
                            v.pop_back();
                        } else if(not isdigit(c)) {
                            v.back().push_back(c);
                        }
                    }
                    return false;
                }();
                if(value_only) throw logic_error("value only");
                chmax(ans, cur);
                // cout << org << " " << cur << "\n";
            } catch(logic_error e) {
                // cout << org << " " << e.what() << "\n";
            }
            return;
        }

        for(char c : {'0', '1', '+', '-', '*', '(', ')'}) {
            org[I[p]] = c;
            dfs(dfs, p + 1);
            org[I[p]] = '.';
        }
    }; dfs(dfs, 0);

    cout << ans << "\n";
}
accuracy: 1
time_ms: 60
memory_kb: 3580
final_rank: 7

code_snippet: #include <bits/stdc++.h>

class ParseError {};

struct Parser {
    using CopyIter = std::string::const_iterator;
    using Iter = CopyIter&;
    std::string line;

    Parser(std::string s): line(s) {}

    void skip(Iter it, char c) {
        if (*it != c) {
            throw ParseError();
        }
        // std::cerr << *it << ' ' << c << std::endl;
        assert(*it == c);
        ++it;
    }

    void check(int value) {
        if (!(0 <= value && value < (1 << 10))) {
            throw ParseError();
        }
    }

    void check() {
        std::vector<char> stack;
        for (auto c: line) {
            if (contain({'+', '-', '*', '('}, c)) {
                stack.push_back(c);
            } else if (c == ')') {
                if (stack.empty() || stack.back() == '(') {
                    throw ParseError();
                }
                while (!stack.empty() && stack.back() != '(') stack.pop_back();
                if (stack.empty()) {
                    throw ParseError();
                }
                assert(stack.back() == '(');
                stack.pop_back();
            }
        }
    }

    int plus(int lhs, int rhs) {
        check(lhs);
        check(rhs);
        check(lhs + rhs);
        return lhs + rhs;
    }

    int minus(int lhs, int rhs) {
        check(lhs);
        check(rhs);
        check(lhs - rhs);
        return lhs - rhs;
    }

    int mul(int lhs, int rhs) {
        check(lhs);
        check(rhs);
        check(lhs * rhs);
        return lhs * rhs;
    }

    bool contain(const std::vector<char>& set, char elem) {
        return std::find(set.begin(), set.end(), elem) != set.end();
    }

    int parse() {
        try {
            check();
            auto it = line.cbegin();
            auto res = expr(it);
            if (it == line.end()) return res;
            return -1;
        } catch(ParseError) {
            return -1;
        }
    }

    int expr(Iter it) {
        auto res = term(it);

        while (it != line.end() && contain({'+', '-'}, *it)) {
            if (*it == '+') {
                skip(it, '+');
                res = plus(res, term(it));
            } else {
                skip(it, '-');
                res = minus(res, term(it));
            }
        }

        return res;
    }

    int term(Iter it) {
        auto res = factor(it);

        while (it != line.end() && contain({'*'}, *it)) {
            skip(it, '*');
            res = mul(res, factor(it));
        }

        return res;
    }

    int factor(Iter it) {
        if (*it == '(') {
            skip(it, '(');
            auto res = expr(it);
            skip(it, ')');
            return res;
        }
        return number(it);
    }

    int number(Iter it) {
        int res = 0;
        if (!contain({'0', '1'}, *it)) {
            throw ParseError();
        }
        while (it != line.end() && contain({'0', '1'}, *it)) {
            char c = *it;
            skip(it, c);
            res = (res << 1) | (c - '0');
            check(res);
        }
        return res;
    }
};

int main() {
    constexpr int W = 7;
    const char alphabet[W] = {'+', '-', '*', '1', '0', '(', ')'};

    std::string line;
    std::cin >> line;

    std::vector<int> dot_index;
    for (int i = 0; i < (int)line.size(); i++) {
        if (line[i] == '.') {
            dot_index.push_back(i);
        }
    }
    assert(dot_index.size() <= 5);

    int n = dot_index.size();
    int m = 1;
    for (int i = 0; i < n; i++) m *= W;

    int ans = -1;
    for (int state = 0; state < m; state++) {
        int temp = state;
        for (int i = 0; i < n; i++) {
            line[dot_index[i]] = alphabet[temp % W];
            temp /= W;
        }
        Parser parser(line);
        ans = std::max(ans, parser.parse());
    }
    std::cout << ans << std::endl;
}
accuracy: 1
time_ms: 40
memory_kb: 3520
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,t) for (int i = (int)(s); i < (int)(t); ++i)
#define all(x) (x).begin(), (x).end()

string s;
string token = "01+-*()";

void check(bool f) {
    if (!f) throw runtime_error("hello");
}

int evaluate();
pair<int, int> expr(int k, bool paren);
pair<int, int> number(int k);

int fix_unknown(int k) {
    if (k == (int)s.size()) {
        // cerr << s << ": ";
        int ans;
        try {
            ans = evaluate();
        } catch (...) {
            ans = -1;
        }
        // cerr << ans << endl;
        return ans;
    }
    if (s[k] != '.') {
        return fix_unknown(k+1);
    }
    int ret = -1;
    for (char c : token) {
        s[k] = c;
        ret = max(ret, fix_unknown(k+1));
    }
    s[k] = '.';
    return ret;
}

int evaluate() {
    auto [x, k] = expr(0, false);
    check(k == (int)s.size());
    return x;
}

bool is_op(char c) {
    return c == '+' || c == '-' || c == '*';
}

pair<int, int> expr(int k, bool paren) {
    // cout << "expr: " << k << " " << need_op << endl;
    int x = 0;
    int term = 0;
    bool first = true;
    bool use_op = false;
    while (k < (int)s.size() && s[k] != ')') {

        char op = '+';

        if (!first) {
            check(is_op(s[k]));
            op = s[k++];
            use_op = true;
        }
        first = false;

        int y;
        if (s[k] == '(') {
            ++k;
            tie(y, k) = expr(k, true);
            check(k >= 0 && s[k] == ')');
            ++k;
        } else {
            tie(y, k) = number(k);
            check(k >= 0);
        }

        if (op == '*') {
            term *= y;
            check(abs(term) < (1<<10));
        } else {
            x += term;
            check(0 <= x && x < (1<<10));
            term = y;
            if (op == '-') term *= -1;
        }
    }
    check(!first);
    x += term;
    check(0 <= x && x < (1<<10));
    if (paren) check(use_op);
    return {x, k};
}

pair<int, int> number(int k) {
    // cout << "number: " << k << endl;
    check(s[k] == '0' || s[k] == '1');
    int n = 0;
    while (k < (int) s.size() && (s[k] == '0' || s[k] == '1')) {
        n = 2*n + (s[k]-'0');
        check(0 <= n && n < (1<<10));
        ++k;
    }
    return {n, k};
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> s;
    cout << fix_unknown(0) << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 3540
final_rank: 5

code_snippet: #include <iostream>
#include <string>

using namespace std;

struct Parser {
    static void check(int x) {
        if (x < 0 || (1 << 10) <= x) throw(0);
    }

    string s;
    int i;
    bool simple;

    explicit Parser(const string& s) : s(s), i(0), simple(true) {
        this->s.push_back('$');
    }

    int expr() {
        auto ret = term();

        while (s[i] == '+' || s[i] == '-') {
            simple = false;
            char op = s[i];

            ++i;
            auto x = term();

            if (op == '+') {
                ret += x;
            } else {
                ret -= x;
            }
            check(ret);
        }

        return ret;
    }

    int term() {
        auto ret = factor();

        while (s[i] == '*') {
            simple = false;

            ++i;
            auto x = factor();

            ret *= x;
            check(ret);
        }

        return ret;
    }

    int factor() {
        if (s[i] == '(') {
            ++i;

            auto ps = simple;
            simple = true;

            auto ret = expr();
            if (s[i] != ')' || simple) throw(0);
            ++i;

            simple = ps;
            return ret;

        } else {
            return number();
        }
    }

    int number() {
        if (!isdigit(s[i])) throw(0);

        int ret = 0;
        while (isdigit(s[i])) {
            ret = (ret << 1) + (s[i++] - '0');
            check(ret);
        }
        return ret;
    }

    int parse() {
        i = 0;
        simple = true;

        try {
            auto ret = expr();
            return s[i] == '$' ? ret : -1;
        } catch (int t) {
            return -1;
        }
    }
};

const string ops{"01+-*()"};

void solve() {
    string s;
    cin >> s;
    int n = s.length();
    Parser p(s);

    int ans = -1;
    auto dfs = [&](auto&& f) -> void {
        int i = 0;
        while (i < n && p.s[i] != '.') ++i;

        if (i < n) {
            for (char c : ops) {
                p.s[i] = c;
                f(f);
            }
            p.s[i] = '.';
        } else {
            ans = max(ans, p.parse());
        }
    };
    dfs(dfs);

    cout << ans << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3564
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

template<class T>
bool chmax(T& a, const T& b) {
    if (a < b) { a = b; return true; }
    return false;
}
template<class T>
bool chmin(T& a, const T& b) {
    if (b < a) { a = b; return true; }
    return false;
}

// std::vector Declaration
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

// std::vector Declaration and Initialization
template<typename T>
vector<T> make_vector(size_t a, T x) { return vector<T>(a, x); }
template<typename T, typename U, typename... Ts>
auto make_vector(size_t a, U b, Ts... ts) {
    return vector<decltype(make_vector<T>(b,ts...))>(a, make_vector<T>(b, ts...));
}

// std::vector Input
template<typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto &e : v) is >> e;
    return is;
}

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    bool a = 1;
    for (auto e : v) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "]";
    return os;
}

// std::array Debug
template<typename T, size_t n>
ostream& operator<<(ostream& os, const array<T, n>& v) {
    os << "[";
    bool a = 1;
    for (auto e : v) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "]";
    return os;
}

// std::deque Debug
template<typename T>
ostream& operator<<(ostream& os, const deque<T>& d) {
    os << "[";
    bool a = 1;
    for (auto e : d) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "]";
    return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << " " << p.second << ")";
    return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
    os << "{";
    bool a = 1;
    for (auto e : st) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "}";
    return os;
}

// std::multiset Debug
template<typename T>
ostream& operator<<(ostream& os, const multiset<T>& st) {
    os << "{";
    bool a = 1;
    for (auto e : st) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "}";
    return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
    os << "{";
    bool a = 1;
    for (auto e : mp) {
        os << (a ? "" : " ");
        os << e.first << ":" << e.second;
        a = 0;
    }
    os << "}";
    return os;
}

// std::tuple Debug
template<int N, class Tuple>
void out(ostream& os, const Tuple& t){}
template<int N, class Tuple, class H, class ...Ts>
void out(ostream& os, const Tuple& t) {
    if (N) os << " ";
    os << get<N>(t);
    out<N+1,Tuple,Ts...>(os, t);
}
template<class ...Ts>
ostream& operator<<(ostream& os, const tuple<Ts...>& t) {
    os << "(";
    out<0,tuple<Ts...>,Ts...>(os, t);
    os << ")";
    return os;
}

// Debug
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl

// Weighted edge
template<typename T>
struct edge {
    int src, to;
    T cost;

    edge() {}
    edge(int to, T cost) : src(-1), to(to), cost(cost) {}
    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    friend ostream& operator<<(ostream& os, const edge& e) {
        return os << "(" << e.src << "->" << e.to << ":" << e.cost << ")";
    }
};

using LL = int64_t;

#define fs first
#define sc second

const int64_t MOD = 1e9+7;

using State = string::const_iterator;
class ParseError {};

int number(State& begin) {
    int ret = 0;
    while (*begin == '0' or *begin == '1') {
        ret <<= 1;
        ret += (*begin - '0');
        if (ret < 0 or 1<<10 <= ret) {
            throw ParseError();
        }
        ++begin;
    }
    return ret;
}

pair<int,int> expression(State& begin);

int factor(State& begin) {
    if (*begin == '(') {
        ++begin;
        int ret, cnt; tie(ret, cnt) = expression(begin);
        if (cnt == 0) {
            throw ParseError();
        }
        if (ret < 0 or 1<<10 <= ret) {
            throw ParseError();
        }
        if (*begin != ')') {
            throw ParseError();
        }
        ++begin;
        return ret;
    } else if (*begin == '0' or *begin == '1') {
        return number(begin);
    } else {
        throw ParseError();
    }
}

pair<int,int> term(State& begin) {
    int prod = 1, cnt = 0;
    while (true) {
        prod *= factor(begin);
        if (prod < 0 or 1<<10 <= prod) {
            throw ParseError();
        }
        if (*begin != '*') {
            return { prod, cnt };
        }
        ++cnt;
        ++begin;
    }
}

pair<int,int> expression(State& begin) {
    int sum = 0, cnt = 0;
    int plus = 1;
    while (true) {
        int s, c; tie(s, c) = term(begin);
        sum += s * plus;
        cnt += c;
        if (sum < 0 or 1<<10 <= sum) {
            throw ParseError();
        }
        if (*begin == '+') {
            plus = 1;
        } else if (*begin == '-') {
            plus = -1;
        } else {
            return { sum, cnt };
        }
        ++cnt;
        ++begin;
    }
}

void test_number() {
    string s = "1010";
    State begin = s.begin();
    assert(number(begin) == 10);
}
void test() {
    //string s = "1+10*10+10*(10+10+1)";
    //State begin = s.begin();
    //assert(expression(begin).first == 15);
    string s = "(1+1+1)";
    State begin = s.begin();
    assert(expression(begin).first == 3);
}


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);


    test_number();
    test();

    string s; cin >> s;
    vector<int> unknown;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '.') {
            unknown.push_back(i);
        }
    }

    int m = unknown.size();

    vector<int> a(m+1);
    vector<char> ch{'0', '1', '+', '*', '-', '(', ')'};

    int ans = numeric_limits<int>::min();

    while (!a[m]) {

        string t = s;
        for (int i = 0; i < m; ++i) {
            t[unknown[i]] = ch[a[i]];
        }

        State begin = t.begin();
        try {
            int val = expression(begin).first;
            if (*begin == '\0') {
                chmax(ans, val);
            }
        } catch (const ParseError& e) {
        }

        for (int i = 0; ++a[i] == ch.size(); ++i) a[i] = 0;
    }

    cout << (ans == numeric_limits<int>::min() ? -1 : ans) << endl;

    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3280
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

template<class T>
bool chmax(T& a, const T& b) {
    if (a < b) { a = b; return true; }
    return false;
}
template<class T>
bool chmin(T& a, const T& b) {
    if (b < a) { a = b; return true; }
    return false;
}

// std::vector Declaration
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

// std::vector Declaration and Initialization
template<typename T>
vector<T> make_vector(size_t a, T x) { return vector<T>(a, x); }
template<typename T, typename U, typename... Ts>
auto make_vector(size_t a, U b, Ts... ts) {
    return vector<decltype(make_vector<T>(b,ts...))>(a, make_vector<T>(b, ts...));
}

// std::vector Input
template<typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto &e : v) is >> e;
    return is;
}

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    bool a = 1;
    for (auto e : v) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "]";
    return os;
}

// std::array Debug
template<typename T, size_t n>
ostream& operator<<(ostream& os, const array<T, n>& v) {
    os << "[";
    bool a = 1;
    for (auto e : v) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "]";
    return os;
}

// std::deque Debug
template<typename T>
ostream& operator<<(ostream& os, const deque<T>& d) {
    os << "[";
    bool a = 1;
    for (auto e : d) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "]";
    return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << " " << p.second << ")";
    return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
    os << "{";
    bool a = 1;
    for (auto e : st) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "}";
    return os;
}

// std::multiset Debug
template<typename T>
ostream& operator<<(ostream& os, const multiset<T>& st) {
    os << "{";
    bool a = 1;
    for (auto e : st) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "}";
    return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
    os << "{";
    bool a = 1;
    for (auto e : mp) {
        os << (a ? "" : " ");
        os << e.first << ":" << e.second;
        a = 0;
    }
    os << "}";
    return os;
}

// std::tuple Debug
template<int N, class Tuple>
void out(ostream& os, const Tuple& t){}
template<int N, class Tuple, class H, class ...Ts>
void out(ostream& os, const Tuple& t) {
    if (N) os << " ";
    os << get<N>(t);
    out<N+1,Tuple,Ts...>(os, t);
}
template<class ...Ts>
ostream& operator<<(ostream& os, const tuple<Ts...>& t) {
    os << "(";
    out<0,tuple<Ts...>,Ts...>(os, t);
    os << ")";
    return os;
}

// Debug
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl

// Weighted edge
template<typename T>
struct edge {
    int src, to;
    T cost;

    edge() {}
    edge(int to, T cost) : src(-1), to(to), cost(cost) {}
    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    friend ostream& operator<<(ostream& os, const edge& e) {
        return os << "(" << e.src << "->" << e.to << ":" << e.cost << ")";
    }
};

using LL = int64_t;

#define fs first
#define sc second

const int64_t MOD = 1e9+7;

using State = string::const_iterator;
class ParseError {};

int number(State& begin) {
    int ret = 0;
    while (*begin == '0' or *begin == '1') {
        ret <<= 1;
        ret += (*begin - '0');
        if (ret >= 1<<10) {
            throw ParseError();
        }
        ++begin;
    }
    return ret;
}

pair<int,int> expression(State& begin);

int factor(State& begin) {
    if (*begin == '(') {
        ++begin;
        int ret, cnt; tie(ret, cnt) = expression(begin);
        if (cnt == 0) {
            throw ParseError();
        }
        if (ret >= 1<<10) {
            throw ParseError();
        }
        if (*begin != ')') {
            throw ParseError();
        }
        ++begin;
        return ret;
    } else if (*begin == '0' or *begin == '1') {
        return number(begin);
    } else {
        throw ParseError();
    }
}

pair<int,int> term(State& begin) {
    int prod = 1, cnt = 0;
    while (true) {
        prod *= factor(begin);
        if (prod >= 1<<10) {
            throw ParseError();
        }
        if (*begin != '*') {
            return { prod, cnt };
        }
        ++cnt;
        ++begin;
    }
}

pair<int,int> expression(State& begin) {
    int sum = 0, cnt = 0;
    int plus = 1;
    while (true) {
        int s, c; tie(s, c) = term(begin);
        sum += s * plus;
        cnt += c;
        if (sum >= 1<<10) {
            throw ParseError();
        }
        if (*begin == '+') {
            plus = 1;
        } else if (*begin == '-') {
            plus = -1;
        } else {
            return { sum, cnt };
        }
        ++cnt;
        ++begin;
    }
}

void test_number() {
    string s = "1010";
    State begin = s.begin();
    assert(number(begin) == 10);
}
void test() {
    //string s = "1+10*10+10*(10+10+1)";
    //State begin = s.begin();
    //assert(expression(begin).first == 15);
    string s = "(1+1+1)";
    State begin = s.begin();
    assert(expression(begin).first == 3);
}


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);


    test_number();
    test();

    string s; cin >> s;
    vector<int> unknown;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '.') {
            unknown.push_back(i);
        }
    }

    int m = unknown.size();

    vector<int> a(m+1);
    vector<char> ch{'0', '1', '+', '*', '-', '(', ')'};

    int ans = numeric_limits<int>::min();

    while (!a[m]) {

        string t = s;
        for (int i = 0; i < m; ++i) {
            t[unknown[i]] = ch[a[i]];
        }

        State begin = t.begin();
        try {
            int val = expression(begin).first;
            if (*begin == '\0') {
                chmax(ans, val);
            }
        } catch (const ParseError& e) {
        }

        for (int i = 0; ++a[i] == ch.size(); ++i) a[i] = 0;
    }

    cout << ans << endl;

    return 0;
}
accuracy: 0.11678832116788321
time_ms: 50
memory_kb: 3280
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;

template<class T>
bool chmax(T& a, const T& b) {
    if (a < b) { a = b; return true; }
    return false;
}
template<class T>
bool chmin(T& a, const T& b) {
    if (b < a) { a = b; return true; }
    return false;
}

// std::vector Declaration
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

// std::vector Declaration and Initialization
template<typename T>
vector<T> make_vector(size_t a, T x) { return vector<T>(a, x); }
template<typename T, typename U, typename... Ts>
auto make_vector(size_t a, U b, Ts... ts) {
    return vector<decltype(make_vector<T>(b,ts...))>(a, make_vector<T>(b, ts...));
}

// std::vector Input
template<typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto &e : v) is >> e;
    return is;
}

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    bool a = 1;
    for (auto e : v) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "]";
    return os;
}

// std::array Debug
template<typename T, size_t n>
ostream& operator<<(ostream& os, const array<T, n>& v) {
    os << "[";
    bool a = 1;
    for (auto e : v) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "]";
    return os;
}

// std::deque Debug
template<typename T>
ostream& operator<<(ostream& os, const deque<T>& d) {
    os << "[";
    bool a = 1;
    for (auto e : d) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "]";
    return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << " " << p.second << ")";
    return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
    os << "{";
    bool a = 1;
    for (auto e : st) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "}";
    return os;
}

// std::multiset Debug
template<typename T>
ostream& operator<<(ostream& os, const multiset<T>& st) {
    os << "{";
    bool a = 1;
    for (auto e : st) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "}";
    return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
    os << "{";
    bool a = 1;
    for (auto e : mp) {
        os << (a ? "" : " ");
        os << e.first << ":" << e.second;
        a = 0;
    }
    os << "}";
    return os;
}

// std::tuple Debug
template<int N, class Tuple>
void out(ostream& os, const Tuple& t){}
template<int N, class Tuple, class H, class ...Ts>
void out(ostream& os, const Tuple& t) {
    if (N) os << " ";
    os << get<N>(t);
    out<N+1,Tuple,Ts...>(os, t);
}
template<class ...Ts>
ostream& operator<<(ostream& os, const tuple<Ts...>& t) {
    os << "(";
    out<0,tuple<Ts...>,Ts...>(os, t);
    os << ")";
    return os;
}

// Debug
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl

// Weighted edge
template<typename T>
struct edge {
    int src, to;
    T cost;

    edge() {}
    edge(int to, T cost) : src(-1), to(to), cost(cost) {}
    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    friend ostream& operator<<(ostream& os, const edge& e) {
        return os << "(" << e.src << "->" << e.to << ":" << e.cost << ")";
    }
};

using LL = int64_t;

#define fs first
#define sc second

const int64_t MOD = 1e9+7;

using State = string::const_iterator;
class ParseError {};

int number(State& begin) {
    int ret = 0;
    while (*begin == '0' or *begin == '1') {
        ret <<= 1;
        ret += (*begin - '0');
        ++begin;
    }
    return ret;
}

pair<int,int> expression(State& begin);

int factor(State& begin) {
    if (*begin == '(') {
        ++begin;
        int ret, cnt; tie(ret, cnt) = expression(begin);
        if (cnt == 0) {
            throw ParseError();
        }
        if (*begin != ')') {
            throw ParseError();
        }
        ++begin;
        return ret;
    } else if (*begin == '0' or *begin == '1') {
        return number(begin);
    } else {
        throw ParseError();
    }
}

pair<int,int> term(State& begin) {
    int prod = 1, cnt = 0;
    while (true) {
        prod *= factor(begin);
        if (*begin != '*') {
            return { prod, cnt };
        }
        ++cnt;
        ++begin;
    }
}

pair<int,int> expression(State& begin) {
    int sum = 0, cnt = 0;
    int plus = 1;
    while (true) {
        int s, c; tie(s, c) = term(begin);
        sum += s * plus;
        cnt += c;
        if (*begin == '+') {
            plus = 1;
        } else if (*begin == '-') {
            plus = -1;
        } else {
            return { sum, cnt };
        }
        ++cnt;
        ++begin;
    }
}

void test_number() {
    string s = "1010";
    State begin = s.begin();
    assert(number(begin) == 10);
}
void test() {
    //string s = "1+10*10+10*(10+10+1)";
    //State begin = s.begin();
    //assert(expression(begin).first == 15);
    string s = "(1+1+1)";
    State begin = s.begin();
    assert(expression(begin).first == 3);
}


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);


    test_number();
    test();

    string s; cin >> s;
    vector<int> unknown;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '.') {
            unknown.push_back(i);
        }
    }

    int m = unknown.size();

    vector<int> a(m+1);
    vector<char> ch{'0', '1', '+', '*', '-', '(', ')'};

    int ans = numeric_limits<int>::min();

    while (!a[m]) {

        string t = s;
        for (int i = 0; i < m; ++i) {
            t[unknown[i]] = ch[a[i]];
        }

        State begin = t.begin();
        try {
            int val = expression(begin).first;
            if (*begin == '\0') {
                chmax(ans, val);
            }
        } catch (const ParseError& e) {
        }

        for (int i = 0; ++a[i] == ch.size(); ++i) a[i] = 0;
    }

    cout << ans << endl;

    return 0;
}
accuracy: 0.043795620437956206
time_ms: 50
memory_kb: 3228
final_rank: 18

code_snippet: #define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-5L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

// geometry library

typedef complex<long double> Point;
typedef pair<complex<long double>, complex<long double>> Line;

typedef struct Circle {
    complex<long double> center;
    long double r;
}Circle;

//内積、 dot(a,b) = |a||b|cos()
long double dot(Point a, Point b) {
    return (a.real() * b.real() + a.imag() * b.imag());
}
//外積、cross(a,b) = |a||b|sin()
long double cross(Point a, Point b) {
    return (a.real() * b.imag() - a.imag() * b.real());
}

//線分と点の距離
long double Dist_Line_Point(Line a, Point b) {
    if (dot(a.second - a.first, b - a.first) < eps) return abs(b - a.first);
    if (dot(a.first - a.second, b - a.second) < eps) return abs(b - a.second);
    return abs(cross(a.second - a.first, b - a.first)) / abs(a.second - a.first);
}

//線分の交差判定
int is_intersected_ls(Line a, Line b) {
    return (cross(a.second - a.first, b.first - a.first) * cross(a.second - a.first, b.second - a.first) < eps) &&
        (cross(b.second - b.first, a.first - b.first) * cross(b.second - b.first, a.second - b.first) < eps);
}

//線分の交点
Point intersection_l(Line a, Line b) {
    Point da = a.second - a.first;
    Point db = b.second - b.first;
    return a.first + da * cross(db, b.first - a.first) / cross(db, da);
}

//線分と線分の距離
long double Dist_Line_Line(Line a, Line b) {
    if (is_intersected_ls(a, b) == 1) {
        return 0;
    }
    return min({ Dist_Line_Point(a,b.first), Dist_Line_Point(a,b.second),Dist_Line_Point(b,a.first),Dist_Line_Point(b,a.second) });
}

//円と円の交点
pair<Point, Point> intersection_Circle_Circle(Circle a, Circle b) {
    long double dist = abs(a.center - b.center);
    assert(dist <= eps + a.r + b.r);
    assert(dist+eps >= abs(a.r - b.r));
    Point target = b.center - a.center;
    long double pointer = target.real() * target.real() + target.imag() * target.imag();
    long double aa = pointer + a.r * a.r - b.r * b.r;
    aa /= 2.0L;
    Point l{ (aa * target.real() + target.imag() * sqrt(pointer * a.r * a.r - aa * aa))/pointer,
            (aa* target.imag() - target.real() * sqrt(pointer * a.r * a.r - aa * aa)) / pointer};
    Point r{ (aa * target.real() - target.imag() * sqrt(pointer * a.r * a.r - aa * aa)) / pointer,
        (aa * target.imag() + target.real() * sqrt(pointer * a.r * a.r - aa * aa)) / pointer };
    r = r + a.center;
    l = l + a.center;
    return mp(l, r);
}

//end of geometry

template<typename A>
A pows(A val, ll b) {
    assert(b >= 1);
    A ans = val;
    b--;
    while (b) {
        if (b % 2) {
            ans *= val;
        }
        val *= val;
        b /= 2LL;
    }
    return ans;
}

template<typename A>
class Compressor {
public:
    bool is_zipped = false;
    map<A, ll> zipper;
    map<ll, A> unzipper;
    queue<A> fetcher;
    Compressor(){
        is_zipped = false;
        zipper.clear();
        unzipper.clear();
    }
    void add(A now) {
        assert(is_zipped == false);
        zipper[now] = 1;
        fetcher.push(now);
    }
    void exec() {
        assert(is_zipped == false);
        int cnt = 0;
        for (auto i = zipper.begin(); i != zipper.end(); ++i) {
            i->second = cnt;
            unzipper[cnt] = i->first;
            cnt++;
        }
        is_zipped = true;
    }
    ll fetch() {
        assert(is_zipped == true);
        A hoge = fetcher.front();
        fetcher.pop();
        return zipper[hoge];
    }
    ll zip(A now) {
        assert(is_zipped == true);
        assert(zipper.find(now) != zipper.end());
        return zipper[now];
    }
    A unzip(ll a) {
        assert(is_zipped == true);
        assert(a < unzipper.size());
        return unzipper[a];
    }
    ll next(A now) {
        auto x = zipper.upper_bound(now);
        if (x == zipper.end()) return zipper.size();
        return (ll)((*x).second);
    }
    ll back(A now) {
        auto x = zipper.lower_bound(now);
        if (x == zipper.begin()) return -1;
        x--;
        return (ll)((*x).second);
    }
};

template<typename A>
class Matrix {
public:
    vector<vector<A>> data;
    Matrix(vector<vector<A>> a) :data(a){

    }
    Matrix operator + (const Matrix obj) {
        vector<vector<A>> ans;
        assert(obj.data.size() == this->data.size());
        assert(obj.data[0].size() == this->data[0].size());
        REP(i, obj.data.size()) {
            ans.push_back(vector<A>());
            REP(q, obj.data[i].size()) {
                A hoge = obj.data[i][q] + (this -> data[i][q]);
                ans.back().push_back(hoge);
            }
        }
        return Matrix(ans);
    }
    Matrix operator - (const Matrix obj) {
        vector<vector<A>> ans;
        assert(obj.data.size() == this->data.size());
        assert(obj.data[0].size() == this->data[0].size());
        REP(i, obj.data.size()) {
            ans.push_back(vector<A>());
            REP(q, obj.data[i].size()) {
                A hoge = this->data[i][q] - obj.data[i][q];
                ans.back().push_back(hoge);
            }
        }
        return Matrix(ans);
    }
    Matrix operator * (const Matrix obj) {
        vector<vector<A>> ans;
        assert(obj.data.size() == this->data[0].size());
        REP(i, this -> data.size()) {
            ans.push_back(vector<A>());
            REP(q, obj.data[0].size()) {
                A hoge = (this -> data[i][0]) * (obj.data[0][q]);
                for(int t = 1;t < obj.data[i].size();++t){
                    hoge += this -> data[i][t] * obj.data[t][q];
                }
                ans.back().push_back(hoge);
            }
        }
        return Matrix(ans);
    }
    Matrix &operator *= (const Matrix obj) {
        *this = (*this * obj);
        return *this;
    }
    Matrix& operator += (const Matrix obj) {
        *this = (*this + obj);
        return *this;
    }
    Matrix& operator -= (const Matrix obj) {
        *this = (*this - obj);
        return *this;
    }
};

class modint {
public:
    using u64 = std::uint_fast64_t;
    u64 value = 0;
    u64 mod;
    modint(ll a, ll b): value(((a%b) + 2 * b) % b),mod(b) {

    }
    modint operator+(const modint rhs) const{
        return modint(*this) += rhs;
    }
    modint operator-(const modint rhs) const{
        return modint(*this) -= rhs;
    }
    modint operator*(const modint rhs) const {
        return modint(*this) *= rhs;
    }
    modint operator/(const modint rhs) const{
        return modint(*this) /= rhs;
    }
    modint& operator+=(const modint rhs) {
        assert(rhs.mod == mod);
        value += rhs.value;
        if (value >= mod) {
            value -= mod;
        }
        return *this;
    }
    modint& operator-=(const modint rhs) {
        assert(rhs.mod == mod);
        if (value < rhs.value) {
            value += mod;
        }
        value -= rhs.value;
        return *this;
    }
    modint& operator*=(const modint rhs) {
        assert(rhs.mod == mod);
        value = (value *  rhs.value) % mod;
        return *this;
    }
    modint& operator/=(modint rhs) {
        assert(rhs.mod == mod);
        ll rem = mod - 2;
        while (rem) {
            if (rem % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            rem /= 2LL;
        }
        return *this;
    }
    bool operator <(modint rhs) const{
        return value < rhs.value;
    }
    friend ostream& operator<<(ostream& os, modint& p) {
        os << p.value;
        return (os);
    }
};

class Dice {
public:
    vector<ll> vertexs;
    //Up: 0,Left: 1,Center: 2,Right: 3,Adj: 4, Down: 5
    Dice(vector<ll> init):vertexs(init){
        
    }
    //Look from Center
    void RtoL() {
        for (int q = 1; q < 4; ++q) {
            swap(vertexs[q], vertexs[q + 1]);
        }
    }
    void LtoR() {
        for (int q = 3; q >= 1; --q) {
            swap(vertexs[q], vertexs[q + 1]);
        }
    }
    void UtoD() {
        swap(vertexs[5], vertexs[4]);
        swap(vertexs[2], vertexs[5]);
        swap(vertexs[0], vertexs[2]);
    }
    void DtoU() {
        swap(vertexs[0], vertexs[2]);
        swap(vertexs[2], vertexs[5]);
        swap(vertexs[5], vertexs[4]);
    }
    bool ReachAble(Dice now) {
        set<Dice> hoge;
        queue<Dice> next;
        next.push(now);
        hoge.insert(now);
        while (next.empty() == false) {
            Dice seeing = next.front();
            next.pop();
            if (seeing == *this) return true;
            seeing.RtoL();
            if (hoge.count(seeing) == 0) {
                hoge.insert(seeing);
                next.push(seeing);
            }
            seeing.LtoR();
            seeing.LtoR();
            if (hoge.count(seeing) == 0) {
                hoge.insert(seeing);
                next.push(seeing);
            }
            seeing.RtoL();
            seeing.UtoD();
            if (hoge.count(seeing) == 0) {
                hoge.insert(seeing);
                next.push(seeing);
            }
            seeing.DtoU();
            seeing.DtoU();
            if (hoge.count(seeing) == 0) {
                hoge.insert(seeing);
                next.push(seeing);
            }
        }
        return false;
    }
    bool operator ==(const Dice& a) {
        for (int q = 0; q < 6; ++q) {
            if (a.vertexs[q] != (*this).vertexs[q]) {
                return false;
            }
        }
        return true;
    }
    bool operator <(const Dice& a) const{
        return (*this).vertexs < a.vertexs;
    }
};

pair<Dice, Dice> TwoDimDice(int center, int up) {
    int target = 1;
    while (true) {
        if (center != target && 7 - center != target && up != target && 7 - up != target) {
            break;
        }
        target++;
    }
    return mp(Dice(vector<ll>{up, target, center, 7 - target, 7 - center, 7 - up}), Dice(vector<ll>{up, 7 - target, center, target, 7 - center, 7 - up}));
}

tuple<Dice, Dice, Dice, Dice> OneDimDice(int center) {
    int bo = min(center, 7 - center);
    pair<int, int> goa;
    if (bo == 1) {
        goa = mp(2, 3);
    }
    else if (bo == 2) {
        goa = mp(1, 3);
    }
    else if(bo == 3){
        goa = mp(1, 2);
    }
    tuple<Dice, Dice, Dice, Dice> now = make_tuple(Dice(vector<ll>{goa.first,goa.second,center,7 - goa.second,7-center,7 - goa.first}), 
        Dice(vector<ll>{goa.first, 7 - goa.second, center, goa.second, 7 - center, 7 - goa.first}),
        Dice(vector<ll>{7 - goa.first, goa.second, center, 7 - goa.second, 7 - center, goa.first}),
        Dice(vector<ll>{7 - goa.first, 7 - goa.second, center, goa.second, 7 - center, goa.first}));
    return now;
}

template<typename A,typename B>
class Dijkstra {
public:
    vector<vector<pair<int, A>>> vertexs;
    B Cost_Function;
    Dijkstra(int n, B cost) : Cost_Function(cost){
        vertexs = vector<vector<pair<int, A>>>(n, vector<pair<int, A>>{});
    }
    ~Dijkstra() {
        vertexs.clear();
    }
    void add_edge(int a, int b, A c) {
        vertexs[a].push_back(mp(b, c));
    }
    vector<ll> build_result(int StartPoint) {
        vector<ll> dist(vertexs.size(), 2e18);
        dist[StartPoint] = 0;
        priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> next;
        next.push(make_pair(0, StartPoint));
        while (next.empty() == false) {
            pair<ll, int> now = next.top();
            next.pop();
            if (dist[now.second] != now.first) continue;
            for (auto x : vertexs[now.second]) {
                ll now_cost = now.first + Cost_Function(x.second);
                if (dist[x.first] > now_cost) {
                    dist[x.first] = now_cost;
                    next.push(mp(now_cost, x.first));
                }
            }
        }
        return dist;
    }
};

class Dinic {
public:
    struct edge {
        int to;
        int cap;
        int rev;
    };
    vector<vector<edge>> Graph;
    vector<int> level;
    vector<int> itr;
    Dinic(int n){
        Graph = vector<vector<edge>>(n, vector<edge>());
    }
    void add_edge(int a, int b, int cap) {
        Graph[a].push_back(edge{ b, cap ,(int)Graph[b].size() });
        Graph[b].push_back(edge{ a,0,(int)Graph[a].size() - 1 });
    }
    void bfs(int s) {
        level = vector<int>(Graph.size(), -1);
        level[s] = 0;
        queue<int> next;
        next.push(s);
        while (next.empty() == false) {
            int now = next.front();
            next.pop();
            for (auto x : Graph[now]) {
                if (x.cap == 0) continue;
                if (level[x.to] == -1) {
                    level[x.to] = level[now] + 1;
                    next.push(x.to);
                }
            }
        }
    }
    int dfs(int now, int goal, int val) {
        if (goal == now) return val;
        for (int& i = itr[now]; i < (int)Graph[now].size(); ++i) {
            edge& target = Graph[now][i];
            if (target.cap > 0&&level[now] < level[target.to]) {
                int d = dfs(target.to, goal, min(val, target.cap));
                if (d > 0) {
                    target.cap -= d;
                    Graph[target.to][target.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    int run(int s,int t) {
        int ans = 0;
        int f = 0;
        while (bfs(s), level[t] >= 0) {
            itr = vector<int>(Graph.size(), 0);
            while ((f = dfs(s, t, 1e9)) > 0) {
                ans += f;
            }
        }
        return ans;
    }
};

//by ei1333
//https://ei1333.github.io/luzhiled/snippets/structure/segment-tree.html
template< typename Monoid >
struct SegmentTree {
    using F = function< Monoid(Monoid, Monoid) >;

    int sz;
    vector< Monoid > seg;

    const F f;
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid& M1) : f(f), M1(M1) {
        sz = 1;
        while (sz < n) sz <<= 1;
        seg.assign(2 * sz + 1, M1);
    }

    void set(int k, const Monoid& x) {
        seg[k + sz] = x;
    }

    void build() {
        for (int k = sz - 1; k > 0; k--) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    void update(int k, const Monoid& x) {
        k += sz;
        seg[k] = x;
        while (k >>= 1) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    Monoid query(int a, int b) {
        Monoid L = M1, R = M1;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if (a & 1) L = f(L, seg[a++]);
            if (b & 1) R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int& k) const {
        return seg[k + sz];
    }

    template< typename C >
    int find_subtree(int a, const C& check, Monoid& M, bool type) {
        while (a < sz) {
            Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
            if (check(nxt)) a = 2 * a + type;
            else M = nxt, a = 2 * a + 1 - type;
        }
        return a - sz;
    }


    template< typename C >
    int find_first(int a, const C& check) {
        Monoid L = M1;
        if (a <= 0) {
            if (check(f(L, seg[1]))) return find_subtree(1, check, L, false);
            return -1;
        }
        int b = sz;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if (a & 1) {
                Monoid nxt = f(L, seg[a]);
                if (check(nxt)) return find_subtree(a, check, L, false);
                L = nxt;
                ++a;
            }
        }
        return -1;
    }

    template< typename C >
    int find_last(int b, const C& check) {
        Monoid R = M1;
        if (b >= sz) {
            if (check(f(seg[1], R))) return find_subtree(1, check, R, true);
            return -1;
        }
        int a = sz;
        for (b += sz; a < b; a >>= 1, b >>= 1) {
            if (b & 1) {
                Monoid nxt = f(seg[--b], R);
                if (check(nxt)) return find_subtree(b, check, R, true);
                R = nxt;
            }
        }
        return -1;
    }
};

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

#define int ll
int num(State& now) {
    int ans = 0;
    while (*now == '0' || *now == '1') {
        ans *= 2LL;
        ans += *now - '0';
        if (ans >= (1 << 10)) {
            return -1;
        }
        now++;
    }
    return ans;
}

int calc(State& now) {
    int ans = 0;
    int next_req = 1;
    if (*now == '0' || *now == '1') {
        ans = num(now);
        if (ans == -1) return -1;
    }
    else if (*now == '(') {
        now++;
        ans = calc(now);
        if (ans == -1) return -1;
        now++;
    }
    else return -1;
    vector<pair<int, int>> nexter;
    nexter.push_back(mp(ans, -1));
    while (*now != ')') {
        next_req = 0;
        if (*now == '+') {
            now++;
            int hoge = 0;
            if (*now == '(') {
                now++;
                hoge = calc(now);
                if (hoge == -1) return -1;
                now++;
            }
            else if (*now == '0' || *now == '1') {
                hoge = num(now);
                if (hoge == -1) return -1;
            }
            else return -1;
            nexter.push_back(mp(hoge, 0));
        }
        else if (*now == '-') {
            now++;
            int hoge = 0;
            if (*now == '(') {
                now++;
                hoge = calc(now);
                if (hoge == -1) return -1;
                now++;
            }
            else if (*now == '0' || *now == '1') {
                hoge = num(now);
                if (hoge == -1) return -1;
            }
            else return -1;
            nexter.push_back(mp(hoge, 1));
        }
        else if (*now == '*') {
            now++;
            int hoge = 0;
            if (*now == '(') {
                now++;
                hoge = calc(now);
                if (hoge == -1) return -1;
                now++;
            }
            else if (*now == '0' || *now == '1') {
                hoge = num(now);
                if (hoge == -1) return -1;
            }
            else return -1;
            nexter.push_back(mp(hoge, 2));
        }
        else if (*now == '0') {
            return -1;
        }
        else if (*now == '1') {
            return -1;
        }
        else if (*now == '(') {
            return -1;
        }
        else break;
    }
    if (next_req == 1) {
        return -1;
    }
    for (int q = 1; q < nexter.size(); ++q) {
        if (nexter[q].second == 2) {
            nexter[q - 1].first *= nexter[q].first;
            if (nexter[q - 1].first >= (1 << 10) || nexter[q - 1].first < 0) return -1;
            nexter.erase(nexter.begin() + q);
            q--;
        }
    }
    for (int q = 1; q < nexter.size(); ++q) {
        if (nexter[q].second == 0) {
            nexter[q - 1].first += nexter[q].first;
            if (nexter[q - 1].first >= (1 << 10) || nexter[q - 1].first < 0) return -1;
            nexter.erase(nexter.begin() + q);
            q--;
        }
        else {
            nexter[q - 1].first -= nexter[q].first;
            if (nexter[q - 1].first >= (1 << 10) || nexter[q - 1].first < 0) return -1;
            nexter.erase(nexter.begin() + q);
            q--;
        }
    }
    return nexter[0].first;
}

void solve() {
    string s;
    cin >> s;
    s = "0+" + s;
    s.push_back(')');
    int ans = -1;
    REP(i, 7 * 7 * 7 * 7 * 7) {
        string b;
        int now = i;
        string c = "01+-*()";
        REP(q, s.length()) {
            if (s[q] == '.') {
                b.push_back(c[now % 7]);
                now /= 7;
            }
            else {
                b.push_back(s[q]);
            }
        }
        int ng = 0;
        for (int q = 0; q < b.length() - 1; ++q) {
            if (b[q] == '(') {
                ng++;
            }
            else if (b[q] == ')') {
                ng--;
            }
            if (ng < 0) {
                b.clear();
                break;
            }
        }
        if (ng != 0) b.clear();
        if (b.size() == 0) continue;
        State hoge = b.begin();

        int nya = calc(hoge);
        if (nya > ans) {
            ans = max(ans, nya);
        }
    }
    cout << ans << endl;
}

#undef int
int main() {
    init();
    solve();
}
accuracy: 1
time_ms: 10
memory_kb: 3240
final_rank: 1

code_snippet: #define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-5L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

// geometry library

typedef complex<long double> Point;
typedef pair<complex<long double>, complex<long double>> Line;

typedef struct Circle {
    complex<long double> center;
    long double r;
}Circle;

//内積、 dot(a,b) = |a||b|cos()
long double dot(Point a, Point b) {
    return (a.real() * b.real() + a.imag() * b.imag());
}
//外積、cross(a,b) = |a||b|sin()
long double cross(Point a, Point b) {
    return (a.real() * b.imag() - a.imag() * b.real());
}

//線分と点の距離
long double Dist_Line_Point(Line a, Point b) {
    if (dot(a.second - a.first, b - a.first) < eps) return abs(b - a.first);
    if (dot(a.first - a.second, b - a.second) < eps) return abs(b - a.second);
    return abs(cross(a.second - a.first, b - a.first)) / abs(a.second - a.first);
}

//線分の交差判定
int is_intersected_ls(Line a, Line b) {
    return (cross(a.second - a.first, b.first - a.first) * cross(a.second - a.first, b.second - a.first) < eps) &&
        (cross(b.second - b.first, a.first - b.first) * cross(b.second - b.first, a.second - b.first) < eps);
}

//線分の交点
Point intersection_l(Line a, Line b) {
    Point da = a.second - a.first;
    Point db = b.second - b.first;
    return a.first + da * cross(db, b.first - a.first) / cross(db, da);
}

//線分と線分の距離
long double Dist_Line_Line(Line a, Line b) {
    if (is_intersected_ls(a, b) == 1) {
        return 0;
    }
    return min({ Dist_Line_Point(a,b.first), Dist_Line_Point(a,b.second),Dist_Line_Point(b,a.first),Dist_Line_Point(b,a.second) });
}

//円と円の交点
pair<Point, Point> intersection_Circle_Circle(Circle a, Circle b) {
    long double dist = abs(a.center - b.center);
    assert(dist <= eps + a.r + b.r);
    assert(dist+eps >= abs(a.r - b.r));
    Point target = b.center - a.center;
    long double pointer = target.real() * target.real() + target.imag() * target.imag();
    long double aa = pointer + a.r * a.r - b.r * b.r;
    aa /= 2.0L;
    Point l{ (aa * target.real() + target.imag() * sqrt(pointer * a.r * a.r - aa * aa))/pointer,
            (aa* target.imag() - target.real() * sqrt(pointer * a.r * a.r - aa * aa)) / pointer};
    Point r{ (aa * target.real() - target.imag() * sqrt(pointer * a.r * a.r - aa * aa)) / pointer,
        (aa * target.imag() + target.real() * sqrt(pointer * a.r * a.r - aa * aa)) / pointer };
    r = r + a.center;
    l = l + a.center;
    return mp(l, r);
}

//end of geometry

template<typename A>
A pows(A val, ll b) {
    assert(b >= 1);
    A ans = val;
    b--;
    while (b) {
        if (b % 2) {
            ans *= val;
        }
        val *= val;
        b /= 2LL;
    }
    return ans;
}

template<typename A>
class Compressor {
public:
    bool is_zipped = false;
    map<A, ll> zipper;
    map<ll, A> unzipper;
    queue<A> fetcher;
    Compressor(){
        is_zipped = false;
        zipper.clear();
        unzipper.clear();
    }
    void add(A now) {
        assert(is_zipped == false);
        zipper[now] = 1;
        fetcher.push(now);
    }
    void exec() {
        assert(is_zipped == false);
        int cnt = 0;
        for (auto i = zipper.begin(); i != zipper.end(); ++i) {
            i->second = cnt;
            unzipper[cnt] = i->first;
            cnt++;
        }
        is_zipped = true;
    }
    ll fetch() {
        assert(is_zipped == true);
        A hoge = fetcher.front();
        fetcher.pop();
        return zipper[hoge];
    }
    ll zip(A now) {
        assert(is_zipped == true);
        assert(zipper.find(now) != zipper.end());
        return zipper[now];
    }
    A unzip(ll a) {
        assert(is_zipped == true);
        assert(a < unzipper.size());
        return unzipper[a];
    }
    ll next(A now) {
        auto x = zipper.upper_bound(now);
        if (x == zipper.end()) return zipper.size();
        return (ll)((*x).second);
    }
    ll back(A now) {
        auto x = zipper.lower_bound(now);
        if (x == zipper.begin()) return -1;
        x--;
        return (ll)((*x).second);
    }
};

template<typename A>
class Matrix {
public:
    vector<vector<A>> data;
    Matrix(vector<vector<A>> a) :data(a){

    }
    Matrix operator + (const Matrix obj) {
        vector<vector<A>> ans;
        assert(obj.data.size() == this->data.size());
        assert(obj.data[0].size() == this->data[0].size());
        REP(i, obj.data.size()) {
            ans.push_back(vector<A>());
            REP(q, obj.data[i].size()) {
                A hoge = obj.data[i][q] + (this -> data[i][q]);
                ans.back().push_back(hoge);
            }
        }
        return Matrix(ans);
    }
    Matrix operator - (const Matrix obj) {
        vector<vector<A>> ans;
        assert(obj.data.size() == this->data.size());
        assert(obj.data[0].size() == this->data[0].size());
        REP(i, obj.data.size()) {
            ans.push_back(vector<A>());
            REP(q, obj.data[i].size()) {
                A hoge = this->data[i][q] - obj.data[i][q];
                ans.back().push_back(hoge);
            }
        }
        return Matrix(ans);
    }
    Matrix operator * (const Matrix obj) {
        vector<vector<A>> ans;
        assert(obj.data.size() == this->data[0].size());
        REP(i, this -> data.size()) {
            ans.push_back(vector<A>());
            REP(q, obj.data[0].size()) {
                A hoge = (this -> data[i][0]) * (obj.data[0][q]);
                for(int t = 1;t < obj.data[i].size();++t){
                    hoge += this -> data[i][t] * obj.data[t][q];
                }
                ans.back().push_back(hoge);
            }
        }
        return Matrix(ans);
    }
    Matrix &operator *= (const Matrix obj) {
        *this = (*this * obj);
        return *this;
    }
    Matrix& operator += (const Matrix obj) {
        *this = (*this + obj);
        return *this;
    }
    Matrix& operator -= (const Matrix obj) {
        *this = (*this - obj);
        return *this;
    }
};

class modint {
public:
    using u64 = std::uint_fast64_t;
    u64 value = 0;
    u64 mod;
    modint(ll a, ll b): value(((a%b) + 2 * b) % b),mod(b) {

    }
    modint operator+(const modint rhs) const{
        return modint(*this) += rhs;
    }
    modint operator-(const modint rhs) const{
        return modint(*this) -= rhs;
    }
    modint operator*(const modint rhs) const {
        return modint(*this) *= rhs;
    }
    modint operator/(const modint rhs) const{
        return modint(*this) /= rhs;
    }
    modint& operator+=(const modint rhs) {
        assert(rhs.mod == mod);
        value += rhs.value;
        if (value >= mod) {
            value -= mod;
        }
        return *this;
    }
    modint& operator-=(const modint rhs) {
        assert(rhs.mod == mod);
        if (value < rhs.value) {
            value += mod;
        }
        value -= rhs.value;
        return *this;
    }
    modint& operator*=(const modint rhs) {
        assert(rhs.mod == mod);
        value = (value *  rhs.value) % mod;
        return *this;
    }
    modint& operator/=(modint rhs) {
        assert(rhs.mod == mod);
        ll rem = mod - 2;
        while (rem) {
            if (rem % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            rem /= 2LL;
        }
        return *this;
    }
    bool operator <(modint rhs) const{
        return value < rhs.value;
    }
    friend ostream& operator<<(ostream& os, modint& p) {
        os << p.value;
        return (os);
    }
};

class Dice {
public:
    vector<ll> vertexs;
    //Up: 0,Left: 1,Center: 2,Right: 3,Adj: 4, Down: 5
    Dice(vector<ll> init):vertexs(init){
        
    }
    //Look from Center
    void RtoL() {
        for (int q = 1; q < 4; ++q) {
            swap(vertexs[q], vertexs[q + 1]);
        }
    }
    void LtoR() {
        for (int q = 3; q >= 1; --q) {
            swap(vertexs[q], vertexs[q + 1]);
        }
    }
    void UtoD() {
        swap(vertexs[5], vertexs[4]);
        swap(vertexs[2], vertexs[5]);
        swap(vertexs[0], vertexs[2]);
    }
    void DtoU() {
        swap(vertexs[0], vertexs[2]);
        swap(vertexs[2], vertexs[5]);
        swap(vertexs[5], vertexs[4]);
    }
    bool ReachAble(Dice now) {
        set<Dice> hoge;
        queue<Dice> next;
        next.push(now);
        hoge.insert(now);
        while (next.empty() == false) {
            Dice seeing = next.front();
            next.pop();
            if (seeing == *this) return true;
            seeing.RtoL();
            if (hoge.count(seeing) == 0) {
                hoge.insert(seeing);
                next.push(seeing);
            }
            seeing.LtoR();
            seeing.LtoR();
            if (hoge.count(seeing) == 0) {
                hoge.insert(seeing);
                next.push(seeing);
            }
            seeing.RtoL();
            seeing.UtoD();
            if (hoge.count(seeing) == 0) {
                hoge.insert(seeing);
                next.push(seeing);
            }
            seeing.DtoU();
            seeing.DtoU();
            if (hoge.count(seeing) == 0) {
                hoge.insert(seeing);
                next.push(seeing);
            }
        }
        return false;
    }
    bool operator ==(const Dice& a) {
        for (int q = 0; q < 6; ++q) {
            if (a.vertexs[q] != (*this).vertexs[q]) {
                return false;
            }
        }
        return true;
    }
    bool operator <(const Dice& a) const{
        return (*this).vertexs < a.vertexs;
    }
};

pair<Dice, Dice> TwoDimDice(int center, int up) {
    int target = 1;
    while (true) {
        if (center != target && 7 - center != target && up != target && 7 - up != target) {
            break;
        }
        target++;
    }
    return mp(Dice(vector<ll>{up, target, center, 7 - target, 7 - center, 7 - up}), Dice(vector<ll>{up, 7 - target, center, target, 7 - center, 7 - up}));
}

tuple<Dice, Dice, Dice, Dice> OneDimDice(int center) {
    int bo = min(center, 7 - center);
    pair<int, int> goa;
    if (bo == 1) {
        goa = mp(2, 3);
    }
    else if (bo == 2) {
        goa = mp(1, 3);
    }
    else if(bo == 3){
        goa = mp(1, 2);
    }
    tuple<Dice, Dice, Dice, Dice> now = make_tuple(Dice(vector<ll>{goa.first,goa.second,center,7 - goa.second,7-center,7 - goa.first}), 
        Dice(vector<ll>{goa.first, 7 - goa.second, center, goa.second, 7 - center, 7 - goa.first}),
        Dice(vector<ll>{7 - goa.first, goa.second, center, 7 - goa.second, 7 - center, goa.first}),
        Dice(vector<ll>{7 - goa.first, 7 - goa.second, center, goa.second, 7 - center, goa.first}));
    return now;
}

template<typename A,typename B>
class Dijkstra {
public:
    vector<vector<pair<int, A>>> vertexs;
    B Cost_Function;
    Dijkstra(int n, B cost) : Cost_Function(cost){
        vertexs = vector<vector<pair<int, A>>>(n, vector<pair<int, A>>{});
    }
    ~Dijkstra() {
        vertexs.clear();
    }
    void add_edge(int a, int b, A c) {
        vertexs[a].push_back(mp(b, c));
    }
    vector<ll> build_result(int StartPoint) {
        vector<ll> dist(vertexs.size(), 2e18);
        dist[StartPoint] = 0;
        priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> next;
        next.push(make_pair(0, StartPoint));
        while (next.empty() == false) {
            pair<ll, int> now = next.top();
            next.pop();
            if (dist[now.second] != now.first) continue;
            for (auto x : vertexs[now.second]) {
                ll now_cost = now.first + Cost_Function(x.second);
                if (dist[x.first] > now_cost) {
                    dist[x.first] = now_cost;
                    next.push(mp(now_cost, x.first));
                }
            }
        }
        return dist;
    }
};

class Dinic {
public:
    struct edge {
        int to;
        int cap;
        int rev;
    };
    vector<vector<edge>> Graph;
    vector<int> level;
    vector<int> itr;
    Dinic(int n){
        Graph = vector<vector<edge>>(n, vector<edge>());
    }
    void add_edge(int a, int b, int cap) {
        Graph[a].push_back(edge{ b, cap ,(int)Graph[b].size() });
        Graph[b].push_back(edge{ a,0,(int)Graph[a].size() - 1 });
    }
    void bfs(int s) {
        level = vector<int>(Graph.size(), -1);
        level[s] = 0;
        queue<int> next;
        next.push(s);
        while (next.empty() == false) {
            int now = next.front();
            next.pop();
            for (auto x : Graph[now]) {
                if (x.cap == 0) continue;
                if (level[x.to] == -1) {
                    level[x.to] = level[now] + 1;
                    next.push(x.to);
                }
            }
        }
    }
    int dfs(int now, int goal, int val) {
        if (goal == now) return val;
        for (int& i = itr[now]; i < (int)Graph[now].size(); ++i) {
            edge& target = Graph[now][i];
            if (target.cap > 0&&level[now] < level[target.to]) {
                int d = dfs(target.to, goal, min(val, target.cap));
                if (d > 0) {
                    target.cap -= d;
                    Graph[target.to][target.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    int run(int s,int t) {
        int ans = 0;
        int f = 0;
        while (bfs(s), level[t] >= 0) {
            itr = vector<int>(Graph.size(), 0);
            while ((f = dfs(s, t, 1e9)) > 0) {
                ans += f;
            }
        }
        return ans;
    }
};

//by ei1333
//https://ei1333.github.io/luzhiled/snippets/structure/segment-tree.html
template< typename Monoid >
struct SegmentTree {
    using F = function< Monoid(Monoid, Monoid) >;

    int sz;
    vector< Monoid > seg;

    const F f;
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid& M1) : f(f), M1(M1) {
        sz = 1;
        while (sz < n) sz <<= 1;
        seg.assign(2 * sz + 1, M1);
    }

    void set(int k, const Monoid& x) {
        seg[k + sz] = x;
    }

    void build() {
        for (int k = sz - 1; k > 0; k--) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    void update(int k, const Monoid& x) {
        k += sz;
        seg[k] = x;
        while (k >>= 1) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    Monoid query(int a, int b) {
        Monoid L = M1, R = M1;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if (a & 1) L = f(L, seg[a++]);
            if (b & 1) R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int& k) const {
        return seg[k + sz];
    }

    template< typename C >
    int find_subtree(int a, const C& check, Monoid& M, bool type) {
        while (a < sz) {
            Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
            if (check(nxt)) a = 2 * a + type;
            else M = nxt, a = 2 * a + 1 - type;
        }
        return a - sz;
    }


    template< typename C >
    int find_first(int a, const C& check) {
        Monoid L = M1;
        if (a <= 0) {
            if (check(f(L, seg[1]))) return find_subtree(1, check, L, false);
            return -1;
        }
        int b = sz;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if (a & 1) {
                Monoid nxt = f(L, seg[a]);
                if (check(nxt)) return find_subtree(a, check, L, false);
                L = nxt;
                ++a;
            }
        }
        return -1;
    }

    template< typename C >
    int find_last(int b, const C& check) {
        Monoid R = M1;
        if (b >= sz) {
            if (check(f(seg[1], R))) return find_subtree(1, check, R, true);
            return -1;
        }
        int a = sz;
        for (b += sz; a < b; a >>= 1, b >>= 1) {
            if (b & 1) {
                Monoid nxt = f(seg[--b], R);
                if (check(nxt)) return find_subtree(b, check, R, true);
                R = nxt;
            }
        }
        return -1;
    }
};

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

#define int ll
int num(State& now) {
    int ans = 0;
    while (*now == '0' || *now == '1') {
        ans *= 2LL;
        ans += *now - '0';
        if (ans >= (1 << 10)) {
            return -1;
        }
        now++;
    }
    return ans;
}

int calc(State& now) {
    int ans = 0;
    int next_req = 1;
    if (*now == '0' || *now == '1') {
        ans = num(now);
        if (ans == -1) return -1;
    }
    else if (*now == '(') {
        now++;
        ans = calc(now);
        if (ans == -1) return -1;
        now++;
    }
    else return -1;
    while (*now != ')') {
        next_req = 0;
        if (*now == '+') {
            now++;
            int hoge = 0;
            if (*now == '(') {
                now++;
                hoge = calc(now);
                if (hoge == -1) return -1;
                now++;
            }
            else if (*now == '0' || *now == '1') {
                hoge = num(now);
                if (hoge == -1) return -1;
            }
            else return -1;
            ans += hoge;
        }
        else if (*now == '-') {
            now++;
            int hoge = 0;
            if (*now == '(') {
                now++;
                hoge = calc(now);
                if (hoge == -1) return -1;
                now++;
            }
            else if (*now == '0' || *now == '1') {
                hoge = num(now);
                if (hoge == -1) return -1;
            }
            else return -1;
            ans -= hoge;
        }
        else if (*now == '*') {
            now++;
            int hoge = 0;
            if (*now == '(') {
                now++;
                hoge = calc(now);
                if (hoge == -1) return -1;
                now++;
            }
            else if (*now == '0' || *now == '1') {
                hoge = num(now);
                if (hoge == -1) return -1;
            }
            else return -1;
            ans *= hoge;
        }
        else if (*now == '0') {
            return -1;
        }
        else if (*now == '1') {
            return -1;
        }
        else if (*now == '(') {
            return -1;
        }
        else break;
        if (ans < 0 || ans >= (1 << 10)) return -1;
    }
    if (next_req == 1) {
        return -1;
    }
    return ans;
}

void solve() {
    string s;
    cin >> s;
    s = "0+" + s;
    s.push_back(')');
    int ans = -1;
    REP(i, 7 * 7 * 7 * 7 * 7) {
        string b;
        int now = i;
        string c = "01+-*()";
        REP(q, s.length()) {
            if (s[q] == '.') {
                b.push_back(c[now % 7]);
                now /= 7;
            }
            else {
                b.push_back(s[q]);
            }
        }
        int ng = 0;
        for (int q = 0; q < b.length() - 1; ++q) {
            if (b[q] == '(') {
                ng++;
            }
            else if (b[q] == ')') {
                ng--;
            }
            if (ng < 0) {
                b.clear();
                break;
            }
        }
        if (ng != 0) b.clear();
        if (b.size() == 0) continue;
        State hoge = b.begin();

        int nya = calc(hoge);
        if (nya > ans) {
            ans = max(ans, nya);
        }
    }
    cout << ans << endl;
}

#undef int
int main() {
    init();
    solve();
}
accuracy: 0.48905109489051096
time_ms: 10
memory_kb: 3240
final_rank: 14

code_snippet: #define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-5L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define seg_size 262144LL
#define MOD 998244353LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

// geometry library

typedef complex<long double> Point;
typedef pair<complex<long double>, complex<long double>> Line;

typedef struct Circle {
    complex<long double> center;
    long double r;
}Circle;

//内積、 dot(a,b) = |a||b|cos()
long double dot(Point a, Point b) {
    return (a.real() * b.real() + a.imag() * b.imag());
}
//外積、cross(a,b) = |a||b|sin()
long double cross(Point a, Point b) {
    return (a.real() * b.imag() - a.imag() * b.real());
}

//線分と点の距離
long double Dist_Line_Point(Line a, Point b) {
    if (dot(a.second - a.first, b - a.first) < eps) return abs(b - a.first);
    if (dot(a.first - a.second, b - a.second) < eps) return abs(b - a.second);
    return abs(cross(a.second - a.first, b - a.first)) / abs(a.second - a.first);
}

//線分の交差判定
int is_intersected_ls(Line a, Line b) {
    return (cross(a.second - a.first, b.first - a.first) * cross(a.second - a.first, b.second - a.first) < 0) &&
        (cross(b.second - b.first, a.first - b.first) * cross(b.second - b.first, a.second - b.first) < 0);
}

//線分の交点
Point intersection_l(Line a, Line b) {
    Point da = a.second - a.first;
    Point db = b.second - b.first;
    return a.first + da * cross(db, b.first - a.first) / cross(db, da);
}

//線分と線分の距離
long double Dist_Line_Line(Line a, Line b) {
    if (is_intersected_ls(a, b) == 1) {
        return 0;
    }
    return min({ Dist_Line_Point(a,b.first), Dist_Line_Point(a,b.second),Dist_Line_Point(b,a.first),Dist_Line_Point(b,a.second) });
}

//円と円の交点
pair<Point, Point> intersection_Circle_Circle(Circle a, Circle b) {
    long double dist = abs(a.center - b.center);
    assert(dist <= eps + a.r + b.r);
    assert(dist+eps >= abs(a.r - b.r));
    Point target = b.center - a.center;
    long double pointer = target.real() * target.real() + target.imag() * target.imag();
    long double aa = pointer + a.r * a.r - b.r * b.r;
    aa /= 2.0L;
    Point l{ (aa * target.real() + target.imag() * sqrt(pointer * a.r * a.r - aa * aa))/pointer,
            (aa* target.imag() - target.real() * sqrt(pointer * a.r * a.r - aa * aa)) / pointer};
    Point r{ (aa * target.real() - target.imag() * sqrt(pointer * a.r * a.r - aa * aa)) / pointer,
        (aa * target.imag() + target.real() * sqrt(pointer * a.r * a.r - aa * aa)) / pointer };
    r = r + a.center;
    l = l + a.center;
    return mp(l, r);
}

//end of geometry



void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

#define int ll
int num(State& a) {
    int ans = 0;
    while (*a == '0' || *a == '1') {
        ans *= 2;
        ans += *a - '0';
        a++;
        if (ans >= (1 << 10)) {
            return -1;
        }
    }
    return ans;
}
int calc(State& a,int ok) {
    int hoge =0;
    if (*a == '(') {
        a++;
        hoge = calc(a, 1);
    }
    else {
        if (*a != '0' && *a != '1') return -1;
        hoge = num(a);
    }
    if (hoge == -1) return -1;
    if (ok == 1 && *a == ')') return -1;
    while (*a != ')' && *a != ' ') {
        if (*a == '+') {
            a++;
            int tmp = 0;
            if (*a == '(') {
                a++;
                tmp = calc(a, 1);
            }
            else {
                if (*a != '0' && *a != '1') return -1;
                tmp = num(a);
            }
            if (tmp == -1) return -1;
            hoge += tmp;
            if (hoge >= (1 << 10)) return -1;
        }
        else if (*a == '-') {
            a++;
            int tmp = 0;
            if (*a == '(') {
                a++;
                tmp = calc(a, 1);
            }
            else {

                if (*a != '0' && *a != '1') return -1;
                tmp = num(a);
            }
            if (tmp == -1) return -1;
            hoge -= tmp;
            if (hoge >= (1 << 10) || hoge < 0) return -1;
        }
        else if (*a == '*') {
            a++;
            int tmp = 0;
            if (*a == '(') {
                a++;
                tmp = calc(a, 1);
            }
            else {
                if (*a != '0' && *a != '1') return -1;
                tmp = num(a);
            }
            if (tmp == -1) return -1;
            hoge *= tmp;
            if (hoge >= (1 << 10) || hoge < 0) return -1;
        }
        else return -1;
    }
    if (*a == ')') a++;
    return hoge;
}
void solve(){
    while (true) {
        string s;
        cin >> s;
        s.push_back(' ');
        int ans = -1;
        for (int i = 0; i < 7 * 7 * 7 * 7 * 7; ++i) {
            string b;
            int now = i;
            REP(q, s.length()) {
                if (s[q] == '.') {
                    if (now % 7 == 0) {
                        b.push_back('0');
                    }
                    else if (now % 7 == 1) {
                        b.push_back('1');
                    }
                    else if (now % 7 == 2) {
                        b.push_back('+');
                    }
                    else if (now % 7 == 3) {
                        b.push_back('-');
                    }
                    else if (now % 7 == 4) {
                        b.push_back('*');
                    }
                    else if (now % 7 == 5) {
                        b.push_back('(');
                    }
                    else if (now % 7 == 6) {
                        b.push_back(')');
                    }
                    now /= 7;
                }
                else {
                    b.push_back(s[q]);
                }
            }
            int cnt = 0;
            REP(q, b.length()-1) {
                if (b[q] == '(') cnt++;
                else if (b[q] == ')') cnt--;
                if (cnt < 0) {
                    b.clear();
                    break;
                }
            }
            if (cnt != 0) b.clear();
            if (b.empty() == true) continue;
            State beg = b.begin();
            ans = max(ans, calc(beg, 0));
        }
        cout << ans << endl;
        return;
    }
}

#undef int
int main() {
    init();
    solve();
}
accuracy: 0.48905109489051096
time_ms: 10
memory_kb: 3236
final_rank: 13

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* 再帰下降法 */
// char *p = str; res = expr(p);

int term(char* &s);
int number(char* &s);
int factor(char* &s);
int expr(char* &s);

const int LIMIT = 1 << 10;

//数
int number(char* &s){
  if (!*s) throw "number";

  int res = 0;
  while('0' <= *s && *s <= '9')
    res = res*2 + (*s++ - '0');

  if (*s == '(') throw "number";

  if (res < 0 || LIMIT <= res)
    throw "number";

  return res;
}

//乗算除算(優先順位:高)
int term(char* &s){
  if (!*s) throw "term";

  int res = factor(s);
  while(1){
    if(*s == '*') res *= factor(++s);
    else if(*s == '/') res /= factor(++s);
    else break;

    if (res < 0 || LIMIT <= res)
      throw "term";
  }

  if (res < 0 || LIMIT <= res)
    throw "term";

  return res;
}

//括弧か数
int factor(char* &s){
  if (!*s) throw "factor";
  if (!isdigit(*s) && *s != '(') throw "factor";

  if(*s != '(') return number(s);
  int res = expr(++s);

  if (!*s) throw "factor";

  s++;

  if (res < 0 || LIMIT <= res)
    throw "factor";

  return res;
}

//式(優先順位: 低)
int expr(char* &s){
  if (!*s) throw "expr";

  int res = term(s);
  while(1){
    if(*s == '+') res += term(++s);
    else if(*s == '-') res -= term(++s);
    else break;

    if (res < 0 || LIMIT <= res)
      throw "term";
  }

  if (res < 0 || LIMIT <= res)
    throw "expr";

  return res;
}

bool check(string s) {
  stack<int> st;

  for (int i=0; i<s.size(); i++) {
    switch (s[i]) {
    case '(':
      st.push(1);
      break;
    case ')': {
      if (st.empty()) return false;
      if (st.top() > 0) return false;
      while(st.size() && st.top() < 0) st.pop();
      if (st.empty()) return false;
      st.pop();
    }
      break;
    case '0':
    case '1':
      break;
    default:
      st.push(-1);
      break;
    }
  }

  while(st.size() && st.top() < 0)
    st.pop();

  return st.empty();
}


int calc(string s2) {
  if (!check(s2)) return -1;

  char s[1000];
  strcpy(s, s2.c_str());
  char *p = s;

  try{
    int res = expr(p);

    if (*p) return -1;

    return res;

  }catch(...){

    return -1;
  }
}

int main(){
  string str;

  cin >> str;

  vector<int> dots;

  for (int i=0; i<str.size(); i++)
    if (str[i] == '.') dots.push_back(i);

  int ans = -1;

  int limit = 7 * 7 * 7 * 7 * 7;
  for (int i=0; i<limit; i++) {
    int tmp = i;

    for (int p : dots) {
      str[p] = "01+-*()"[tmp % 7];
      tmp /= 7;
    }

    int res = calc(str);
    if (ans < res) {
      debug(str); debug(res);
    }

    ans = max(ans, res);
  }

  cout << ans << endl;

  return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 3268
final_rank: 8

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* 再帰下降法 */
// char *p = str; res = expr(p);

int term(char* &s);
int number(char* &s);
int factor(char* &s);
int expr(char* &s);

const int LIMIT = 1 << 10;

//数
int number(char* &s){
  if (!*s) throw "number";

  int res = 0;
  while('0' <= *s && *s <= '9')
    res = res*2 + (*s++ - '0');

  if (*s == '(') throw "number";

  if (res < 0 || LIMIT <= res)
    throw "number";

  return res;
}

//乗算除算(優先順位:高)
int term(char* &s){
  if (!*s) throw "term";

  int res = factor(s);
  while(1){
    if(*s == '*') res *= factor(++s);
    else if(*s == '/') res /= factor(++s);
    else break;
  }

  if (res < 0 || LIMIT <= res)
    throw "term";

  return res;
}

//括弧か数
int factor(char* &s){
  if (!*s) throw "factor";
  if (!isdigit(*s) && *s != '(') throw "factor";

  if(*s != '(') return number(s);
  int res = expr(++s);

  if (!*s) throw "factor";

  s++;

  if (res < 0 || LIMIT <= res)
    throw "factor";

  return res;
}

//式(優先順位: 低)
int expr(char* &s){
  if (!*s) throw "expr";

  int res = term(s);
  while(1){
    if(*s == '+') res += term(++s);
    else if(*s == '-') res -= term(++s);
    else break;
  }

  if (res < 0 || LIMIT <= res)
    throw "expr";

  return res;
}

bool check(string s) {
  stack<int> st;

  for (int i=0; i<s.size(); i++) {
    switch (s[i]) {
    case '(':
      st.push(1);
      break;
    case ')': {
      if (st.empty()) return false;
      if (st.top() > 0) return false;
      while(st.size() && st.top() < 0) st.pop();
      if (st.empty()) return false;
      st.pop();
    }
      break;
    case '0':
    case '1':
      break;
    default:
      st.push(-1);
      break;
    }
  }

  while(st.size() && st.top() < 0)
    st.pop();

  return st.empty();
}


int calc(string s2) {
  if (!check(s2)) return -1;

  char s[1000];
  strcpy(s, s2.c_str());
  char *p = s;

  try{
    int res = expr(p);

    if (*p) return -1;

    return res;

  }catch(...){

    return -1;
  }
}

int main(){
  string str;

  cin >> str;

  vector<int> dots;

  for (int i=0; i<str.size(); i++)
    if (str[i] == '.') dots.push_back(i);

  int ans = -1;

  int limit = 7 * 7 * 7 * 7 * 7;
  for (int i=0; i<limit; i++) {
    int tmp = i;

    for (int p : dots) {
      str[p] = "01+-*()"[tmp % 7];
      tmp /= 7;
    }

    int res = calc(str);
    if (ans < res) {
      debug(str); debug(res);
    }

    ans = max(ans, res);
  }

  cout << ans << endl;

  return 0;
}
accuracy: 0.656934306569343
time_ms: 100
memory_kb: 3268
final_rank: 12

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* 再帰下降法 */
// char *p = str; res = expr(p);

int term(char* &s);
int number(char* &s);
int factor(char* &s);
int expr(char* &s);

const int LIMIT = 1 << 10;

//数
int number(char* &s){
  if (!*s) throw "number";

  int res = 0;
  while('0' <= *s && *s <= '9')
    res = res*2 + (*s++ - '0');

  if (res < 0 || LIMIT <= res)
    throw "number";

  return res;
}

//乗算除算(優先順位:高)
int term(char* &s){
  if (!*s) throw "term";

  int res = factor(s);
  while(1){
    if(*s == '*') res *= factor(++s);
    else if(*s == '/') res /= factor(++s);
    else break;
  }

  if (res < 0 || LIMIT <= res)
    throw "term";

  return res;
}

//括弧か数
int factor(char* &s){
  if (!*s) throw "factor";

  if(*s != '(') return number(s);
  int res = expr(++s);

  if (!*s) throw "factor";

  s++;

  if (res < 0 || LIMIT <= res)
    throw "factor";

  return res;
}

//式(優先順位: 低)
int expr(char* &s){
  if (!*s) throw "expr";

  int res = term(s);
  while(1){
    if(*s == '+') res += term(++s);
    else if(*s == '-') res -= term(++s);
    else break;
  }

  if (res < 0 || LIMIT <= res)
    throw "expr";

  return res;
}

bool check(string s) {
  stack<int> st;

  for (int i=0; i<s.size(); i++) {
    switch (s[i]) {
    case '(':
      st.push(1);
      break;
    case ')': {
      if (st.empty()) return false;
      if (st.top() > 0) return false;
      while(st.size() && st.top() < 0) st.pop();
      if (st.empty()) return false;
      st.pop();
    }
      break;
    case '0':
    case '1':
      break;
    default:
      st.push(-1);
      break;
    }
  }

  return true;
}


int calc(string s2) {
  if (!check(s2)) return -1;

  char s[1000];
  strcpy(s, s2.c_str());
  char *p = s;

  try{
    int res = expr(p);

    if (*p) return -1;

    return res;

  }catch(...){

    return -1;
  }
}

int main(){
  string str;

  cin >> str;

  vector<int> dots;

  for (int i=0; i<str.size(); i++)
    if (str[i] == '.') dots.push_back(i);

  int ans = -1;

  int limit = 7 * 7 * 7 * 7 * 7;
  for (int i=0; i<limit; i++) {
    int tmp = i;

    for (int p : dots) {
      str[p] = "01+-*()"[tmp % 7];
      tmp /= 7;
    }

    int res = calc(str);
    debug(str); debug(res);

    ans = max(ans, res);
  }

  cout << ans << endl;

  return 0;
}
accuracy: 0.0364963503649635
time_ms: 30
memory_kb: 3212
final_rank: 19

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* 再帰下降法 */
// char *p = str; res = expr(p);

int term(char* &s);
int number(char* &s);
int factor(char* &s);
int expr(char* &s);

const int LIMIT = 1 << 10;

//数
int number(char* &s){
  if (!*s) throw "number";

  int res = 0;
  while('0' <= *s && *s <= '9')
    res = res*2 + (*s++ - '0');

  if (res < 0 || LIMIT <= res)
    throw "number";

  return res;
}

//乗算除算(優先順位:高)
int term(char* &s){
  if (!*s) throw "term";

  int res = factor(s);
  while(1){
    if(*s == '*') res *= factor(++s);
    else if(*s == '/') res /= factor(++s);
    else break;
  }

  if (res < 0 || LIMIT <= res)
    throw "term";

  return res;
}

//括弧か数
int factor(char* &s){
  if (!*s) throw "factor";

  if(*s != '(') return number(s);
  int res = expr(++s);

  if (!*s) throw "factor";

  s++;

  if (res < 0 || LIMIT <= res)
    throw "factor";

  return res;
}

//式(優先順位: 低)
int expr(char* &s){
  if (!*s) throw "expr";

  int res = term(s);
  while(1){
    if(*s == '+') res += term(++s);
    else if(*s == '-') res -= term(++s);
    else break;
  }

  if (res < 0 || LIMIT <= res)
    throw "expr";

  return res;
}

bool check(string s) {
  bool open = false;
  bool onlyNumber = false;

  for (char c : s) {
    switch (c) {
    case '(':
      open = true;
      onlyNumber = true;
      break;
    case ')':
      if (open && onlyNumber) return false;
      open = false;
      break;
    case '0':
    case '1':
      break;
    default:
      onlyNumber = false;
      break;
    }
  }

  return true;
}


int calc(string s2) {
  if (!check(s2)) return -1;

  char s[1000];
  strcpy(s, s2.c_str());
  char *p = s;

  try{
    int res = expr(p);

    if (*p) return -1;

    return res;

  }catch(...){

    return -1;
  }
}

int main(){
  string str;

  cin >> str;

  vector<int> dots;

  for (int i=0; i<str.size(); i++)
    if (str[i] == '.') dots.push_back(i);

  int ans = -1;

  int limit = 7 * 7 * 7 * 7 * 7;
  for (int i=0; i<limit; i++) {
    int tmp = i;

    for (int p : dots) {
      str[p] = "01+-*()"[tmp % 7];
      tmp /= 7;
    }

    int res = calc(str);
    debug(str); debug(res);

    ans = max(ans, res);
  }

  cout << ans << endl;

  return 0;
}
accuracy: 0.021897810218978103
time_ms: 30
memory_kb: 3160
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef string::const_iterator State;
class ParseError {};

int digit(State& begin);
int number(State& begin);
int term(State& begin);
int fact(State& begin);
int expr(State& begin);

int digit(State& begin) {
    int res = *begin - '0';
    begin++;
    return res;
}

int number(State& begin) {
    if (!isdigit(*begin)) throw ParseError();
    int res = digit(begin);
    while (isdigit(*begin)) {
        res *= 2;
        res += digit(begin);
    }
    if (res >= 1024 || 0 > res) throw ParseError();
    return res;
}

int term(State& begin) {
    int res = fact(begin);
    while (*begin == '*') {
        begin++;
        res *= fact(begin);
    }
    if (res >= 1024 || 0 > res) throw ParseError();
    return res;
}

int fact(State& begin) {
    if (*begin == '(') {
        begin++;
        int res = expr(begin);
        if (*begin != ')') throw ParseError();
        begin++;
        return res;
    }
    return number(begin);
}

int expr(State& begin) {
    int res = term(begin);
    while (true) {
        if (*begin == '+') {
            begin++;
            res += term(begin);
        } else if (*begin == '-') {
            begin++;
            res -= term(begin);
        } else {
            break;
        }
        if (res >= 1024 || 0 > res) throw ParseError();
    }
    return res;
}

bool check(string s) {
    vector<int> v;
    set<int> S;
    map<int, bool> m;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '(') {
            v.push_back(i);
            S.insert(i);
        }
        if ((s[i] == '*' || s[i] == '+' || s[i] == '-') && v.size()) {
            m[v[v.size() - 1]] = true;
        }
        if (s[i] == ')') {
            v.pop_back();
        }
    }
    bool flag = true;
    for (auto x : S) {
        flag &= m[x];
    }
    return flag;
}

int solve(string s) {
    State begin = s.begin();
    try {
        int res = expr(begin);
        if (begin == s.end() && check(s)) {
            return res;
        } else {
            return -1;
        }
    } catch (ParseError p) {
        return -1;
    }
}

int main() {
    string s;
    cin >> s;
    string kouho = "01+-*()";
    int SIZE = 1;
    int n = 7;
    int N = 0;
    vector<int> index;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '.') {
            index.push_back(i);
            N++;
        }
    }
    for (int i = 0; i < N; i++) SIZE *= n;
    vector<vector<char>> v(SIZE, vector<char>());
    for (int rep = 0; rep < N; rep++) {
        SIZE /= n;
        for (int i = 0; i < v.size(); i++) {
            v[i].push_back(kouho[(i / SIZE) % n]);
        }
    }
    int ans = -1;
    for (auto V : v) {
        for (int i = 0; i < N; i++) {
            s[index[i]] = V[i];
        }
        ans = max(ans, solve(s));
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 4020
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef string::const_iterator State;
class ParseError {};

int factor(State& s);

int digit(State& s) {
    if ('0' <= *s && *s <= '1') {
        return *s - '0';
    } else {
        throw ParseError();
    }
}

int number(State& s) {
    if (!isdigit(*s)) throw ParseError();
    int res = 0;
    while (isdigit(*s)) {
        res *= 2;
        res += *s - '0';
        s++;
    }
    if (res >= 1024) {
        throw ParseError();
    }
    return res;
}

int term(State& s) {
    int res = (*s == '(' ? factor(s) : number(s));
    while (true) {
        if (*s == '*') {
            s++;
            res *= (*s == '(' ? factor(s) : number(s));
            if (res >= 1024) throw ParseError();
        } else {
            break;
        }
    }
    return res;
}

int expression(State& s) {
    int counter = 0;
    int res = term(s);
    while (true) {
        if (*s == '+') {
            s++;
            res += term(s);
            counter++;
        } else if (*s == '-') {
            s++;
            res -= term(s);
            counter++;
        } else {
            break;
        }
        if (res >= 1024) throw ParseError();
    }
    return res;
}

int factor(State& s) {
    if (*s == '(') {
        s++;
        int res = expression(s);
        if (*s != ')') throw ParseError();
        s++;
        return res;
    } else {
        return expression(s);
    }
}

bool check(string s) {
    vector<int> v;
    set<int> S;
    map<int, bool> m;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '(') {
            v.push_back(i);
            S.insert(i);
        }
        if ((s[i] == '*' || s[i] == '+' || s[i] == '-') && v.size()) {
            m[v[v.size() - 1]] = true;
        }
        if (s[i] == ')') {
            v.pop_back();
        }
    }
    bool flag = true;
    for (auto x : S) {
        flag &= m[x];
    }
    return flag;
}

int solve(string s) {
    State begin = s.begin();
    try {
        int res = factor(begin);
        if (begin != s.end() || !check(s)) {
            return -1;
        } else {
            return res;
        }
    } catch (ParseError p) {
        return -1;
    }
}

int main() {
    string s;
    cin >> s;
    string kouho = "01+-*().";
    int SIZE = 1;
    int n = 8;
    int N = 0;
    vector<int> index;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '.') {
            index.push_back(i);
            N++;
        }
    }
    for (int i = 0; i < N; i++) SIZE *= n;
    vector<vector<char>> v(SIZE, vector<char>());
    for (int rep = 0; rep < N; rep++) {
        SIZE /= n;
        for (int i = 0; i < v.size(); i++) {
            v[i].push_back(kouho[(i / SIZE) % n]);
        }
    }
    int ans = -1;
    for (auto V : v) {
        for (int i = 0; i < N; i++) {
            s[index[i]] = V[i];
        }
        // cerr << s << solve(s) << endl;
        ans = max(ans, solve(s));
    }
    cout << ans << endl;
}
accuracy: 0.06569343065693431
time_ms: 90
memory_kb: 4816
final_rank: 17

code_snippet: #include <cstdio>
#include <cctype>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <stdexcept>

#define fprintf(...) void(0)

const std::string chs="01+-*()";

bool next_assignment(std::vector<size_t> &d) {
  for (size_t i=d.size(); i--;) {
    if (d[i] < 6) {
      ++d[i];
      return true;
    }
    d[i] = 0;
  }
  return false;
}

int apply(int lhs, char op, int rhs) {
  if (op == '+') {
    lhs += rhs;
  } else if (op == '-') {
    lhs -= rhs;
  } else if (op == '*') {
    lhs *= rhs;
  }
  if (!(0 <= lhs && lhs < 1024))
    throw std::logic_error("overflow");

  return lhs;
}

int parse(
    const std::string &s, size_t &i, size_t preced=0) {

  static const std::vector<std::string> ops={"+-", "*"};

  if (preced == ops.size()) {
    if (s[i] == '(') {
      fprintf(stderr, "starting from %zu\n", i);
      size_t j=i;
      parse(s, ++j, preced);
      int res=parse(s, ++i);
      if (!(i < s.length() && s[i] == ')'))
        throw std::logic_error("mismatch parentheses");
      fprintf(stderr, "i: %zu, j: %zu\n", i, j);
      if (i == j)
        throw std::logic_error("redundant parentheses");
      ++i;
      return res;
    }
    if (isdigit(s[i])) {
      int res=s[i]-'0';
      while (++i < s.length() && isdigit(s[i])) {
        res = res*2+s[i]-'0';
        if (res >= 1024) throw std::logic_error("overflow");
      }
      return res;
    }
    throw std::logic_error("unexpected");
  }

  int res=parse(s, i, preced+1);
  while (i < s.length()) {
    char op=s[i];
    if (!std::count(ops[preced].begin(), ops[preced].end(), op)) break;
    int tmp=parse(s, ++i, preced+1);
    res = apply(res, op, tmp);
  }
  return res;
}

int parse(const std::string &s, std::vector<size_t> &d) {
  std::string t;
  size_t i=0;
  for (char ch: s) {
    if (ch == '.') {
      t += chs[d[i++]];
      continue;
    }
    t += ch;
  }
  i = 0;
  fprintf(stderr, "%s\n", t.c_str());
  int res=parse(t, i);
  fprintf(stderr, "[%zu]\n", i);
  if (i < t.length())
    throw std::logic_error("garbage");
  return res;
}

int main() {
  char buf[128];
  scanf("%s", buf);
  std::string s=buf;
  size_t dot=std::count(s.begin(), s.end(), '.');
  std::vector<size_t> d(dot);

  int res=-1;
  do {
    try {
      res = std::max(res, parse(s, d));
    } catch (std::logic_error &e) {
      fprintf(stderr, "failed: %s\n", e.what());
    }
  } while (next_assignment(d));
  printf("%d\n", res);
}
accuracy: 1
time_ms: 140
memory_kb: 3044
final_rank: 10

code_snippet: #include <cstdio>
#include <cctype>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <stdexcept>

#define fprintf(...) void(0)

const std::string chs="01+-*()";

bool next_assignment(std::vector<size_t> &d) {
  for (size_t i=d.size(); i--;) {
    if (d[i] < 6) {
      ++d[i];
      return true;
    }
    d[i] = 0;
  }
  return false;
}

int apply(int lhs, char op, int rhs) {
  if (op == '+') {
    lhs += rhs;
  } else if (op == '-') {
    lhs -= rhs;
  } else if (op == '*') {
    lhs *= rhs;
  }
  if (!(0 <= lhs && lhs < 1024))
    throw std::logic_error("overflow");

  return lhs;
}

int parse(
    const std::string &s, size_t &i, size_t preced=0) {

  static const std::vector<std::string> ops={"+-", "*"};

  if (preced == ops.size()) {
    if (s[i] == '(') {
      fprintf(stderr, "starting from %zu\n", i);
      size_t j=i;
      parse(s, ++j, preced);
      int res=parse(s, ++i);
      if (!(i < s.length() && s[i] == ')'))
        throw std::logic_error("mismatch parentheses");
      fprintf(stderr, "i: %zu, j: %zu\n", i, j);
      if (i == j)
        throw std::logic_error("redundant parentheses");
      ++i;
      return res;
    }
    if (isdigit(s[i])) {
      int res=s[i]-'0';
      while (++i < s.length() && isdigit(s[i])) {
        res = res*2+s[i]-'0';
      }
      return res;
    }
    throw std::logic_error("unexpected");
  }

  int res=parse(s, i, preced+1);
  while (i < s.length()) {
    char op=s[i];
    if (!std::count(ops[preced].begin(), ops[preced].end(), op)) break;
    int tmp=parse(s, ++i, preced+1);
    res = apply(res, op, tmp);
  }
  return res;
}

int parse(const std::string &s, std::vector<size_t> &d) {
  std::string t;
  size_t i=0;
  for (char ch: s) {
    if (ch == '.') {
      t += chs[d[i++]];
      continue;
    }
    t += ch;
  }
  i = 0;
  fprintf(stderr, "%s\n", t.c_str());
  int res=parse(t, i);
  fprintf(stderr, "[%zu]\n", i);
  if (i < t.length())
    throw std::logic_error("garbage");
  return res;
}

int main() {
  char buf[128];
  scanf("%s", buf);
  std::string s=buf;
  size_t dot=std::count(s.begin(), s.end(), '.');
  std::vector<size_t> d(dot);

  int res=-1;
  do {
    try {
      res = std::max(res, parse(s, d));
    } catch (std::logic_error &e) {
      fprintf(stderr, "failed: %s\n", e.what());
    }
  } while (next_assignment(d));
  printf("%d\n", res);
}
accuracy: 0.08029197080291971
time_ms: 110
memory_kb: 3024
final_rank: 16