#include<stdio.h> int main()
{
int p,e,i,d,i1,j1,num; num=0; scanf("%d%d%d%d",&p,&e,&i,&d);
while(p!= -1 || e!=-1 || i!=-1 || d!=-1)
{ for(i1=0;;i1++)
{
if( (p+23*i1-e)% 28 ==0)
{
j1= (p+23*i1-e)/ 28; break;
}
} while( (28*j1 + e - i) % 33 !=0)
{
i1+=28; j1+=23;
} num++; if(28*j1 + e -d <=0)
{ printf("Case %d: the next triple peak occurs in %d days.\n",num,
28*j1 + e +23*28*33 -d);
} else
printf("Case %d: the next triple peak occurs in %d days.\n",num,
28*j1 + e -d); scanf("%d%d%d%d",&p,&e,&i,&d);
}
return 0;
}
{
int p,e,i,d,i1,j1,num; num=0; scanf("%d%d%d%d",&p,&e,&i,&d);
while(p!= -1 || e!=-1 || i!=-1 || d!=-1)
{ for(i1=0;;i1++)
{
if( (p+23*i1-e)% 28 ==0)
{
j1= (p+23*i1-e)/ 28; break;
}
} while( (28*j1 + e - i) % 33 !=0)
{
i1+=28; j1+=23;
} num++; if(28*j1 + e -d <=0)
{ printf("Case %d: the next triple peak occurs in %d days.\n",num,
28*j1 + e +23*28*33 -d);
} else
printf("Case %d: the next triple peak occurs in %d days.\n",num,
28*j1 + e -d); scanf("%d%d%d%d",&p,&e,&i,&d);
}
return 0;
}