#include #include class Bin_Tree { public: Bin_Tree(const int &v) :left{ nullptr }, right{ nullptr }, val{ v }, doubled{ false } {}; void insert(const int &v) { if (v == val) doubled = true; else if (v < val) { if (left) left->insert(v); else left = std::unique_ptr(new Bin_Tree(v)); } else { if (right) right->insert(v); else right = std::unique_ptr(new Bin_Tree(v)); } } int count_unique() const { int sum = 0; if (left) sum += left->count_unique(); if (right) sum += right->count_unique(); if (doubled) return sum; else return sum + 1; } private: std::unique_ptr left, right; const int val; bool doubled; }; int main() { int n; std::cin >> n; Bin_Tree root(0); for (; n > 0; --n) { int a; std::cin >> a; root.insert(a); } std::cout << root.count_unique() - 1 << std::endl; return 0; }