import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int p = sc.nextInt();
        int e = sc.nextInt();
        int i = sc.nextInt();
        int d = sc.nextInt();
        int ans = d;
        while (ans == 0 || (ans - p) % 23 != 0 || (ans - e) % 28 != 0 || (ans - i) % 33 != 0) {
            ans++;
        }
        System.out.println("Case: the next triple peak occurs in " + (ans - d) + " days.");
    }
}