#include using namespace std; #define rep(i, n) for (decltype(n) i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (decltype(n) i = 1, i##_len = (n); i <= i##_len; ++i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((int)(x).size()) #define pl(s) cout << (s) << "\n"; #define plx(s) {cout << (s) << "\n"; exit(0);} #define yes(s) cout << ((s)?"Yes":"No") << "\n"; #define bit(n) (1LL << ((int)(n))) #define get1bit(x,n) (((x) >> (int)(n)) & 1) #define pcnt(x) __builtin_popcountll(x) #define flog(x) (63 - __builtin_clzll(x)) #define clog(x) (((x)==1)?0:(64-__builtin_clzll((x)-1))) #define cdiv(x,y) (((x)+(y)-1)/(y)) #define lb(a,x) distance((a).begin(),lower_bound((a).begin(),(a).end(),(x))) #define ub(a,x) distance((a).begin(),upper_bound((a).begin(),(a).end(),(x))) #ifdef __LOCAL #include #define dump(...) DUMPOUT << " " << string(#__VA_ARGS__) << ": " << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl << " ", dump_func(__VA_ARGS__) #else #define dump(...) #endif using ll = long long; using ld = long double; template using V = vector; template inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;} template inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;} template istream &operator>>(istream &is, complex &v) {T x, y; is >> x >> y; v.real(x); v.imag(y); return is;} template istream &operator>>(istream &is, V &v) {for (auto&& e : v) is >> e;return is;} template istream &operator>>(istream &is, pair &v) {is >> v.first >> v.second;return is;} template istream &operator>>(istream &is, array &v) {for (auto&& e : v) is >> e;return is;} template inline string join(const T& v, string sep = " ") {if (v.size() == 0) return "" ;stringstream ss;for (auto&& e : v) ss << sep << e;return ss.str().substr(1);} template inline void uniq(T& a, bool presort = true){if (presort) sort(all(a));a.erase(unique(all(a)),a.end());} template vector compress(vector &x){auto ret = x; uniq(ret); rep(i,sz(x)) x[i] = lb(ret, x[i]); return ret;} template constexpr bool between(T a, T x, T b) {return (a <= x && x < b);} template constexpr bool intersect(T l1, T r1, T l2, T r2) {return max(l1,l2) <= min(r1,r2);} template V make_vec(size_t n, T a) {return V(n, a);} template auto make_vec(size_t n, Ts... ts) {return V(n, make_vec(ts...));} template inline V CUM(V &a) {int n = sz(a); V ret(n+1); rep(i,n) ret[i+1] = a[i] + ret[i]; return ret;} template inline V DIF(V &a) {int n = sz(a)-1; V ret(n); rep(i,n) ret[i] = a[i+1] - a[i]; return ret;} constexpr ll TEN(int n) {return (n == 0) ? 1 : 10 * TEN(n - 1);} constexpr ll POW(ll x, ll n) {ll ret = 1;while (n > 0) {if (n & 1) ret *= x;x *= x;n >>= 1;}return ret;} constexpr ll MODPOW(ll x, ll n, ll m) {ll ret = 1;while (n > 0) {if (n&1) ret = ret * x % m;x = x * x % m;n >>= 1;}return ret;} constexpr ll nC2(ll n) {assert(between(ll(0),n,ll(3037000501)));return n * (n-1)/2;} constexpr ll NSUM(ll n) {assert(between(ll(0),n,ll(3037000500)));return n * (n+1)/2;} constexpr ll pos1d(ll y, ll x, ll h, ll w) {assert(between(ll(0),y,h));assert(between(ll(0),x,w));return y*w + x;} constexpr pair pos2d(ll p, ll h, ll w) {ll y = p/w, x = p - y*w;assert(between(ll(0),y,h));assert(between(ll(0),x,w));return {y, x};} V> buildComb(int n = 60) {V> v(n+1, V(n+1));rep(i,sz(v)) {v[i][0] = 1; v[i][i] = 1;}for (int j = 1; j < sz(v); ++j) for (int k = 1; k < j; ++k) v[j][k] = v[j-1][k-1] + v[j-1][k];return v;} inline bool palindrome(const string& s){return equal(all(s), s.rbegin());} inline string upper(string s) {for(auto&& e: s) e = between('a',e,(char)('z'+1)) ? e - ('a'-'A') : e;return s;} inline string lower(string s) {for(auto&& e: s) e = between('A',e,(char)('Z'+1)) ? e + ('a'-'A') : e;return s;} inline string replace(string s, map &from, V &to) {for (auto&& e: s) e = '0' + (char)(to[from[e]]);return s;} struct IOS {IOS() {cin.tie(nullptr); ios::sync_with_stdio(false); dump("");}} IO; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; const int mod = 10; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} template struct Kitamasa{ vector a; // 初期値ベクトル vector d; // 係数ベクトル int k; Kitamasa(vector& a, vector& d) : a(a), d(d), k((int)a.size()) {} // a_n の係数ベクトルを求める vector dfs(int64_t n){ if(n == k) return d; vector res(k); if(n & 1 || n < k * 2){ vector x = dfs(n - 1); for(int i = 0; i < k; ++i) res[i] = d[i] * x[k - 1]; for(int i = 0; i + 1 < k; ++i) res[i + 1] += x[i]; } else{ vector> x(k, vector(k)); x[0] = dfs(n >> 1); for(int i = 0; i + 1 < k; ++i){ for(int j = 0; j < k; ++j) x[i + 1][j] = d[j] * x[i][k - 1]; for(int j = 0; j + 1 < k; ++j) x[i + 1][j + 1] += x[i][j]; } for(int i = 0; i < k; ++i){ for(int j = 0; j < k; ++j){ res[j] += x[0][i] * x[i][j]; } } } return res; } // a_n を求める T calc(ll n){ vector x = dfs(n); T res = 0; for(int i = 0; i < k; ++i) res += x[i] * a[i]; return res; } }; struct Solver { V> G; V memo; void solve() { // int n;cin >> n; // yes(between(10,n,100)); // string t = "kyoprotenkei90"; // map mp2; // rep(i,sz(t)) { // mp2[t[i]]++; // } // string s; cin >> s; // map mp; // rep(i,sz(s)) { // mp[s[i]]++; // } // bool failed = false; // for(auto [key,value] : mp2) { // if (mp[key] != value) { // failed = true; // break; // } // } // yes(!failed) // ll n; cin >> n; // ll ans = 0; // for (ll x = 1; x*x < n*n; ++x) { // ll yy = n*n - x*x; // ll y = sqrt(yy); // if (y > 0 && y*y != n*n - x*x) continue; // //dump(x,y,x*x,y*y); // ++ans; // } // pl(ans) // ll n; cin >> n; // V e(n); cin >> e; // ll bn = bit(n); // for (ll i = 1; i < bn; ++i) { // ll pa = 0; // bitset<12> bi, bj, bk; // bi = i; // rep(j,n) if (get1bit(i,j)) pa += e[j]; // for (ll j = bn-1; j >= 1; --j) { // ll pb = 0, pc = 0; // j &= (bn-1) - i; // bj = j; // ll k = (bn-1) - (i+j); // bk = k; // if (j == 0 || k == 0) continue; // rep(l,n) { // if (get1bit(j,l)) pb += e[l]; // if (get1bit(k,l)) pc += e[l]; // } // //dump(bi,bj,bk,pa,pb,pc); // if (pa == pb && pb == pc) { // dump(bi,bj,bk,pa,pb,pc); // plx("Yes") // } // } // } // pl("No") ll p, q, r, k; cin >> p >> q >> r >> k; V a(3); a[0] = p; a[1] = q; a[2] = r; V b(4,1); dump(a); auto kita = Kitamasa(a, b); pl(kita.calc(k-1).x) } } solver; signed main(void) {solver.solve();return 0;}