program Projectd;

{$APPTYPE CONSOLE}
{$O+,R+,Q+,D+,L+}
uses
  testlib,SysUtils;

const nmax = 50000;
      kmax = 100;
type point = record x,y,f,num:integer end;
     triangle = array[1..3] of point;
     pp=array[1..2*nmax] of point;
var n,k,num,i,j: integer;
  s: pp;
  a: array[1..nmax,0..10*kmax] of integer;
  list,v: array[1..nmax]of integer;
  data: array[1..nmax]of record p1,p2:point end;
procedure QuickSort(var A: pp; Lo, Hi: Integer);

procedure Sort(l, r: Integer);
var
  i, j: integer;
  x, y: point;
begin
  i := l; j := r; x := a[(l+r) DIV 2];
  repeat
    while (a[i].y < x.y)or(a[i].y = x.y)and(a[i].f > x.f) do i := i + 1;
    while (x.y < a[j].y)or(x.y = a[j].y)and(x.f > a[j].f) do j := j - 1;
    if i <= j then
    begin
      y := a[i]; a[i] := a[j]; a[j] := y;
      i := i + 1; j := j - 1;
    end;
  until i > j;
  if l < j then Sort(l, j);
  if i < r then Sort(i, r);
end;

begin {QuickSort};
  Sort(Lo,Hi);
end;

procedure readdata;
var i,j,m:integer;
    t:triangle;
    p:point;
begin
  m:=0;
  n:=inf.readlongint;
  for i:=1 to n do
  begin
    for j:=1 to 3 do
      begin
        t[j].x:=inf.readlongint;
        t[j].y:=inf.readlongint;
        t[j].num:=i
      end;
    if t[1].y>t[2].y then
      begin p:=t[1]; t[1]:=t[2]; t[2]:=p end;
    if t[2].y>t[3].y then
      begin p:=t[2]; t[2]:=t[3]; t[3]:=p end;
    if t[1].y>t[2].y then
      begin p:=t[1]; t[1]:=t[2]; t[2]:=p end;
    inc(m);
    t[1].f := 1;
    t[3].f := -1;
    s[m] := t[1];
    inc(m);
    s[m] := t[3];
    data[i].p1:=t[1];
    data[i].p2:=t[3];
  end;
  for i:=1 to n do
   begin
    list[i]:=ouf.readlongint;
    if (list[i]<=0) or (list[i]>n) then quit(_wa,'illegal car number');
    if v[list[i]]>0 then quit(_wa,'car '+inttostr(list[i])+' starts twice');
    inc(v[list[i]]);
   end;
end;
function vector(x1,y1,x2,y2:comp):comp;
begin
  vector:=x1*y2-x2*y1;
end;
function less(i,j:integer):boolean;
begin
  less:=vector(data[i].p2.x-data[i].p1.x,data[i].p2.y-data[i].p1.y,
               data[j].p1.x-data[i].p1.x,data[j].p1.y-data[i].p1.y)<0;
end;
procedure buildgraph;
var i,j,cur:integer;
  t: array[1..kmax] of integer;
begin
  cur:=0;
  for i:=1 to 2*n do
    if s[i].f=1 then
     begin
      for j:=1 to cur do
        if less(t[j],s[i].num) then
          begin
            inc(a[s[i].num,0]);
            inc(v[t[j]]);
            a[s[i].num,a[s[i].num,0]]:=t[j]
          end                  else
          begin
            inc(a[t[j],0]);
            inc(v[s[i].num]);
            a[t[j],a[t[j],0]]:=s[i].num
          end;
      inc(cur); t[cur]:=s[i].num
     end
    else {s[i].f=-1}
      begin
        j:=1;
        while t[j]<>s[i].num do inc(j);
        t[j]:=t[cur];
        dec(cur);
      end
end;
function cross(i,j:integer):boolean;
begin
  cross:=(data[i].p1.y>=data[j].p1.y)and(data[i].p1.y<=data[j].p2.y)and
     not less(j,i) or
     not((data[i].p1.y>=data[j].p1.y)and(data[i].p1.y<=data[j].p2.y))and
    (data[i].p2.y>=data[j].p1.y)and(data[i].p2.y<=data[j].p2.y)and
     less(i,j)or
     (data[j].p1.y>=data[i].p1.y)and(data[j].p1.y<=data[i].p2.y)and
     less(i,j)
end;
begin
  fillchar(v,sizeof(v),0);
  readdata;
  quicksort(s,1,2*n);
//  fillchar(a,sizeof(a),0);
  fillchar(v,sizeof(v),0);
  buildgraph;
  num:=0;
 for i:=1 to n do
    if v[list[i]]>0 then
    quit(_wa, 'check1.the car '+inttostr(list[i])+' can''t start') else
    for j:=1 to a[list[i],0] do
      dec(v[a[list[i],j]]);
if n<1100 then begin
  fillchar(v,sizeof(v),0);
  for i:=1 to n do
   begin
    for j:=1 to n do
     if (list[i]<>j)and (v[j]=0)  then
       if cross(list[i],j) then
         quit(_wa, 'check2.the car '+inttostr(list[i])+' can''t start');
    v[list[i]]:=1;
   end;  
end;
  quit(_ok,'');
end.
                       