var
  infile, outfile, ansfile: text;
  kol,n,i,zbir,t:longint;
  a:array[1..1000000] of longint;
begin
  assign(infile, paramStr(1));
  assign(outfile, paramStr(2));
  assign(ansfile, paramStr(3));
  reset(infile);
  reset(outfile);
  reset(ansfile);
  readln(infile,kol);
  close(infile);
  for i:=1 to kol do
    readln(ansfile,a[i]);
  close(ansfile);
  readln(outfile,n);
  if n<1 then begin
               writeln(0);
               close(outfile);
               halt(0);
              end;
  zbir:=0;
  for i:=1 to n do
    begin
     read(outfile,t);
     if (t<1) or (t>kol) then begin
                               writeln(0);
                               close(outfile);
                               halt(0);
                              end;
     zbir:=(zbir+a[t]) mod 1073741789;
    end;
  if zbir=0 then writeln(10)
            else writeln(0);
  close(outfile);
end.
