#include #include #include #include using namespace std; struct Range { unsigned min; unsigned max; bool contains(const Range &in) const { return min <= in.min && max >= in.max; } bool overlaps(const Range &in) const { return min <= in.max && in.min <= max; } }; typedef vector> Input; Input parse() { Input data; for (string line; getline(cin, line);) { array entry; sscanf(line.c_str(), "%u-%u,%u-%u", &entry[0].min, &entry[0].max, &entry[1].min, &entry[1].max); data.push_back(entry); } return data; } unsigned p1(const Input &input) { return count_if(input.begin(), input.end(), [](decltype(input[0]) i){ return i[0].contains(i[1]) || i[1].contains(i[0]); }); } unsigned p2(const Input &input) { return count_if(input.begin(), input.end(), [](decltype(input[0]) i){ return i[0].overlaps(i[1]); }); } int main() { auto input = parse(); cout << p1(input) << endl; cout << p2(input) << endl; }