#include #define endl "\n" //←これ using namespace std; typedef long long ll; typedef long double ld; typedef pair pll; typedef pair pdl; typedef pair pld; typedef pair pdd; #define rep(i,n) for(ll i=0; i<(ll)(n); i++) #define repo(i,n) for(ll i=1; i<(ll)(n); i++) #define pb push_back #define np next_permutation #define fi first #define se second #define all(x) (x).begin(),(x).end() #define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin()) #define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin()) #define cou(x) __builtin_popcountll(x) const ld pi=acos(-1.0); const ll INF = 1LL<<61; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b vl(ll n,ll x){ vector re(n,x); return re;} vector> vl(ll n, ll m,ll x){ vector> re(n,vector(m,x)); return re;} vector>> vl(ll n, ll m, ll l,ll x){ vector>> re(n,vector>(m,vector(l,x))); return re;} templatevoid out(T x) {cout << x << endl;} templatevoid out(T x,T y) {cout << x << " " << y << endl;} templatevoid out(T x,T y,T z) {cout << x << " " << y << " " << z << endl;} templatevoid out(T x,T y,T z,T a) {cout << x << " " << y << " " << z << " " << a << endl;} templatevoid out(pair p) {cout << p.fi << " " << p.se << endl;} templatevoid vout(vector &v) { if(v.size() > 0) { for(auto it = v.begin(); it < v.end(); it++) { cout << *it; if(it != v.end() - 1) cout << " "; } } cout << endl; } templatevoid vout(vector> &v) { if(v.size() > 0) { for(auto it = v.begin(); it < v.end(); it++) { vout(*it); } } } templatevoid vout(vector> &v) { if(v.size() > 0) { for(auto it = v.begin(); it < v.end(); it++) { out(*it); } } } //——————————————————matrix 行列——————————————————————————— template< class T > struct mat { std::vector< std::vector< T > > A; mat() {} mat(size_t n, size_t m) : A(n, std::vector< T >(m, 0)) {} mat(size_t n) : A(n, std::vector< T >(n, 0)) {}; size_t height() const { return (A.size()); } size_t width() const { return (A[0].size()); } inline const std::vector< T > &operator[](ll k) const { return (A.at(k)); } inline std::vector< T > &operator[](ll k) { return (A.at(k)); } static mat I(size_t n) { mat ma(n); rep(i,n) ma[i][i] = 1; return (ma); } mat &operator*=(const mat &B) { size_t n = height(), m = B.width(), p = width(); assert(p == B.height()); std::vector< std::vector< T > > C(n, std::vector< T >(m, 0)); rep(i,n) rep(j,m) rep(k,p) C[i][j] = ((C[i][j] + (*this)[i][k] * B[k][j])%10+10)%10; A.swap(C); return (*this); } mat operator*(const mat &B) const { return (mat(*this) *= B); } mat pow(int64_t k) const { auto res = I(A.size()); auto M = *this; while (k > 0) { if (k & 1) { res *= M; } M *= M; k >>= 1; } return res; } }; template void vout(mat ma) { rep(i,ma.height()) vout(ma[i]); } //————————————————————————————————————————————————— int main(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision (15); ll a,b,c,d; cin>>a>>b>>c>>d; mat ma(3,3); ma[0]={1,1,1}; ma[1]={1,0,0}; ma[2]={0,1,0}; ma=ma.pow(d-3); mat st(3,1); st[0][0]=c%10; st[1][0]=b%10; st[2][0]=a%10; st=ma*st; out(st[0][0]); }