Problem:
小学生のイクタ君は、ある日おじいさんから数式が書かれた紙をもらった。
どうやらおじいさんは数式の答えの金額だけお小遣いをくれるらしい。
イクタ君はまだ足し算、引き算、掛け算しか習ってなかったので、数式にも足し算と引き算と掛け算しか使われていない。
通常の計算では足し算と引き算より掛け算を先に計算しなければならないのだが、イクタ君は演算子の優先順位についての理解があやふやだったので、とりあえず数式の計算結果が最大になるような都合の良い優先順位を考えることにした。
+−×
の3つの二項演算子と括弧を含む数式が与えられる。
3つの演算子の優先順位を任意に変更して、数式を最大化したときの計算結果を答えよ。
ただし、以下の点に注意せよ。
演算子は必ず左結合である。
(同じ優先順位の演算子は必ず数式の左側から計算する。)
異なる演算子が同じ優先順位であってもよい。
一つの数式を計算している途中で優先順位を変更してはならない。
Input
入力は以下の形式で与えられる。
0〜9の数字と演算子'+','-','*'、括弧'(',')'で構成された数式
正確に記述すると入力は以下のBNFで示される形式になっている
<expr> ::= ( <expr> ) | <number> | <expr> <op> <expr>
<op> ::= + | - | *
<number>は非負整数を表す。
Constraints
入力は以下の制約を満たす。
数式は200文字以下である。
どのような優先順位を設定しても、計算の結果やその途中で64bit整数型でoverflowするようなことはない。
Output
数式から得られる最大値を1行で出力せよ。
Sample Input 1
3-2*3
Output for the Sample Input 1
3
*の優先順位を-より低くすることでこのようになる。
Sample Input 2
(5-3*4)*(0-2+1)
Output for the Sample Input 2
21
優先順位は+>*>-
Sample Input 3
1-2+3-4+5-6*0
Output for the Sample Input 3
3
優先順位が一般的な場合
Sample Input 4
(1989967-3*1-211+4487)
Output for the Sample Input 4
8511076028

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)

string S;
vector<char> P = { '+','-','*' };
vector<set<char>> t(3);
ll ope(ll a, ll b, char p) {
    if (p == '+')return a + b;
    else if (p == '-')return a - b;
    else return a * b;
}

ll expr(ll l, ll r) {
    ll k = 0;
    bool notn = 1;
    for (ll i = l; i < r; i++) {
        if (S[i] < '0' || '9' < S[i]) {
            notn = 0;
            break;
        }
    }
    if (notn) {
        return stoll(S.substr(l, r - l));
    }

    rep(u, 3) {
        bool op1 = 1;
        ll res = -1e18;
        char Lop;
        ll LL = l;
        for (ll i = l; i < r; i++) {
            if (S[i] == '(')k++;
            else if (S[i] == ')') {
                k--;
            }
            if (t[u].count(S[i])) {
                if (k == 0) {
                    if (op1)res = expr(LL, i);
                    else res = ope(res, expr(LL, i), Lop);
                    LL = i + 1;
                    op1 = 0;
                    Lop = S[i];
                }
            }
        }
        if (!op1)return ope(res, expr(LL, r), Lop);
    }


    return expr(l + 1, r - 1);


}

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

    cin >> S;
    ll an = (1ll<<63);
    an=-an;
    rep(bi, (1 << 12)) {
        rep(k, 3)t[k].clear();
        ll bit = bi;
        bool OOK = 1;
        rep(m, 3) {
            ll n = bit % 4;
            if (n == 3) {
                OOK = 0;
                break;
                continue;
            }
            else t[n].insert(P[m]);
            bit /= 4;
        }
        if (!OOK)continue;;
        ll d = expr(0, S.size());
        an=max(an,d);
    }
    cout << an << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3448
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#include <complex>
#include <random>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vvvvvll = vector<vvvvll>;
using vvvvvvll = vector<vvvvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vvvvb = vector<vvvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vvvvd = vector<vvvd>;
using vvvvvd = vector<vvvvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;
#define tN(t) (t==1?XN:YN)
#define tS(t) (t==1?XS:YS)
#define tA(t) (t==1?XA:YA)

