#include #include using namespace atcoder; #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using mint = modint1000000007; template struct Matrix { int h, w; vector> d; Matrix() {} Matrix(int h, int w, T val=0): h(h), w(w), d(h, vector(w,val)) {} Matrix& unit() { assert(h == w); rep(i,h) d[i][i] = 1; return *this; } const vector& operator[](int i) const { return d[i];} vector& operator[](int i) { return d[i];} Matrix operator*(const Matrix& a) const { assert(w == a.h); Matrix r(h, a.w); rep(i,h)rep(k,w)rep(j,a.w) { r[i][j] += d[i][k]*a[k][j]; } return r; } Matrix pow(long long t) const { assert(h == w); if (!t) return Matrix(h,h).unit(); if (t == 1) return *this; Matrix r = pow(t>>1); r = r*r; if (t&1) r = r*(*this); return r; } }; int main() { ll a, b, c, d, e, n; cin >> a >> b >> c >> d >> e >> n; Matrix A(4, 4), x(4, 1); x[0][0] = (a+b)+(c*b+d*a+e); x[1][0] = a+b; x[2][0] = a; x[3][0] = 1; A[0][0] = c+1; A[0][1] = d-c; A[0][2] = -d; A[0][3] = e; A[1][0] = A[2][1] = A[3][3] = 1; x = A.pow(n)*x; mint ans = x[2][0]; cout << ans.val() << '\n'; return 0; }