http://poj.org/problem?id=1006
#include<cstdio>
int main(){
int p,e,i,d;
int ct=1;
while(scanf("%d%d%d%d",&p,&e,&i,&d)!=EOF){
if(e==-1)break;
long long ans=(p*5544+e*14421+i*1288+21252-d)%21252;
if(ans==0)ans=21252;
printf("Case %d: the next triple peak occurs in %I64d days.\n",ct++,ans);
}
return 0;
}