1 /**************************************************************
2 Problem: 3240
3 User: wjy1998
4 Language: C++
5 Result: Accepted
6 Time:332 ms
7 Memory:2760 kb
8 ****************************************************************/
9
10 #include<cstdio>
11 typedef long long ll;struct M{ll x,y;}t1,t2,t3;ll P=1e9+7,a,b,c,d,n,m,phi;
12 char s1[1000010],s2[1000010];
13 void F(char*s,ll&aa){for(int t=0;s[t];t++)aa=(aa*10+s[t]-‘0‘)%phi;}
14 M operator*(const M&a,const M&b){return (M){a.x*b.x%P,(a.x*b.y+a.y)%P};}
15 M operator^(M t,ll k){M f=t;for(--k;k;k>>=1,t=t*t)if(k&1)f=f*t;return f;}
16 int main(){
17 scanf("%s%s%lld%lld%lld%lld",s1,s2,&a,&b,&c,&d);
18 if(a==1&&c==1)phi=P;else phi=P-1;
19 F(s1,n),F(s2,m),t1=(M){a,b},t2=(M){c,d};t1=t1^(m-1),t3=t2*t1;t3=t3^(n-1);t1=t1*t3;
20 printf("%lld\n",(t1.x+t1.y)%P);
21 }