시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 1679 729 618 43.521%

문제

재귀 호출만 생각하면 신이 난다! 아닌가요?

다음과 같은 재귀함수 w(a, b, c)가 있다.

if a <= 0 or b <= 0 or c <= 0, then w(a, b, c) returns:
    1

if a > 20 or b > 20 or c > 20, then w(a, b, c) returns:
    w(20, 20, 20)

if a < b and b < c, then w(a, b, c) returns:
    w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c)

otherwise it returns:
    w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1)

위의 함수를 구현하는 것은 매우 쉽다. 하지만, 그대로 구현하면 값을 구하는데 매우 오랜 시간이 걸린다. (예를 들면, a=15, b=15, c=15)

a, b, c가 주어졌을 때, w(a, b, c)를 출력하는 프로그램을 작성하시오.

입력

입력은 세 정수로 이루어져 있으며, 한 줄에 하나씩 주어진다. 입력의 마지막은 -1 -1 -1로 나타낸다.

출력

입력으로 주어진 각각의 a, b, c에 대해서, w(a, b, c)를 출력한다.

예제 입력 1

1 1 1
2 2 2
10 4 6
50 50 50
-1 7 18
-1 -1 -1

예제 출력 1

w(1, 1, 1) = 2
w(2, 2, 2) = 4
w(10, 4, 6) = 523
w(50, 50, 50) = 1048576
w(-1, 7, 18) = 1
W3sicHJvYmxlbV9pZCI6IjkxODQiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWMyZTBcdWIwOThcdWIyOTQgXHVkNTY4XHVjMjE4IFx1YzJlNFx1ZDU4OSIsImRlc2NyaXB0aW9uIjoiPHA+XHVjN2FjXHVhZGMwIFx1ZDYzOFx1Y2Q5Y1x1YjljYyBcdWMwZGRcdWFjMDFcdWQ1NThcdWJhNzQgXHVjMmUwXHVjNzc0IFx1YjA5Y1x1YjJlNCEgXHVjNTQ0XHViMmNjXHVhYzAwXHVjNjk0PzxcL3A+XHJcblxyXG48cD5cdWIyZTRcdWM3NGNcdWFjZmMgXHVhYzE5XH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