{$apptype console}
{$o-,r+,q+}
uses
  sysutils, testlib, math;

type
  int = longint;

const
  MAXN = 1000;
  EPS = 1.1e-3;

var
  ja, pa : extended;
  a, b, p, q, r : array[1..MAXN] of int;
  px : array[1..MAXN] of extended;
  rpa : extended;
  n, i : int;

begin
  ja := ans.readreal();
  pa := ouf.readreal();

  if (pa > ja + EPS) then
  begin
    quit(_wa, format('Answer too big: ja = %.6f, pa = %.6f', [ja, pa]));
  end;

  n := inf.readlongint();
  for i := 1 to n do
  begin
    a[i] := inf.readlongint();
    b[i] := inf.readlongint();
    p[i] := inf.readlongint();
    q[i] := inf.readlongint();
    r[i] := inf.readlongint();
  end;

  for i := 1 to n do
  begin
    px[i] := ouf.readreal();  
  end;

  for i := 1 to n do
  begin
    rpa := rpa + p[i] * px[i] * px[i] + q[i] * px[i] + r[i];
  end;

  if (abs(rpa - pa) > EPS) then
  begin
    quit(_wa, format('Wrong function value: promised %.6f, but %.6f actually', [pa, rpa]));
  end;

  if (ja > pa + EPS) then
  begin
    quit(_fail, format('Participant has better answer: pa = %.6f, ja = %.6f', [pa, ja]));
  end;
  
  quit(_ok, format('Answer is %.6f, n = %d', [ja, n]));

end.