#include #include //小数点出力用 //cout << fixed << setprecision(10) << ans; #include #include #include #include #include #include #include #include using ll = long long; using namespace std; #define modPHash (ll)((1LL<<61)-1) #define modP (ll)1'000'000'007 bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); } int clk4(int num) { return (num - 2) * (num % 2); } void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); } vector> mul(vector>& A, vector>& B, int size) { vector>res; for (int i = 0; i < size; i++) { vectorrow; for (int j = 0; j < size; j++) { ll tmp = 0; for (int k = 0; k < size; k++) { tmp += (A[i][k] * B[k][j]) % modP; } row.push_back(tmp % modP); } res.push_back(row); } return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); vectorI(4); vector>M(4, I); ll X, Y, Z, ONE; ONE = 1; cin >> X; X += modP; X %= modP; Z = X; cin >> Y; Y += modP; Y %= modP; cin >> M[1][1] >> M[1][2] >> M[1][3]; M[1][1] += modP; M[1][2] += modP; M[1][3] += modP; M[1][1] %= modP; M[1][2] %= modP; M[1][3] %= modP; ll N; cin >> N; M[0][0] = 1; M[0][1] = 1; M[2][1] = 1; M[3][3] = 1; vector>EX[64]; EX[0] = M; for (int k = 1;k < 64;k++) { EX[k] = mul(EX[k - 1], EX[k - 1], 4); } for (int k = 0;k < 64;k++) { if ((N >> k) & 1) { ll XX = (X * EX[k][0][0] + Y * EX[k][0][1] + Z * EX[k][0][2] + ONE * EX[k][0][3]) % modP; ll YY = (X * EX[k][1][0] + Y * EX[k][1][1] + Z * EX[k][1][2] + ONE * EX[k][1][3]) % modP; ll ZZ = (X * EX[k][2][0] + Y * EX[k][2][1] + Z * EX[k][2][2] + ONE * EX[k][2][3]) % modP; ll ONEONE = (X * EX[k][3][0] + Y * EX[k][3][1] + Z * EX[k][3][2] + ONE * EX[k][3][3]) % modP; X = XX; Y = YY; Z = ZZ; ONE = ONEONE; } } cout << X; return 0; }