#include<iostream> using namespace std; typedef long long LL; const int MOD = 10000; const int N = 1e6 + 10; int arr[N]; LL a0,a1,p,q,k; int main(void) { cin >> arr[0] >> arr[1] >> p >> q >> k; LL res = 0; for(int i = 2;i <= k;i++) { arr[i] = (p * arr[i - 1] + q * arr[i - 2]) % MOD; } cout << arr[k] << endl; return 0; }