//代码还是比较简单的,按天数枚举即可,就是英文最后有些读不懂了,还是查的翻译...
#include "stdio.h"

int main(){
    int physical,emotional,intellectual;//分别为记录对应的日期(今年第几天出现)
    int date;//现在是今年第几天
    scanf("%d%d%d%d",&physical,&emotional,&intellectual,&date);
    int nextday = 1;
    bool p_flag,e_flag,i_flag;
    while (true){
        p_flag = false;e_flag = false;i_flag = false;
        if((nextday + date - physical)%23 == 0)
            p_flag = true;
        if((nextday + date - emotional)%28 == 0)
            e_flag = true;
        if((nextday + date - intellectual)%33 == 0)
            i_flag = true;
        if(p_flag && e_flag && i_flag)
            break;
        ++nextday;
    }
    printf("Case: the next triple peak occurs in %d days.",nextday);
}