#include <vector>
class Set {
public:
explicit Set(const std::vector<int64_t> &input) {
for (auto elem : input)
_data.push_back(elem);
}
Set() {}
Set Union(const Set &other) const {
auto newSet = _data;
const auto &otherData = other.Data();
auto otherSize = other.Data().size();
for (size_t i = 0; i < otherSize; ++i) {
bool uniq = true;
for (size_t j = 0; j < _data.size(); ++j) {
if (_data[j] == otherData[i]) {
uniq = false;
break;
}
}
if (uniq)
newSet.push_back(otherData[i]);
}
return Set(newSet);
}
Set Intersection(const Set &other) const {
const auto &thisData = _data;
const auto &otherData = other._data;
std::vector<int64_t> buf;
for (auto elem : thisData)
for (auto elemOther : otherData) {
if (elem == elemOther) {
buf.push_back(elem);
break;
}
}
return Set(buf);
}
Set Difference(const Set &other) const {
const auto &thisData = this->Data().size() > other.Data().size()
? Data() : other.Data();
const auto &otherData = this->Data().size() < other.Data().size()
? Data() : other.Data();
auto size_other = otherData.size();
auto this_size = thisData.size();
bool notUniq = true;
std::vector<int64_t> buf;
for (size_t i = 0; i < this_size; i++) {
notUniq = true;
for (size_t j = 0; j < size_other; j++) {
if (otherData[j] == thisData[i]) {
notUniq = false;
break;
}
}
if (notUniq)
buf.push_back(thisData[i]);
}
return Set(buf);
}
Set SymmetricDifference(const Set &other) const {
auto this_set = Data();
auto other_set = other.Data();
auto size_other = other_set.size();
auto this_size = this_set.size();
std::vector<int64_t> new_v;
for (size_t i = 0; i < this_size; i++)
if (!other.Contains(this_set[i])) new_v.push_back(this_set[i]);
for (size_t i = 0; i < size_other; i++)
if (!Contains(other_set[i])) new_v.push_back(other_set[i]);
return Set(new_v);
}
std::vector<int64_t> Data() const {
return _data;
}
void Add(int64_t num) {
bool uniq = true;
for (auto elem : _data)
if (elem == num) {
uniq = false;
break;
}
if (uniq)
_data.push_back(num);
}
void Remove(int64_t num) {
for (size_t i = 0; i < _data.size(); ++i) {
if (num == _data[i]) {
_data.erase(std::begin(_data) + i);
break;
}
}
}
bool Contains(int64_t num) const {
bool contains = true;
for (auto elem : _data)
if (elem == num) {
contains = false;
break;
}
return contains;
}
Set(const Set &) = delete;
private:
std::vector<int64_t> _data;
};