﻿var
  xp: array[0..4]of real;
  yp: array[0..4]of real;
  k: array[1..4]of real;
  b: array[1..4]of real;
  tmp: array[0..4]of real;
  flag: array[1..6]of integer = (0, 0, 0, 0, 0, 0);
  cnt, cnt2: integer;
  maxX, minX: real;
  inside: boolean;

begin
  cnt := 1;
  cnt2 := 3;
  for var i := 0 to 4 do
  begin
    if(i = 0) then write('Введите координаты точки: ')
    else write('Введите x', i, ' и y', i, ': ');
    read(xp[i], yp[i]);
  end;
  maxX := xp[1];
  minX := xp[1];
  for var i := 2 to 4 do
  begin
    if(xp[i] > maxX) then maxX := xp[i];
    if(xp[i] < minX) then minX := xp[i];
  end;
  for var i := 1 to 3 do
  begin
    k[i] := 0;
    if((xp[i] - xp[i + 1]) = 0) then begin flag[cnt] := i;cnt += 1; end
    else
    begin
      flag[cnt2] := i;
      cnt2 += 1;
      k[i] := (yp[i] - yp[i + 1]) / (xp[i] - xp[i + 1]);
    end;
    b[i] := yp[i + 1] - k[i] * xp[i + 1];
  end;
  k[4] := 0;
  if((xp[1] - xp[4]) = 0) then flag[cnt] := 4
  else
  begin
    flag[cnt2] := 4;
    k[4] := (yp[1] - yp[4]) / (xp[1] - xp[4]);
  end;
  b[4] := yp[1] - k[4] * xp[1];
  
  for var i := 1 to 4 do
  begin
    tmp[i] := k[i] * xp[0] + b[i];
  end;
  
  if(cnt <> 1) then
  begin
    if(((k[flag[3]] * xp[0] + b[flag[3]]) >= (k[flag[4]] * xp[0] + b[flag[4]])) 
    and (yp[0] <= k[flag[3]] * xp[0] + b[flag[3]]) and (yp[0] >= k[flag[4]] * xp[0] + b[flag[4]])
    and ((xp[0] <= maxX) and (xp[0] >= minX))) then
      inside := true
    else if(((k[flag[3]] * xp[0] + b[flag[3]]) <= (k[flag[4]] * xp[0] + b[flag[4]])) 
    and (yp[0] >= k[flag[3]] * xp[0] + b[flag[3]]) and (yp[0] <= k[flag[4]] * xp[0] + b[flag[4]])
    and ((xp[0] <= maxX) and (xp[0] >= minX))) then
      inside := true
    else if(((k[flag[3]] * xp[0] + b[flag[3]]) >= (k[flag[4]] * xp[0] + b[flag[4]])) 
    and (yp[0] <= k[flag[3]] * xp[0] + b[flag[3]]) and (yp[0] >= k[flag[4]] * xp[0] + b[flag[4]])
    and ((xp[0] <= maxX) and (xp[0] >= minX))) then
      inside := true
    else if(((k[flag[3]] * xp[0] + b[flag[3]]) <= (k[flag[4]] * xp[0] + b[flag[4]])) 
    and (yp[0] >= k[flag[3]] * xp[0] + b[flag[3]]) and (yp[0] <= k[flag[4]] * xp[0] + b[flag[4]])
    and ((xp[0] <= maxX) and (xp[0] >= minX))) then
      inside := true;
  end
  else
  begin
    //1
    if(((tmp[1]) >= (tmp[2])) and ((tmp[1]) >= (tmp[3])) and ((tmp[1]) >= (tmp[4])) 
    and ((tmp[2]) >= (tmp[3])) and ((tmp[2]) >= (tmp[4])) and ((xp[0] <= maxX) and (xp[0] >= minX))
    and (yp[0] <= tmp[1]) and (yp[0] <= tmp[2]) and (yp[0] >= tmp[3]) and (yp[0] >= tmp[4])) then
      inside := true
    else if(((tmp[1]) >= (tmp[2])) and ((tmp[1]) >= (tmp[3])) and ((tmp[1]) >= (tmp[4])) 
    and ((tmp[3]) >= (tmp[2])) and ((tmp[3]) >= (tmp[1])) and ((xp[0] <= maxX) and (xp[0] >= minX))
    and (yp[0] <= tmp[1]) and (yp[0] <= tmp[3]) and (yp[0] >= tmp[3]) and (yp[0] >= tmp[4]) ) then
      inside := true
    else if(((tmp[1]) >= (tmp[2])) and ((tmp[1]) >= (tmp[3])) and ((tmp[1]) >= (tmp[4])) 
    and ((tmp[4]) >= (tmp[2])) and ((tmp[4]) >= (tmp[3])) and ((xp[0] <= maxX) and (xp[0] >= minX))
    and (yp[0] <= tmp[1]) and (yp[0] <= tmp[4]) and (yp[0] >= tmp[3]) and (yp[0] >= tmp[2])) then
      inside := true
      //2
    else if(((tmp[2]) >= (tmp[1])) and ((tmp[2]) >= (tmp[3])) and ((tmp[2]) >= (tmp[4])) 
    and ((tmp[1]) >= (tmp[4])) and ((tmp[1]) >= (tmp[3])) and ((xp[0] <= maxX) and (xp[0] >= minX))
    and (yp[0] <= tmp[2]) and (yp[0] <= tmp[1]) and (yp[0] >= tmp[3]) and (yp[0] >= tmp[4])) then
      inside := true
    else if(((tmp[2]) >= (tmp[1])) and ((tmp[2]) >= (tmp[3])) and ((tmp[2]) >= (tmp[4])) 
    and ((tmp[3]) >= (tmp[4])) and ((tmp[3]) >= (tmp[1])) and ((xp[0] <= maxX) and (xp[0] >= minX))
    and (yp[0] <= tmp[2]) and (yp[0] <= tmp[3]) and (yp[0] >= tmp[1]) and (yp[0] >= tmp[4])) then
      inside := true
    else if(((tmp[2]) >= (tmp[1])) and ((tmp[2]) >= (tmp[3])) and ((tmp[2]) >= (tmp[4])) 
    and ((tmp[4]) >= (tmp[1])) and ((tmp[4]) >= (tmp[3])) and ((xp[0] <= maxX) and (xp[0] >= minX))
    and (yp[0] <= tmp[2]) and (yp[0] <= tmp[4]) and (yp[0] >= tmp[3]) and (yp[0] >= tmp[1])) then
      inside := true
    //3
    else if(((tmp[3]) >= (tmp[1])) and ((tmp[3]) >= (tmp[2])) and ((tmp[3]) >= (tmp[4])) 
    and ((tmp[1]) >= (tmp[2])) and ((tmp[1]) >= (tmp[4])) and ((xp[0] <= maxX) and (xp[0] >= minX))
    and (yp[0] <= tmp[3]) and (yp[0] <= tmp[1]) and (yp[0] >= tmp[2]) and (yp[0] >= tmp[4])) then
      inside := true
    else if(((tmp[3]) >= (tmp[1])) and ((tmp[3]) >= (tmp[2])) and ((tmp[3]) >= (tmp[4])) 
    and ((tmp[2]) >= (tmp[1])) and ((tmp[2]) >= (tmp[4])) and ((xp[0] <= maxX) and (xp[0] >= minX))
    and (yp[0] <= tmp[3]) and (yp[0] <= tmp[2]) and (yp[0] >= tmp[1]) and (yp[0] >= tmp[4])) then
      inside := true
    else if(((tmp[3]) >= (tmp[1])) and ((tmp[3]) >= (tmp[2])) and ((tmp[3]) >= (tmp[4])) 
    and ((tmp[4]) >= (tmp[2])) and ((tmp[4]) >= (tmp[1])) and ((xp[0] <= maxX) and (xp[0] >= minX))
    and (yp[0] <= tmp[3]) and (yp[0] <= tmp[4]) and (yp[0] >= tmp[1]) and (yp[0] >= tmp[2]) ) then
      inside := true
    //4
    else if(((tmp[4]) >= (tmp[1])) and ((tmp[4]) >= (tmp[2])) and ((tmp[4]) >= (tmp[3])) 
    and ((tmp[1]) >= (tmp[2])) and ((tmp[1]) >= (tmp[3])) and ((xp[0] <= maxX) and (xp[0] >= minX))
    and (yp[0] <= tmp[4]) and (yp[0] <= tmp[1]) and (yp[0] >= tmp[2]) and (yp[0] >= tmp[3]) ) then
      inside := true
    else if(((tmp[4]) >= (tmp[1])) and ((tmp[4]) >= (tmp[2])) and ((tmp[4]) >= (tmp[3])) 
    and ((tmp[2]) >= (tmp[3])) and ((tmp[2]) >= (tmp[1])) and ((xp[0] <= maxX) and (xp[0] >= minX))
    and (yp[0] <= tmp[4]) and (yp[0] <= tmp[2]) and (yp[0] >= tmp[3]) and (yp[0] >= tmp[1]) ) then
      inside := true
    else if(((tmp[4]) >= (tmp[1])) and ((tmp[4]) >= (tmp[2])) and ((tmp[4]) >= (tmp[3])) 
    and ((tmp[3]) >= (tmp[2])) and ((tmp[3]) >= (tmp[1])) and ((xp[0] <= maxX) and (xp[0] >= minX))
    and (yp[0] <= tmp[4]) and (yp[0] <= tmp[3]) and (yp[0] >= tmp[2]) and (yp[0] >= tmp[1]) ) then
      inside := true
  end;
  if(inside) then write('Принадлежит')
  else write('Не принадлежит');
end.