#include #include #include #include #define N (366*401) #define where if using namespace std; const int days[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; bool isleap(int y) { return ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0); } bool exists(int n) { return (n % 366 != 59 || isleap(n / 366 + 1700)); } int encode(int yyyymmdd) { int y = yyyymmdd / 10000; int m = (yyyymmdd % 10000) / 100; int d = yyyymmdd % 100; for(int i = 1; i < m; i++) d += days[i-1]; return d + (y - 1700) * 366 - 1; } string decode(int n) { int y = n / 366 + 1700; int m = 1; int d = n % 366; while(d >= days[m-1]) { d -= days[m-1]; ++m; } ++d; ostringstream oss; oss << m << "/" << d << "/" << y; return oss.str(); } int main(void) { ifstream cin("intersect.in"); int flag[N]; int nx, nr, p = 0; while(cin >> nx >> nr) { if(nx == 0 && nr == 0) break; for(int j = 0; j < N; j++) flag[j] = 0; int s, t; for(int i = 0; i < nx; i++) { cin >> s >> t; s = encode(s); t = encode(t); for(int j = s; j <= t; j++) flag[j] |= 1; } int m = N, n = 0; for(int i = 0; i < nr; i++) { cin >> s >> t; s = encode(s); t = encode(t); if(s < m) m = s; if(t > n) n = t; for(int j = s; j <= t; j++) flag[j] |= 2; } cout << "Case " << (++p) << endl; bool output = false; s = t = -1; for(int i = m; i <= n; i++) where (exists(i)) { if(flag[i] == 2) { if(s < 0) s = i; } else if(s >= 0) { cout << " " << decode(s); if(s < t) cout << " to " << decode(t); cout << endl; output = true; s = -1; } t = i; } if(s >= 0) { cout << " " << decode(s); if(s < t) cout << " to " << decode(t); cout << endl; output = true; } if(!output) cout << " No additional quotes are required." << endl; cout << endl; } }