시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
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
W3sicHJvYmxlbV9pZCI6IjQxMTAiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWIyZjlcdWFkNmNcdWIzMDAiLCJkZXNjcmlwdGlvbiI6IjxwPlxyXG5cdFx1YjJmOVx1YWQ2Y1x1YjMwMCBcdWM3MDRcdWM1ZDAgXHVkNzcwXHVjMGM5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