template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    if (b == 0)return a;
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}
ll sqrtz(ll N) {
    ll L = 0;
    ll R = sqrt(N) + 10000;
    while (abs(R - L) > 1) {
        ll mid = (R + L) / 2;
        if (mid * mid <= N)L = mid;
        else R = mid;
    }
    return L;

}

vector<ll> fact, factinv, inv;
ll mod = 998244353;
void prenCkModp(ll n) {
    fact.resize(n + 5);
    factinv.resize(n + 5);
    inv.resize(n + 5);
    fact.at(0) = fact.at(1) = 1;
    factinv.at(0) = factinv.at(1) = 1;
    inv.at(1) = 1;
    for (ll i = 2; i < n + 5; i++) {
        fact.at(i) = (fact.at(i - 1) * i) % mod;
        inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
        factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
    }

}
ll nCk(ll n, ll k) {
    if (n < k) return 0;
    return fact.at(n) * (factinv.at(k) * factinv.at(n - k) % mod) % mod;
}
ll modPow(ll a, ll n, ll p) {
    ll res = 1;
    ll k = a;
    while (n > 0) {
        if (n % 2 == 1) {
            res *= k;
            if (res > p)res %= p;
        }
        k = k * k;
        if (k > p)k %= p;
        n /= 2;
    }
    return res;
}

ll inva(ll N) {
    ll a = N, b = mod, c = 1, d = 0;
    while (b > 0) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        c -= t * d;
        swap(c, d);

    }
    c %= mod;
    if (c < 0)c += mod;
    return c;

}
string S;
vector<char> P = { '+','-','*' };
vector<set<char>> t(3);
ll ope(ll a, ll b, char p) {
    if (p == '+')return a + b;
    else if (p == '-')return a - b;
    else return a * b;
}

ll expr(ll l, ll r) {
    ll k = 0;
    bool notn = 1;
    for (ll i = l; i < r; i++) {
        if (S[i] < '0' || '9' < S[i]) {
            notn = 0;
            break;
        }
    }
    if (notn) {
        return stoll(S.substr(l, r - l));
    }

    rep(u, 3) {
        bool op1 = 1;
        ll res = -1e18;
        char Lop;
        ll LL = l;
        for (ll i = l; i < r; i++) {
            if (S[i] == '(')k++;
            else if (S[i] == ')') {
                k--;
            }
            if (t[u].count(S[i])) {
                if (k == 0) {
                    if (op1)res = expr(LL, i);
                    else res = ope(res, expr(LL, i), Lop);
                    LL = i + 1;
                    op1 = 0;
                    Lop = S[i];
                }
            }
        }
        if (!op1)return ope(res, expr(LL, r), Lop);
    }


    return expr(l + 1, r - 1);


}

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

    cin >> S;
    sort(all(P));
    ll an = (1ll<<63);
    an=-an;
    rep(bi, (1 << 12)) {
        rep(k, 3)t[k].clear();
        ll bit = bi;
        bool OOK = 1;
        rep(m, 3) {
            ll n = bit % 4;
            if (n == 3) {
                OOK = 0;
                break;
                continue;
            }
            else t[n].insert(P[m])
                ;
            bit /= 4;


        }
        if (!OOK)continue;;
        ll d = expr(0, S.size());
        chmax(an,d);
    }
    cout << an << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3452
final_rank: 3

code_snippet: #include <bits/stdc++.h>
#include <complex>
#include <random>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vvvvvll = vector<vvvvll>;
using vvvvvvll = vector<vvvvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vvvvb = vector<vvvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vvvvd = vector<vvvd>;
using vvvvvd = vector<vvvvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;
#define tN(t) (t==1?XN:YN)
#define tS(t) (t==1?XS:YS)
#define tA(t) (t==1?XA:YA)

