我推了三个小时还TM推错了。。我是真的不熟悉组合数啊。。
代码:
const big=1000000007;
var
k,p,n,m,a,b,a1,b1,a2,b2,x,y:int64;
l,r:array[0..100000]of int64;
fac,fa:array[0..200000]of int64;
ans:int64;
i,j:longint;
function pow(a,b:int64):int64;
var
base,r:int64;
begin
r:=1;
base:=a;
while b<>0 do
begin
if b and 1<>0 then r:=(r*base) mod big;
base:=(base*base) mod big;
b:=b div 2;
end;
exit(r);
end;
begin
fac[0]:=1;
for i:=1 to 200000 do fac[i]:=(fac[i-1]*i)mod big;
readln(n,a,b);
for i:=1 to n do read(l[i]);
for j:=1 to n do read(r[j]);
ans:=0;
fa[1]:=1;
dec(n);
for i:=2 to n do
begin
fa[i]:=fac[n+i-2]*pow(fac[i-1],big-2)mod big*pow(fac[n-1],big-2)mod big;
end;
inc(n);
for i:=2 to n do
begin
ans:=(ans+pow(b,n-1)*pow(a,n-i)mod big*fa[n-i+1]mod big*r[i]mod big)mod big;
ans:=(ans+pow(b,n-i)*pow(a,n-1)mod big*fa[n-i+1]mod big*l[i]mod big)mod big;
end;
writeln(ans mod big);
end.