#include #include #include using namespace std; class Range { public: unsigned min; unsigned max; bool contains(const Range &in) { return min <= in.min && max >= in.max; } bool overlaps(const Range &in) { return (min <= in.min && in.min <= max) || (min <= in.max && in.max <= max) || (in.min <= min && min <= in.max) || (in.min <= max && max <= in.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) { unsigned count = 0; for (auto i : input) if (i[0].contains(i[1]) || i[1].contains(i[0])) count++; return count; } unsigned p2(const Input &input) { unsigned count = 0; for (auto i : input) if (i[0].overlaps(i[1])) count++; return count; } int main() { Input input = parse(); cout << p1(input) << endl; cout << p2(input) << endl; }