시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 20 5 4 36.364%

문제

당구대 위에 흰색 공과 빨간색 공이 있다. 흰색 공은 쿠션(당구대의 모서리)을 N번 만큼 맞춘 뒤 빨간색 공을 맞춰야 한다. 이 때, 흰색 공이 이동한 거리의 최소값을 구하려고 한다.

쿠션은 입사각과 반사각이 항상 같고, 공의 지름은 무시할 수 있다. 당구대의 꼭지점을 원점으로 사용하고, 모서리는 항상 축에 평행하다. 만약, 공이 당구대의 구석(꼭지점)을 맞춘다면, 이것은 쿠션을 2번 맞춘 것으로 친다. 흰색 공은 빨간색 공을 맞추기 전에 쿠션을 반드시 N번 맞춰야 한다.

입력

입력은 여러개의 테스트 케이스로 이루어져 있다. 각 케이스는 일곱개의 정수가 한 줄로 이루어져 있다.

L W CX CY TX TY N

처음 두 정수 L과 W(2 ≤ L,W ≤ 100)는 테이블의 크기이다. 다음 두 X,Y쌍은 흰색 공과 빨간색 공의 (X,Y)좌표이다. 흰색 공의 좌표는 (CX,CY)이고, 빨간색 공의 좌표는 (TX,TY)이다. 또, 0 < CX,TX < L, 0 < CY,TY < W이고, (CX,CY)는 (TX,TY)와 같지 않다. 마지막 정수 N(0 ≤ N ≤ 100)은 빨간 공을 맞추기 전에 맞춰야하는 쿠션의 수다.

테스트 케이스의 마지막은 0 7개가 주어진다.

출력

각 테스트 케이스에 대해 흰색 공이 움직인 거리의 최소값을 소수점 셋째짜리까지 출력한다. 넷째자리에서 반올림하면 된다.

예제 입력 1

20 15 10 1 12 1 1
10 20 1 2 7 16 2
0 0 0 0 0 0 0

예제 출력 1

2.828
19.698
W3sicHJvYmxlbV9pZCI6IjQxMTAiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWIyZjlcdWFkNmNcdWIzMDAiLCJkZXNjcmlwdGlvbiI6IjxwPlxyXG5cdFx1YjJmOVx1YWQ2Y1x1YjMwMCBcdWM3MDRcdWM1ZDAgXHVkNzcwXHVjMGM5IFx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