class Main
{
static int distance(int a, int b, int c, int d)
{
int ans = 0;
if (a > b)
{
int temp = a;
a = b;
b = temp;
}
if (c > d)
{
int temp = c;
c = d;
d = temp;
}
if (b < c || a > d)
{
ans = 0;
}
else
{
int l = 0, r = 0;
ans = r - l;
}
return ans;
}
public static void main
(String[] args
) {
java.
util.
Scanner in
= new java.
util.
Scanner(System.
in); int x1 = in.nextInt(), y1 = in.nextInt(), x2 = in.nextInt(), y2 = in.nextInt();
int x3 = in.nextInt(), y3 = in.nextInt(), x4 = in.nextInt(), y4 = in.nextInt();
if (x1 != x2)
{
System.
out.
println(y1
< Math.
max(y3, y4
) && y1
> Math.
min(y3, y4
) ? distance
(x1, x2, x3, x4
) : 0); }
else
{
System.
out.
println(x1
< Math.
max(x3, x4
) && x1
> Math.
min(x3, x4
) ? distance
(y1, y2, y3, y4
) : 0); }
}
}
Y2xhc3MgTWFpbgp7CQoJc3RhdGljIGludCBkaXN0YW5jZShpbnQgYSwgaW50IGIsIGludCBjLCBpbnQgZCkKCXsKCQlpbnQgYW5zID0gMDsKCQlpZiAoYSA+IGIpIAoJCXsKCQkJaW50IHRlbXAgPSBhOwoJCQlhID0gYjsKCQkJYiA9IHRlbXA7CgkJfQoJCWlmIChjID4gZCkKCQl7CgkJCWludCB0ZW1wID0gYzsKCQkJYyA9IGQ7CgkJCWQgPSB0ZW1wOwoJCX0KCQlpZiAoYiA8IGMgfHwgYSA+IGQpIAoJCXsKCQkJYW5zID0gMDsKCQl9IAoJCWVsc2UgCgkJewoJCQlpbnQgbCA9IDAsIHIgPSAwOwoJCQlsID0gTWF0aC5tYXgoYSwgYyk7CgkJCXIgPSBNYXRoLm1pbihiLCBkKTsKCQkJYW5zID0gciAtIGw7CgkJfQoJCXJldHVybiBhbnM7Cgl9CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgCgl7CgkJamF2YS51dGlsLlNjYW5uZXIgaW4gPSBuZXcgamF2YS51dGlsLlNjYW5uZX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