using namespace std; #include #include #include #include #include #include #include typedef long long ll; ll INF = LLONG_MAX / 2; int main() { int N; cin >> N; int plus = 1, minus = 0; vector a; while (N--) { string s; cin >> s; char c = s[0]; if (c == '+') plus++; else if (c == '-') minus++; else a.push_back(c - '0'); } int n = a.size(); sort(a.begin(), a.end()); vector ma(1< _ma(1<>i & 1) x = x * 10 + a[i]; ll y = 0; for (int i = n - 1; i >= 0; i--) if (T>>i & 1) y = y * 10 + a[i]; _ma[S | T] = max(_ma[S | T], ma[S] + y); _mi[S | T] = min(_mi[S | T], mi[S] + x); } ma = _ma; mi = _mi; } while (minus--) { vector _ma(1<>i & 1) x = x * 10 + a[i]; ll y = 0; for (int i = n - 1; i >= 0; i--) if (T>>i & 1) y = y * 10 + a[i]; _ma[S | T] = max(_ma[S | T], ma[S] - x); _mi[S | T] = min(_mi[S | T], mi[S] - y); } ma = _ma; mi = _mi; } cout << ma[(1<