#include <iostream>
#include <sstream>
#include <map>
#include <cctype>
#include <string>
int main() {
std::string line;
while (std::getline(std::cin, line)) {
std::map<std::string, int> terms;
std::istringstream iss(line);
std::string token;
int constant = 0;
while (iss >> token) {
int sign = 1;
if (token == "+") continue;
if (token == "-") {
sign = -1;
iss >> token;
}
size_t i = 0;
while (i < token.size() && (isdigit(token[i]) || token[i] == '-')) i++;
int coeff = 1;
if (i > 0) coeff = std::stoi(token.substr(0, i));
std::string var = token.substr(i);
if (var.empty()) {
constant += sign * coeff;
} else {
terms[var] += sign * coeff;
}
}
std::ostringstream oss;
bool first = true;
for (const auto& [var, coeff] : terms) {
if (coeff == 0) continue;
if (!first && coeff > 0) oss << " + ";
else if (coeff < 0) oss << " - ";
else if (!first) oss << " + ";
if (abs(coeff) != 1) oss << abs(coeff);
else if (coeff == -1 && first) oss << "-";
oss << var;
first = false;
}
if (constant != 0) {
if (!first && constant > 0) oss << " + ";
else if (constant < 0) oss << " - ";
else if (!first) oss << " + ";
oss << abs(constant);
}
std::string result = oss.str();
if (result.empty()) result = "0";
std::cout << result << std::endl;
}
return 0;
}