def shizidinli(a, b, c, d):
    for i in range(1, 21253):
        k = d + i
        if (k-a) % 23 == 0 and (k-b) % 28 == 0 and (k-c) % 33 == 0:
            print('Case: the next triple peak occurs in {} days.'.format(i))
            break

# while True:
#     try:

s = list(map(int, input().split()))
shizidinli(s[0], s[1], s[2], s[3])
    # except:
    #     break