#include <iostream>
#include <cstring> 
#include <algorithm>
#include <math.h>
#include <string.h> 
#include <stdlib.h>
using namespace std;
int main(){
	int body = 23;
	int motion = 28;
	int intell = 33;

	int p, e, i ,d, day;
	cin >> p >> e >> i >> d;
    for(day = 1;day <= 21252 ; day++){
        if ((day-p)%body == 0 && (day-e)%motion == 0 && (day-i)%intell == 0) break;
    }
	cout << "Case: the next triple peak occurs in "<< day-d << " days.";
}