#include <iostream>
#include <set>

using namespace std;

void print(set<int>& s)
{
    cout << "\ns = {";
    auto p = s.begin();
    while (p != s.end())
        cout << *p++ << ",}"[p==s.end()];
}

void print(multiset<int>& s)
{
    cout << "\nms = {";
    auto p = s.begin();
    while (p != s.end())
        cout << *p++ << ",}"[p==s.end()];
}

int main()
{

    int a[] = { 7, 4, 9, 1, 1, 4, 8 };
    set<int> s(a, a + 7);
    print(s);
    s.insert(3);
    print(s);
    s.erase(3);
    print(s);
    set<int>::iterator ix = s.find(4);
    s.erase(ix);
    print(s);
    s.erase(s.find(7), s.find(9));
    print(s);
    cout << "\nCount of 1: " << s.count(1);
    cout << "\nCount of 2: " << s.count(2);
    s.insert(2);
    s.insert(4);
    s.insert(5);
    s.insert(7);
    print(s);
    
    auto it = s.lower_bound(5);
    cout << "\nThe lower bound of 5 is " << *it << ".";
    it = s.lower_bound(6);
    cout << "\nThe lower bound of 6 is " << *it << ".";
    it = s.lower_bound(10);
    if (it == s.end()) cout << "\nThe lower bound of 10 is at the end of the range.";
    
    it = s.upper_bound(5);
    cout << "\nThe upper bound of 5 is " << *it << ".";
    it = s.upper_bound(6);
    cout << "\nThe upper bound of 6 is " << *it << ".";
    it = s.upper_bound(10);
    if (it == s.end()) cout << "\nThe upper bound of 10 is at the end of the range.";
    
    auto it_pair  = s.equal_range(5);
    cout << "\nThe bounds of 5 are " << *it_pair.first << " and " << *it_pair.second << ".";
    
    int b[] = {1, 1, 2, 3, 4, 4, 4, 5};
	multiset<int> ms(b, b+8);
	print(ms);
	
	auto p = ms.lower_bound(4);
	cout<<"\n";
    while (p != ms.upper_bound(4))
        cout << *p++ << " ";
}