program yuki3679 implicit none integer h, w, a, b, r1, c1, r2, c2, p, q, x, y read (*,*) h, w read (*,*) a, b read (*,*) r1, c1, r2, c2 read (*,*) p, q if (a < r1) then x = r1 else if (a > r2) then x = r2 else x = a end if if (b < c1) then y = c1 else if (b > c2) then y = c2 else y = b end if write (6,fmt='(I0)') abs(x-a) + abs(y-b) + abs(p-x) + abs(q-y) + abs(a-p) + abs(b-q) end program yuki3679