#include #include using namespace std; int main() { long long p, q, r, k; cin >> p >> q >> r >> k; long one, two, three; one = p % 10; two = q % 10; three = r % 10; for (long long i = 3; i < k; i++) { long tmp = three; three = (one + two + three) % 10; one = two; two = tmp; } cout << three << endl; return 0; }