#include using namespace std; using ll = long long; int main() { int p[4]; ll k; cin >> p[0] >> p[1] >> p[2] >> k; for (int i = 0; i < 3; i++) { p[i] %= 10; } int x[1000] = {}, y[2000]; for (int l = 4; l < 2000; l++) { int s = 0, t = 0, u = 1; for (int i = 0; i < 3; i++) { s += p[i]; t += p[i] * u; u *= 10; } p[3] = s % 10; if (l == k) { cout << p[3] << endl; exit(0); } if (x[t] != 0) { ll c = l - x[t]; ll l0 = x[t] + (k - l) % c; cout << y[l0] << endl; exit(0); } x[t] = l; y[l] = p[3]; for (int i = 0; i < 3; i++) { p[i] = p[i + 1]; } } return 0; }