시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 29 2 2 66.667%

문제

도전 24는 초등학생들이 주로 하는 수학 게임이다. 이 게임을 시작할 때, 각 참가자는 양의 정수 i1, i2, i3, i4가 써있는 4장의 카드를 받는다. 그 다음, 사칙연산과 모든 숫자를 적절히 조합해서 24를 만드는 사람이 이긴다. 각 숫자는 모두 한 번씩 사용해야 한다. 나눗셈은 나누어 떨어질 때만 사용할 수 있다. (6/2는 되지만, 6/4는 안된다) 예를 들어, 7, 2, 5, 1을 받았을 때, 24를 만들 수 있는 방법은 (7-2)*5-1, (7+1)*(5-2)가 있다.

창영이는 도전 24와 규칙은 비슷하지만 목표가  조금 다른 게임을 하려고 한다. 수 4개가 주어졌을 때, 만들 수 있는 수를 모두 찾아보려고 한다. 그리고 나서, 연속하는 가장 긴 구간을 찾으려고 한다. 예를 들어, 7, 2, 5, 1인 경우에는 -18부터 26까지가 가장 긴 구간이다. +와 -를 사용해서, 어떤 수를 음수로 만들 수는 없다. 즉, 이항 연산자로만 사용할 수 있다.

입력

입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄에 수 4개가 주어진다. 수는 모두 양의 정수이고, 100을 넘지 않는다. 그리고, 중복되지 않는다.

출력

각 테스트 케이스에 대해서, 케이스 번호와 가장 긴 구간을 아래 예제 출력 형식처럼 출력한다. 만약 가장 긴 연속 구간이 여러개일 경우에는 구간의 시작 값이 가장 큰 것을 출력한다.

예제 입력 1

7 2 5 1
8 15 38 3
0 0 0 0

예제 출력 1

Case 1: -18 to 26
Case 2: 150 to 153

힌트

W3sicHJvYmxlbV9pZCI6IjQwNDQiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWIzYzRcdWM4MDQgMjQiLCJkZXNjcmlwdGlvbiI6IjxwPlxyXG5cdFx1YjNjNFx1YzgwNCAyNFx1YjI5NCBcdWNkMDhcdWI0ZjFcdWQ1NTlcdWMwZGRcdWI0ZTRcdWM3Nz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