Program generator; uses crt; var k,m,b,n:longint; a,x:array [1..30] of integer; f1,f2:text; xn:integer; begin clrscr; assign (f1,'input.txt'); reset (f1); read (f1,k); readln (f1,m); for i:=1 to k do read (f1,a[i]); read (f1,b); for i:=1 to k do read (f1,x[i]); read (f1,n); close (f1); for i:=1 to k do begin xn:=xn+(a[n]*x[n-i]) mod m; end; xn:=xn+b mod m; assign (f2,'output.txt'); rewrite (f2); write (f2,xn); close (f2); end.