var
n,a,b,g,i,lastans:longint;
c,d,e:int64;
s:ansistring;
x:array[1..50000]of longint;
a0,b0:array[1..500000]of longint;
c0:array[1..500000]of int64;
ans:array[1..500000]of longint;
begin
assign(input,'hard.in');
assign(output,'hard.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do
read(x[i]);
repeat
readln(a,b,c);
a:=a+lastans;b:=b+lastans;c:=c+lastans;
if (a=0)and(b=0)and(c=0)then exit;
lastans:=0;
for g:=1 to g do
if (a=a0[g])and(b=b0[g])and(c=c0[g]) then
begin
lastans:=ans[g];
break;
end;
if lastans=0 then
begin
for i:=1 to n do
begin
d:=1;
d:=d*a*(i+1)*x[i]*x[i];
e:=1;
e:=e*(b+1)*i*x[i]+c+i;
if d=-e then
begin
lastans:=i;
break;
end;
end;
inc(g);
a0[g]:=a;b0[g]:=b;c0[g]:=c;ans[g]:=lastans;
end;
writeln(lastans);
until eof;
close(input);close(output);
end.