#include <iostream>

using namespace std;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int p, e, i, d;
    cin >> p >> e >> i >> d;
    for(int j = 1; j <= 21252; j++)
    {
        if((d + j - p) % 23 == 0 && (d + j - e) % 28 == 0 && (d + j - i) % 33 == 0)
        {
            cout << "Case: the next triple peak occurs in " << j << " days.";
        }
    }
    return 0;
}