题解
代码
const
mood=1000000007;
var
n,aa,bb:longint;
mi,ans:int64;
l,t:array [0..200001] of longint;
a,b,f,jc:array [0..200001] of int64;
procedure init;
var
i:longint;
begin
readln(n,aa,bb);
for i:=1 to n do
read(l[i]);
for i:=1 to n do
read(t[i]);
end;
function ksm(x:longint):int64;
var
sum:int64;
begin
if x=0 then exit(1);
if x=1 then exit(mi);
sum:=ksm(x div 2);
sum:=(sum*sum) mod mood;
if x mod 2=1 then sum:=(sum*mi) mod mood;
exit(sum);
end;
procedure main;
var
i:longint;
begin
jc[1]:=1;
a[0]:=1; a[1]:=aa;
b[0]:=1; b[1]:=bb;
f[0]:=1; f[1]:=1;
for i:=2 to n*2 do
begin
jc[i]:=(jc[i-1]*i) mod mood;
mi:=jc[i];
f[i]:=ksm(mood-2);
a[i]:=(a[i-1]*aa) mod mood;
b[i]:=(b[i-1]*bb) mod mood;
end;
for i:=2 to n do
begin
ans:=(ans+(((((((((jc[2*n-i-2]*f[n-2]) mod mood)*f[n-i]) mod mood)*a[n-i]) mod mood)*b[n-1]) mod mood)*t[i]) mod mood) mod mood;
ans:=(ans+(((((((((jc[2*n-i-2]*f[n-2]) mod mood)*f[n-i]) mod mood)*a[n-1]) mod mood)*b[n-i]) mod mood)*l[i]) mod mood) mod mood;
end;
write(ans);
end;
begin
init;
main;
end.