template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    if (b == 0)return a;
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}
ll sqrtz(ll N) {
    ll L = 0;
    ll R = sqrt(N) + 10000;
    while (abs(R - L) > 1) {
        ll mid = (R + L) / 2;
        if (mid * mid <= N)L = mid;
        else R = mid;
    }
    return L;

}

vector<ll> fact, factinv, inv;
ll mod = 998244353;
void prenCkModp(ll n) {
    fact.resize(n + 5);
    factinv.resize(n + 5);
    inv.resize(n + 5);
    fact.at(0) = fact.at(1) = 1;
    factinv.at(0) = factinv.at(1) = 1;
    inv.at(1) = 1;
    for (ll i = 2; i < n + 5; i++) {
        fact.at(i) = (fact.at(i - 1) * i) % mod;
        inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
        factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
    }

}
ll nCk(ll n, ll k) {
    if (n < k) return 0;
    return fact.at(n) * (factinv.at(k) * factinv.at(n - k) % mod) % mod;
}
ll modPow(ll a, ll n, ll p) {
    ll res = 1;
    ll k = a;
    while (n > 0) {
        if (n % 2 == 1) {
            res *= k;
            if (res > p)res %= p;
        }
        k = k * k;
        if (k > p)k %= p;
        n /= 2;
    }
    return res;
}

ll inva(ll N) {
    ll a = N, b = mod, c = 1, d = 0;
    while (b > 0) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        c -= t * d;
        swap(c, d);

    }
    c %= mod;
    if (c < 0)c += mod;
    return c;

}
string S;
vector<char> P = { '+','-','*' };
vector<set<char>> t(3);
ll ope(ll a, ll b, char p) {
    if (p == '+')return a + b;
    else if (p == '-')return a - b;
    else return a * b;
}

ll expr(ll l, ll r) {
    ll k = 0;
    bool notn = 1;
    for (ll i = l; i < r; i++) {
        if (S[i] < '0' || '9' < S[i]) {
            notn = 0;
            break;
        }
    }
    if (notn) {
        return stoll(S.substr(l, r - l));
    }

    rep(u, 3) {
        bool op1 = 1;
        ll res = -1e18;
        char Lop;
        ll LL = l;
        for (ll i = l; i < r; i++) {
            if (S[i] == '(')k++;
            else if (S[i] == ')') {
                k--;
            }
            if (t[u].count(S[i])) {
                if (k == 0) {
                    if (op1)res = expr(LL, i);
                    else res = ope(res, expr(LL, i), Lop);
                    LL = i + 1;
                    op1 = 0;
                    Lop = S[i];
                }
            }
        }
        if (!op1)return ope(res, expr(LL, r), Lop);
    }


    return expr(l + 1, r - 1);


}

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

    cin >> S;
    sort(all(P));
    ll an = -((1ll<<61)+1)*2-1;
    rep(bi, (1 << 12)) {
        rep(k, 3)t[k].clear();
        ll bit = bi;
        bool OOK = 1;
        rep(m, 3) {
            ll n = bit % 4;
            if (n == 3) {
                OOK = 0;
                break;
                continue;
            }
            else t[n].insert(P[m])
                ;
            bit /= 4;


        }
        if (!OOK)continue;;
        ll d = expr(0, S.size());
        chmax(an,d);
    }
    cout << an << endl;
}
accuracy: 0.15126050420168066
time_ms: 10
memory_kb: 3484
final_rank: 8

code_snippet: #include <bits/stdc++.h>
#include <complex>
#include <random>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vvvvvll = vector<vvvvll>;
using vvvvvvll = vector<vvvvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vvvvb = vector<vvvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vvvvd = vector<vvvd>;
using vvvvvd = vector<vvvvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;
#define tN(t) (t==1?XN:YN)
#define tS(t) (t==1?XS:YS)
#define tA(t) (t==1?XA:YA)

