#!/usr/bin/env python3 from sys import stdin data = [(range(a1, a2+1), range(b1, b2+1)) for (a1, a2), (b1, b2) in [(map(int, a.split("-")), map(int, b.split("-"))) for a, b in [x.split(",") for x in stdin.readlines()]]] print(sum(all(x in b for x in a) or all(x in a for x in b) for a, b in data)) print(sum(bool(set(a) & set(b)) for a, b in data))