#include <iostream>
#include <vector>
#include <cstdint>
#include <tuple>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
typedef std::tuple<std::uint64_t, std::uint64_t> Data;
typedef std::vector<Data> DType;
typedef std::map<double, DType> MType;
typedef std::vector<std::string> SType;
bool CheckInput(std::string & S){
char Ch[] = "01234567890 /";
bool F = false;
for (std::size_t i = 0; i < S.size(); i++){
F = false;
for (auto& o : Ch){
if (S[i] == o){
F = true;
break;
}
}
if (F == false) return false;
}
return true;
}
std::uint64_t gcd(std::uint64_t a, std::uint64_t b){
return b == 0 ? a : gcd(b, a % b);
}
SType GetInput(){
std::string S;
SType ST;
while (std::cin >> S){
if (CheckInput(S) == true){
ST.push_back(S);
}
else{
std::cout << S << " is BAD INPUT!" << std::endl;
}
}
return ST;
}
Data MakeData(std::string& S){
std::stringstream SS;
std::uint64_t A = 0;
std::uint64_t B = 0;
std::uint64_t C = 0;
char Ch = '\0';
SS << S;
if (S.find_first_of(' ') != -1)SS >> A;
SS >> B;
SS >> Ch;
SS >> C;
B += A*C;
return std::make_tuple(B, C);
}
MType MakeHoge(SType &S){
MType M;
Data D;
for (auto& o : S){
D = MakeData(o);
M[std::get<0>(D) / static_cast<double>(std::get<1>(D))].push_back(D);
}
return M;
}
bool Show(MType& M){
std::uint64_t A = 0;
std::uint64_t B = 0;
std::uint64_t C = 0;
for (auto& oo : M){
A = std::get<0>(oo.second[0]) / std::get<1>(oo.second[0]);
B = std::get<0>(oo.second[0]) % std::get<1>(oo.second[0]);
C = gcd(std::get<0>(oo.second[0]), std::get<1>(oo.second[0]));
C = std::max<std::uint64_t>(1, C);
std::cout << '[';
if (A != 0) std::cout << A;
if (A != 0 && B != 0) std::cout << '+';
if (B != 0) std::cout <<(std::get<0>(oo.second[0])-A*std::get<1>(oo.second[0])) / C << '/' << std::get<1>(oo.second[0]) / C;
if (A == 0 && B == 0) std::cout << 0;
std::cout << ']';
for (auto o : oo.second){
A = std::get<0>(o) / std::get<1>(o);
B = std::get<0>(o) % std::get<1>(o);
if (A != 0 && B!=0) std::cout << A << '+';
if (B != 0){
std::cout << (std::get<0>(o)-A*std::get<1>(o)) << '/' << std::get<1>(o) << ',';
}else if (B != 0 || A != 0){
std::cout << std::get<0>(o) << '/' << std::get<1>(o) << ',';
}
if (A == 0 && B == 0) std::cout << 0;
}
std::cout << std::endl;
}
return true;
}
int main(){
SType S{ "1/2", "1/3", "2/3", "1 1/3", "2/2", "3/2", "4/2", "2/8", "9/6","2/4" };
MType M;
//S = GetInput();
M = MakeHoge(S);
Show(M);
return 0;
}