시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 113 14 13 20.000%

문제

재현이는 마인크래프트를 너무 많이 한 나머지, 우리가 사는 지구 또한 직육면체 모양이어야 한다고 생각하게 되었다. 재현이는 자신이 가진 군단을 동원하여, 지구를 각 변의 길이가 ℓx × ℓy × ℓz인 직육면체로 만드는 대공사를 했다. 이 공사로 인해 새로운 모양의 지구 표면 위에서의 위치는 깔끔하게 3차원 데카르트 좌표계로 표현되게 되었고, 재현이는 크게 만족해했다. 또한, 재현이는 그리니치 천문대를 없애고, 자신의 집을 지구의 꼭짓점 (0, 0, 0)에 지었다.

한편, 이번 공사로 인해 집이 강제로 (x, y, z)에 옮겨진 승원이는 물리를 공부하던 도중, 물리 책에서 재현이의 집이 지구 좌표계의 기준으로 소개되고 있는 것을 발견했다. 자신의 성스러운 물리 책에서는 재현이의 이름조차 보기 싫었던 승원이는 페이스북에서 지구가 다시 둥글어져야 한다고 주장하기 시작했다.

페이스북을 통해 이 사실을 알게 된 재현이는 승원이를 체포하기 위해, 승원이에게 가기 위한 최단경로의 길이가 얼마인지 궁금해하게 되었다. 재현이를 도와 승원이가 다시는 허튼 수작을 부리지 못하도록 만들자.

만약 ℓx = 1, ℓ= 2, ℓ= 1, x = 1, y = 2, z = 1이라면, (0, 0, 0)에 있는 재현이가 (1, 2, 1)에 있는 승원이에게 가기 위한 최단경로는 (0, 0, 0)에서 (1, 1, 0)을 거쳐, (1, 2, 1)로 가는 경로이다. 이 최단경로의 길이는 √8 이다.

입력

각 입력 파일은 여러 개의 테스트 케이스를 포함하며, 각각은 6개의 정수 ℓx, ℓy, ℓz, x, y, z (단, 1 ≤ ℓx, ℓy, ℓz ≤ 1000) 으로 이루어진다. 승원이의 위치 (x,y,z)는 항상 직육면체 지구의 6개의 면들 중 하나 위에 있음이 보장된다. 또한, 파일의 마지막 줄은 ℓx = ℓy = ℓz = x = y = z = 0 인 경우로 되어 있으며, 이에 대해서는 답을 출력하지 않아야 한다.

출력

각각의 테스트 케이스에 대해, 한 줄에 최단경로의 길이의 제곱을 나타내는 양의 정수를 출력하시오. (주의 : 최단경로의 길이의 제곱은 항상 정수이므로, 답은 근사치가 아닌 정확한 값으로 출력되어야 한다.)

예제 입력 1

1 1 2 1 1 2
1 1 1 1 1 1
0 0 0 0 0 0

예제 출력 1

8
5
W3sicHJvYmxlbV9pZCI6Ijc2ODciLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWM5YzBcdWFkNmMgXHVjOWMxXHVjNzIxXHViYTc0XHVjY2I0XHVjMTI0IiwiZGVzY3JpcHRpb24iOiI8cD5cdWM3YWNcdWQ2MDRcdWM3NzRcdWIyOTQgXHViOWM4XHVjNzc4XHVkMDZjXHViNzk4XHVkNTA0XHVkMmI4XHViOTdjIFx1YjEwOFx1YmIzNCBcdWI5Y2VcdWM3NzQgXHVkNTVjIFx1YjA5OFx1YmEzOFx1YzljMCwgXHVjNmIwXHViOWFjXHVhYzAwIFx1YzBhY1x1YjI5NCBcdWM5YzBcdWFkNmMgXHViNjEwXHVkNTVjIFx1YzljMVx1YzcyMVx1YmE3NFx1Y2NiNCBcdWJhYThcdWM1OTFcdWM3NzRcdWM1YjRcdWM1N2MgXHVkNTVjXHViMmU0XHVhY2UwIFx1YzBkZFx1YWMwMVx1ZDU1OFx1YWM4YyBcdWI0MThcdWM1YzhcdWIyZTQuIFx1YzdhY1x1ZDYwNFx1Yzc3NFx1YjI5NCBcdWM3OTBcdWMyZTBcdWM3NzQgXHVhYzAwXHVjOWM0IFx1YWQ3MFx1YjJlOFx1Yzc0NCBcdWIzZDlcdWM2ZDBcdWQ1NThcdWM1ZWMsIFx1YzljMFx1YWQ2Y1x1Yjk3YyBcdWFjMDEgXHViY2MwXHVjNzU4Jm5ic3A7XHVhZTM4XHVjNzc0XHVhYzAwIFx1MjExMzxzdWI+eDxcL3N1Yj4mbmJzcDsmdGltZXM7IFx1MjExMzxzdWI+eTxcL3N1Yj4mbmJzcDsmdGltZX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