#include using namespace std; long long p, q, r, K; long long A[1 << 24]; int main() { // Step #1. Input cin >> p >> q >> r >> K; A[1] = p % 10LL; A[2] = q % 10LL; A[3] = r % 10LL; // Step #2. Solve for (long long i = 4; i <= K; i++) A[i] = (A[i - 1] + A[i - 2] + A[i - 3]) % 10LL; cout << A[K] << endl; return 0; }