import std.stdio, std.conv; import std.algorithm, std.range, std.random; import std.string, std.array, std.container, std.bigint; import std.typecons, std.ascii; int[] d; int main() { int n; readf("%d\n", &n); int[] d; int pn, mn; foreach (i; 0..n) { char c; readf(" %c", &c); if (isDigit(c)) { d ~= to!int(""~c); } else { final switch(c) { case '+': pn++; break; case '-': mn++; break; } } } d.sort!"a > b"; auto dd = d.dup; long sm = 0; foreach (i; 0..mn) { sm -= d.back; d.popBack; } foreach (i; 0..pn) { sm += d.back; d.popBack; } sm += d.map!(to!string).join.to!long; if (mn != 0) { writeln(sm, " ", -1 * sm); return 0; } d = dd; long[] buf = new long[](pn+1); foreach (i; 0..d.length) { buf[i % (pn+1)] *= 10; buf[i % (pn+1)] += d[i]; } writeln(sm, " ", buf.sum); return 0; }