#include #include #include #include #include using namespace atcoder; using namespace std; using ll = long long; using ull = unsigned long long; using mll = static_modint<998244353>; #define rep(i,n) for(int i=0; i<(n); i++) template struct static_matrix { Elem X[matrix_sz][matrix_sz] = {}; static static_matrix id() { static_matrix res; rep(i, matrix_sz) res[i][i] = 1; return res; } Elem* operator[](int x) { return X[x]; } const Elem* operator[](int x) const { return X[x]; } static_matrix operator+(const static_matrix& r) const { static_matrix res; rep(i, matrix_sz) rep(j, matrix_sz) res[i][j] = X[i][j] + r[i][j]; return res; } static_matrix operator-(const static_matrix& r) const { static_matrix res; rep(i, matrix_sz) rep(j, matrix_sz) res[i][j] = X[i][j] - r[i][j]; return res; } static_matrix operator*(const static_matrix& r) const { static_matrix res; rep(i, matrix_sz) rep(j, matrix_sz) rep(k, matrix_sz) res[i][j] += X[i][k] * r[k][j]; return res; } static_matrix pow(ll N) const { if (N == 0) return id(); static_matrix res = pow(N / 2); res = res * res; if (N % 2 == 1) res = res * *this; return res; } }; using Mat = static_matrix,3>; int main(){ ll p,q,r,k; cin >> p >> q >> r >> k; k -= 3; Mat G; G[1][0] = 1; G[2][1] = 1; G[0][2] = 1; G[1][2] = 1; G[2][2] = 1; G = G.pow(k); auto ans = (G[0][2] * p + G[1][2] * q + G[2][2] * r).val(); cout << ans << endl; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_inst;