template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    if (b == 0)return a;
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}
ll sqrtz(ll N) {
    ll L = 0;
    ll R = sqrt(N) + 10000;
    while (abs(R - L) > 1) {
        ll mid = (R + L) / 2;
        if (mid * mid <= N)L = mid;
        else R = mid;
    }
    return L;

}

vector<ll> fact, factinv, inv;
ll mod = 998244353;
void prenCkModp(ll n) {
    fact.resize(n + 5);
    factinv.resize(n + 5);
    inv.resize(n + 5);
    fact.at(0) = fact.at(1) = 1;
    factinv.at(0) = factinv.at(1) = 1;
    inv.at(1) = 1;
    for (ll i = 2; i < n + 5; i++) {
        fact.at(i) = (fact.at(i - 1) * i) % mod;
        inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
        factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
    }

}
ll nCk(ll n, ll k) {
    if (n < k) return 0;
    return fact.at(n) * (factinv.at(k) * factinv.at(n - k) % mod) % mod;
}
ll modPow(ll a, ll n, ll p) {
    ll res = 1;
    ll k = a;
    while (n > 0) {
        if (n % 2 == 1) {
            res *= k;
            if (res > p)res %= p;
        }
        k = k * k;
        if (k > p)k %= p;
        n /= 2;
    }
    return res;
}

ll inva(ll N) {
    ll a = N, b = mod, c = 1, d = 0;
    while (b > 0) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        c -= t * d;
        swap(c, d);

    }
    c %= mod;
    if (c < 0)c += mod;
    return c;

}
string S;
vector<char> P = { '+','-','*' };
vector<set<char>> t(3);
ll ope(ll a, ll b, char p) {
    if (p == '+')return a + b;
    else if (p == '-')return a - b;
    else return a * b;
}

