#include // #include // #include using namespace std; // using namespace atcoder; // using bint = boost::multiprecision::cpp_int; using ll = long long; using ull = unsigned long long; using P = pair; #define rep(i,n) for(ll i = 0;i < (ll)n;i++) #define ALL(x) (x).begin(),(x).end() #define MOD 1000000007 void ch(ll &a,ll &b,ll &c){ int k = (a+b+c)%10; a = b;b = c;c = k; } int main(){ ll p,q,r,K; cin >> p >> q >> r >> K; p %= 10;q %= 10;r %= 10; vector>> memo(10,vector>(10,vector(10,-1))); memo[p][q][r] = 1; int l = 0,loop = 1; for(int i = 2;i <= 100000;i++){ ch(p,q,r); if(i == K){ cout << p << "\n"; return 0; } if(memo[p][q][r] != -1){ l = memo[p][q][r] - 1; loop -= l; break; } loop++; memo[p][q][r] = loop; } K -= l+1; K %= loop; cout << loop << "\n"; while(K--)ch(p,q,r); cout << p << "\n"; return 0; }