#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; typedef long long ll; typedef long double ld; typedef std::pair pii; typedef std::pair pil; typedef std::pair pli; typedef std::pair pll; typedef std::pair pid; typedef std::pair pis; typedef std::pair pls; typedef std::vector vb; typedef std::vector vvb; typedef std::vector vi; typedef std::vector vvi; typedef std::vector vvvi; typedef std::vector vvvvi; typedef std::vector vl; typedef std::vector vvl; typedef std::vector vvvl; typedef std::vector vvvvl; typedef std::vector vd; typedef std::vector vvd; typedef std::vector vs; #define rep(i,n) for(auto i=0; i=0; --i) #define repdm(i,e,n) for(auto i=n-1; i>=e; --i) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() template inline bool chmax(T& a, T b, int eq = 0) { if (a < b || (a == b && eq)) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b, int eq = 0) { if (a > b || (a == b && eq)) { a = b; return 1; } return 0; } template * = nullptr> constexpr istream& operator>>(istream& is, mint& x) noexcept {long long v = 0; std::cin >> v; x = v; return is;} template * = nullptr> constexpr ostream& operator<<(ostream& os, const mint& x) noexcept {os << x.val(); return os;} inline void _n() { std::cout << std::endl; } template inline void _(const T a) { std::cout << a; } template inline void _l(const T a) { _(a); _n(); } template inline void _s(const T a) { _(a); _(' '); } template inline void _v(const std::vector v) { for(auto a : v) _(a); } template inline void _vl(const std::vector v) { for(auto a : v) _l(a); } template inline void _vs(const std::vector v) { for(auto a : v) _s(a); _n(); } template inline void _vvl(const std::vector> v) { for(auto a : v) { _v(a); _n(); } } template inline void _vvs(const std::vector> v) { for(auto a : v) { _vs(a); } } inline void ynl(const bool b) {_l(b ? "yes" : "no");} inline void yns(const bool b) {_l(b ? "Yes" : "No");} inline void ynu(const bool b) {_l(b ? "YES" : "NO");} constexpr int INF = numeric_limits::max() >> 1; constexpr long long INF_LL = numeric_limits::max() >> 1LL; constexpr long long MOD1 = 1000000007; constexpr long long MOD9 = 998244353; using mint1 = atcoder::modint1000000007; using mint9 = atcoder::modint998244353; //* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *// template struct matrix { using vec = std::vector; using mat = std::vector>; mat _matrix; matrix() {} matrix(int n) : _matrix(n, vec(n, 0)) {} matrix(int n, int m) : _matrix(n, vec(m, 0)) {} int height() const { return (int)_matrix.size(); } int width() const { return (int)_matrix[0].size(); } static matrix id(int n) { matrix Id(n); for(int i = 0; i < n; i++) Id[i][i] = 1; return Id; } inline const vec &operator[](int k) const { return (_matrix.at(k)); } inline vec &operator[](int k) { return (_matrix.at(k)); } matrix operator+(const matrix &rhs) const { return (matrix(*this) += rhs); } matrix operator-(const matrix &rhs) const { return (matrix(*this) -= rhs); } matrix operator*(const T &rhs) const { return (matrix(*this) *= rhs); } matrix operator*(const matrix &rhs) const { return (matrix(*this) *= rhs); } matrix &operator+= (const matrix &rhs) { int n = height(), m = width(); assert(n == rhs.height() && m == rhs.width()); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) (*this)[i][j] += rhs[i][j]; return (*this); } matrix &operator-= (const matrix &rhs) { int n = height(), m = width(); assert(n == rhs.height() && m == rhs.width()); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) (*this)[i][j] -= rhs[i][j]; return (*this); } matrix &operator*= (const T &rhs) { int n = height(), m = width(); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) (*this)[i][j] *= rhs; return (*this); } matrix &operator*= (const matrix &rhs) { int n = height(), m = rhs.width(), l = width(); assert(l == rhs.height()); mat R(n, vec(m, 0)); for(int i = 0; i < n; i++) for(int k = 0; k < l; k++) for(int j = 0; j < m; j++) R[i][j] += (*this)[i][k] * rhs[k][j]; _matrix.swap(R); return (*this); } matrix &pow_inplace(long long p) { assert(height() == width()); assert(p >= 0); matrix R = matrix::id(height()); while(p > 0) { if(p & 1) R *= *this; *this *= *this; p >>= 1LL; } _matrix.swap(R._matrix); return *this; } matrix pow(long long p) const { return matrix(*this).pow_inplace(p); } vec operate(const vec &v) { int n = height(), m = width(); assert(m == v.size()); vec r(m, 0); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) r[i] += (*this)[i][j] * v[j]; return r; } }; void solve() { using mint = atcoder::modint; mint::set_mod(10); ll p, q, r; cin >> p >> q >> r; ll K; cin >> K; matrix M(3); M[0][0] = M[0][1] = M[0][2] = M[1][0] = M[2][1] = 1; M = M.pow_inplace(K-3); vector av = M.operate({r, q, p}); mint ans = av[0]; _l(ans); } //* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *// int main() { std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); std::cin.tie(0); std::cout.tie(0); std::ios::sync_with_stdio(false); solve(); return 0; }