ll expr(ll l, ll r) {
    ll k = 0;
    bool notn = 1;
    for (ll i = l; i < r; i++) {
        if (S[i] < '0' || '9' < S[i]) {
            notn = 0;
            break;
        }
    }
    if (notn) {
        return stoll(S.substr(l, r - l));
    }

    rep(u, 3) {
        bool op1 = 1;
        ll res = -1e18;
        char Lop;
        ll LL = l;
        for (ll i = l; i < r; i++) {
            if (S[i] == '(')k++;
            else if (S[i] == ')') {
                k--;
            }
            if (t[u].count(S[i])) {
                if (k == 0) {
                    if (res < -1e17)res = expr(LL, i);
                    else res = ope(res, expr(LL, i), Lop);
                    LL = i + 1;
                    op1 = 0;
                    Lop = S[i];
                }
            }
        }
        if (!op1)return ope(res, expr(LL, r), Lop);
    }


    return expr(l + 1, r - 1);


}

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

    cin >> S;
    sort(all(P));
    ll an = -1e18;
    rep(bi, (1 << 12)) {
        rep(k, 3)t[k].clear();
        ll bit = bi;
        bool OOK = 1;
        rep(m, 3) {
            ll n = bit % 4;
            if (n == 3) {
                OOK = 0;
                break;
                continue;
            }
            else t[n].insert(P[m])
                ;
            bit /= 4;


        }
        if (!OOK)continue;;
        ll d = expr(0, S.size());
        chmax(an,d);
    }
    cout << an << endl;
}
accuracy: 0.15126050420168066
time_ms: 10
memory_kb: 3448
final_rank: 7

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

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

  string s;
  cin >> s;
  int n = s.size();
  long long ans = LLONG_MIN;
  for (int pp=0;pp<3;pp++) {
    for (int pm=0;pm<3;pm++) {
      for (int pt=0;pt<3;pt++) {
        deque<string> q;
        string tmp = "";
        for (int i=0;i<n;i++) {
          if (s[i] < '0' || s[i] > '9') {
            if (tmp != "") {
              q.push_back(tmp);
              tmp = "";
            }
            q.push_back(s.substr(i,1));
          }
          else {
            tmp += s.substr(i,1);
          }
        }
        if (tmp != "") {
          q.push_back(tmp);
          tmp = "";
        }
        while (q.size() > 1) {
          bool update = false;
          deque<string> qnew;
          /*while (!q.empty()) {
            cout << q.front() << ' ';
            qnew.push_back(q.front());
            q.pop_front();
          }
          cout << endl;
          while (!qnew.empty()) {
            q.push_back(qnew.front());
            qnew.pop_front();
          }*/
          while (q.size() >= 3) {
            string n1 = q.front();
            q.pop_front();
            string n2 = q.front();
            q.pop_front();
            string n3 = q.front();
            q.pop_front();
            if (n1 == "(" && n3 == ")") {
              qnew.push_back(n2);
              update = true;
              break;
            }
            else {
              qnew.push_back(n1);
              q.push_front(n3);
              q.push_front(n2);
            }
          }
          while (!qnew.empty()) {
            q.push_front(qnew.back());
            qnew.pop_back();
          }
          if (update) continue;
          update = false;
          // num op num
          int udep = -1;
          int ndep = 0;
          int up = -1;
          int np = 0;
          int uind = -1;
          int nind = 0;
          if (q.front() == "(") ndep++;
          while (q.size() >= 3) {
            string n1 = q.front();
            q.pop_front();
            string n2 = q.front();
            q.pop_front();
            string n3 = q.front();
            q.pop_front();
            if (n2 == "(") {
              ndep++;
            }
            else if (n2 == ")") {
              ndep--;
            }
            else if (n2 == "+" && n1 != ")" && n3 != "(") {
              if (ndep > udep) {
                udep = ndep;
                up = pp;
                uind = nind;
              }
              else if (ndep == udep) {
                if (pp > up) {
                  up = pp;
                  uind = nind;
                }
              }
            }
            else if (n2 == "-" && n1 != ")" && n3 != "(") {
              if (ndep > udep) {
                udep = ndep;
                up = pm;
                uind = nind;
              }
              else if (ndep == udep) {
                if (pm > up) {
                  up = pm;
                  uind = nind;
                }
              }
            }
            else if (n2 == "*" && n1 != ")" && n3 != "(") {
              if (ndep > udep) {
                udep = ndep;
                up = pt;
                uind = nind;
              }
              else if (ndep == udep) {
                if (pt > up) {
                  up = pt;
                  uind = nind;
                }
              }
            }
            qnew.push_back(n1);
            q.push_front(n3);
            q.push_front(n2);
            nind++;
          }
          while (!q.empty()) {
            qnew.push_back(q.front());
            q.pop_front();
          }
          int cnt = 0;
          while (cnt < uind) {
            q.push_back(qnew.front());
            qnew.pop_front();
            cnt++;
          }
          string n1 = qnew.front();
          qnew.pop_front();
          string n2 = qnew.front();
          qnew.pop_front();
          string n3 = qnew.front();
          qnew.pop_front();
          long long v1 = atoll(n1.c_str());
          long long v3 = atoll(n3.c_str());
          long long v;
          if (n2 == "+") v = v1+v3;
          if (n2 == "-") v = v1-v3;
          if (n2 == "*") v = v1*v3;
          string sv = to_string(v);
          q.push_back(sv);
          while (!qnew.empty()) {
            q.push_back(qnew.front());
            qnew.pop_front();
          }
        }
        string las = q.front();
        q.pop_front();
        long long kans = atoll(las.c_str());
        ans = max(ans,kans);
      }
    }
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3580
final_rank: 5

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

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

  string s;
  cin >> s;
  int n = s.size();
  long long ans = LLONG_MIN;
  for (int pp=0;pp<3;pp++) {
    for (int pm=0;pm<3;pm++) {
      for (int pt=0;pt<3;pt++) {
        deque<string> q;
        string tmp = "";
        for (int i=0;i<n;i++) {
          if (s[i] < '0' || s[i] > '9') {
            if (tmp != "") {
              q.push_back(tmp);
              tmp = "";
            }
            q.push_back(s.substr(i,1));
          }
          else {
            tmp += s.substr(i,1);
          }
        }
        if (tmp != "") {
          q.push_back(tmp);
          tmp = "";
        }
        while (q.size() > 1) {
          bool update = false;
          deque<string> qnew;
          /*while (!q.empty()) {
            cout << q.front() << ' ';
            qnew.push_back(q.front());
            q.pop_front();
          }
          cout << endl;
          while (!qnew.empty()) {
            q.push_back(qnew.front());
            qnew.pop_front();
          }*/
          while (q.size() >= 3) {
            string n1 = q.front();
            q.pop_front();
            string n2 = q.front();
            q.pop_front();
            string n3 = q.front();
            q.pop_front();
            if (n1 == "(" && n3 == ")") {
              qnew.push_back(n2);
              update = true;
              break;
            }
            else {
              qnew.push_back(n1);
              q.push_front(n3);
              q.push_front(n2);
            }
          }
          while (!qnew.empty()) {
            q.push_front(qnew.back());
            qnew.pop_back();
          }
          if (update) continue;
          update = false;
          // num op num
          int udep = -1;
          int ndep = 0;
          int up = -1;
          int np = 0;
          int uind = -1;
          int nind = 0;
          if (q.front() == "(") ndep++;
          while (q.size() >= 3) {
            string n1 = q.front();
            q.pop_front();
            string n2 = q.front();
            q.pop_front();
            string n3 = q.front();
            q.pop_front();
            if (n2 == "(") {
              ndep++;
            }
            else if (n2 == ")") {
              ndep--;
            }
            else if (n2 == "+" && n1 != ")" && n3 != "(") {
              if (ndep > udep) {
                udep = ndep;
                up = pp;
                uind = nind;
              }
              else if (ndep == udep) {
                if (pp > up) {
                  up = pp;
                  uind = nind;
                }
              }
            }
            else if (n2 == "-" && n1 != ")" && n3 != "(") {
              if (ndep > udep) {
                udep = ndep;
                up = pm;
                uind = nind;
              }
              else if (ndep == udep) {
                if (pm > up) {
                  up = pm;
                  uind = nind;
                }
              }
            }
            else if (n2 == "*" && n1 != ")" && n3 != "(") {
              if (ndep > udep) {
                udep = ndep;
                up = pt;
                uind = nind;
              }
              else if (ndep == udep) {
                if (pt > up) {
                  up = pt;
                  uind = nind;
                }
              }
            }
            qnew.push_back(n1);
            q.push_front(n3);
            q.push_front(n2);
            nind++;
          }
          while (!q.empty()) {
            qnew.push_back(q.front());
            q.pop_front();
          }
          int cnt = 0;
          while (cnt < uind) {
            q.push_back(qnew.front());
            qnew.pop_front();
            cnt++;
          }
          string n1 = qnew.front();
          qnew.pop_front();
          string n2 = qnew.front();
          qnew.pop_front();
          string n3 = qnew.front();
          qnew.pop_front();
          long long v1 = atoll(n1.c_str());
          long long v3 = atoll(n3.c_str());
          long long v;
          if (n2 == "+") v = v1+v3;
          if (n2 == "-") v = v1-v3;
          if (n2 == "*") v = v1*v3;
          string sv = to_string(v);
          q.push_back(sv);
          while (!qnew.empty()) {
            q.push_back(qnew.front());
            qnew.pop_front();
          }
        }
        string las = q.front();
        q.pop_front();
        long long kans = atoll(las.c_str());
        ans = max(ans,kans);
      }
    }
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3564
final_rank: 4

code_snippet: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

#define INF -1LL<<63

string S;
char U[11] = "0123456789";
int junjo[4] = { 0,0,1,1 };

long long STOI(string V) {
	int LEN = V.size();
	if (LEN == 0) { return 0; }
	return (V[LEN - 1] - '0') + 10 * (STOI(V.substr(0, LEN - 1)));
}
long long calc(int L, int R) {
	int K = 0;
	vector<int>junjo2[4];
	for (int i = 0; i<4; i++) {
		junjo2[junjo[i]].push_back(i);
	}
	for (int i = 0; i<4; i++) {
		if (junjo2[i].size() >= 1) {
			for (int j = R - 1; j >= L; j--) {
				if (S[j] == '(') { K++; }
				if (S[j] == ')') { K--; }
				for (int k = 0; k<junjo2[i].size(); k++) {
					if (junjo2[i][k] == 0) {
						if (S[j] == '+' && K == 0) {
							return calc(L, j) + calc(j + 1, R);
						}
					}
					if (junjo2[i][k] == 1) {
						if (S[j] == '-' && K == 0) {
							return calc(L, j) - calc(j + 1, R);
						}
					}
					if (junjo2[i][k] == 2) {
						if (S[j] == '*' && K == 0) {
							return calc(L, j)*calc(j + 1, R);
						}
					}
					if (junjo2[i][k] == 3) {
						if (S[j] == '/' && K == 0) {
							return calc(L, j) / calc(j + 1, R);
						}
					}
				}
			}
		}
	}
	if (S[L] == '(' && S[R - 1] == ')') { return calc(L + 1, R - 1); }
	return STOI(S.substr(L, R - L));
}


int main() {
	long long maxn = INF;
	int POW[4] = { 1,4,16,64 };
	cin >> S;
	S += '=';
	for (int i = 0; i < 256; i++) {
		for (int j = 0; j < 4; j++) {
			junjo[j] = (i / POW[j]) % 4;
		}
		maxn = max(maxn, calc(0, S.size() - 1));
	}
	cout << maxn << endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1228
final_rank: 1

code_snippet: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

#define INF 1LL<<60

string S;
char U[11] = "0123456789";
int junjo[4] = { 0,0,1,1 };

long long STOI(string V) {
	int LEN = V.size();
	if (LEN == 0) { return 0; }
	return (V[LEN - 1] - '0') + 10 * (STOI(V.substr(0, LEN - 1)));
}
long long calc(int L, int R) {
	int K = 0;
	vector<int>junjo2[4];
	for (int i = 0; i<4; i++) {
		junjo2[junjo[i]].push_back(i);
	}
	for (int i = 0; i<4; i++) {
		if (junjo2[i].size() >= 1) {
			for (int j = R - 1; j >= L; j--) {
				if (S[j] == '(') { K++; }
				if (S[j] == ')') { K--; }
				for (int k = 0; k<junjo2[i].size(); k++) {
					if (junjo2[i][k] == 0) {
						if (S[j] == '+' && K == 0) {
							return calc(L, j) + calc(j + 1, R);
						}
					}
					if (junjo2[i][k] == 1) {
						if (S[j] == '-' && K == 0) {
							return calc(L, j) - calc(j + 1, R);
						}
					}
					if (junjo2[i][k] == 2) {
						if (S[j] == '*' && K == 0) {
							return calc(L, j)*calc(j + 1, R);
						}
					}
					if (junjo2[i][k] == 3) {
						if (S[j] == '/' && K == 0) {
							return calc(L, j) / calc(j + 1, R);
						}
					}
				}
			}
		}
	}
	if (S[L] == '(' && S[R - 1] == ')') { return calc(L + 1, R - 1); }
	return STOI(S.substr(L, R - L));
}


int main() {
	long long maxn = -INF;
	int POW[4] = { 1,4,16,64 };
	cin >> S;
	S += '=';
	for (int i = 0; i < 256; i++) {
		for (int j = 0; j < 4; j++) {
			junjo[j] = (i / POW[j]) % 4;
		}
		maxn = max(maxn, calc(0, S.size() - 1));
	}
	cout << maxn << endl;
	return 0;
}
accuracy: 0.15126050420168066
time_ms: 10
memory_kb: 1228
final_rank: 6